News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

ChatGPT local deployment and construction

posted on 2023-06-06 12:57     read(480)     comment(0)     like(21)     collect(4)


This article briefly describes the detailed tutorial of the local deployment of the Tsinghua open source project ChatGLM. Tsinghua's open source project ChatGLM-6B has released an open source version. This project can be directly deployed on a local computer for testing, and you can experience the fun of chatting with AI without networking.

Project address: GitHub - THUDM/ChatGLM-6B: ChatGLM-6B: Open Source Bilingual Dialogue Language Model | An Open Bilingual Dialogue Language Model

Official website introduction:

ChatGLM-6B is an open-source, Chinese-English bilingual dialogue language model based on  the General Language Model (GLM)  architecture with 6.2 billion parameters. Combined with model quantization technology, users can deploy locally on consumer-grade graphics cards (only 6GB of video memory is required at the INT4 quantization level). ChatGLM-6B uses technology similar to ChatGPT, optimized for Chinese Q&A and dialogue. After about 1T identifiers of Chinese and English bilingual training, supplemented by supervision and fine-tuning, feedback self-help, human feedback reinforcement learning and other technologies, ChatGLM-6B with 6.2 billion parameters has been able to generate answers that are quite in line with human preferences. For more information, please refer to our blog .

In order to facilitate downstream developers to customize models for their own application scenarios, we have also implemented an   efficient parameter fine-tuning method  (use guide) based on P-Tuning v2  . Under the INT4 quantization level, only 7GB of video memory is required to start fine-tuning.

However, due to the small size of ChatGLM-6B, it is currently known to have considerable limitations , such as factual/mathematical logic errors, possible generation of harmful/biased content, weak contextual ability, self-awareness confusion, and Generate content that completely contradicts Chinese instructions for English instructions. Please understand these issues before use to avoid misunderstandings. A larger ChatGLM based on the 130 billion parameter  GLM-130B  is under development in internal testing.

The first step is to install Python locally

This step is temporarily omitted, you can download and install the Python environment yourself.

Python download address: Download Python | Python.org

Note: Install version >9 and above, it is recommended to install version 10.

The second step is to download the project package

See the project address above for the address, download it directly and unzip it. I unzip it here to E:\chatGPT\.

The third step is to download the model package chatglm

Download address: https://huggingface.co/THUDM/chatglm-6b/tree/main

Official website introduction:

ChatGLM-6B is an open source dialogue language model that supports Chinese-English bilingual question-answering. It is based on the  General Language Model (GLM)  architecture and has 6.2 billion parameters. Combined with model quantization technology, users can deploy locally on consumer-grade graphics cards (only 6GB of video memory is required at the INT4 quantization level). ChatGLM-6B uses the same technology as  ChatGLM  , optimized for Chinese Q&A and dialogue. After about 1T identifiers of Chinese-English bilingual training, supplemented by supervision and fine-tuning, feedback self-help, human feedback reinforcement learning and other technologies, ChatGLM-6B with 6.2 billion parameters has been able to generate answers that are quite in line with human preferences.

Note: After downloading, put it under the second-step program package, and create the directory chatglm-6b by yourself , as follows:

The fourth step is to download the dependency package

Window + R shortcut key to open the running window, enter cmd to open the console command line, and enter the program directory.

Execute the following two commands respectively:

pip install -r requirements.txt

pip install built

Note: If an error is reported during execution, please refer to the error handling at the end of the article.

Wait for the dependent package to download successfully, the result is as follows:

The fifth step, run the web version demo

Execute the following command to run the demo of the web version, as follows:

python web_demo.py

The program will run a Web Server and output the address. Open the output address in a browser to use it. The latest version of Demo realizes the effect of a typewriter, and the speed experience is greatly improved. Note that due to the slow network access of Gradio in China,  demo.queue().launch(share=True, inbrowser=True) all networks will be forwarded by the Gradio server when enabled, resulting in a significant decline in the typewriter experience. Now the default startup method has been changed.  share=FalseIf there is a need for public network access, it can be modified to  share=True start again.

The execution results are as follows:

Note: If the execution prompt information does not match the above picture, please refer to the error handling at the end of the article.

The seventh step is to test the web version program

Open the address in the browser and visit, enter the question, and you can see that ChatGLM will give a reply.

Very Good! Checking the performance of the computer, I feel that the CPU and memory are going to burst ^ ^

The eighth step, run the command line Demo

Execute the following command to run the demo of the command line version, as follows:

python cli_demo.py

The program will conduct an interactive dialogue on the command line, enter instructions on the command line and press Enter to generate a reply, enter  clear to clear the dialogue history, and enter to  stop terminate the program.

