runninglsy commited on
Commit
a0243df
·
1 Parent(s): 7c18e76

update README

Browse files
Files changed (1) hide show
  1. README.md +225 -3
README.md CHANGED
@@ -1,3 +1,225 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - AIDC-AI/Ovis-dataset
5
+ library_name: transformers
6
+ tags:
7
+ - MLLM
8
+ pipeline_tag: image-text-to-text
9
+ language:
10
+ - en
11
+ - zh
12
+ ---
13
+
14
+ # Ovis2-34B
15
+ <div align="center">
16
+ <img src=https://cdn-uploads.huggingface.co/production/uploads/637aebed7ce76c3b834cea37/3IK823BZ8w-mz_QfeYkDn.png width="30%"/>
17
+ </div>
18
+
19
+ ## Introduction
20
+ [GitHub](https://github.com/AIDC-AI/Ovis) | [Paper](https://arxiv.org/abs/2405.20797)
21
+
22
+ We are pleased to announce the release of **Ovis2**, our latest advancement in multi-modal large language models (MLLMs). Ovis2 inherits the innovative architectural design of the Ovis series, aimed at structurally aligning visual and textual embeddings. As the successor to Ovis1.6, Ovis2 incorporates significant improvements in both dataset curation and training methodologies.
23
+
24
+ **Key Features**:
25
+
26
+ - **Small Model Performance**: Optimized training strategies enable small-scale models to achieve higher capability density, demonstrating cross-tier leading advantages.
27
+
28
+ - **Enhanced Reasoning Capabilities**: Significantly strengthens Chain-of-Thought (CoT) reasoning abilities through the combination of instruction tuning and preference learning.
29
+
30
+ - **Video and Multi-Image Processing**: Video and multi-image data are incorporated into training to enhance the ability to handle complex visual information across frames and images.
31
+
32
+ - **Multilingual Support and OCR**: Enhances multilingual OCR beyond English and Chinese and improves structured data extraction from complex visual elements like tables and charts.
33
+
34
+ <div align="center">
35
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/658a8a837959448ef5500ce5/TIlymOb86R6_Mez3bpmcB.png" width="100%" />
36
+ </div>
37
+
38
+ ## Model Zoo
39
+
40
+ | Ovis MLLMs | ViT | LLM | Model Weights | Demo |
41
+ |:-----------|:-----------------------:|:---------------------:|:-------------------------------------------------------:|:--------------------------------------------------------:|
42
+ | Ovis2-1B | aimv2-large-patch14-448 | Qwen2.5-0.5B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-1B) | [Space](https://huggingface.co/spaces/AIDC-AI/Ovis2-1B) |
43
+ | Ovis2-2B | aimv2-large-patch14-448 | Qwen2.5-1.5B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-2B) | [Space](https://huggingface.co/spaces/AIDC-AI/Ovis2-2B) |
44
+ | Ovis2-4B | aimv2-huge-patch14-448 | Qwen2.5-3B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-4B) | [Space](https://huggingface.co/spaces/AIDC-AI/Ovis2-4B) |
45
+ | Ovis2-8B | aimv2-huge-patch14-448 | Qwen2.5-7B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-8B) | [Space](https://huggingface.co/spaces/AIDC-AI/Ovis2-8B) |
46
+ | Ovis2-16B | aimv2-huge-patch14-448 | Qwen2.5-14B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-16B) | [Space](https://huggingface.co/spaces/AIDC-AI/Ovis2-16B) |
47
+ | Ovis2-34B | aimv2-1B-patch14-448 | Qwen2.5-32B-Instruct | [Huggingface](https://huggingface.co/AIDC-AI/Ovis2-34B) | - |
48
+
49
+ ## Performance
50
+
51
+ <div align="center">
52
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/658a8a837959448ef5500ce5/ab9kU1Gvq66GvldRg0tzR.png" width="100%" />
53
+ </div>
54
+
55
+ |Benchmark|Ovis2-1B|Ovis2-2B|Ovis2-4B|Ovis2-8B|Ovis2-16B|Ovis2-34B|
56
+ |:---:|:---:|:---:|:---:|:---:|:---:|:---:|
57
+ |MMBench-V1.1<sub>test</sub>|68.5|77.2|81.4|83.3|85.2|86.2|
58
+ |MMStar|52.0|59.0|61.7|64.4|66.9|69.4|
59
+ |MMMU<sub>val</sub>|36.0|45.3|48.0|59.0|59.6|65.6|
60
+ |MathVista<sub>testmini</sub>|59.5|64.4|69.1|71.4|74.9|77.0|
61
+ |HallBench<sub>avg</sub>|44.5|50.2|54.0|56.0|55.9|58.8|
62
+ |AI2D<sub>test</sub>|76.8|82.6|85.5|86.8|86.1|88.4|
63
+ |OCRBench|88.7|87.5|91.0|89.3|88.2|89.8|
64
+ |MMVet|50.3|58.6|65.5|68.5|68.4|75.5|
65
+ |Average|59.5|65.6|69.5|72.3|73.1|76.3|
66
+
67
+ ## Usage
68
+ Below is a code snippet demonstrating how to run Ovis with various input types. For additional usage instructions, including inference wrapper and Gradio UI, please refer to [Ovis GitHub](https://github.com/AIDC-AI/Ovis?tab=readme-ov-file#inference).
69
+ ```bash
70
+ pip install torch==2.4.0 transformers==4.46.2 numpy==1.25.0 pillow==10.3.0
71
+ pip install flash-attn==2.7.0.post2 --no-build-isolation
72
+ ```
73
+ ```python
74
+ import torch
75
+ from PIL import Image
76
+ from transformers import AutoModelForCausalLM
77
+
78
+ # load model
79
+ model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis2-34B",
80
+ torch_dtype=torch.bfloat16,
81
+ multimodal_max_length=32768,
82
+ trust_remote_code=True).cuda()
83
+ text_tokenizer = model.get_text_tokenizer()
84
+ visual_tokenizer = model.get_visual_tokenizer()
85
+
86
+ # single-image input
87
+ image_path = '/data/images/example_1.jpg'
88
+ images = [Image.open(image_path)]
89
+ max_partition = 9
90
+ text = 'Describe the image.'
91
+ query = f'<image>\n{text}'
92
+
93
+ ## cot-style input
94
+ # cot_suffix = "Provide a step-by-step solution to the problem, and conclude with 'the answer is' followed by the final solution."
95
+ # image_path = '/data/images/example_1.jpg'
96
+ # images = [Image.open(image_path)]
97
+ # max_partition = 9
98
+ # text = "What's the area of the shape?"
99
+ # query = f'<image>\n{text}\n{cot_suffix}'
100
+
101
+ ## multiple-images input
102
+ # image_paths = [
103
+ # '/data/images/example_1.jpg',
104
+ # '/data/images/example_2.jpg',
105
+ # '/data/images/example_3.jpg'
106
+ # ]
107
+ # images = [Image.open(image_path) for image_path in image_paths]
108
+ # max_partition = 4
109
+ # text = 'Describe each image.'
110
+ # query = '\n'.join([f'Image {i+1}: <image>' for i in range(len(images))]) + '\n' + text
111
+
112
+ ## text-only input
113
+ # images = []
114
+ # max_partition = None
115
+ # text = 'Hello'
116
+ # query = text
117
+
118
+ # format conversation
119
+ prompt, input_ids, pixel_values = model.preprocess_inputs(query, images, max_partition=max_partition)
120
+ attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
121
+ input_ids = input_ids.unsqueeze(0).to(device=model.device)
122
+ attention_mask = attention_mask.unsqueeze(0).to(device=model.device)
123
+ if pixel_values is not None:
124
+ pixel_values = pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device)
125
+ pixel_values = [pixel_values]
126
+
127
+ # generate output
128
+ with torch.inference_mode():
129
+ gen_kwargs = dict(
130
+ max_new_tokens=1024,
131
+ do_sample=False,
132
+ top_p=None,
133
+ top_k=None,
134
+ temperature=None,
135
+ repetition_penalty=None,
136
+ eos_token_id=model.generation_config.eos_token_id,
137
+ pad_token_id=text_tokenizer.pad_token_id,
138
+ use_cache=True
139
+ )
140
+ output_ids = model.generate(input_ids, pixel_values=pixel_values, attention_mask=attention_mask, **gen_kwargs)[0]
141
+ output = text_tokenizer.decode(output_ids, skip_special_tokens=True)
142
+ print(f'Output:\n{output}')
143
+ ```
144
+
145
+ <details>
146
+ <summary>Batch Inference</summary>
147
+
148
+ ```python
149
+ import torch
150
+ from PIL import Image
151
+ from transformers import AutoModelForCausalLM
152
+
153
+ # load model
154
+ model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis2-34B",
155
+ torch_dtype=torch.bfloat16,
156
+ multimodal_max_length=32768,
157
+ trust_remote_code=True).cuda()
158
+ text_tokenizer = model.get_text_tokenizer()
159
+ visual_tokenizer = model.get_visual_tokenizer()
160
+
161
+ # preprocess inputs
162
+ batch_inputs = [
163
+ ('/data/images/example_1.jpg', 'What colors dominate the image?'),
164
+ ('/data/images/example_2.jpg', 'What objects are depicted in this image?'),
165
+ ('/data/images/example_3.jpg', 'Is there any text in the image?')
166
+ ]
167
+
168
+ batch_input_ids = []
169
+ batch_attention_mask = []
170
+ batch_pixel_values = []
171
+
172
+ for image_path, text in batch_inputs:
173
+ image = Image.open(image_path)
174
+ query = f'<image>\n{text}'
175
+ prompt, input_ids, pixel_values = model.preprocess_inputs(query, [image], max_partition=9)
176
+ attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
177
+ batch_input_ids.append(input_ids.to(device=model.device))
178
+ batch_attention_mask.append(attention_mask.to(device=model.device))
179
+ batch_pixel_values.append(pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device))
180
+
181
+ batch_input_ids = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_input_ids], batch_first=True,
182
+ padding_value=0.0).flip(dims=[1])
183
+ batch_input_ids = batch_input_ids[:, -model.config.multimodal_max_length:]
184
+ batch_attention_mask = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_attention_mask],
185
+ batch_first=True, padding_value=False).flip(dims=[1])
186
+ batch_attention_mask = batch_attention_mask[:, -model.config.multimodal_max_length:]
187
+
188
+ # generate outputs
189
+ with torch.inference_mode():
190
+ gen_kwargs = dict(
191
+ max_new_tokens=1024,
192
+ do_sample=False,
193
+ top_p=None,
194
+ top_k=None,
195
+ temperature=None,
196
+ repetition_penalty=None,
197
+ eos_token_id=model.generation_config.eos_token_id,
198
+ pad_token_id=text_tokenizer.pad_token_id,
199
+ use_cache=True
200
+ )
201
+ output_ids = model.generate(batch_input_ids, pixel_values=batch_pixel_values, attention_mask=batch_attention_mask,
202
+ **gen_kwargs)
203
+
204
+ for i in range(len(batch_inputs)):
205
+ output = text_tokenizer.decode(output_ids[i], skip_special_tokens=True)
206
+ print(f'Output {i + 1}:\n{output}\n')
207
+ ```
208
+ </details>
209
+
210
+ ## Citation
211
+ If you find Ovis useful, please consider citing the paper
212
+ ```
213
+ @article{lu2024ovis,
214
+ title={Ovis: Structural Embedding Alignment for Multimodal Large Language Model},
215
+ author={Shiyin Lu and Yang Li and Qing-Guo Chen and Zhao Xu and Weihua Luo and Kaifu Zhang and Han-Jia Ye},
216
+ year={2024},
217
+ journal={arXiv:2405.20797}
218
+ }
219
+ ```
220
+
221
+ ## License
222
+ This project is licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt) (SPDX-License-Identifier: Apache-2.0).
223
+
224
+ ## Disclaimer
225
+ We used compliance-checking algorithms during the training process, to ensure the compliance of the trained model to the best of our ability. Due to the complexity of the data and the diversity of language model usage scenarios, we cannot guarantee that the model is completely free of copyright issues or improper content. If you believe anything infringes on your rights or generates improper content, please contact us, and we will promptly address the matter.