Update README.md
Browse files
README.md
CHANGED
@@ -1,110 +1,117 @@
|
|
1 |
-
---
|
2 |
-
license: other
|
3 |
-
license_name: tongyi-qwen
|
4 |
-
license_link: >-
|
5 |
-
https://github.com/QwenLM/Qwen/blob/main/Tongyi%20Qianwen%20LICENSE%20AGREEMENT
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
*
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
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 |
-
inputs =
|
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 |
```
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: tongyi-qwen
|
4 |
+
license_link: >-
|
5 |
+
https://github.com/QwenLM/Qwen/blob/main/Tongyi%20Qianwen%20LICENSE%20AGREEMENT
|
6 |
+
pipeline_tag: image-text-to-text
|
7 |
+
tags:
|
8 |
+
- multimodal
|
9 |
+
library_name: transformers
|
10 |
+
base_model:
|
11 |
+
- Qwen/Qwen2-0.5B
|
12 |
+
|
13 |
+
---
|
14 |
+
# SliMM: A Simple LMM baseline with Dynamic Visual Resolution π
|
15 |
+
|
16 |
+
[[π Project Page](https://deepstack-vl.github.io/)]
|
17 |
+
[[π Paper](https://arxiv.org/abs/2406.04334)]
|
18 |
+
|
19 |
+
|
20 |
+
## π₯ Latest Update
|
21 |
+
* [2024/12/12] Our [first version](https://huggingface.co/collections/menglc/slimm-675bd737c2965037a6b52d05) is out! We release a strong 0.5B baseline model [SliMM-Qwen2-0.5B](https://huggingface.co/menglc/SliMM-Qwen2-0.5B) and advanced baseline [SliMM-DeepStackM-Qwen2-0.5B](https://huggingface.co/menglc/SliMM-DeepStackM-Qwen2-0.5B). We release a strong 2B model [SliMM-DeepStackE-Qwen2VL-2B](https://huggingface.co/menglc/SliMM-DeepStackE-Qwen2VL-2B) continous fine-tuned from Qwen2VL-2B, which save 4x fewer visual tokens for LLM with. Training scrips are avaliable [here]()!
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
## Introduction
|
26 |
+
|
27 |
+
* **Advanced Techniques**: We incorporate native dynamic resolution, as used in Qwen2-VL, for high-resolution visual encoding, replacing the previous cumbersome Multi-Crop/AnyRes methods. Moreover, building on DeepStack [1], we maintain the same principle of interting stacked visual tokens into **multiple layers** of the LLMs. We propose two enhanced versions for native resolution vision encoding: DeepStack-MidLayers, which improves performance with negligible additional FLOPs by stacking multi-level visual tokens from the middle layers of the vision encoder, and DeepStack-Efficient, which reduces visual token usage while maintaining high performance.
|
28 |
+
* **Seamless Integration**: Easily use LLaVA-format training data in our codebase.
|
29 |
+
* **Training Efficiency**: Fine-tuning on the 748K LLaVA-Next-DATA for on epoch takes only 4 hours for 0.5/2B Qwen2 and 6 hours for a 7B on 8xH100, which is more than 2x faster than LLaVA-OV codebase.
|
30 |
+
* **Strong Baseline Model for Small LMMs**: We establish a robust baseline using widely-used public available datasets, including LCS-758K (Stage-1), LLaVA-OV-MidStage (Stage 1.5), and LLaVA-OneVision SI (Stage 2).
|
31 |
+
|
32 |
+
[1] *DeepStack: Deeply Stacking Visual Tokens is Surprisingly Simple and Effective for LMMs*
|
33 |
+
|
34 |
+
## Quick Start
|
35 |
+
|
36 |
+
|
37 |
+
```bash
|
38 |
+
git clone https://github.com/MengLcool/SliMM.git
|
39 |
+
cd SliMM
|
40 |
+
pip install -e .
|
41 |
+
```
|
42 |
+
|
43 |
+
```Python
|
44 |
+
# this is very similar to qwen2-vl
|
45 |
+
from slimm.model.processor import SliMMQwen2VLProcessor
|
46 |
+
from slimm.model.slimm import SliMMForConditionalGeneration
|
47 |
+
from slimm.model.utils_vl import process_vision_info
|
48 |
+
|
49 |
+
model_path = "menglc/SliMM-Qwen2-0.5B"
|
50 |
+
|
51 |
+
model = SliMMForConditionalGeneration.from_pretrained(
|
52 |
+
model_path, torch_dtype="auto", device_map="auto"
|
53 |
+
)
|
54 |
+
|
55 |
+
processor = SliMMQwen2VLProcessor.from_pretrained(model_path)
|
56 |
+
|
57 |
+
messages = [
|
58 |
+
{
|
59 |
+
"role": "user",
|
60 |
+
"content": [
|
61 |
+
{
|
62 |
+
"type": "image",
|
63 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
64 |
+
},
|
65 |
+
{"type": "text", "text": "Describe this image."},
|
66 |
+
],
|
67 |
+
}
|
68 |
+
]
|
69 |
+
|
70 |
+
# Preparation for inference
|
71 |
+
text = processor.apply_chat_template(
|
72 |
+
messages, tokenize=False, add_generation_prompt=True
|
73 |
+
)
|
74 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
75 |
+
inputs = processor(
|
76 |
+
text=[text],
|
77 |
+
images=image_inputs,
|
78 |
+
videos=video_inputs,
|
79 |
+
padding=True,
|
80 |
+
return_tensors="pt",
|
81 |
+
)
|
82 |
+
inputs = inputs.to("cuda")
|
83 |
+
|
84 |
+
# Inference: Generation of the output
|
85 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
86 |
+
generated_ids_trimmed = [
|
87 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
88 |
+
]
|
89 |
+
output_text = processor.batch_decode(
|
90 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
91 |
+
)
|
92 |
+
print(output_text)
|
93 |
+
```
|
94 |
+
|
95 |
+
## Benchmarks
|
96 |
+
|
97 |
+
| Benchmark | MMMU (Val) | ChartQA (Test) | AI2D (test) | DocVQA (val)
|
98 |
+
|-------------------------|------------|----------------|-------------|-------------|
|
99 |
+
|NanoLLaVA-Qwen1.5-0.5B |28.6 | NA |NA |NA |
|
100 |
+
|OmniVLM v1 |39.9 | 59.2 |NA |NA |
|
101 |
+
|OmniVLM v2 |**40.0** | 61.9 |NA |NA |
|
102 |
+
|LLaVA-OV-SI-Qwen2.5-0.5B |31.2 | 61.0 |54.2 |75.0 |
|
103 |
+
|LLaVA-OV-Qwen2.5-0.5B |31.4 | 61.4 |57.1 |73.7 |
|
104 |
+
|SliMM-Qwen2-0.5B |30.6 | 64.2 |58.4 |77.0 |
|
105 |
+
|SliMM-DeepStackM-Qwen2-0.5B|**31.4** | **65.2** |**60.3** |**77.7** |
|
106 |
+
|
107 |
+
## π Citation
|
108 |
+
If you find our work helpful, please consider citing our paper :paperclip: and starring our repo :star2: :
|
109 |
+
|
110 |
+
```
|
111 |
+
@inproceedings{meng2024deepstack,
|
112 |
+
title={DeepStack: Deeply Stacking Visual Tokens is Surprisingly Simple and Effective for LMMs},
|
113 |
+
author={Meng, Lingchen and Yang, Jianwei and Tian, Rui and Dai, Xiyang and Wu, Zuxuan and Gao, Jianfeng and Jiang, Yu-Gang},
|
114 |
+
booktitle={NeurIPS},
|
115 |
+
year={2024}
|
116 |
+
}
|
117 |
```
|