ShuaiBai623 commited on
Commit
4648525
·
verified ·
1 Parent(s): 9020d3a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +290 -3
README.md CHANGED
@@ -1,3 +1,290 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: image-text-to-text
4
+ library_name: transformers
5
+ base_model:
6
+ - Qwen/Qwen3-VL-2B-Instruct
7
+ base_model_relation: quantized
8
+ ---
9
+ <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
10
+ <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
11
+ </a>
12
+
13
+ # Qwen3-VL-2B-Instruct-FP8
14
+
15
+ > This repository contains an FP8 quantized version of the [Qwen3-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct) model. The quantization method is fine-grained fp8 quantization with block size of 128, and its performance metrics are nearly identical to those of the original BF16 model. Enjoy!
16
+
17
+
18
+ Meet Qwen3-VL — the most powerful vision-language model in the Qwen series to date.
19
+
20
+ This generation delivers comprehensive upgrades across the board: superior text understanding & generation, deeper visual perception & reasoning, extended context length, enhanced spatial and video dynamics comprehension, and stronger agent interaction capabilities.
21
+
22
+ Available in Dense and MoE architectures that scale from edge to cloud, with Instruct and reasoning‑enhanced Thinking editions for flexible, on‑demand deployment.
23
+
24
+
25
+ #### Key Enhancements:
26
+
27
+ * **Visual Agent**: Operates PC/mobile GUIs—recognizes elements, understands functions, invokes tools, completes tasks.
28
+
29
+ * **Visual Coding Boost**: Generates Draw.io/HTML/CSS/JS from images/videos.
30
+
31
+ * **Advanced Spatial Perception**: Judges object positions, viewpoints, and occlusions; provides stronger 2D grounding and enables 3D grounding for spatial reasoning and embodied AI.
32
+
33
+ * **Long Context & Video Understanding**: Native 256K context, expandable to 1M; handles books and hours-long video with full recall and second-level indexing.
34
+
35
+ * **Enhanced Multimodal Reasoning**: Excels in STEM/Math—causal analysis and logical, evidence-based answers.
36
+
37
+ * **Upgraded Visual Recognition**: Broader, higher-quality pretraining is able to “recognize everything”—celebrities, anime, products, landmarks, flora/fauna, etc.
38
+
39
+ * **Expanded OCR**: Supports 32 languages (up from 19); robust in low light, blur, and tilt; better with rare/ancient characters and jargon; improved long-document structure parsing.
40
+
41
+ * **Text Understanding on par with pure LLMs**: Seamless text–vision fusion for lossless, unified comprehension.
42
+
43
+
44
+ #### Model Architecture Updates:
45
+
46
+ <p align="center">
47
+ <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-VL/qwen3vl_arc.jpg" width="80%"/>
48
+ <p>
49
+
50
+
51
+ 1. **Interleaved-MRoPE**: Full‑frequency allocation over time, width, and height via robust positional embeddings, enhancing long‑horizon video reasoning.
52
+
53
+ 2. **DeepStack**: Fuses multi‑level ViT features to capture fine‑grained details and sharpen image–text alignment.
54
+
55
+ 3. **Text–Timestamp Alignment:** Moves beyond T‑RoPE to precise, timestamp‑grounded event localization for stronger video temporal modeling.
56
+
57
+
58
+ This is the weight repository for Qwen3-VL-2B-Instruct-FP8.
59
+
60
+
61
+ ---
62
+
63
+ ## Model Performance
64
+
65
+ **Multimodal performance**
66
+
67
+ ![](https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-VL/qwen3vl_2b_32b_vl_instruct.jpg)
68
+
69
+ **Pure text performance**
70
+ ![](https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-VL/qwen3vl_2b_32b_text_instruct.jpg)
71
+
72
+ ## Quickstart
73
+
74
+ Currently, 🤗 Transformers does not support loading these weights directly. Stay tuned!
75
+
76
+ We recommend deploying the model using vLLM or SGLang, with example launch commands provided below. For details on the runtime environment and deployment, please refer to this [link](https://github.com/QwenLM/Qwen3-VL?tab=readme-ov-file#deployment).
77
+
78
+ ### vLLM Inference
79
+
80
+ Here we provide a code snippet demonstrating how to use vLLM to run inference with Qwen3-VL locally. For more details on efficient deployment with vLLM, please refer to the [community deployment guide](https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen3-VL.html).
81
+
82
+ ```python
83
+ # -*- coding: utf-8 -*-
84
+ import torch
85
+ from qwen_vl_utils import process_vision_info
86
+ from transformers import AutoProcessor
87
+ from vllm import LLM, SamplingParams
88
+
89
+ import os
90
+ os.environ['VLLM_WORKER_MULTIPROC_METHOD'] = 'spawn'
91
+
92
+ def prepare_inputs_for_vllm(messages, processor):
93
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
94
+ # qwen_vl_utils 0.0.14+ reqired
95
+ image_inputs, video_inputs, video_kwargs = process_vision_info(
96
+ messages,
97
+ image_patch_size=processor.image_processor.patch_size,
98
+ return_video_kwargs=True,
99
+ return_video_metadata=True
100
+ )
101
+ print(f"video_kwargs: {video_kwargs}")
102
+
103
+ mm_data = {}
104
+ if image_inputs is not None:
105
+ mm_data['image'] = image_inputs
106
+ if video_inputs is not None:
107
+ mm_data['video'] = video_inputs
108
+
109
+ return {
110
+ 'prompt': text,
111
+ 'multi_modal_data': mm_data,
112
+ 'mm_processor_kwargs': video_kwargs
113
+ }
114
+
115
+
116
+ if __name__ == '__main__':
117
+ # messages = [
118
+ # {
119
+ # "role": "user",
120
+ # "content": [
121
+ # {
122
+ # "type": "video",
123
+ # "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
124
+ # },
125
+ # {"type": "text", "text": "这段视频有多长"},
126
+ # ],
127
+ # }
128
+ # ]
129
+
130
+ messages = [
131
+ {
132
+ "role": "user",
133
+ "content": [
134
+ {
135
+ "type": "image",
136
+ "image": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-VL/receipt.png",
137
+ },
138
+ {"type": "text", "text": "Read all the text in the image."},
139
+ ],
140
+ }
141
+ ]
142
+
143
+ # TODO: change to your own checkpoint path
144
+ checkpoint_path = "Qwen/Qwen3-VL-2B-Instruct-FP8"
145
+ processor = AutoProcessor.from_pretrained(checkpoint_path)
146
+ inputs = [prepare_inputs_for_vllm(message, processor) for message in [messages]]
147
+
148
+ llm = LLM(
149
+ model=checkpoint_path,
150
+ trust_remote_code=True,
151
+ gpu_memory_utilization=0.70,
152
+ enforce_eager=False,
153
+ tensor_parallel_size=torch.cuda.device_count(),
154
+ seed=0
155
+ )
156
+
157
+ sampling_params = SamplingParams(
158
+ temperature=0,
159
+ max_tokens=1024,
160
+ top_k=-1,
161
+ stop_token_ids=[],
162
+ )
163
+
164
+ for i, input_ in enumerate(inputs):
165
+ print()
166
+ print('=' * 40)
167
+ print(f"Inputs[{i}]: {input_['prompt']=!r}")
168
+ print('\n' + '>' * 40)
169
+
170
+ outputs = llm.generate(inputs, sampling_params=sampling_params)
171
+ for i, output in enumerate(outputs):
172
+ generated_text = output.outputs[0].text
173
+ print()
174
+ print('=' * 40)
175
+ print(f"Generated text: {generated_text!r}")
176
+ ```
177
+
178
+ ### SGLang Inference
179
+
180
+ Here we provide a code snippet demonstrating how to use SGLang to run inference with Qwen3-VL locally.
181
+
182
+ ```python
183
+ import time
184
+ from PIL import Image
185
+ from sglang import Engine
186
+ from qwen_vl_utils import process_vision_info
187
+ from transformers import AutoProcessor, AutoConfig
188
+
189
+ if __name__ == "__main__":
190
+ # TODO: change to your own checkpoint path
191
+ checkpoint_path = "Qwen/Qwen3-VL-2B-Instruct-FP8"
192
+ processor = AutoProcessor.from_pretrained(checkpoint_path)
193
+
194
+ messages = [
195
+ {
196
+ "role": "user",
197
+ "content": [
198
+ {
199
+ "type": "image",
200
+ "image": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-VL/receipt.png",
201
+ },
202
+ {"type": "text", "text": "Read all the text in the image."},
203
+ ],
204
+ }
205
+ ]
206
+
207
+ text = processor.apply_chat_template(
208
+ messages,
209
+ tokenize=False,
210
+ add_generation_prompt=True
211
+ )
212
+
213
+ image_inputs, _ = process_vision_info(messages, image_patch_size=processor.image_processor.patch_size)
214
+
215
+ llm = Engine(
216
+ model_path=checkpoint_path,
217
+ enable_multimodal=True,
218
+ mem_fraction_static=0.8,
219
+ tp_size=torch.cuda.device_count(),
220
+ attention_backend="fa3"
221
+ )
222
+
223
+ start = time.time()
224
+ sampling_params = {"max_new_tokens": 1024}
225
+ response = llm.generate(prompt=text, image_data=image_inputs, sampling_params=sampling_params)
226
+ print(f"Response costs: {time.time() - start:.2f}s")
227
+ print(f"Generated text: {response['text']}")
228
+ ```
229
+
230
+
231
+ ### Generation Hyperparameters
232
+ #### VL
233
+ ```bash
234
+ export greedy='false'
235
+ export top_p=0.8
236
+ export top_k=20
237
+ export temperature=0.7
238
+ export repetition_penalty=1.0
239
+ export presence_penalty=1.5
240
+ export out_seq_length=16384
241
+ ```
242
+
243
+ #### Text
244
+ ```bash
245
+ export greedy='false'
246
+ export top_p=1.0
247
+ export top_k=40
248
+ export repetition_penalty=1.0
249
+ export presence_penalty=2.0
250
+ export temperature=1.0
251
+ export out_seq_length=32768
252
+ ```
253
+
254
+
255
+ ## Citation
256
+
257
+ If you find our work helpful, feel free to give us a cite.
258
+
259
+ ```
260
+ @misc{qwen3technicalreport,
261
+ title={Qwen3 Technical Report},
262
+ author={Qwen Team},
263
+ year={2025},
264
+ eprint={2505.09388},
265
+ archivePrefix={arXiv},
266
+ primaryClass={cs.CL},
267
+ url={https://arxiv.org/abs/2505.09388},
268
+ }
269
+
270
+ @article{Qwen2.5-VL,
271
+ title={Qwen2.5-VL Technical Report},
272
+ author={Bai, Shuai and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Song, Sibo and Dang, Kai and Wang, Peng and Wang, Shijie and Tang, Jun and Zhong, Humen and Zhu, Yuanzhi and Yang, Mingkun and Li, Zhaohai and Wan, Jianqiang and Wang, Pengfei and Ding, Wei and Fu, Zheren and Xu, Yiheng and Ye, Jiabo and Zhang, Xi and Xie, Tianbao and Cheng, Zesen and Zhang, Hang and Yang, Zhibo and Xu, Haiyang and Lin, Junyang},
273
+ journal={arXiv preprint arXiv:2502.13923},
274
+ year={2025}
275
+ }
276
+
277
+ @article{Qwen2VL,
278
+ title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
279
+ author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang},
280
+ journal={arXiv preprint arXiv:2409.12191},
281
+ year={2024}
282
+ }
283
+
284
+ @article{Qwen-VL,
285
+ title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
286
+ author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
287
+ journal={arXiv preprint arXiv:2308.12966},
288
+ year={2023}
289
+ }
290
+ ```