环境:Ubuntu20.04.6
安装步骤
1、打开Ubuntu,新建文件夹mkdir chatglmcpp,并进入,将ChatGLM.cpp存储库克隆到该文件夹中:
git clone --recursive https://github.com/li-plus/chatglm.cpp.git && cd chatglm.cpp
GitHub - li-plus/chatglm.cpp:ChatGLM-6B & ChatGLM2-6B & ChatGLM3 & 更多 LLM 的C++实现
2、 安装用于加载和量化 Hugging Face 模型的必要软件包:
python3 -m pip install -U pip
python3 -m pip install torch tabulate tqdm transformers accelerate sentencepiece
3、用于将 ChatGLM-6B 转换为量化的 GGML 格式(直接运行该代码是会默认从hugging face下载chatglm3-6b模型到THUDM文件夹中。-i :模型路径 -t:量化类型 -o:转换后的模型输出文件名):
python3 chatglm_cpp/convert.py -i THUDM/chatglm-6b -t q4_0 -o chatglm-ggml.bin
PS.如果在下载模型时出现网络错误的情况,我们可以先在modelscope中下载该模型:
chatglm3-6b · 模型库 (modelscope.cn)
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
python3 chatglm_cpp/convert.py -i THUDM/chatglm3-6b/ -t q4_0 -o chatglm-ggml.bin
4、使用 CMake 编译项目,没有cmake可以先运行sudo apt install cmake安装:
cmake -B build
cmake --build build -j --config Release
5、完成之后就可以运行了
./build/bin/main -m chatglm-ggml.bin -p 你好
交互式模式下运行:
./build/bin/main -m chatglm-ggml.bin -i
遇到的问题
在对模型进行量化式出现:RuntimeError:Internal:could not parse ModelProto from THUDM/chatglm3-6b/tokenizer.model
因为在Ubuntu中下载模型没有成功下载,虽然文件中有模型名字,但是文件大小不对,需要重新下载模型。