Ubuntu
commited on
Commit
β’
0fe7ab5
1
Parent(s):
1e1d266
readme
Browse files
.mdl
DELETED
Binary file (54 Bytes)
|
|
.msc
DELETED
Binary file (1.7 kB)
|
|
.mv
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
Revision:master,CreatedAt:1715952141
|
|
|
|
README.md
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: cogvlm2
|
4 |
+
license_link: >-
|
5 |
+
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
pipeline_tag: text-generation
|
9 |
+
tags:
|
10 |
+
- chat
|
11 |
+
- cogvlm2
|
12 |
+
|
13 |
+
inference: false
|
14 |
+
---
|
15 |
+
|
16 |
+
# CogVLM2
|
17 |
+
|
18 |
+
<div align="center">
|
19 |
+
<img src=https://github.com/THUDM/CogVLM2/blob/main/resources/logo.svg width="40%"/>
|
20 |
+
</div>
|
21 |
+
<p align="center">
|
22 |
+
π Join us on <a href="https://github.com/THUDM/CogVLM2/blob/main/resources/WECHAT.md" target="_blank">WeChat</a>
|
23 |
+
</p>
|
24 |
+
<p align="center">
|
25 |
+
πExperience the larger-scale CogVLM model on the <a href="https://open.bigmodel.cn/dev/api#super-humanoid">ZhipuAI Open Platform</a>.
|
26 |
+
</p>
|
27 |
+
|
28 |
+
|
29 |
+
## Model introduction
|
30 |
+
|
31 |
+
We launch a new generation of **CogVLM2** series of models and open source two models built with [Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct). Compared with the previous generation of CogVLM open source models, the CogVLM2 series of open source models have the following improvements:
|
32 |
+
|
33 |
+
1. Significant improvements in many benchmarks such as `TextVQA`, `DocVQA`.
|
34 |
+
2. Support **8K** content length.
|
35 |
+
3. Support image resolution up to **1344 * 1344**.
|
36 |
+
4. Provide an open source model version that supports both **Chinese and English**.
|
37 |
+
|
38 |
+
You can see the details of the CogVLM2 family of open source models in the table below:
|
39 |
+
|
40 |
+
| Model name | cogvlm2-llama3-chat-19B | cogvlm2-llama3-chinese-chat-19B |
|
41 |
+
|------------------|-------------------------------------|-------------------------------------|
|
42 |
+
| Base Model | Meta-Llama-3-8B-Instruct | Meta-Llama-3-8B-Instruct |
|
43 |
+
| Language | English | Chinese, English |
|
44 |
+
| Model size | 19B | 19B |
|
45 |
+
| Task | Image understanding, dialogue model | Image understanding, dialogue model |
|
46 |
+
| Text length | 8K | 8K |
|
47 |
+
| Image resolution | 1344 * 1344 | 1344 * 1344 |
|
48 |
+
|
49 |
+
## Benchmark
|
50 |
+
|
51 |
+
Our open source models have achieved good results in many lists compared to the previous generation of CogVLM open source models. Its excellent performance can compete with some non-open source models, as shown in the table below:
|
52 |
+
|
53 |
+
| Model | Open Source | LLM Size | TextVQA | DocVQA | ChartQA | OCRbench | MMMU | MMVet | MMBench |
|
54 |
+
|--------------------------------|-------------|----------|----------|----------|----------|----------|----------|----------|----------|
|
55 |
+
| LLaVA-1.5 | β
| 13B | 61.3 | - | - | 337 | 37.0 | 35.4 | 67.7 |
|
56 |
+
| Mini-Gemini | β
| 34B | 74.1 | - | - | - | 48.0 | 59.3 | 80.6 |
|
57 |
+
| LLaVA-NeXT-LLaMA3 | β
| 8B | - | 78.2 | 69.5 | - | 41.7 | - | 72.1 |
|
58 |
+
| LLaVA-NeXT-110B | β
| 110B | - | 85.7 | 79.7 | - | 49.1 | - | 80.5 |
|
59 |
+
| InternVL-1.5 | β
| 20B | 80.6 | 90.9 | **83.8** | 720 | 46.8 | 55.4 | **82.3** |
|
60 |
+
| QwenVL-Plus | β | - | 78.9 | 91.4 | 78.1 | 726 | 51.4 | 55.7 | 67.0 |
|
61 |
+
| Claude3-Opus | β | - | - | 89.3 | 80.8 | 694 | **59.4** | 51.7 | 63.3 |
|
62 |
+
| Gemini Pro 1.5 | β | - | 73.5 | 86.5 | 81.3 | - | 58.5 | - | - |
|
63 |
+
| GPT-4V | β | - | 78.0 | 88.4 | 78.5 | 656 | 56.8 | **67.7** | 75.0 |
|
64 |
+
| CogVLM1.1 (Ours) | β
| 7B | 69.7 | - | 68.3 | 590 | 37.3 | 52.0 | 65.8 |
|
65 |
+
| CogVLM2-LLaMA3 (Ours) | β
| 8B | 84.2 | **92.3** | 81.0 | 756 | 44.3 | 60.4 | 80.5 |
|
66 |
+
| CogVLM2-LLaMA3-Chinese (Ours) | β
| 8B | **85.0** | 88.4 | 74.7 | **780** | 42.8 | 60.5 | 78.9 |
|
67 |
+
|
68 |
+
All reviews were obtained without using any external OCR tools ("pixel only").
|
69 |
+
## Quick Start
|
70 |
+
|
71 |
+
here is a simple example of how to use the model to chat with the CogVLM2 model.
|
72 |
+
```python
|
73 |
+
import torch
|
74 |
+
from PIL import Image
|
75 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
76 |
+
|
77 |
+
MODEL_PATH = "THUDM/cogvlm2-llama3-chat-19B"
|
78 |
+
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
79 |
+
TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8 else torch.float16
|
80 |
+
|
81 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
82 |
+
MODEL_PATH,
|
83 |
+
trust_remote_code=True
|
84 |
+
)
|
85 |
+
model = AutoModelForCausalLM.from_pretrained(
|
86 |
+
MODEL_PATH,
|
87 |
+
torch_dtype=TORCH_TYPE,
|
88 |
+
trust_remote_code=True,
|
89 |
+
).to(DEVICE).eval()
|
90 |
+
|
91 |
+
text_only_template = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {} ASSISTANT:"
|
92 |
+
|
93 |
+
while True:
|
94 |
+
image_path = input("image path >>>>> ")
|
95 |
+
if image_path == '':
|
96 |
+
print('You did not enter image path, the following will be a plain text conversation.')
|
97 |
+
image = None
|
98 |
+
text_only_first_query = True
|
99 |
+
else:
|
100 |
+
image = Image.open(image_path).convert('RGB')
|
101 |
+
|
102 |
+
history = []
|
103 |
+
|
104 |
+
while True:
|
105 |
+
query = input("Human:")
|
106 |
+
if query == "clear":
|
107 |
+
break
|
108 |
+
|
109 |
+
if image is None:
|
110 |
+
if text_only_first_query:
|
111 |
+
query = text_only_template.format(query)
|
112 |
+
text_only_first_query = False
|
113 |
+
else:
|
114 |
+
old_prompt = ''
|
115 |
+
for _, (old_query, response) in enumerate(history):
|
116 |
+
old_prompt += old_query + " " + response + "\n"
|
117 |
+
query = old_prompt + "USER: {} ASSISTANT:".format(query)
|
118 |
+
if image is None:
|
119 |
+
input_by_model = model.build_conversation_input_ids(
|
120 |
+
tokenizer,
|
121 |
+
query=query,
|
122 |
+
history=history,
|
123 |
+
template_version='chat'
|
124 |
+
)
|
125 |
+
else:
|
126 |
+
input_by_model = model.build_conversation_input_ids(
|
127 |
+
tokenizer,
|
128 |
+
query=query,
|
129 |
+
history=history,
|
130 |
+
images=[image],
|
131 |
+
template_version='chat'
|
132 |
+
)
|
133 |
+
inputs = {
|
134 |
+
'input_ids': input_by_model['input_ids'].unsqueeze(0).to(DEVICE),
|
135 |
+
'token_type_ids': input_by_model['token_type_ids'].unsqueeze(0).to(DEVICE),
|
136 |
+
'attention_mask': input_by_model['attention_mask'].unsqueeze(0).to(DEVICE),
|
137 |
+
'images': [[input_by_model['images'][0].to(DEVICE).to(TORCH_TYPE)]] if image is not None else None,
|
138 |
+
}
|
139 |
+
gen_kwargs = {
|
140 |
+
"max_new_tokens": 2048,
|
141 |
+
"pad_token_id": 128002,
|
142 |
+
}
|
143 |
+
with torch.no_grad():
|
144 |
+
outputs = model.generate(**inputs, **gen_kwargs)
|
145 |
+
outputs = outputs[:, inputs['input_ids'].shape[1]:]
|
146 |
+
response = tokenizer.decode(outputs[0])
|
147 |
+
response = response.split("<|end_of_text|>")[0]
|
148 |
+
print("\nCogVLM2:", response)
|
149 |
+
history.append((query, response))
|
150 |
+
```
|
151 |
+
|
152 |
+
|
153 |
+
## License
|
154 |
+
|
155 |
+
This model is released under the CogVLM2 [LICENSE](LICENSE). For models built with Meta Llama 3, please also adhere to the [LLAMA3_LICENSE](LLAMA3_LICENSE).
|
156 |
+
|
157 |
+
## Citation
|
158 |
+
|
159 |
+
If you find our work helpful, please consider citing the following papers
|
160 |
+
|
161 |
+
```
|
162 |
+
@misc{wang2023cogvlm,
|
163 |
+
title={CogVLM: Visual Expert for Pretrained Language Models},
|
164 |
+
author={Weihan Wang and Qingsong Lv and Wenmeng Yu and Wenyi Hong and Ji Qi and Yan Wang and Junhui Ji and Zhuoyi Yang and Lei Zhao and Xixuan Song and Jiazheng Xu and Bin Xu and Juanzi Li and Yuxiao Dong and Ming Ding and Jie Tang},
|
165 |
+
year={2023},
|
166 |
+
eprint={2311.03079},
|
167 |
+
archivePrefix={arXiv},
|
168 |
+
primaryClass={cs.CV}
|
169 |
+
}
|
170 |
+
```
|