DA
DealiAxy
2023年04月23日

ChatGLM-6B本地部署

下载项目代码 git clone https://github.com/THUDM/ChatGLM-6B.git 创建虚拟环境,建议使用 conda 管理 conda create -n chatglm python==3.8 安装依赖 conda activate chatglm pip install -r requirements.txt conda install cudatoolkit=

未分类
1292
5 分钟阅读

下载项目代码

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

创建虚拟环境,建议使用 conda 管理

conda create -n chatglm python==3.8

安装依赖

conda activate chatglm
pip install -r requirements.txt
conda install cudatoolkit=11.7 -c nvidia

PS:没有安装 cudatoolkit 的话,会报 RuntimeError: Library cudart is not initialized 错误

但 issues 里也有人说可以通过使用CPU输出量化模型后直接调用的方式解决,暂未尝试。

issues 地址: https://github.com/THUDM/ChatGLM-6B/issues/115

硬件需求

量化等级最低 GPU 显存(推理)最低 GPU 显存(高效参数微调)
FP16(无量化)13 GB14 GB
INT88 GB9 GB
INT46 GB7 GB

修改一下启动参数

model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()

使用量化模型

# 按需修改,目前只支持 4/8 bit 量化
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).quantize(4).half().cuda()

下载模型和启动 Gradio 界面

cd ChatGLM-6B
python web_demo.py

运行效果

图片准备加载中...