一、准备
1: Clone the ChatGLM.cpp repository into your local machine
下载到 D:\LLM\chatglm.cpp
命令: git clone --recursive https://github.com/li-plus/chatglm.cpp.git && cd chatglm.cpp二、量化模型
2.1 Install necessary packages for loading and quantizing Hugging Face models:
使用这个工具执行命令
命令: python -m pip install torch tabulate tqdm transformers accelerate sentencepiece
2.2 Use convert.py to transform ChatGLM-6B into quantized GGML format. For example, to convert the fp16 original model to q4_0 (quantized int4) GGML model, run
命令: python chatglm_cpp/convert.py -i THUDM/chatglm3-6b -t q4_0 -o chatglm3-ggml.bin
前置条件 安装python 环境 ,pip 包管理器,CMake 工具(Visual Studio 中安装,选择C++模块),torch、transformers 包 ,模型选择 ChatGLM3-6B 模型下载 到 D:\LLM\chatglm.cpp\THUDM![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/ee43033f-834a-4131-81ef-a662ceca9b01)
一、准备 1: Clone the ChatGLM.cpp repository into your local machine 下载到 D:\LLM\chatglm.cpp 命令: git clone --recursive https://github.com/li-plus/chatglm.cpp.git && cd chatglm.cpp 二、量化模型 2.1 Install necessary packages for loading and quantizing Hugging Face models: 使用这个工具执行命令![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/bef0c3c5-7800-47a4-a66e-3e1909dea4d1)
命令: python -m pip install torch tabulate tqdm transformers accelerate sentencepiece 2.2 Use convert.py to transform ChatGLM-6B into quantized GGML format. For example, to convert the fp16 original model to q4_0 (quantized int4) GGML model, run 命令: python chatglm_cpp/convert.py -i THUDM/chatglm3-6b -t q4_0 -o chatglm3-ggml.bin![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/fe7a6014-d1d7-4573-9a13-8d9247ddfce7)
三、构建并运行 D:\LLM\chatglm.cpp![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/632ec65c-017a-4595-abba-3551241c394f)
使用 CMake 编译项目: 使用 Visual Studio 命令行工具执行以下命令![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/f2785622-1216-42da-9973-46a486c18d52)
命令: cmake -B build 命令: cmake --build build -j --config Release
现在您可以通过运行以下命令与量化的 ChatGLM3-6B 模型聊天: 命令: D:\LLM\chatglm.cpp\build\bin\main.exe -m chatglm3-ggml.bin -p 你好 浏览器中聊天 命令:python D:\LLM\chatglm.cpp\examples\web_demo.py -m chatglm3-ggml.bin![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/c9db5d4d-abbc-42ca-93d2-720e91c78990)
四、常见报错 报错 1
解决1
![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/72e5c1c3-72cf-4c2c-a8e3-7e041dcb6591)
报错 2
解决2
![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/a646f92c-ea3f-41b2-99f2-fb2aefd2b4cf)
报错3![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/1b14a33b-bb8a-4b71-b5af-a10753975916)
解决3![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/828e691f-4a96-4cc9-9111-86e2952ebd4d)
Visual Studio 中安装CMake,Nmake
解决4
解决4
Visual Studio 中安装CMake
![image](https://github.com/li-plus/chatglm.cpp/assets/15125588/eb593a53-b07a-41cd-91b3-5be4d6925bb0)