Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
VisualGLM-6B_pytorch
Commits
3fe98be6
Commit
3fe98be6
authored
Feb 28, 2024
by
wangsen
Browse files
Initial commit
parent
3199eb84
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
9 additions
and
6 deletions
+9
-6
README.md
README.md
+6
-3
model/__pycache__/__init__.cpython-38.pyc
model/__pycache__/__init__.cpython-38.pyc
+0
-0
model/__pycache__/blip2.cpython-38.pyc
model/__pycache__/blip2.cpython-38.pyc
+0
-0
model/__pycache__/chat.cpython-38.pyc
model/__pycache__/chat.cpython-38.pyc
+0
-0
model/__pycache__/infer_util.cpython-38.pyc
model/__pycache__/infer_util.cpython-38.pyc
+0
-0
model/__pycache__/visualglm.cpython-38.pyc
model/__pycache__/visualglm.cpython-38.pyc
+0
-0
test.py
test.py
+3
-3
No files found.
README.md
View file @
3fe98be6
...
@@ -29,6 +29,7 @@ docker run -it -v /path/your_data/:/path/your_data/ --shm-size=32G --privileged=
...
@@ -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)执行模型:
使用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
...
@@ -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
cd /home/VisualGLM-6B
python cli_demo_hf.py
python cli_demo_hf.py
```
```
程序会自动下载sat模型
,并在
命令行中进行交互式的对话,输入指示并回车即可生成回复,输入 clear 可以清空对话历史,输入 stop 终止程序。
如果不修改模型路径,
程序会自动下载sat模型
(由于涉及到访问外网,可能无法下载)。执行上面命令,则可以通过
命令行中进行交互式的对话,输入指示并回车即可生成回复,输入 clear 可以清空对话历史,输入 stop 终止程序。
API部署
###
API部署
推理
首先需要安装额外的依赖 pip install fastapi uvicorn,然后运行仓库中的 api.py:
首先需要安装额外的依赖 pip install fastapi uvicorn,然后运行仓库中的 api.py:
...
...
model/__pycache__/__init__.cpython-38.pyc
0 → 100644
View file @
3fe98be6
File added
model/__pycache__/blip2.cpython-38.pyc
0 → 100644
View file @
3fe98be6
File added
model/__pycache__/chat.cpython-38.pyc
0 → 100644
View file @
3fe98be6
File added
model/__pycache__/infer_util.cpython-38.pyc
0 → 100644
View file @
3fe98be6
File added
model/__pycache__/visualglm.cpython-38.pyc
0 → 100644
View file @
3fe98be6
File added
test.py
View file @
3fe98be6
from
transformers
import
AutoTokenizer
,
AutoModel
from
transformers
import
AutoTokenizer
,
AutoModel
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"/data"
,
trust_remote_code
=
True
)
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"/data
/visualGLM
"
,
trust_remote_code
=
True
)
model
=
AutoModel
.
from_pretrained
(
"/data/"
,
trust_remote_code
=
True
).
half
().
cuda
()
model
=
AutoModel
.
from_pretrained
(
"/data/
visualGLM
"
,
trust_remote_code
=
True
).
half
().
cuda
()
image_path
=
"/
data/000000546717
.jpg"
image_path
=
"/
home/visualglm-6b/examples/wechat
.jpg"
response
,
history
=
model
.
chat
(
tokenizer
,
image_path
,
"描述这张图片。"
,
history
=
[])
response
,
history
=
model
.
chat
(
tokenizer
,
image_path
,
"描述这张图片。"
,
history
=
[])
print
(
response
)
print
(
response
)
response
,
history
=
model
.
chat
(
tokenizer
,
image_path
,
"这张图片可能是在什么场所拍摄的?"
,
history
=
history
)
response
,
history
=
model
.
chat
(
tokenizer
,
image_path
,
"这张图片可能是在什么场所拍摄的?"
,
history
=
history
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment