当前位置:   article > 正文

ChatGLM3 在线体验及部署经验_chatglm3在线体验

chatglm3在线体验

本文主要介绍使用virtualenv库生成venv,进而部署/运行ChatGLM3-6B开源双语对话语言模型的方法。

1. 在线体验

本文代码已部署到百度飞桨AI Studio平台,以供大家在线体验。

项目链接:ChatGLM3 在线体验

2. 环境部署

virtualenv环境部署代码如下:

  1. git clone https://github.com/THUDM/ChatGLM3
  2. cd ChatGLM3
  3. pip install -U virtualenv
  4. python -m virtualenv venv
  5. source venv/bin/activate
  6. pip install --upgrade pip
  7. pip install protobuf transformers cpm_kernels torch gradio mdtex2html sentencepiece accelerate peft

实测仅安装 protobuf transformers cpm_kernels torch gradio mdtex2html sentencepiece accelerate peft 这些库就可以运行Gradio交互式界面进行对话。

如果有其他需求,可以根据 requirements.txt 文件安装其他依赖库。

requirements.txt 文件内容:

  1. # basic requirements
  2. transformers==4.40.0
  3. cpm_kernels>=1.0.11
  4. torch>=2.3.0
  5. vllm>=0.4.2
  6. gradio>=4.26.0
  7. sentencepiece>=0.2.0
  8. sentence_transformers>=2.7.0
  9. accelerate>=0.29.2
  10. streamlit>=1.33.0
  11. fastapi>=0.110.0
  12. loguru~=0.7.2
  13. mdtex2html>=1.3.0
  14. latex2mathml>=3.77.0
  15. jupyter_client>=8.6.1
  16. # for openai demo
  17. openai>=1.30.1
  18. pydantic>=2.7.1
  19. sse-starlette>=2.1.0
  20. uvicorn>=0.29.0
  21. timm>=0.9.16
  22. tiktoken>=0.6.0
  23. # for langchain demo
  24. langchain>=0.2.1
  25. langchain_community>=0.2.0
  26. langchainhub>=0.1.15
  27. arxiv>=2.1.0

3. 模型下载

原始链接:https://huggingface.co/THUDM/chatglm3-6b

镜像链接:https://hf-mirror.com/THUDM/chatglm3-6b

由于官方后续提供了.safetensors格式的模型,目前模型下载页内容很多,这里采用wget下载.safetensors版模型对应的文件(共18个文件,约12GB)。

项目demo中默认模型路径为 ChatGLM3/THUDM/chatglm3-6b,可以通过定义MODEL_PATH环境变量从其他路径加载模型。

下载代码:

  1. cd ~/ChatGLM3
  2. mkdir THUDM THUDM/chatglm3-6b
  3. cd THUDM/chatglm3-6b
  4. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/MODEL_LICENSE
  5. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/README.md
  6. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/config.json
  7. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/configuration_chatglm.py
  8. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00001-of-00007.safetensors
  9. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00002-of-00007.safetensors
  10. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00003-of-00007.safetensors
  11. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00004-of-00007.safetensors
  12. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00005-of-00007.safetensors
  13. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00006-of-00007.safetensors
  14. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model-00007-of-00007.safetensors
  15. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/model.safetensors.index.json
  16. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/modeling_chatglm.py
  17. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/quantization.py
  18. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/special_tokens_map.json
  19. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/tokenization_chatglm.py
  20. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/tokenizer.model
  21. wget https://hf-mirror.com/THUDM/chatglm3-6b/resolve/main/tokenizer_config.json

4. 运行

ChatGLM3的运行很简单,激活虚拟环境后运行 basic_demo/web_demo_gradio.py 文件即可。

  1. cd ChatGLM3
  2. source venv/bin/activate
  3. python basic_demo/web_demo_gradio.py

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/949922
推荐阅读
相关标签
  

闽ICP备14008679号