ChatGLM3-6B部署
ZhipuAI/chatglm3-6b 模型文件地址 chatglm3-6B-32k-int4 量化的模型地址
ChatGLM3 代码仓库
ChatGLM3 技术文档
cpolar http xxx
端口
/anaconda3/envs/chatglm2/lib/python3.8/site-packages/gradio$
networking.py
硬件环境
最低要求:
为了能够流畅运行 Int4 版本的 ChatGLM3-6B,最低的配置要求:
内存:>= 8GB
显存: >= 5GB(1060 6GB,2060 6GB)
为了能够流畅运行 FP16 版本的,ChatGLM3-6B,最低的配置要求:
内存:>= 16GB
显存: >= 13GB(4080 16GB)
Mac开发者无需关注GPU的限制。对于搭载了 Apple Silicon 或者 AMD GPU 的 Mac,可以使用 MPS 后端来在 GPU 上运行 ChatGLM3-6B。需要参考 Apple 的 官方说明 安装 PyTorch-Nightly(正确的版本号应该是2.x.x.dev2023xxxx,而不是 2.x.x)。
如果使用CPU加载,可以忽略显存的要求,但是速度非常慢
软件环境
Python环境
请开发者按照仓库中的requirements.txt来安装对应的依赖,并需要注意:
python
版本推荐3.10 - 3.11
transformers
库版本推荐为 4.36.2
torch
推荐使用 2.0 及以上的版本,以获得最佳的推理性能
2、配置环境
建议最好自己新建一个conda环境
conda create -n chatglm3 python==3.10
conda activate chatglm3
conda activate chatglm31
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple
pip install gradio==3.40.0 -i https://pypi.mirrors.ustc.edu.cn/simple
+++++++++++++++++++
修改requirements.txt
# basic requirementstransformers>=4.41.0
cpm_kernels>=1.0.11
torch>=2.3.0
#vllm>=0.4.2
gradio==3.40.0
sentencepiece>=0.2.0
sentence_transformers>=2.7.0
accelerate>=0.29.2
streamlit>=1.33.0
fastapi>=0.110.0
loguru~=0.7.2
mdtex2html>=1.3.0
latex2mathml>=3.77.0
jupyter_client>=8.6.1# for openai demo
openai>=1.30.1
pydantic
sse-starlette>=2.1.0
uvicorn>=0.29.0
timm>=0.9.16
tiktoken>=0.6.0# for langchain demolangchain>=0.2.0
langchain_community>=0.2.0
langchainhub>=0.1.15
arxiv>=2.1.0
pip install vllm==0.2.0 -i https://pypi.mirrors.ustc.edu.cn/simple
pip install peft
二、本地加载chatglm3-6B-32k-int4模型
打开pycharm运行
web_demo.py
或
python basic_demo/web_demo_gradio.py
python web_demo.py
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
源码安装
克隆代码和模型
模型基础运行代码已经上传到 github 和 SwanHub 两个平台,两个平台的信息同步。开发者通过以下方式下载模型代码。
-
从 github 下载源码
git clone https://github.com/THUDM/ChatGLM3.git
-
从 SwanHub 下载源码
git clone https://swanhub.co/ZhipuAI/ChatGLM3.git
通过以下方式下载模型文件
-
下载模型文件前请先确保`git lfs`命令已安装,安装教程请参考这里。
-
模型文件已上传至 Huggingface, Modelsope , SwanHub 三个平台,用户可以快速安装模型。
-
若使用 Huggingface 下载模型
git lfs install
git clone https://huggingface.co/THUDM/chatglm3-6b.git
-
若使用 Modelscope 下载模型
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
-
若使用 SwanHub 下载模型
git lfs install
git clone https://swanhub.co/ZhipuAI/chatglm3-6b.git
安装依赖
使用 pip 安装依赖:
cd ChatGLM3
pip install -r requirements.txt
运行demo
使用本地模型加载并使用命令行来问答
python basic_demo/cli_demo.py
使用本地模型加载并使用web_demo来问答
python basic_demo/web_demo_gradio.py
通过以下命令启动基于 Gradio 的网页版 demo
python basic_demo/web_demo_streamlit.py