Update README.md
Browse files
README.md
CHANGED
@@ -10,234 +10,173 @@ language:
|
|
10 |
- multilingual
|
11 |
tags:
|
12 |
- internvl
|
13 |
-
- vision
|
14 |
-
- ocr
|
15 |
-
- multi-image
|
16 |
-
- video
|
17 |
- custom_code
|
18 |
---
|
19 |
|
20 |
# InternVL2_5-1B
|
21 |
|
22 |
-
[\[π GitHub\]](https://github.com/OpenGVLab/InternVL) [\[π Blog\]](https://internvl.github.io/blog/)
|
23 |
-
[\[π InternVL 2.5 Report\]]()
|
24 |
-
[\[π InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[π InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
|
25 |
-
[\[π¨οΈ Chat Demo\]](https://internvl.opengvlab.com/) [\[π€ HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[π Quick Start\]](#quick-start) [\[π Documents\]](https://internvl.readthedocs.io/en/latest/)
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
## Introduction
|
30 |
|
31 |
-
We are excited to introduce InternVL 2.5
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
40 |
-
|
|
41 |
-
|
|
42 |
-
|
|
43 |
-
|
|
44 |
-
|
|
45 |
-
| InternVL2_5-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
### Multimodal Multilingual Understanding
|
124 |
|
125 |
-
|
126 |
-
<tr>
|
127 |
-
<td rowspan="2">Model Name</td>
|
128 |
-
<td colspan="6">MMMB</td>
|
129 |
-
<td colspan="6">MultiMMB</td>
|
130 |
-
<td>MTVQA</td>
|
131 |
-
</tr>
|
132 |
-
<tr>
|
133 |
-
<td>en</td>
|
134 |
-
<td>zh</td>
|
135 |
-
<td>pt</td>
|
136 |
-
<td>ar</td>
|
137 |
-
<td>tr</td>
|
138 |
-
<td>ru</td>
|
139 |
-
<td>en</td>
|
140 |
-
<td>zh</td>
|
141 |
-
<td>pt</td>
|
142 |
-
<td>ar</td>
|
143 |
-
<td>tr</td>
|
144 |
-
<td>ru</td>
|
145 |
-
<td>(avg)</td>
|
146 |
-
</tr>
|
147 |
-
<tr>
|
148 |
-
<td>InternVL2-1B</td>
|
149 |
-
<td>73.2</td>
|
150 |
-
<td>67.4</td>
|
151 |
-
<td>55.5</td>
|
152 |
-
<td>53.5</td>
|
153 |
-
<td>43.8</td>
|
154 |
-
<td>55.2</td>
|
155 |
-
<td>67.9</td>
|
156 |
-
<td>61.2</td>
|
157 |
-
<td>50.8</td>
|
158 |
-
<td>43.3</td>
|
159 |
-
<td>31.8</td>
|
160 |
-
<td>52.7</td>
|
161 |
-
<td>12.6</td>
|
162 |
-
</tr>
|
163 |
-
<tr>
|
164 |
-
<td>InternVL2.5-1B</td>
|
165 |
-
<td>78.8</td>
|
166 |
-
<td>70.2</td>
|
167 |
-
<td>61.5</td>
|
168 |
-
<td>55.0</td>
|
169 |
-
<td>45.3</td>
|
170 |
-
<td>61.1</td>
|
171 |
-
<td>72.5</td>
|
172 |
-
<td>64.7</td>
|
173 |
-
<td>57.0</td>
|
174 |
-
<td>43.0</td>
|
175 |
-
<td>37.8</td>
|
176 |
-
<td>53.2</td>
|
177 |
-
<td>21.4</td>
|
178 |
-
</tr>
|
179 |
-
<tr>
|
180 |
-
<td>Qwen2-VL-2B</td>
|
181 |
-
<td>78.3</td>
|
182 |
-
<td>74.2</td>
|
183 |
-
<td>72.6</td>
|
184 |
-
<td>68.3</td>
|
185 |
-
<td>61.8</td>
|
186 |
-
<td>72.8</td>
|
187 |
-
<td>72.1</td>
|
188 |
-
<td>71.1</td>
|
189 |
-
<td>69.9</td>
|
190 |
-
<td>61.1</td>
|
191 |
-
<td>54.4</td>
|
192 |
-
<td>69.3</td>
|
193 |
-
<td>20.0</td>
|
194 |
-
</tr>
|
195 |
-
<tr>
|
196 |
-
<td>InternVL2-2B</td>
|
197 |
-
<td>79.4</td>
|
198 |
-
<td>71.6</td>
|
199 |
-
<td>54.0</td>
|
200 |
-
<td>43.5</td>
|
201 |
-
<td>46.4</td>
|
202 |
-
<td>48.1</td>
|
203 |
-
<td>73.8</td>
|
204 |
-
<td>69.6</td>
|
205 |
-
<td>51.4</td>
|
206 |
-
<td>29.8</td>
|
207 |
-
<td>31.3</td>
|
208 |
-
<td>42.3</td>
|
209 |
-
<td>10.9</td>
|
210 |
-
</tr>
|
211 |
-
<tr>
|
212 |
-
<td>InternVL2.5-2B</td>
|
213 |
-
<td>81.4</td>
|
214 |
-
<td>74.4</td>
|
215 |
-
<td>58.2</td>
|
216 |
-
<td>48.3</td>
|
217 |
-
<td>46.4</td>
|
218 |
-
<td>53.2</td>
|
219 |
-
<td>76.5</td>
|
220 |
-
<td>71.6</td>
|
221 |
-
<td>55.9</td>
|
222 |
-
<td>37.3</td>
|
223 |
-
<td>33.9</td>
|
224 |
-
<td>44.8</td>
|
225 |
-
<td>21.8</td>
|
226 |
-
</tr>
|
227 |
-
</table>
|
228 |
-
|
229 |
-
|
230 |
-
### Invitation to Evaluate InternVL
|
231 |
-
|
232 |
-
We welcome MLLM benchmark developers to assess our InternVL series models. If you need to add your evaluation results here, please contact me at [[email protected]](mailto:[email protected]).
|
233 |
|
234 |
-
|
235 |
|
236 |
-
|
237 |
|
238 |
-
|
239 |
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
### Model Loading
|
243 |
|
@@ -270,21 +209,6 @@ model = AutoModel.from_pretrained(
|
|
270 |
trust_remote_code=True).eval()
|
271 |
```
|
272 |
|
273 |
-
#### BNB 4-bit Quantization
|
274 |
-
|
275 |
-
```python
|
276 |
-
import torch
|
277 |
-
from transformers import AutoTokenizer, AutoModel
|
278 |
-
path = "OpenGVLab/InternVL2_5-1B"
|
279 |
-
model = AutoModel.from_pretrained(
|
280 |
-
path,
|
281 |
-
torch_dtype=torch.bfloat16,
|
282 |
-
load_in_4bit=True,
|
283 |
-
low_cpu_mem_usage=True,
|
284 |
-
use_flash_attn=True,
|
285 |
-
trust_remote_code=True).eval()
|
286 |
-
```
|
287 |
-
|
288 |
#### Multiple GPUs
|
289 |
|
290 |
The reason for writing the code this way is to avoid errors that occur during multi-GPU inference due to tensors not being on the same device. By ensuring that the first and last layers of the large language model (LLM) are on the same device, we prevent such errors.
|
@@ -298,7 +222,7 @@ def split_model(model_name):
|
|
298 |
device_map = {}
|
299 |
world_size = torch.cuda.device_count()
|
300 |
num_layers = {
|
301 |
-
'InternVL2_5-1B': 24, '
|
302 |
'InternVL2_5-26B': 48, 'InternVL2_5-38B': 64, 'InternVL2_5-78B': 80}[model_name]
|
303 |
# Since the first GPU will be used for ViT, treat it as half a GPU.
|
304 |
num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))
|
@@ -543,13 +467,13 @@ response, history = model.chat(tokenizer, pixel_values, question, generation_con
|
|
543 |
num_patches_list=num_patches_list, history=None, return_history=True)
|
544 |
print(f'User: {question}\nAssistant: {response}')
|
545 |
|
546 |
-
question = 'Describe this video in detail.
|
547 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
548 |
num_patches_list=num_patches_list, history=history, return_history=True)
|
549 |
print(f'User: {question}\nAssistant: {response}')
|
550 |
```
|
551 |
|
552 |
-
#### Streaming
|
553 |
|
554 |
Besides this method, you can also use the following code to get streamed output.
|
555 |
|
@@ -594,7 +518,7 @@ pip install lmdeploy>=0.5.3
|
|
594 |
|
595 |
LMDeploy abstracts the complex inference process of multi-modal Vision-Language Models (VLM) into an easy-to-use pipeline, similar to the Large Language Model (LLM) inference pipeline.
|
596 |
|
597 |
-
#### A 'Hello, world'
|
598 |
|
599 |
```python
|
600 |
from lmdeploy import pipeline, TurbomindEngineConfig
|
@@ -609,11 +533,11 @@ print(response.text)
|
|
609 |
|
610 |
If `ImportError` occurs while executing this case, please install the required dependency packages as prompted.
|
611 |
|
612 |
-
#### Multi-images
|
613 |
|
614 |
When dealing with multiple images, you can put them all in one list. Keep in mind that multiple images will lead to a higher number of input tokens, and as a result, the size of the context window typically needs to be increased.
|
615 |
|
616 |
-
|
617 |
|
618 |
```python
|
619 |
from lmdeploy import pipeline, TurbomindEngineConfig
|
@@ -634,7 +558,7 @@ response = pipe((f'Image-1: {IMAGE_TOKEN}\nImage-2: {IMAGE_TOKEN}\ndescribe thes
|
|
634 |
print(response.text)
|
635 |
```
|
636 |
|
637 |
-
#### Batch
|
638 |
|
639 |
Conducting inference with batch prompts is quite straightforward; just place them within a list structure:
|
640 |
|
@@ -654,7 +578,7 @@ response = pipe(prompts)
|
|
654 |
print(response)
|
655 |
```
|
656 |
|
657 |
-
#### Multi-turn
|
658 |
|
659 |
There are two ways to do the multi-turn conversations with the pipeline. One is to construct messages according to the format of OpenAI and use above introduced method, the other is to use the `pipeline.chat` interface.
|
660 |
|
@@ -717,18 +641,18 @@ print(response)
|
|
717 |
|
718 |
## License
|
719 |
|
720 |
-
This project is released under the MIT
|
721 |
|
722 |
## Citation
|
723 |
|
724 |
If you find this project useful in your research, please consider citing:
|
725 |
|
726 |
```BibTeX
|
727 |
-
@article{
|
728 |
-
title={
|
729 |
-
author={
|
730 |
-
journal={arXiv preprint arXiv:
|
731 |
-
year={
|
732 |
}
|
733 |
@article{chen2024far,
|
734 |
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
@@ -736,12 +660,10 @@ If you find this project useful in your research, please consider citing:
|
|
736 |
journal={arXiv preprint arXiv:2404.16821},
|
737 |
year={2024}
|
738 |
}
|
739 |
-
@article{
|
740 |
-
title={
|
741 |
-
author={
|
742 |
-
journal={arXiv preprint arXiv:
|
743 |
-
year={
|
744 |
}
|
745 |
-
|
746 |
```
|
747 |
-
|
|
|
10 |
- multilingual
|
11 |
tags:
|
12 |
- internvl
|
|
|
|
|
|
|
|
|
13 |
- custom_code
|
14 |
---
|
15 |
|
16 |
# InternVL2_5-1B
|
17 |
|
18 |
+
[\[π GitHub\]](https://github.com/OpenGVLab/InternVL) [\[π Blog\]](https://internvl.github.io/blog/) [\[π InternVL 1.0\]](https://arxiv.org/abs/2312.14238) [\[π InternVL 1.5\]](https://arxiv.org/abs/2404.16821) [\[π InternVL 2.5\]](https://github.com/OpenGVLab/InternVL/blob/main/InternVL2_5_report.pdf)
|
|
|
|
|
|
|
19 |
|
20 |
+
[\[π¨οΈ Chat Demo\]](https://internvl.opengvlab.com/) [\[π€ HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[π Quick Start\]](#quick-start) [\[π Documents\]](https://internvl.readthedocs.io/en/latest/)
|
21 |
+
|
22 |
+
<div align="center">
|
23 |
+
<img width="500" alt="image" src="https://cdn-uploads.huggingface.co/production/uploads/64006c09330a45b03605bba3/zJsd2hqd3EevgXo6fNgC-.png">
|
24 |
+
</div>
|
25 |
|
26 |
## Introduction
|
27 |
|
28 |
+
We are excited to introduce **InternVL 2.5**, an advanced multimodal large language model (MLLM) series that builds upon InternVL 2.0, maintaining its core model architecture while introducing significant enhancements in training and testing strategies as well as data quality.
|
29 |
+
|
30 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/5HDAGOQOZvS1EtI107Ac-.png)
|
31 |
+
|
32 |
+
## InternVL 2.5 Family
|
33 |
+
|
34 |
+
In the following table, we provide an overview of the InternVL 2.5 series.
|
35 |
+
|
36 |
+
| Model Name | Vision Part | Language Part | HF Link |
|
37 |
+
| :-------------: | :-------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------: | :---------------------------------------------------------: |
|
38 |
+
| InternVL2_5-1B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-1B) |
|
39 |
+
| InternVL2_5-2B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [internlm2_5-1_8b-chat](https://huggingface.co/internlm/internlm2_5-1_8b-chat) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-2B) |
|
40 |
+
| InternVL2_5-4B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-4B) |
|
41 |
+
| InternVL2_5-8B | [InternViT-300M-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-300M-448px-V2_5) | [internlm2_5-7b-chat](https://huggingface.co/internlm/internlm2_5-7b-chat) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-8B) |
|
42 |
+
| InternVL2_5-26B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [internlm2_5-20b-chat](https://huggingface.co/internlm/internlm2_5-20b-chat) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-26B) |
|
43 |
+
| InternVL2_5-38B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-38B) |
|
44 |
+
| InternVL2_5-78B | [InternViT-6B-448px-V2_5](https://huggingface.co/OpenGVLab/InternViT-6B-448px-V2_5) | [Qwen2.5-72B-Instruct](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct) | [π€ link](https://huggingface.co/OpenGVLab/InternVL2_5-78B) |
|
45 |
+
|
46 |
+
## Model Architecture
|
47 |
+
|
48 |
+
As shown in the following figure, InternVL 2.5 retains the same model architecture as its predecessors, InternVL 1.5 and 2.0, following the "ViT-MLP-LLM" paradigm. In this new version, we integrate a newly incrementally pre-trained InternViT with various pre-trained LLMs, including InternLM 2.5 and Qwen 2.5, using a randomly initialized MLP projector.
|
49 |
+
|
50 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/BiiyXN6NOk0p-3rl3ueyL.png)
|
51 |
+
|
52 |
+
As in the previous version, we applied a pixel unshuffle operation, reducing the number of visual tokens to one-quarter of the original. Besides, we adopted a similar dynamic resolution strategy as InternVL 1.5, dividing images into tiles of 448Γ448 pixels. The key difference, starting from InternVL 2.0, is that we additionally introduced support for multi-image and video data.
|
53 |
+
|
54 |
+
## Training Strategy
|
55 |
+
|
56 |
+
### Dynamic High-Resolution for Multimodal Data
|
57 |
+
|
58 |
+
In InternVL 2.0 and 2.5, we extend the dynamic high-resolution training approach, enhancing its capabilities to handle multi-image and video datasets.
|
59 |
+
|
60 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/xoMY6rwRrNxbAGYPNyU8g.png)
|
61 |
+
|
62 |
+
- For single-image datasets, the total number of tiles `n_max` are allocated to a single image for maximum resolution. Visual tokens are enclosed in `<img>` and `</img>` tags.
|
63 |
+
|
64 |
+
- For multi-image datasets, the total number of tiles `n_max` are distributed across all images in a sample. Each image is labeled with auxiliary tags like `Image-1` and enclosed in `<img>` and `</img>` tags.
|
65 |
+
|
66 |
+
- For videos, each frame is resized to 448Γ448. Frames are labeled with tags like `Frame-1` and enclosed in `<img>` and `</img>` tags, similar to images.
|
67 |
+
|
68 |
+
### Single Model Training Pipeline
|
69 |
+
|
70 |
+
The training pipeline for a single model in InternVL 2.5 is structured across three stages, designed to enhance the model's visual perception and multimodal capabilities.
|
71 |
+
|
72 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/5NduZeCPLgPJTFr0RGTq3.png)
|
73 |
+
|
74 |
+
- **Stage 1: MLP Warmup.** In this stage, only the MLP projector is trained while the vision encoder and language model are frozen. A dynamic high-resolution training strategy is applied for better performance, despite increased cost. This phase ensures robust cross-modal alignment and prepares the model for stable multimodal training.
|
75 |
+
|
76 |
+
- **Stage 1.5: ViT Incremental Learning (Optional).** This stage allows incremental training of the vision encoder and MLP projector using the same data as Stage 1. It enhances the encoderβs ability to handle rare domains like multilingual OCR and mathematical charts. Once trained, the encoder can be reused across LLMs without retraining, making this stage optional unless new domains are introduced.
|
77 |
+
|
78 |
+
- **Stage 2: Full Model Instruction Tuning.** The entire model is trained on high-quality multimodal instruction datasets. Strict data quality controls are enforced to prevent degradation of the LLM, as noisy data can cause issues like repetitive or incorrect outputs. After this stage, the training process is complete.
|
79 |
+
|
80 |
+
### Progressive Scaling Strategy
|
81 |
+
|
82 |
+
We introduce a progressive scaling strategy to align the vision encoder with LLMs efficiently. This approach trains with smaller LLMs first (e.g., 20B) to optimize foundational visual capabilities and cross-modal alignment before transferring the vision encoder to larger LLMs (e.g., 72B) without retraining. This reuse skips intermediate stages for larger models.
|
83 |
+
|
84 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/AVb_PSxhJq1z2eUFNYoqQ.png)
|
85 |
+
|
86 |
+
Compared to Qwen2-VL's 1.4 trillion tokens, InternVL2.5-78B uses only 120 billion tokensβless than one-tenth. This strategy minimizes redundancy, maximizes pre-trained component reuse, and enables efficient training for complex vision-language tasks.
|
87 |
+
|
88 |
+
### Training Enhancements
|
89 |
+
|
90 |
+
To improve real-world adaptability and performance, we introduce two key techniques:
|
91 |
+
|
92 |
+
- **Random JPEG Compression**: Random JPEG compression with quality levels between 75 and 100 is applied as a data augmentation technique. This simulates image degradation from internet sources, enhancing the model's robustness to noisy images.
|
93 |
+
|
94 |
+
- **Loss Reweighting**: To balance the NTP loss across responses of different lengths, we use a reweighting strategy called **square averaging**. This method balances contributions from responses of varying lengths, mitigating biases toward longer or shorter responses.
|
95 |
+
|
96 |
+
### Data Organization
|
97 |
+
|
98 |
+
#### Dataset Configuration
|
99 |
+
|
100 |
+
In InternVL 2.0 and 2.5, the organization of the training data is controlled by several key parameters to optimize the balance and distribution of datasets during training.
|
101 |
+
|
102 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/2LJe24b1ua3gjI9gDitVl.png)
|
103 |
+
|
104 |
+
- **Data Augmentation:** JPEG compression is applied conditionally: enabled for image datasets to enhance robustness and disabled for video datasets to maintain consistent frame quality.
|
105 |
+
|
106 |
+
- **Maximum Tile Number:** The parameter `n_max` controls the maximum tiles per dataset. For example, higher values (24β36) are used for multi-image or high-resolution data, lower values (6β12) for standard images, and 1 for videos.
|
107 |
+
|
108 |
+
- **Repeat Factor:** The repeat factor `r` adjusts dataset sampling frequency. Values below 1 reduce a dataset's weight, while values above 1 increase it. This ensures balanced training across tasks and prevents overfitting or underfitting.
|
109 |
+
|
110 |
+
#### Data Filtering Pipeline
|
111 |
+
|
112 |
+
During development, we found that LLMs are highly sensitive to data noise, with even small anomaliesβlike outliers or repetitive dataβcausing abnormal behavior during inference. Repetitive generation, especially in long-form or CoT reasoning tasks, proved particularly harmful.
|
113 |
+
|
114 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/aka8ZRiKF3ajdyZBnNFZI.png)
|
115 |
+
|
116 |
+
To address this challenge and support future research, we designed an efficient data filtering pipeline to remove low-quality samples.
|
117 |
+
|
118 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/70l1UxnX-Arn0NoOGwpth.png)
|
119 |
+
|
120 |
+
The pipeline includes two modules, for **pure-text data**, three key strategies are used:
|
121 |
+
|
122 |
+
1. **LLM-Based Quality Scoring**: Each sample is scored (0β10) using a pre-trained LLM with domain-specific prompts. Samples scoring below a threshold (e.g., 7) are removed to ensure high-quality data.
|
123 |
+
2. **Repetition Detection**: Repetitive samples are flagged using LLM-based prompts and manually reviewed. Samples scoring below a stricter threshold (e.g., 3) are excluded to avoid repetitive patterns.
|
124 |
+
3. **Heuristic Rule-Based Filtering**: Anomalies like abnormal sentence lengths or duplicate lines are detected using rules. Flagged samples undergo manual verification to ensure accuracy before removal.
|
125 |
+
|
126 |
+
For **multimodal data**, two strategies are used:
|
127 |
+
|
128 |
+
1. **Repetition Detection**: Repetitive samples in non-academic datasets are flagged and manually reviewed to prevent pattern loops. High-quality datasets are exempt from this process.
|
129 |
+
2. **Heuristic Rule-Based Filtering**: Similar rules are applied to detect visual anomalies, with flagged data verified manually to maintain integrity.
|
130 |
+
|
131 |
+
#### Training Data
|
132 |
+
|
133 |
+
As shown in the following figure, from InternVL 1.5 to 2.0 and then to 2.5, the fine-tuning data mixture has undergone iterative improvements in scale, quality, and diversity. For more information about the training data, please refer to our technical report.
|
134 |
+
|
135 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/GaTY9Lde02YzclASMthDa.png)
|
136 |
+
|
137 |
+
## Evaluation on Multimodal Capability
|
138 |
+
|
139 |
+
### Multimodal Reasoning and Mathematics
|
140 |
|
141 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/ihFWMRHbF0lpFTkLqnnj1.png)
|
142 |
+
|
143 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/Nrzq0kjlitjp_jrJCqtwX.png)
|
144 |
+
|
145 |
+
### OCR, Chart, and Document Understanding
|
146 |
+
|
147 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/3yCMoLjlbsqY7ZJViGzih.png)
|
148 |
+
|
149 |
+
### Multi-Image & Real-World Comprehension
|
150 |
+
|
151 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/DSnalmEyhDVQ9GE0GPCla.png)
|
152 |
+
|
153 |
+
### Comprehensive Multimodal & Hallucination Evaluation
|
154 |
+
|
155 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/Z7Raj3TGDiV1H81pDHtoG.png)
|
156 |
+
|
157 |
+
### Visual Grounding
|
158 |
+
|
159 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/lPcIrng8MPSg_PM1hpDPt.png)
|
160 |
|
161 |
### Multimodal Multilingual Understanding
|
162 |
|
163 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/BPpbAOX36RV8RTnm3j-gs.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
+
### Video Understanding
|
166 |
|
167 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/uD5aYt2wNYL94Xn8MOVih.png)
|
168 |
|
169 |
+
## Evaluation on Language Capability
|
170 |
|
171 |
+
Training InternVL 2.0 models led to a decline in pure language capabilities. InternVL 2.5 addresses this by collecting more high-quality open-source data and filtering out low-quality data, achieving better preservation of pure language performance.
|
172 |
+
|
173 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64119264f0f81eb569e0d569/mxuSKvSY-kfI8zePpXj6y.png)
|
174 |
+
|
175 |
+
## Quick Start
|
176 |
+
|
177 |
+
We provide an example code to run `InternVL2_5-1B` using `transformers`.
|
178 |
+
|
179 |
+
> Please use transformers>=4.37.2 to ensure the model works normally.
|
180 |
|
181 |
### Model Loading
|
182 |
|
|
|
209 |
trust_remote_code=True).eval()
|
210 |
```
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
#### Multiple GPUs
|
213 |
|
214 |
The reason for writing the code this way is to avoid errors that occur during multi-GPU inference due to tensors not being on the same device. By ensuring that the first and last layers of the large language model (LLM) are on the same device, we prevent such errors.
|
|
|
222 |
device_map = {}
|
223 |
world_size = torch.cuda.device_count()
|
224 |
num_layers = {
|
225 |
+
'InternVL2_5-1B': 24, 'InternVL2_5-2B': 24, 'InternVL2_5-4B': 36, 'InternVL2_5-8B': 32,
|
226 |
'InternVL2_5-26B': 48, 'InternVL2_5-38B': 64, 'InternVL2_5-78B': 80}[model_name]
|
227 |
# Since the first GPU will be used for ViT, treat it as half a GPU.
|
228 |
num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))
|
|
|
467 |
num_patches_list=num_patches_list, history=None, return_history=True)
|
468 |
print(f'User: {question}\nAssistant: {response}')
|
469 |
|
470 |
+
question = 'Describe this video in detail.'
|
471 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
472 |
num_patches_list=num_patches_list, history=history, return_history=True)
|
473 |
print(f'User: {question}\nAssistant: {response}')
|
474 |
```
|
475 |
|
476 |
+
#### Streaming Output
|
477 |
|
478 |
Besides this method, you can also use the following code to get streamed output.
|
479 |
|
|
|
518 |
|
519 |
LMDeploy abstracts the complex inference process of multi-modal Vision-Language Models (VLM) into an easy-to-use pipeline, similar to the Large Language Model (LLM) inference pipeline.
|
520 |
|
521 |
+
#### A 'Hello, world' Example
|
522 |
|
523 |
```python
|
524 |
from lmdeploy import pipeline, TurbomindEngineConfig
|
|
|
533 |
|
534 |
If `ImportError` occurs while executing this case, please install the required dependency packages as prompted.
|
535 |
|
536 |
+
#### Multi-images Inference
|
537 |
|
538 |
When dealing with multiple images, you can put them all in one list. Keep in mind that multiple images will lead to a higher number of input tokens, and as a result, the size of the context window typically needs to be increased.
|
539 |
|
540 |
+
question = 'Describe this video in detail.'
|
541 |
|
542 |
```python
|
543 |
from lmdeploy import pipeline, TurbomindEngineConfig
|
|
|
558 |
print(response.text)
|
559 |
```
|
560 |
|
561 |
+
#### Batch Prompts Inference
|
562 |
|
563 |
Conducting inference with batch prompts is quite straightforward; just place them within a list structure:
|
564 |
|
|
|
578 |
print(response)
|
579 |
```
|
580 |
|
581 |
+
#### Multi-turn Conversation
|
582 |
|
583 |
There are two ways to do the multi-turn conversations with the pipeline. One is to construct messages according to the format of OpenAI and use above introduced method, the other is to use the `pipeline.chat` interface.
|
584 |
|
|
|
641 |
|
642 |
## License
|
643 |
|
644 |
+
This project is released under the MIT License. This project uses the pre-trained Qwen2.5-0.5B-Instruct as a component, which is licensed under the Apache License 2.0.
|
645 |
|
646 |
## Citation
|
647 |
|
648 |
If you find this project useful in your research, please consider citing:
|
649 |
|
650 |
```BibTeX
|
651 |
+
@article{gao2024mini,
|
652 |
+
title={Mini-internvl: A flexible-transfer pocket multimodal model with 5\% parameters and 90\% performance},
|
653 |
+
author={Gao, Zhangwei and Chen, Zhe and Cui, Erfei and Ren, Yiming and Wang, Weiyun and Zhu, Jinguo and Tian, Hao and Ye, Shenglong and He, Junjun and Zhu, Xizhou and others},
|
654 |
+
journal={arXiv preprint arXiv:2410.16261},
|
655 |
+
year={2024}
|
656 |
}
|
657 |
@article{chen2024far,
|
658 |
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
|
|
660 |
journal={arXiv preprint arXiv:2404.16821},
|
661 |
year={2024}
|
662 |
}
|
663 |
+
@article{chen2023internvl,
|
664 |
+
title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},
|
665 |
+
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 Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},
|
666 |
+
journal={arXiv preprint arXiv:2312.14238},
|
667 |
+
year={2023}
|
668 |
}
|
|
|
669 |
```
|
|