shimmyshimmer commited on
Commit
9e7f59c
Β·
verified Β·
1 Parent(s): 7f0edde

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +571 -0
README.md ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-VL-3B-Instruct
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ pipeline_tag: image-text-to-text
7
+ license: apache-2.0
8
+ tags:
9
+ - multimodal
10
+ - qwen
11
+ - qwen2
12
+ - unsloth
13
+ - transformers
14
+ - vision
15
+ ---
16
+
17
+ <div>
18
+ <p style="margin-bottom: 0;">
19
+ <em>Unsloth's <a href="https://unsloth.ai/blog/dynamic-4bit">Dynamic 4-bit Quants</a> is selectively quantized, greatly improving accuracy over standard 4-bit.</em>
20
+ </p>
21
+ <div style="display: flex; gap: 5px; align-items: center; ">
22
+ <a href="https://github.com/unslothai/unsloth/">
23
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
24
+ </a>
25
+ <a href="https://discord.gg/unsloth">
26
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
27
+ </a>
28
+ <a href="https://docs.unsloth.ai/">
29
+ <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
30
+ </a>
31
+ </div>
32
+ <h1 style="margin-top: 0rem;">Finetune LLMs 2-5x faster with 70% less memory via Unsloth</h2>
33
+ </div>
34
+ We have a free Google Colab Tesla T4 notebook for Qwen2-VL (7B) here: https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2_VL_(7B)-Vision.ipynb
35
+
36
+ ## ✨ Finetune for Free
37
+
38
+ All notebooks are **beginner friendly**! Add your dataset, click "Run All", and you'll get a 2x faster finetuned model which can be exported to GGUF, vLLM or uploaded to Hugging Face.
39
+
40
+ | Unsloth supports | Free Notebooks | Performance | Memory use |
41
+ |-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
42
+ | **Llama-3.2 (3B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(1B_and_3B)-Conversational.ipynb) | 2.4x faster | 58% less |
43
+ | **Llama-3.2 (11B vision)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(11B)-Vision.ipynb) | 2x faster | 60% less |
44
+ | **Qwen2 VL (7B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2_VL_(7B)-Vision.ipynb) | 1.8x faster | 60% less |
45
+ | **Qwen2.5 (7B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2.5_(7B)-Alpaca.ipynb) | 2x faster | 60% less |
46
+ | **Llama-3.1 (8B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.1_(8B)-Alpaca.ipynb) | 2.4x faster | 58% less |
47
+ | **Phi-3.5 (mini)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Phi_3.5_Mini-Conversational.ipynb) | 2x faster | 50% less |
48
+ | **Gemma 2 (9B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma2_(9B)-Alpaca.ipynb) | 2.4x faster | 58% less |
49
+ | **Mistral (7B)** | [▢️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_(7B)-Conversational.ipynb) | 2.2x faster | 62% less |
50
+
51
+ [<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="200"/>](https://docs.unsloth.ai)
52
+
53
+ - This [Llama 3.2 conversational notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(1B_and_3B)-Conversational.ipynb) is useful for ShareGPT ChatML / Vicuna templates.
54
+ - This [text completion notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_(7B)-Text_Completion.ipynb) is for raw text. This [DPO notebook](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) replicates Zephyr.
55
+ - \* Kaggle has 2x T4s, but we use 1. Due to overhead, 1x T4 is 5x faster.
56
+
57
+ # Qwen2.5-VL
58
+
59
+ ## Introduction
60
+
61
+ In the past five months since Qwen2-VL’s release, numerous developers have built new models on the Qwen2-VL vision-language models, providing us with valuable feedback. During this period, we focused on building more useful vision-language models. Today, we are excited to introduce the latest addition to the Qwen family: Qwen2.5-VL.
62
+
63
+ #### Key Enhancements:
64
+ * **Understand things visually**: Qwen2.5-VL is not only proficient in recognizing common objects such as flowers, birds, fish, and insects, but it is highly capable of analyzing texts, charts, icons, graphics, and layouts within images.
65
+
66
+ * **Being agentic**: Qwen2.5-VL directly plays as a visual agent that can reason and dynamically direct tools, which is capable of computer use and phone use.
67
+
68
+ * **Understanding long videos and capturing events**: Qwen2.5-VL can comprehend videos of over 1 hour, and this time it has a new ability of cpaturing event by pinpointing the relevant video segments.
69
+
70
+ * **Capable of visual localization in different formats**: Qwen2.5-VL can accurately localize objects in an image by generating bounding boxes or points, and it can provide stable JSON outputs for coordinates and attributes.
71
+
72
+ * **Generating structured outputs**: for data like scans of invoices, forms, tables, etc. Qwen2.5-VL supports structured outputs of their contents, benefiting usages in finance, commerce, etc.
73
+
74
+
75
+ #### Model Architecture Updates:
76
+
77
+ * **Dynamic Resolution and Frame Rate Training for Video Understanding**:
78
+
79
+ We extend dynamic resolution to the temporal dimension by adopting dynamic FPS sampling, enabling the model to comprehend videos at various sampling rates. Accordingly, we update mRoPE in the time dimension with IDs and absolute time alignment, enabling the model to learn temporal sequence and speed, and ultimately acquire the ability to pinpoint specific moments.
80
+
81
+ <p align="center">
82
+ <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/>
83
+ <p>
84
+
85
+
86
+ * **Streamlined and Efficient Vision Encoder**
87
+
88
+ We enhance both training and inference speeds by strategically implementing window attention into the ViT. The ViT architecture is further optimized with SwiGLU and RMSNorm, aligning it with the structure of the Qwen2.5 LLM.
89
+
90
+
91
+ We have three models with 3, 7 and 72 billion parameters. This repo contains the instruction-tuned 7B Qwen2.5-VL model. For more information, visit our [Blog](https://qwenlm.github.io/blog/qwen2.5-vl/) and [GitHub](https://github.com/QwenLM/Qwen2.5-VL).
92
+
93
+
94
+
95
+ ## Evaluation
96
+
97
+ ### Image benchmark
98
+
99
+
100
+ | Benchmark | InternVL2.5-8B | MiniCPM-o 2.6 | GPT-4o-mini | Qwen2-VL-7B |**Qwen2.5-VL-7B** |
101
+ | :--- | :---: | :---: | :---: | :---: | :---: |
102
+ | MMMU<sub>val</sub> | 56 | 50.4 | **60**| 54.1 | 58.6|
103
+ | MMMU-Pro<sub>val</sub> | 34.3 | - | 37.6| 30.5 | 41.0|
104
+ | DocVQA<sub>test</sub> | 93 | 93 | - | 94.5 | **95.7** |
105
+ | InfoVQA<sub>test</sub> | 77.6 | - | - |76.5 | **82.6** |
106
+ | ChartQA<sub>test</sub> | 84.8 | - |- | 83.0 |**87.3** |
107
+ | TextVQA<sub>val</sub> | 79.1 | 80.1 | -| 84.3 | **84.9**|
108
+ | OCRBench | 822 | 852 | 785 | 845 | **864** |
109
+ | CC_OCR | 57.7 | | | 61.6 | **77.8**|
110
+ | MMStar | 62.8| | |60.7| **63.9**|
111
+ | MMBench-V1.1-En<sub>test</sub> | 79.4 | 78.0 | 76.0| 80.7 | **82.6** |
112
+ | MMT-Bench<sub>test</sub> | - | - | - |**63.7** |63.6 |
113
+ | MMStar | **61.5** | 57.5 | 54.8 | 60.7 |63.9 |
114
+ | MMVet<sub>GPT-4-Turbo</sub> | 54.2 | 60.0 | 66.9 | 62.0 | **67.1**|
115
+ | HallBench<sub>avg</sub> | 45.2 | 48.1 | 46.1| 50.6 | **52.9**|
116
+ | MathVista<sub>testmini</sub> | 58.3 | 60.6 | 52.4 | 58.2 | **68.2**|
117
+ | MathVision | - | - | - | 16.3 | **25.07** |
118
+
119
+ ### Video Benchmarks
120
+
121
+ | Benchmark | Qwen2-VL-7B | **Qwen2.5-VL-7B** |
122
+ | :--- | :---: | :---: |
123
+ | MVBench | 67.0 | **69.6** |
124
+ | PerceptionTest<sub>test</sub> | 66.9 | **70.5** |
125
+ | Video-MME<sub>wo/w subs</sub> | 63.3/69.0 | **65.1**/**71.6** |
126
+ | LVBench | | 45.3 |
127
+ | LongVideoBench | | 54.7 |
128
+ | MMBench-Video | 1.44 | 1.79 |
129
+ | TempCompass | | 71.7 |
130
+ | MLVU | | 70.2 |
131
+ | CharadesSTA/mIoU | 43.6|
132
+
133
+ ### Agent benchmark
134
+ | Benchmarks | Qwen2.5-VL-7B |
135
+ |-------------------------|---------------|
136
+ | ScreenSpot | 84.7 |
137
+ | ScreenSpot Pro | 29.0 |
138
+ | AITZ_EM | 81.9 |
139
+ | Android Control High_EM | 60.1 |
140
+ | Android Control Low_EM | 93.7 |
141
+ | AndroidWorld_SR | 25.5 |
142
+ | MobileMiniWob++_SR | 91.4 |
143
+
144
+ ## Requirements
145
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
146
+ ```
147
+ pip install git+https://github.com/huggingface/transformers accelerate
148
+ ```
149
+ or you might encounter the following error:
150
+ ```
151
+ KeyError: 'qwen2_5_vl'
152
+ ```
153
+
154
+
155
+ ## Quickstart
156
+
157
+ Below, we provide simple examples to show how to use Qwen2.5-VL with πŸ€– ModelScope and πŸ€— Transformers.
158
+
159
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
160
+ ```
161
+ pip install git+https://github.com/huggingface/transformers accelerate
162
+ ```
163
+ or you might encounter the following error:
164
+ ```
165
+ KeyError: 'qwen2_5_vl'
166
+ ```
167
+
168
+
169
+ We offer a toolkit to help you handle various types of visual input more conveniently, as if you were using an API. This includes base64, URLs, and interleaved images and videos. You can install it using the following command:
170
+
171
+ ```bash
172
+ # It's highly recommanded to use `[decord]` feature for faster video loading.
173
+ pip install qwen-vl-utils[decord]==0.0.8
174
+ ```
175
+
176
+ If you are not using Linux, you might not be able to install `decord` from PyPI. In that case, you can use `pip install qwen-vl-utils` which will fall back to using torchvision for video processing. However, you can still [install decord from source](https://github.com/dmlc/decord?tab=readme-ov-file#install-from-source) to get decord used when loading video.
177
+
178
+ ### Using πŸ€— Transformers to Chat
179
+
180
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
181
+
182
+ ```python
183
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
184
+ from qwen_vl_utils import process_vision_info
185
+
186
+ # default: Load the model on the available device(s)
187
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
188
+ "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto"
189
+ )
190
+
191
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
192
+ # model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
193
+ # "Qwen/Qwen2.5-VL-7B-Instruct",
194
+ # torch_dtype=torch.bfloat16,
195
+ # attn_implementation="flash_attention_2",
196
+ # device_map="auto",
197
+ # )
198
+
199
+ # default processer
200
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
201
+
202
+ # The default range for the number of visual tokens per image in the model is 4-16384.
203
+ # You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.
204
+ # min_pixels = 256*28*28
205
+ # max_pixels = 1280*28*28
206
+ # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
207
+
208
+ messages = [
209
+ {
210
+ "role": "user",
211
+ "content": [
212
+ {
213
+ "type": "image",
214
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
215
+ },
216
+ {"type": "text", "text": "Describe this image."},
217
+ ],
218
+ }
219
+ ]
220
+
221
+ # Preparation for inference
222
+ text = processor.apply_chat_template(
223
+ messages, tokenize=False, add_generation_prompt=True
224
+ )
225
+ image_inputs, video_inputs = process_vision_info(messages)
226
+ inputs = processor(
227
+ text=[text],
228
+ images=image_inputs,
229
+ videos=video_inputs,
230
+ padding=True,
231
+ return_tensors="pt",
232
+ )
233
+ inputs = inputs.to("cuda")
234
+
235
+ # Inference: Generation of the output
236
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
237
+ generated_ids_trimmed = [
238
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
239
+ ]
240
+ output_text = processor.batch_decode(
241
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
242
+ )
243
+ print(output_text)
244
+ ```
245
+ <details>
246
+ <summary>Multi image inference</summary>
247
+
248
+ ```python
249
+ # Messages containing multiple images and a text query
250
+ messages = [
251
+ {
252
+ "role": "user",
253
+ "content": [
254
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
255
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
256
+ {"type": "text", "text": "Identify the similarities between these images."},
257
+ ],
258
+ }
259
+ ]
260
+
261
+ # Preparation for inference
262
+ text = processor.apply_chat_template(
263
+ messages, tokenize=False, add_generation_prompt=True
264
+ )
265
+ image_inputs, video_inputs = process_vision_info(messages)
266
+ inputs = processor(
267
+ text=[text],
268
+ images=image_inputs,
269
+ videos=video_inputs,
270
+ padding=True,
271
+ return_tensors="pt",
272
+ )
273
+ inputs = inputs.to("cuda")
274
+
275
+ # Inference
276
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
277
+ generated_ids_trimmed = [
278
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
279
+ ]
280
+ output_text = processor.batch_decode(
281
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
282
+ )
283
+ print(output_text)
284
+ ```
285
+ </details>
286
+
287
+ <details>
288
+ <summary>Video inference</summary>
289
+
290
+ ```python
291
+ # Messages containing a images list as a video and a text query
292
+ messages = [
293
+ {
294
+ "role": "user",
295
+ "content": [
296
+ {
297
+ "type": "video",
298
+ "video": [
299
+ "file:///path/to/frame1.jpg",
300
+ "file:///path/to/frame2.jpg",
301
+ "file:///path/to/frame3.jpg",
302
+ "file:///path/to/frame4.jpg",
303
+ ],
304
+ },
305
+ {"type": "text", "text": "Describe this video."},
306
+ ],
307
+ }
308
+ ]
309
+
310
+ # Messages containing a local video path and a text query
311
+ messages = [
312
+ {
313
+ "role": "user",
314
+ "content": [
315
+ {
316
+ "type": "video",
317
+ "video": "file:///path/to/video1.mp4",
318
+ "max_pixels": 360 * 420,
319
+ "fps": 1.0,
320
+ },
321
+ {"type": "text", "text": "Describe this video."},
322
+ ],
323
+ }
324
+ ]
325
+
326
+ # Messages containing a video url and a text query
327
+ messages = [
328
+ {
329
+ "role": "user",
330
+ "content": [
331
+ {
332
+ "type": "video",
333
+ "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
334
+ },
335
+ {"type": "text", "text": "Describe this video."},
336
+ ],
337
+ }
338
+ ]
339
+
340
+ #In Qwen 2.5 VL, frame rate information is also input into the model to align with absolute time.
341
+ # Preparation for inference
342
+ text = processor.apply_chat_template(
343
+ messages, tokenize=False, add_generation_prompt=True
344
+ )
345
+ image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
346
+ inputs = processor(
347
+ text=[text],
348
+ images=image_inputs,
349
+ videos=video_inputs,
350
+ fps=fps,
351
+ padding=True,
352
+ return_tensors="pt",
353
+ **video_kwargs,
354
+ )
355
+ inputs = inputs.to("cuda")
356
+
357
+ # Inference
358
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
359
+ generated_ids_trimmed = [
360
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
361
+ ]
362
+ output_text = processor.batch_decode(
363
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
364
+ )
365
+ print(output_text)
366
+ ```
367
+
368
+ Video URL compatibility largely depends on the third-party library version. The details are in the table below. change the backend by `FORCE_QWENVL_VIDEO_READER=torchvision` or `FORCE_QWENVL_VIDEO_READER=decord` if you prefer not to use the default one.
369
+
370
+ | Backend | HTTP | HTTPS |
371
+ |-------------|------|-------|
372
+ | torchvision >= 0.19.0 | βœ… | βœ… |
373
+ | torchvision < 0.19.0 | ❌ | ❌ |
374
+ | decord | βœ… | ❌ |
375
+ </details>
376
+
377
+ <details>
378
+ <summary>Batch inference</summary>
379
+
380
+ ```python
381
+ # Sample messages for batch inference
382
+ messages1 = [
383
+ {
384
+ "role": "user",
385
+ "content": [
386
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
387
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
388
+ {"type": "text", "text": "What are the common elements in these pictures?"},
389
+ ],
390
+ }
391
+ ]
392
+ messages2 = [
393
+ {"role": "system", "content": "You are a helpful assistant."},
394
+ {"role": "user", "content": "Who are you?"},
395
+ ]
396
+ # Combine messages for batch processing
397
+ messages = [messages1, messages2]
398
+
399
+ # Preparation for batch inference
400
+ texts = [
401
+ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
402
+ for msg in messages
403
+ ]
404
+ image_inputs, video_inputs = process_vision_info(messages)
405
+ inputs = processor(
406
+ text=texts,
407
+ images=image_inputs,
408
+ videos=video_inputs,
409
+ padding=True,
410
+ return_tensors="pt",
411
+ )
412
+ inputs = inputs.to("cuda")
413
+
414
+ # Batch Inference
415
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
416
+ generated_ids_trimmed = [
417
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
418
+ ]
419
+ output_texts = processor.batch_decode(
420
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
421
+ )
422
+ print(output_texts)
423
+ ```
424
+ </details>
425
+
426
+ ### πŸ€– ModelScope
427
+ We strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
428
+
429
+
430
+ ### More Usage Tips
431
+
432
+ For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
433
+
434
+ ```python
435
+ # You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
436
+ ## Local file path
437
+ messages = [
438
+ {
439
+ "role": "user",
440
+ "content": [
441
+ {"type": "image", "image": "file:///path/to/your/image.jpg"},
442
+ {"type": "text", "text": "Describe this image."},
443
+ ],
444
+ }
445
+ ]
446
+ ## Image URL
447
+ messages = [
448
+ {
449
+ "role": "user",
450
+ "content": [
451
+ {"type": "image", "image": "http://path/to/your/image.jpg"},
452
+ {"type": "text", "text": "Describe this image."},
453
+ ],
454
+ }
455
+ ]
456
+ ## Base64 encoded image
457
+ messages = [
458
+ {
459
+ "role": "user",
460
+ "content": [
461
+ {"type": "image", "image": "data:image;base64,/9j/..."},
462
+ {"type": "text", "text": "Describe this image."},
463
+ ],
464
+ }
465
+ ]
466
+ ```
467
+ #### Image Resolution for performance boost
468
+
469
+ The model supports a wide range of resolution inputs. By default, it uses the native resolution for input, but higher resolutions can enhance performance at the cost of more computation. Users can set the minimum and maximum number of pixels to achieve an optimal configuration for their needs, such as a token count range of 256-1280, to balance speed and memory usage.
470
+
471
+ ```python
472
+ min_pixels = 256 * 28 * 28
473
+ max_pixels = 1280 * 28 * 28
474
+ processor = AutoProcessor.from_pretrained(
475
+ "Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
476
+ )
477
+ ```
478
+
479
+ Besides, We provide two methods for fine-grained control over the image size input to the model:
480
+
481
+ 1. Define min_pixels and max_pixels: Images will be resized to maintain their aspect ratio within the range of min_pixels and max_pixels.
482
+
483
+ 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
484
+
485
+ ```python
486
+ # min_pixels and max_pixels
487
+ messages = [
488
+ {
489
+ "role": "user",
490
+ "content": [
491
+ {
492
+ "type": "image",
493
+ "image": "file:///path/to/your/image.jpg",
494
+ "resized_height": 280,
495
+ "resized_width": 420,
496
+ },
497
+ {"type": "text", "text": "Describe this image."},
498
+ ],
499
+ }
500
+ ]
501
+ # resized_height and resized_width
502
+ messages = [
503
+ {
504
+ "role": "user",
505
+ "content": [
506
+ {
507
+ "type": "image",
508
+ "image": "file:///path/to/your/image.jpg",
509
+ "min_pixels": 50176,
510
+ "max_pixels": 50176,
511
+ },
512
+ {"type": "text", "text": "Describe this image."},
513
+ ],
514
+ }
515
+ ]
516
+ ```
517
+
518
+ ### Processing Long Texts
519
+
520
+ The current `config.json` is set for context length up to 32,768 tokens.
521
+ To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
522
+
523
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
524
+
525
+ {
526
+ ...,
527
+ "type": "yarn",
528
+ "mrope_section": [
529
+ 16,
530
+ 24,
531
+ 24
532
+ ],
533
+ "factor": 4,
534
+ "original_max_position_embeddings": 32768
535
+ }
536
+
537
+ However, it should be noted that this method has a significant impact on the performance of temporal and spatial localization tasks, and is therefore not recommended for use.
538
+
539
+ At the same time, for long video inputs, since MRoPE itself is more economical with ids, the max_position_embeddings can be directly modified to a larger value, such as 64k.
540
+
541
+
542
+
543
+
544
+ ## Citation
545
+
546
+ If you find our work helpful, feel free to give us a cite.
547
+
548
+ ```
549
+ @misc{qwen2.5-VL,
550
+ title = {Qwen2.5-VL},
551
+ url = {https://qwenlm.github.io/blog/qwen2.5-vl/},
552
+ author = {Qwen Team},
553
+ month = {January},
554
+ year = {2025}
555
+ }
556
+
557
+ @article{Qwen2VL,
558
+ title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
559
+ 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},
560
+ journal={arXiv preprint arXiv:2409.12191},
561
+ year={2024}
562
+ }
563
+
564
+ @article{Qwen-VL,
565
+ title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
566
+ 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},
567
+ journal={arXiv preprint arXiv:2308.12966},
568
+ year={2023}
569
+ }
570
+ ```
571
+