ChatGLM-6B 中英双语的对话语言模型的安装和使用

ChatGLM-6B

 https://github.com/THUDM/ChatGLM-6B

 

 

 Python 3.7 

 module: openssl1.1.1a  libffi-devel 

 [Python-3.7.17]# ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl

 

 

 transformers  4.31.0

 huggingface-hub 0.14.1

 

 pip        23.2

 setuptools 68.0.0




--更换国内源:

HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

--临时:pip命令+ -i  +镜像地址。例如 pip install numpy -i https://mirrors.aliyun.com/pypi/simple/

--常用:在更新到最新版本pip后,pip config set global.index-url+国内镜像地址,例如  


阿里云 http://mirrors.aliyun.com/pypi/simple/ 

豆瓣(douban) http://pypi.douban.com/simple/ 

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/



--openssl install 

# ./config shared zlib

# make

# make install


mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl /usr/include/openssl.bak # 如报mv: cannot stat ‘/usr/include/openssl’: No such file or directory可忽略此步

find / -name openssl

ln -s /usr/local/bin/openssl /usr/bin/openssl

ln -s /usr/local/include/openssl /usr/include/openssl

echo "/usr/local/lib64/" >> /etc/ld.so.conf

ldconfig 

openssl version -a



-- huggingface_hub-0.14.1

# pip install -e .

  Building editable for huggingface-hub (pyproject.toml) ... done

  Created wheel for huggingface-hub: filename=huggingface_hub-0.14.1-0.editable-py3-none-any.whl size=8022 sha256=7eb5a5e2e698d9efc22ccced0c82cc7fa20262998786535bbeb121c2491e92c7

Stored in directory: /tmp/pip-ephem-wheel-cache-6tfs52jm/wheels/10/72/50/a4dac0523a1cb847b9b7b3bf0358447a39693e3baa3ea59dac

Successfully built huggingface-hub

Installing collected packages: zipp, urllib3, typing-extensions, tqdm, pyyaml, packaging, idna, fsspec, filelock, charset-normalizer, certifi, requests, importlib-metadata, huggingface-hub

  WARNING: The script tqdm is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The script normalizer is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The script huggingface-cli is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed certifi-2023.5.7 charset-normalizer-3.2.0 filelock-3.12.2 fsspec-2023.1.0 huggingface-hub-0.14.1 idna-3.4 importlib-metadata-6.7.0 packaging-23.1 pyyaml-6.0.1 requests-2.31.0 tqdm-4.65.0 typing-extensions-4.7.1 urllib3-2.0.3 zipp-3.15.0

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv



--transformers==4.31.0.dev0

[transformers]# pip install -e .

Requirement already satisfied: tqdm>=4.27 in /usr/local/python3/lib/python3.7/site-packages (from transformers==4.31.0.dev0) (4.65.0)

INFO: pip is looking at multiple versions of transformers to determine which version is compatible with other requirements. This could take a while.

ERROR: Package 'transformers' requires a different Python: 3.7.17 not in '>=3.8.0'


[update python3.8]

Building wheels for collected packages: transformers

  Building editable for transformers (pyproject.toml) ... done

  Created wheel for transformers: filename=transformers-4.31.0.dev0-0.editable-py3-none-any.whl size=37426 sha256=75a2c51a979c74c7c2b2cf3895d21e975216ca239812e9d5465ce80f1c9eedf7

  Stored in directory: /tmp/pip-ephem-wheel-cache-5yx20_35/wheels/2c/32/2b/b9c0eda8d8d9d423fa8a53bed7bc30d61da41b611e362f3d27

Successfully built transformers

Installing collected packages: tokenizers, safetensors, urllib3, typing-extensions, tqdm, regex, pyyaml, packaging, numpy, idna, fsspec, filelock, charset-normalizer, certifi, requests, huggingface-hub, transformers

  WARNING: The script tqdm is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The scripts f2py, f2py3 and f2py3.8 are installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The script normalizer is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The script huggingface-cli is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  WARNING: The script transformers-cli is installed in '/usr/local/python3/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed certifi-2023.5.7 charset-normalizer-3.2.0 filelock-3.12.2 fsspec-2023.6.0 huggingface-hub-0.16.4 idna-3.4 numpy-1.24.4 packaging-23.1 pyyaml-6.0.1 regex-2023.6.3 requests-2.31.0 safetensors-0.3.1 tokenizers-0.13.3 tqdm-4.65.0 transformers-4.31.0.dev0 typing-extensions-4.7.1 urllib3-2.0.4

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv




--tutorial-env install-----


(tutorial-env) [root@localhost ~]# source tutorial-env/bin/activate

(tutorial-env) [root@localhost ~]# pip list

Package    Version

---------- -------

pip        23.2

setuptools 68.0.0

wheel      0.40.0


--install huggingface_hub-0.14.1

(tutorial-env) [root@localhost huggingface_hub-0.14.1]# pip install -e .

Obtaining file:///root/transformers/huggingface_hub-0.14.1

  Installing build dependencies ... done

  Checking if build backend supports build_editable ... done

  Getting requirements to build editable ... done

  Preparing editable metadata (pyproject.toml) ... done

Collecting filelock (from huggingface-hub==0.14.1)

  Obtaining dependency information for filelock from https://files.pythonhosted.org/packages/00/45/ec3407adf6f6b5bf867a4462b2b0af27597a26bd3cd6e2534cb6ab029938/filelock-3.12.2-py3-none-any.whl.metadata

  Using cached filelock-3.12.2-py3-none-any.whl.metadata (2.7 kB)

Collecting fsspec (from huggingface-hub==0.14.1)

  Obtaining dependency information for fsspec from https://files.pythonhosted.org/packages/e3/bd/4c0a4619494188a9db5d77e2100ab7d544a42e76b2447869d8e124e981d8/fsspec-2023.6.0-py3-none-any.whl.metadata

  Using cached fsspec-2023.6.0-py3-none-any.whl.metadata (6.7 kB)

Collecting requests (from huggingface-hub==0.14.1)

  Obtaining dependency information for requests from https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl.metadata

  Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)

Collecting tqdm>=4.42.1 (from huggingface-hub==0.14.1)

  Using cached tqdm-4.65.0-py3-none-any.whl (77 kB)

Collecting pyyaml>=5.1 (from huggingface-hub==0.14.1)

  Obtaining dependency information for pyyaml>=5.1 from https://files.pythonhosted.org/packages/c8/6b/6600ac24725c7388255b2f5add93f91e58a5d7efaf4af244fdbcc11a541b/PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata

  Using cached PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.1 kB)

Collecting typing-extensions>=3.7.4.3 (from huggingface-hub==0.14.1)

  Obtaining dependency information for typing-extensions>=3.7.4.3 from https://files.pythonhosted.org/packages/ec/6b/63cc3df74987c36fe26157ee12e09e8f9db4de771e0f3404263117e75b95/typing_extensions-4.7.1-py3-none-any.whl.metadata

  Using cached typing_extensions-4.7.1-py3-none-any.whl.metadata (3.1 kB)

Collecting packaging>=20.9 (from huggingface-hub==0.14.1)

  Using cached packaging-23.1-py3-none-any.whl (48 kB)

Collecting charset-normalizer<4,>=2 (from requests->huggingface-hub==0.14.1)

  Obtaining dependency information for charset-normalizer<4,>=2 from https://files.pythonhosted.org/packages/cb/e7/5e43745003bf1f90668c7be23fc5952b3a2b9c2558f16749411c18039b36/charset_normalizer-3.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata

  Using cached charset_normalizer-3.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)

Collecting idna<4,>=2.5 (from requests->huggingface-hub==0.14.1)

  Using cached idna-3.4-py3-none-any.whl (61 kB)

Collecting urllib3<3,>=1.21.1 (from requests->huggingface-hub==0.14.1)

  Obtaining dependency information for urllib3<3,>=1.21.1 from https://files.pythonhosted.org/packages/9b/81/62fd61001fa4b9d0df6e31d47ff49cfa9de4af03adecf339c7bc30656b37/urllib3-2.0.4-py3-none-any.whl.metadata

  Using cached urllib3-2.0.4-py3-none-any.whl.metadata (6.6 kB)

Collecting certifi>=2017.4.17 (from requests->huggingface-hub==0.14.1)

  Using cached certifi-2023.5.7-py3-none-any.whl (156 kB)

Using cached PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (736 kB)

Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)

Using cached filelock-3.12.2-py3-none-any.whl (10 kB)

Using cached fsspec-2023.6.0-py3-none-any.whl (163 kB)

Using cached requests-2.31.0-py3-none-any.whl (62 kB)

Using cached charset_normalizer-3.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)

Using cached urllib3-2.0.4-py3-none-any.whl (123 kB)

Building wheels for collected packages: huggingface-hub

  Building editable for huggingface-hub (pyproject.toml) ... done

  Created wheel for huggingface-hub: filename=huggingface_hub-0.14.1-0.editable-py3-none-any.whl size=8022 sha256=91be6efebd01de102db28de6ab15553a0f04cae56b047684b4297767599c00fe

  Stored in directory: /tmp/pip-ephem-wheel-cache-om1tcu2w/wheels/cf/06/61/3a0e32361317c3caf9664c10ed4caf48b19966df592ad320cc

Successfully built huggingface-hub

Installing collected packages: urllib3, typing-extensions, tqdm, pyyaml, packaging, idna, fsspec, filelock, charset-normalizer, certifi, requests, huggingface-hub

Successfully installed certifi-2023.5.7 charset-normalizer-3.2.0 filelock-3.12.2 fsspec-2023.6.0 huggingface-hub-0.14.1 idna-3.4 packaging-23.1 pyyaml-6.0.1 requests-2.31.0 tqdm-4.65.0 typing-extensions-4.7.1 urllib3-2.0.4


