Commit 3fe98be6 authored by wangsen's avatar wangsen
Browse files

Initial commit

parent 3199eb84
......@@ -29,6 +29,7 @@ docker run -it -v /path/your_data/:/path/your_data/ --shm-size=32G --privileged=
```
## 推理
### 代码推理
使用Huggingface transformers库调用模型,通过下面地址下载模型https://huggingface.co/THUDM/visualglm-6b/tree/main , 可以通过如下代码(其中图像路径为本地路径,模型路径为THUDM/visulglm-6b)执行模型:
```
......@@ -47,14 +48,16 @@ Specify both input_ids and inputs_embeds at the same time, will use inputs_embed
这张照片中,一位女士坐在沙发上使用笔记本电脑和鼠标。她似乎正在浏览网页或工作。她的姿势表明她在放松、享受或专注于她的工作。背景中的瓶子可能暗示着饮料或其他日常用品的存在。椅子和沙发的布置也表明这是一个舒适的环境,适合休息或进行轻松的工作活动。
考虑到照片的背景和场景设置,可以推断出这个场景是一个舒适的环境中拍摄的照片,例如家庭住宅或休闲空间。这位女士坐在一张沙发上,周围有瓶子和其他物品,这表明这个地方可能有一些日常用品或装饰。这种布置可能会鼓励人们放松身心并享受他们的日常活动,比如观看电影、阅读书籍或者与亲朋好友聊天。
```
命令行 Demo
### 交互式命令行推理
修改cli_demo_hf.py 中模型路径THUDM/visualglm-6b为本地模型路径,模型本地下载地址为https://huggingface.co/THUDM/visualglm-6b/tree/main
```
cd /home/VisualGLM-6B
python cli_demo_hf.py
```
程序会自动下载sat模型,并在命令行中进行交互式的对话,输入指示并回车即可生成回复,输入 clear 可以清空对话历史,输入 stop 终止程序。
如果不修改模型路径,程序会自动下载sat模型(由于涉及到访问外网,可能无法下载)。执行上面命令,则可以通过命令行中进行交互式的对话,输入指示并回车即可生成回复,输入 clear 可以清空对话历史,输入 stop 终止程序。
API部署
### API部署推理
首先需要安装额外的依赖 pip install fastapi uvicorn,然后运行仓库中的 api.py:
......
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("/data", trust_remote_code=True)
model = AutoModel.from_pretrained("/data/", trust_remote_code=True).half().cuda()
image_path = "/data/000000546717.jpg"
tokenizer = AutoTokenizer.from_pretrained("/data/visualGLM", trust_remote_code=True)
model = AutoModel.from_pretrained("/data/visualGLM", trust_remote_code=True).half().cuda()
image_path ="/home/visualglm-6b/examples/wechat.jpg"
response, history = model.chat(tokenizer, image_path, "描述这张图片。", history=[])
print(response)
response, history = model.chat(tokenizer, image_path, "这张图片可能是在什么场所拍摄的?", history=history)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment