使用

  1. VisualGLM-6B 仓库:THUDM/VisualGLM-6B#github
  2. visualglm-6b 模型:THUDM/visualglm-6b#huggingface
  3. chatglm-6b 模型:THUDM/chatglm-6b#huggingface

模型下载

方式一:

安装 git-lfs 后使用 Git 克隆:

git clone https://huggingface.co/THUDM/visualglm-6b

方式二

手动从清华大学云盘下载: 清华大学云盘

# 先克隆
git clone https://github.com/THUDM/VisualGLM-6B.git
 
# 进入目录后安装依赖
cd VisualGLM-6B
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt

使用

本地加载模型

假设下载的模型参数保存在 VisualGLM-6B 中,目录名为: visualglm-6b

交互式

先进入 Python 交互式环境:

cd VisualGLM-6B
python3

然后执行:

from transformers import AutoTokenizer, AutoModel
model_path = "THUDM/visualglm-6b" # 下载的模型参数目录
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).half().cuda()
 
img_file = "bus.jpg" # 当前目录下图片名称
response, history = model.chat(tokenizer, img_file, "描述这张图片。", history=[])
 
print(response)

模型微调

模型微调需要先安装 deepspeed 库和 cuda

参考