1 前言
ChatGLM3
是智谱AI和清华大学KEG实验室联合发布的新一代对话预训练模型,chatglm3-6b采用了全新设计的Prompt格式,除正常的多轮对话外。同时原生支持工具调用(Function Call)、代码执行(Code Interpreter)和Agent任务等复杂场景。
- 更强大的基础模型:ChatGLM3-6B的基础模型ChatGLM3-6B-Base采用了更多样的训练数据、更充分的训练步数和更合理的训练策略。在语义、数学、推理、代码、知识等不同角度的数据集上测评显示,ChatGLM3-6B-Base具有在10B以下的预训练模型中最强的性能。
- 更完整的功能支持:ChatGLM3-6B采用了全新设计的Prompt格式,除正常的多轮对话外。同时原生支持工具调用(Function Call)、代码执行(Code Interpreter)和Agent任务等复杂场景。
- 更全面的开源序列:除了对话模型ChatGLM3-6B外,还开源了基础模型ChatGLM3-6B-Base、长文本对话模型ChatGLM3-6B-32K
2 环境检查
2.1 操作系统
对于操作系统而言,Windows、Mac OS、Linux都是支持的,而对于架构而言,x86是肯定支持的,arm64则要看情况,有些库或者包,有编译aarch64版本的,则也可以使用,没有则需要自己去编译。可玩性完全看个人能力。
2.2 硬件环境
前提条件:未使用其他量化方式,使用了其他量化方式可以以更小资源进行推理
最低要求:
- 内存:>=8gb
- 显存:>=6gb
2.3 软件环境
- python:3.9/3.10
- torch: >=2.0
- transformers: 4.40.2
2.4 实验环境
- system:
Windows11
、wsl2
- gpu:
RTX 3060(12G)
- cuda: 12.2
- python: 3.10
- transformers: 4.40.2
- torch: 2.2.2
3.模型下载
目前最大的模型平台国内是modelscope,国外则是huggingface,由于一些原因,使用国内的更加便捷一些,只有一些不方便找的模型才去外面下载。
3.1使用modelscope库下载
from modelscope import snapshot_download
model_dir = snapshot_download("ZhipuAI/chatglm3-6b", cache_dir="/root/modelscope_models")
- cache_dir: 指定下载保存路径
3.2 使用git下载
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
4.使用
from modelscope import AutoTokenizer, AutoModel, snapshot_download
model_dir = "/root/modelscope_models/ZhipuAI/chatglm3-6b"
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModel.from_pretrained(model_dir, trust_remote_code=True).half().cuda()
model = model.eval()
response = model.chat(tokenizer, "您好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)
参考资料
- ValueError: too many values to unpack:https://blog.csdn.net/qq_40838014/article/details/140463923
- chatglm4-6b部署、量化遇到的问题解决方案:https://blog.csdn.net/qq_40231723/article/details/134622935
- chatglm3-6b模型下载:https://modelscope.cn/models/zhipuai/chatglm3-6b
- 智谱:https://github.com/THUDM/ChatGLM3
- huggingface:https://huggingface.co/THUDM/chatglm3-6b
异常报错
- ValueError: too many values to unpack
pip install transformers==4.40.2
- WSL2加载模型出现killed,在用户目录下,新建
.wslconfig
文件
[wsl2]
memory=14GB
swap=16GB
localhostForwarding=true