wzk1015 commited on
Commit
1f1c12d
·
verified ·
1 Parent(s): 0d5b434

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +2 -312
README.md CHANGED
@@ -17,219 +17,11 @@ tags:
17
 
18
  # Mono-InternVL-2B
19
 
20
- [\[⭐️Project Page\]](https://internvl.github.io/blog/2024-10-10-Mono-InternVL/) [\[📜 Mono-InternVL Paper\]](https://arxiv.org/abs/2410.08202) [\[📝 公众号报道\]](https://mp.weixin.qq.com/s/FmjG0Gp5ow7mm2Vzd9ppPg) [\[🚀 Quick Start\]](#quick-start)
21
 
22
- [切换至中文版](#简介)
23
 
24
- <a id="radar"></a>
25
 
26
- ![image/png](images/fig1.jpg)
27
-
28
- ![image/png](images/fig2.jpg)
29
-
30
- ## News🔥🔥🔥
31
- - **2025.2**: 🎉🎉 Mono-InternVL is accepted by **CVPR 2025**.
32
- - **2024.11**: Mono-InternVL is supported by [lmdeploy](https://github.com/InternLM/lmdeploy/pull/2727)
33
- - **2024.11**: Mono-InternVL is supported by [vllm](https://github.com/vllm-project/vllm/pull/9528).
34
-
35
- ## Introduction
36
-
37
- We release Mono-InternVL, a **monolithic** multimodal large language model (MLLM) that integrates visual encoding and textual decoding into a single LLM. In Mono-InternVL, a set of visual experts is embedded into the pre-trained LLM via a mixture-of-experts (MoE) mechanism. By freezing the LLM, Mono-InternVL ensures that visual capabilities are optimized without compromising the pre-trained language knowledge. Based on this structure, an innovative Endogenous Visual Pretraining (EViP) is introduced to realize coarse-to-fine visual learning.
38
-
39
-
40
-
41
- Mono-InternVL achieves superior performance compared to state-of-the-art MLLM Mini-InternVL-2B-1.5 and significantly outperforms other monolithic MLLMs, as shown in the [radar chart](#radar) above. Meanwhile, it achieves better deployment efficiency, with first token latency reduced by up to 67%.
42
-
43
-
44
-
45
- This repository contains the instruction-tuned Mono-InternVL-2B model, which has 1.8B activated parameters (3B in total). It is built upon [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b). For more details, please refer to our [paper](https://arxiv.org/abs/2410.08202).
46
-
47
-
48
-
49
-
50
-
51
- ## Performance
52
- | Benchmark | Chameleon-7B | EVE-7B (HD) | Emu3 | Mini-InternVL-2B-1-5 | Mono-InternVL-2B |
53
- | :--------------------------: | :----------: | :---------: | :--------: | :------------------: | :--------------: |
54
- | Type | Monolithic | Monolithic | Monolithic | Modular | Monolithic |
55
- | #Activated Params | 7B | 7B | 8B | 2.2B | 1.8B |
56
- | | | | | | |
57
- | MMVet | 8.3 | 25.7 | 37.2 | 39.3 | 40.1 |
58
- | MMMU<sub>val</sub> | 25.4 | 32.6 | 31.6 | 34.6 | 33.7 |
59
- | MME<sub>sum</sub> | 170 | 1628 | — | 1902 | 1875 |
60
- | MMBench-EN<sub>test</sub> | 31.1 | 52.3 | 58.5 | 70.9 | 65.5 |
61
- | MathVista<sub>testmini</sub> | 22.3 | 34.2 | — | 41.1 | 45.7 |
62
- | SEED-Image | 30.6 | 64.6 | 68.2 | 69.8 | 67.4 |
63
- | OCRBench | 7 | 398 | 687 | 654 | 767 |
64
- | Hallusion-Bench | 17.1 | 26.4 | — | 37.5 | 34.8 |
65
- | CCBench<sub>dev</sub> | 3.5 | 16.3 | — | 63.5 | 66.3 |
66
- | Avg<sub>multimodal</sub> | 16.1 | 38.9 | — | 54.4 | 55.2 |
67
- | | | | | | |
68
- | TextVQA<sub>val</sub> | 4.8 | 56.8 | 64.7 | 70.5 | 72.6 |
69
- | SQA-I<sub>test</sub> | 47.2 | 64.9 | 89.2 | 84.9 | 93.6 |
70
- | GQA<sub>test</sub> | — | 62.6 | 60.3 | 61.6 | 59.5 |
71
- | DocVQA<sub>test</sub> | 1.5 | 53.0 | 76.3 | 85.0 | 80.0 |
72
- | AI2D<sub>test</sub> | 46.0 | 61.0 | 70.0 | 69.8 | 68.6 |
73
- | ChartQA<sub>test</sub> | 2.9 | 59.1 | 68.6 | 74.8 | 73.7 |
74
- | InfoVQA<sub>test</sub> | 5.0 | 25.0 | 43.8 | 55.4 | 43.0 |
75
- | Avg<sub>VQA</sub> | 17.9 | 54.6 | 67.6 | 71.7 | 70.1 |
76
-
77
- - Sources of the results include the original papers, our evaluation with [VLMEvalKit](https://github.com/open-compass/VLMEvalKit), and [OpenCompass](https://rank.opencompass.org.cn/leaderboard-multimodal/?m=REALTIME).
78
- - Average scores are computed by normalizing each metric to a range between 0 and 100.
79
- - Please note that evaluating the same model using different testing toolkits can result in slight differences, which is normal. Updates to code versions and variations in environment and hardware can also cause minor discrepancies in results.
80
-
81
-
82
-
83
- Limitations: Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information.
84
-
85
-
86
-
87
- ## Quick Start
88
-
89
- We provide an example code to run Mono-InternVL-2B inference using `transformers`.
90
-
91
- > Please use transformers==4.37.2 to ensure the model works normally.
92
-
93
-
94
- ### Inference with Transformers
95
-
96
- ```python
97
- import numpy as np
98
- import torch
99
- import torchvision.transforms as T
100
- from decord import VideoReader, cpu
101
- from PIL import Image
102
- from torchvision.transforms.functional import InterpolationMode
103
- from transformers import AutoModel, AutoTokenizer
104
-
105
- IMAGENET_MEAN = (0.485, 0.456, 0.406)
106
- IMAGENET_STD = (0.229, 0.224, 0.225)
107
-
108
- def build_transform(input_size):
109
- MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
110
- transform = T.Compose([
111
- T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
112
- T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
113
- T.ToTensor(),
114
- T.Normalize(mean=MEAN, std=STD)
115
- ])
116
- return transform
117
-
118
- def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
119
- best_ratio_diff = float('inf')
120
- best_ratio = (1, 1)
121
- area = width * height
122
- for ratio in target_ratios:
123
- target_aspect_ratio = ratio[0] / ratio[1]
124
- ratio_diff = abs(aspect_ratio - target_aspect_ratio)
125
- if ratio_diff < best_ratio_diff:
126
- best_ratio_diff = ratio_diff
127
- best_ratio = ratio
128
- elif ratio_diff == best_ratio_diff:
129
- if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
130
- best_ratio = ratio
131
- return best_ratio
132
-
133
- def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
134
- orig_width, orig_height = image.size
135
- aspect_ratio = orig_width / orig_height
136
-
137
- # calculate the existing image aspect ratio
138
- target_ratios = set(
139
- (i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
140
- i * j <= max_num and i * j >= min_num)
141
- target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
142
-
143
- # find the closest aspect ratio to the target
144
- target_aspect_ratio = find_closest_aspect_ratio(
145
- aspect_ratio, target_ratios, orig_width, orig_height, image_size)
146
-
147
- # calculate the target width and height
148
- target_width = image_size * target_aspect_ratio[0]
149
- target_height = image_size * target_aspect_ratio[1]
150
- blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
151
-
152
- # resize the image
153
- resized_img = image.resize((target_width, target_height))
154
- processed_images = []
155
- for i in range(blocks):
156
- box = (
157
- (i % (target_width // image_size)) * image_size,
158
- (i // (target_width // image_size)) * image_size,
159
- ((i % (target_width // image_size)) + 1) * image_size,
160
- ((i // (target_width // image_size)) + 1) * image_size
161
- )
162
- # split the image
163
- split_img = resized_img.crop(box)
164
- processed_images.append(split_img)
165
- assert len(processed_images) == blocks
166
- if use_thumbnail and len(processed_images) != 1:
167
- thumbnail_img = image.resize((image_size, image_size))
168
- processed_images.append(thumbnail_img)
169
- return processed_images
170
-
171
- def load_image(image_file, input_size=448, max_num=12):
172
- image = Image.open(image_file).convert('RGB')
173
- transform = build_transform(input_size=input_size)
174
- images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
175
- pixel_values = [transform(image) for image in images]
176
- pixel_values = torch.stack(pixel_values)
177
- return pixel_values
178
-
179
-
180
- path = 'OpenGVLab/Mono-InternVL-2B'
181
- model = AutoModel.from_pretrained(
182
- path,
183
- torch_dtype=torch.bfloat16,
184
- low_cpu_mem_usage=True,
185
- trust_remote_code=True).eval().cuda()
186
- tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
187
-
188
- # set the max number of tiles in `max_num`
189
- pixel_values = load_image('./examples/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
190
- generation_config = dict(max_new_tokens=1024, do_sample=True)
191
-
192
- # pure-text conversation (纯文本对话)
193
- question = 'Hello, who are you?'
194
- response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
195
- print(f'User: {question}\nAssistant: {response}')
196
-
197
- question = 'Can you tell me a story?'
198
- response, history = model.chat(tokenizer, None, question, generation_config, history=history, return_history=True)
199
- print(f'User: {question}\nAssistant: {response}')
200
-
201
- # single-image single-round conversation (单图单轮对话)
202
- question = '<image>\nPlease describe the image shortly.'
203
- response = model.chat(tokenizer, pixel_values, question, generation_config)
204
- print(f'User: {question}\nAssistant: {response}')
205
-
206
- # single-image multi-round conversation (单图多轮对话)
207
- question = '<image>\nPlease describe the image in detail.'
208
- response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
209
- print(f'User: {question}\nAssistant: {response}')
210
-
211
- question = 'Please write a poem according to the image.'
212
- response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=history, return_history=True)
213
- print(f'User: {question}\nAssistant: {response}')
214
- ```
215
-
216
- ### Inference with LMDeploy
217
-
218
- Please install lmdeploy>=0.6.3 for Mono-InternVL support.
219
-
220
- ```python
221
- from lmdeploy import pipeline
222
- from lmdeploy.vl import load_image
223
-
224
- image = load_image('./examples/image1.jpg')
225
- pipe = pipeline('OpenGVLab/Mono-InternVL-2B')
226
- response = pipe(('Please describe the image shortly.', image))
227
- print(response.text)
228
- ```
229
-
230
- ## License
231
-
232
- This project is released under the MIT license, while InternLM2 is licensed under the Apache-2.0 license.
233
 
234
  ## Citation
235
 
@@ -242,107 +34,5 @@ If you find this project useful in your research, please consider citing:
242
  journal={arXiv preprint arXiv:2410.08202},
243
  year={2024}
244
  }
245
-
246
- @article{chen2024far,
247
- title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
248
- author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
249
- journal={arXiv preprint arXiv:2404.16821},
250
- year={2024}
251
- }
252
-
253
- @inproceedings{chen2024internvl,
254
- title={Internvl: Scaling up vision foundation models and aligning for generic visual-linguistic tasks},
255
- author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and others},
256
- booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
257
- pages={24185--24198},
258
- year={2024}
259
- }
260
  ```
261
 
262
-
263
-
264
-
265
-
266
- ## 简介
267
-
268
- 我们发布了Mono-InternVL,这是一种**原生**多模态大语言模型,将视觉编码和文本解码集成到一个单一的大语言模型中。在Mono-InternVL中,一组视觉专家通过专家混合机制嵌入到预训练的语言模型中。通过冻结语言模型的语言部分参数,Mono-InternVL确保了视觉能力的优化,同时不会影响预训练的语言知识。基于这一结构,我们引入了内生视觉预训练(Endogenous Visual Pretraining, EViP),实现了由粗粒度到精粒度的视觉学习。
269
-
270
- Mono-InternVL在性能上优于当前最先进的多模态语言模型Mini-InternVL-2B-1.5,并且显著超越了其他原生多模态模型,如上方的[雷达图](#radar)所示。同时,它的部署效率也得到了提升,首个单词的延迟降低了最多达67%。
271
-
272
- 本仓库包含了经过指令微调的Mono-InternVL-2B模型,它是基于[internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b)搭建的。更多详细信息,请参阅我们的[论文](https://arxiv.org/abs/2410.08202)和[公众号报道](https://mp.weixin.qq.com/s/FmjG0Gp5ow7mm2Vzd9ppPg)。
273
-
274
-
275
-
276
- ## 性能测试
277
- | 评测数据集 | Chameleon-7B | EVE-7B (HD) | Emu3 | Mini-InternVL-2B-1-5 | Mono-InternVL-2B |
278
- | :--------------------------: | :----------: | :---------: | :----: | :------------------: | :--------------: |
279
- | 模型种类 | 原生 | 原生 | 原生 | 非原生 | 原生 |
280
- | 激活参数 | 7B | 7B | 8B | 2.2B | 1.8B |
281
- | | | | | | |
282
- | MMVet | 8.3 | 25.7 | 37.2 | 39.3 | 40.1 |
283
- | MMMU<sub>val</sub> | 25.4 | 32.6 | 31.6 | 34.6 | 33.7 |
284
- | MME<sub>sum</sub> | 170 | 1628 | — | 1902 | 1875 |
285
- | MMBench-EN<sub>test</sub> | 31.1 | 52.3 | 58.5 | 70.9 | 65.5 |
286
- | MathVista<sub>testmini</sub> | 22.3 | 34.2 | — | 41.1 | 45.7 |
287
- | SEED-Image | 30.6 | 64.6 | 68.2 | 69.8 | 67.4 |
288
- | OCRBench | 7 | 398 | 687 | 654 | 767 |
289
- | Hallusion-Bench | 17.1 | 26.4 | — | 37.5 | 34.8 |
290
- | CCBench<sub>dev</sub> | 3.5 | 16.3 | — | 63.5 | 66.3 |
291
- | Avg<sub>multimodal</sub> | 16.1 | 38.9 | — | 54.4 | 55.2 |
292
- | | | | | | |
293
- | TextVQA<sub>val</sub> | 4.8 | 56.8 | 64.7 | 70.5 | 72.6 |
294
- | SQA-I<sub>test</sub> | 47.2 | 64.9 | 89.2 | 84.9 | 93.6 |
295
- | GQA<sub>test</sub> | — | 62.6 | 60.3 | 61.6 | 59.5 |
296
- | DocVQA<sub>test</sub> | 1.5 | 53.0 | 76.3 | 85.0 | 80.0 |
297
- | AI2D<sub>test</sub> | 46.0 | 61.0 | 70.0 | 69.8 | 68.6 |
298
- | ChartQA<sub>test</sub> | 2.9 | 59.1 | 68.6 | 74.8 | 73.7 |
299
- | InfoVQA<sub>test</sub> | 5.0 | 25.0 | 43.8 | 55.4 | 43.0 |
300
- | Avg<sub>VQA</sub> | 17.9 | 54.6 | 67.6 | 71.7 | 70.1 |
301
-
302
- - 以上结果的来源包括相应的原始论文、我们基于[VLMEvalKit](https://github.com/open-compass/VLMEvalKit)的评测,以及[OpenCompass](https://rank.opencompass.org.cn/leaderboard-multimodal/?m=REALTIME)。
303
- - 平均分数Avg通过将每个指标归一化到0至100之间来计算。
304
- - 请注意,使用不同的测试工具包评估同一模型可能会导致评测结果的细微差异,这是正常的。代码版本的更新、环境和硬件的变化也可能导致结果的微小差异。
305
-
306
-
307
-
308
- ## 快速上手
309
-
310
- 我们提供了一个示例代码,用于使用 `transformers` 进行 Mono-InternVL-2B 推理。
311
-
312
- > 请使用 transformers==4.37.2 以确保模型正常运行。
313
-
314
- 示例代码请[点击这里](#quick-start)。
315
-
316
-
317
- ## 开源许可证
318
-
319
- 该项目采用 MIT 许可证发布,而 InternLM2 则采用 Apache-2.0 许可证。
320
-
321
- ## 引用
322
-
323
- 如果您发现此项目对您的研究有用,可以考虑引用我们的论文:
324
-
325
- ```BibTeX
326
- @article{luo2024mono,
327
- title={Mono-InternVL: Pushing the Boundaries of Monolithic Multimodal Large Language Models with Endogenous Visual Pre-training},
328
- author={Luo, Gen and Yang, Xue and Dou, Wenhan and Wang, Zhaokai and Liu, Jiawen and Dai, Jifeng and Qiao, Yu and Zhu, Xizhou},
329
- journal={arXiv preprint arXiv:2410.08202},
330
- year={2024}
331
- }
332
-
333
- @article{chen2024far,
334
- title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
335
- author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
336
- journal={arXiv preprint arXiv:2404.16821},
337
- year={2024}
338
- }
339
-
340
- @inproceedings{chen2024internvl,
341
- title={Internvl: Scaling up vision foundation models and aligning for generic visual-linguistic tasks},
342
- author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and others},
343
- booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
344
- pages={24185--24198},
345
- year={2024}
346
- }
347
-
348
- ```
 
17
 
18
  # Mono-InternVL-2B
19
 
20
+ This repository contains the instruction-tuned Mono-InternVL-2B model, which has 1.8B activated parameters (3B in total). It is built upon [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b).
21
 
22
+ Please refer to our [**paper**](https://huggingface.co/papers/2410.08202), [**project page**](https://internvl.github.io/blog/2024-10-10-Mono-InternVL/) and [**GitHub repository**](https://github.com/OpenGVLab/mono-internvl) for introduction and usage.
23
 
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  ## Citation
27
 
 
34
  journal={arXiv preprint arXiv:2410.08202},
35
  year={2024}
36
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  ```
38