内容纲要
问题
AutoDL HuggingFace连不上,无法下载ChatGLM3-6B模型
原因
网络原因,无法访问
解决方案
使用ModelScope社区镜像下载
模型下载代码
pip install modelscope
from modelscope.models import Model
model = Model.from_pretrained('ZhipuAI/chatglm3-6b')
或
from modelscope import snapshot_download
model_dir = snapshot_download("ZhipuAI/chatglm3-6b", revision = "v1.0.0")
在.cache/modelscope目录下找到模型文件夹后,复制其路径
from transformers import AutoModel
model = AutoModel.from_pretrained("your_path")
git下载
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
代码调用
可以通过如下代码调用 ChatGLM3-6B 模型来生成对话:
from modelscope import AutoTokenizer, AutoModel, snapshot_download
model_dir = snapshot_download("ZhipuAI/chatglm3-6b", revision = "v1.0.0")
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModel.from_pretrained(model_dir, trust_remote_code=True).half().cuda()
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)