--install transformers

(tutorial-env) [root@localhost transformers]# pip install -e .

Obtaining file:///root/transformers

  Installing build dependencies ... done

  Checking if build backend supports build_editable ... done

  Getting requirements to build editable ... done

  Preparing editable metadata (pyproject.toml) ... done

Requirement already satisfied: filelock in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (3.12.2)

Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (0.14.1)

Collecting numpy>=1.17 (from transformers==4.31.0.dev0)

  Obtaining dependency information for numpy>=1.17 from https://files.pythonhosted.org/packages/98/5d/5738903efe0ecb73e51eb44feafba32bdba2081263d40c5043568ff60faf/numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata

  Using cached numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.6 kB)

Requirement already satisfied: packaging>=20.0 in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (23.1)

Requirement already satisfied: pyyaml>=5.1 in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (6.0.1)

Collecting regex!=2019.12.17 (from transformers==4.31.0.dev0)

  Obtaining dependency information for regex!=2019.12.17 from https://files.pythonhosted.org/packages/c4/3d/d7ed16c298101bc7f5e3a65aef1ab34c1d7e1a89893491a4b1faf20701aa/regex-2023.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata

  Using cached regex-2023.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (40 kB)

Requirement already satisfied: requests in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (2.31.0)

Collecting tokenizers!=0.11.3,<0.14,>=0.11.1 (from transformers==4.31.0.dev0)

  Using cached tokenizers-0.13.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.8 MB)

Collecting safetensors>=0.3.1 (from transformers==4.31.0.dev0)

  Using cached safetensors-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)

Requirement already satisfied: tqdm>=4.27 in /root/tutorial-env/lib/python3.8/site-packages (from transformers==4.31.0.dev0) (4.65.0)

Requirement already satisfied: fsspec in /root/tutorial-env/lib/python3.8/site-packages (from huggingface-hub<1.0,>=0.14.1->transformers==4.31.0.dev0) (2023.6.0)

Requirement already satisfied: typing-extensions>=3.7.4.3 in /root/tutorial-env/lib/python3.8/site-packages (from huggingface-hub<1.0,>=0.14.1->transformers==4.31.0.dev0) (4.7.1)

Requirement already satisfied: charset-normalizer<4,>=2 in /root/tutorial-env/lib/python3.8/site-packages (from requests->transformers==4.31.0.dev0) (3.2.0)

Requirement already satisfied: idna<4,>=2.5 in /root/tutorial-env/lib/python3.8/site-packages (from requests->transformers==4.31.0.dev0) (3.4)

Requirement already satisfied: urllib3<3,>=1.21.1 in /root/tutorial-env/lib/python3.8/site-packages (from requests->transformers==4.31.0.dev0) (2.0.4)

Requirement already satisfied: certifi>=2017.4.17 in /root/tutorial-env/lib/python3.8/site-packages (from requests->transformers==4.31.0.dev0) (2023.5.7)

Using cached numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)

Using cached regex-2023.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (772 kB)

Building wheels for collected packages: transformers

  Building editable for transformers (pyproject.toml) ... done

  Created wheel for transformers: filename=transformers-4.31.0.dev0-0.editable-py3-none-any.whl size=37426 sha256=25c802dc14e50dfc00fb8d3433f09418deb094340fd51777c2334839b9043031

  Stored in directory: /tmp/pip-ephem-wheel-cache-3vmtjkyr/wheels/2c/32/2b/b9c0eda8d8d9d423fa8a53bed7bc30d61da41b611e362f3d27

Successfully built transformers

Installing collected packages: tokenizers, safetensors, regex, numpy, transformers

Successfully installed numpy-1.24.4 regex-2023.6.3 safetensors-0.3.1 tokenizers-0.13.3 transformers-4.31.0.dev0


(tutorial-env) [root@localhost ~]# pip list

Package            Version     Editable project location

------------------ ----------- -----------------------------------------

certifi            2023.5.7

charset-normalizer 3.2.0

filelock           3.12.2

fsspec             2023.6.0

huggingface-hub    0.14.1      /root/transformers/huggingface_hub-0.14.1

idna               3.4

numpy              1.24.4

packaging          23.1

pip                23.2

PyYAML             6.0.1

regex              2023.6.3

requests           2.31.0

safetensors        0.3.1

setuptools         68.0.0

tokenizers         0.13.3

tqdm               4.65.0

transformers       4.31.0.dev0 /root/transformers

typing_extensions  4.7.1

urllib3            2.0.4

wheel              0.40.0



--install PyTorch, TensorFlow >= 2.0   | CPU,GPU

--cuda11.7  直接拉取2023年5-6月数据

pip3 install numpy --pre torch[dynamo] torchvision torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cu117 -i https://pypi.tuna.tsinghua.edu.cn/simple


--cpu

pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cpu



--两种运行模式启动

python web_demo.py

python cli_demo.py


请使用浏览器的分享功能分享到微信等