一、克隆项目到本地

项目地址:

git clone https://github.com/THUDM/ChatGLM2-6B.git
cd ChatGLM2-6B
pip install -r requirements.txt


二、下载模型

模型下载地址:

https://huggingface.co/THUDM/chatglm2-6b/tree/main

模型中几个较大的文件可以通过云盘下载:

清华云盘地址 https://cloud.tsinghua.edu.cn/d/674208019e314311ab5c/

阿里云盘地址 https://www.aliyundrive.com/s/G7j8vZmZG5C/folder/649d4dd40731a785e362486595c62b50f56cc120


量化模型下载地址:

https://huggingface.co/THUDM/chatglm2-6b-int4/tree/main


使用CPU运行可以下载量化模型

下载所有文件后放到ChatGLM2-6B/THUDM/chatglm2-6b-int4/文件夹下,然后修改web_demo.py:

tokenizer = AutoTokenizer.from_pretrained("C:\\ChatGLM2-6B\\THUDM\\chatglm2-6b-int4", trust_remote_code=True)

model = AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b-int4", trust_remote_code=True).float()

三、windows系统使用量化后的模型还需要安装gcc环境

下载tdm-gcc-10.3.0.exe
下载地址 
安装时勾选openmp

四、运行

python web_demo.py

   

错误处理方式如下:

错误1.ModuleNotFoundError: No module named 'transformers_modules.THUDM/chatglm2-6b

问题原因:
transformers==4.30.2版本原因,卸载后安装低一点的版本
解决方法:
1.卸载transformers
pip uninstall transformers
2.安装低版本transformers
pip install transformers==4.26.0

错误2.RuntimeError: Internal: D:\a\sentencepiece\sentencepiece\src\sentencepiece_processor.cc(1102) [model_proto->ParseFromArray(serialized.data(), serialized.size())]

问题原因:模型配置文件等下载不全
解决方法:重新下载tokenizer.model

错误3.AssertionError: Torch not compiled with CUDA enabled

问题原因:没有GPU或没有安装CUDA-Toolkit驱动
解决方法:
方法1.安装CUDA-Toolkit驱动
方法2.使用CPU运行,修改web_demo.py中AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b", trust_remote_code=True).cuda()
改为AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b", trust_remote_code=True).float()



标签: ChatGLM, 人工智能, AI

添加新评论