Error 1: Downloading dependent packages timed out

  1. E:\chatGPT\ChatGLM-6B-main>pip install -r requirements.txt
  2. Collecting protobuf<3.20.1,>=3.19.5
  3.   Downloading protobuf-3.20.0-cp310-cp310-win_amd64.whl (903 kB)
  4.      ---------------------------------------- 903.8/903.8 kB 4.0 kB/s eta 0:00:00
  5. Collecting transformers==4.27.1
  6.   Downloading transformers-4.27.1-py3-none-any.whl (6.7 MB)
  7.      ----------- ---------------------------- 2.0/6.7 MB 5.4 kB/s eta 0:14:29
  8. ERROR: Exception:
  9. Traceback (most recent call last):
  10.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
  11.     yield
  12.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in read
  13.     data = self._fp_read(amt) if not fp_closed else b""
  14.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_read
  15.     return self._fp.read(amt) if amt is not None else self._fp.read()
  16.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 90, in read
  17.     data = self.__fp.read(amt)
  18.   File "D:\Python\Python310\lib\http\client.py", line 465, in read
  19.     s = self.fp.read(amt)
  20.   File "D:\Python\Python310\lib\socket.py", line 705, in readinto
  21.     return self._sock.recv_into(b)
  22.   File "D:\Python\Python310\lib\ssl.py", line 1274, in recv_into
  23.     return self.read(nbytes, buffer)
  24.   File "D:\Python\Python310\lib\ssl.py", line 1130, in read
  25.     return self._sslobj.read(len, buffer)
  26. TimeoutError: The read operation timed out
  27. During handling of the above exception, another exception occurred:
  28. Traceback (most recent call last):
  29.   File "D:\Python\Python310\lib\site-packages\pip\_internal\cli\base_command.py", line 160, in exc_logging_wrapper
  30.     status = run_func(*args)
  31.   File "D:\Python\Python310\lib\site-packages\pip\_internal\cli\req_command.py", line 247, in wrapper
  32.     return func(self, options, args)
  33.   File "D:\Python\Python310\lib\site-packages\pip\_internal\commands\install.py", line 419, in run
  34.     requirement_set = resolver.resolve(
  35.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 92, in resolve
  36.     result = self._result = resolver.resolve(
  37.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 481, in resolve
  38.     state = resolution.resolve(requirements, max_rounds=max_rounds)
  39.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 348, in resolve
  40.     self._add_to_criteria(self.state.criteria, r, parent=None)
  41.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
  42.     if not criterion.candidates:
  43.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
  44.     return bool(self._sequence)
  45.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__
  46.     return any(self)
  47.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>
  48.     return (c for c in iterator if id(c) not in self._incompatible_ids)
  49.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_built
  50.     candidate = func()
  51.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 206, in _make_candidate_from_link
  52.     self._link_candidate_cache[link] = LinkCandidate(
  53.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 297, in __init__
  54.     super().__init__(
  55.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 162, in __init__
  56.     self.dist = self._prepare()
  57.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 231, in _prepare
  58.     dist = self._prepare_distribution()
  59.   File "D:\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 308, in _prepare_distribution
  60.     return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
  61.   File "D:\Python\Python310\lib\site-packages\pip\_internal\operations\prepare.py", line 491, in prepare_linked_requirement
  62.     return self._prepare_linked_requirement(req, parallel_builds)
  63.   File "D:\Python\Python310\lib\site-packages\pip\_internal\operations\prepare.py", line 536, in _prepare_linked_requirement
  64.     local_file = unpack_url(
  65.   File "D:\Python\Python310\lib\site-packages\pip\_internal\operations\prepare.py", line 166, in unpack_url
  66.     file = get_http_url(
  67.   File "D:\Python\Python310\lib\site-packages\pip\_internal\operations\prepare.py", line 107, in get_http_url
  68.     from_path, content_type = download(link, temp_dir.path)
  69.   File "D:\Python\Python310\lib\site-packages\pip\_internal\network\download.py", line 147, in __call__
  70.     for chunk in chunks:
  71.   File "D:\Python\Python310\lib\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_bar
  72.     for chunk in iterable:
  73.   File "D:\Python\Python310\lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks
  74.     for chunk in response.raw.stream(
  75.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 622, in stream
  76.     data = self.read(amt=amt, decode_content=decode_content)
  77.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 560, in read
  78.     with self._error_catcher():
  79.   File "D:\Python\Python310\lib\contextlib.py", line 153, in __exit__
  80.     self.gen.throw(typ, value, traceback)
  81.   File "D:\Python\Python310\lib\site-packages\pip\_vendor\urllib3\response.py", line 443, in _error_catcher
  82.     raise ReadTimeoutError(self._pool, None, "Read timed out.")
  83. pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
  84. E:\chatGPT\ChatGLM-6B-main>

You can see that the error message prompts timeout, it should be a network problem, you can try to add the parameter of timeout setting in the command, the command is modified as follows:

pip --default-timeout=1688 install -r requirements.txt

Question 2: Download the model package in real time again

When running the program, if you see that the model package is downloaded again in the prompt message, and the model package prepared in the third step is not used, you need to copy the model package to the cache directory when the program is running. The cache path may be as follows:

C:\Users\user directory\.cache\huggingface\hub\models--THUDM--chatglm-6b\snapshots\fb23542cfe773f89b72a6ff58c3a57895b664a23

Copy the model package to this directory and run the program again.

Good Luck!



Category of website: technical article > Blog

Author:evilangel

link:http://www.pythonblackhole.com/blog/article/81184/17fcf256557cca726acb/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

21 0
collect article
collected

Comment content: (supports up to 255 characters)