git clone https://github.com/THUDM/ChatGLM-6B.git
进入项目:
cd ChatGLM-6B
下载依赖:
pip install -r requiremnets.txt
运行如下代码即可自动下载:
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)
或者手动下载: https://huggingface.co/THUDM/chatglm-6b
运行如下代码即可自动下载:
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True).quantize(4).half().cuda()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)
或者手动下载: https://huggingface.co/THUDM/chatglm-6b-int4
手动下载需要修改"THUDM/chatglm-6b-int4"为你的模型路径。
在ChatGLM-6B项目根目录,运行下面cmd
python api.py
修改:
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True, resume_download=True).half().cuda()
# 4bit量化
# model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True, resume_download=True).quantize(
# 4).half().cuda()
# 8bit量化
# model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True, resume_download=True).quantize(
# 8).half().cuda()
然后运行:
python api.py
pip install -r requirements_glmqa.txt
修改chatglm_document_qa.py第67行代码:
documents = load_documents("你的文档目录")
python chatglm_document_qa.py