li-plus / chatglm.cpp

C++ implementation of ChatGLM-6B & ChatGLM2-6B & ChatGLM3 & GLM4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows系统 安装 chatGLM 分享

kevin-hu-lab opened this issue · comments

前置条件
安装python 环境 ,pip 包管理器,CMake 工具(Visual Studio 中安装,选择C++模块),torch、transformers 包 ,模型选择 ChatGLM3-6B
模型下载 到 D:\LLM\chatglm.cpp\THUDM
image

一、准备
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

命令: 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

三、构建并运行
D:\LLM\chatglm.cpp
image

使用 CMake 编译项目:
使用 Visual Studio 命令行工具执行以下命令
image

命令: 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

四、常见报错
报错 1
image
解决1
image

报错 2
image
解决2
image

报错3
image

解决3
image

Visual Studio 中安装CMake,Nmake

解决4
image
解决4
Visual Studio 中安装CMake
image
image

最后一步启动

先设置模型位置
set MODEL=..\chatglm-ggml.bin
在启动服务
uvicorn chatglm_cpp.openai_api:app --host 127.0.0.1 --port 8000

请问你机器有GPU?我这convert就报错了,提示没cuda.dll。
再一个想问下,这个是不是就是CPU推理呢?我试着在云服务器有GPU跑这个,结果发现竟然也是CPU推理。