diddytpq commited on
Commit
d02506c
·
verified ·
1 Parent(s): 83a7c4f

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - Qwen/Qwen2.5-VL-7B-Instruct
4
+ ---
5
+ # Qwen/Qwen2.5-VL-7B-Instruct (Quantized)
6
+
7
+ ## Description
8
+ This model is a quantized version of the original model [`Qwen/Qwen2.5-VL-7B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct).
9
+
10
+ It's quantized using the BitsAndBytes library to 4-bit using the [bnb-my-repo](https://huggingface.co/spaces/bnb-community/bnb-my-repo) space.
11
+
12
+ ## Quantization Details
13
+ - **Quantization Type**: int4
14
+ - **bnb_4bit_quant_type**: nf4
15
+ - **bnb_4bit_use_double_quant**: True
16
+ - **bnb_4bit_compute_dtype**: bfloat16
17
+ - **bnb_4bit_quant_storage**: uint8
18
+
19
+
20
+
21
+ # 📄 Original Model Information
22
+
23
+
24
+ ---
25
+ license: apache-2.0
26
+ language:
27
+ - en
28
+ pipeline_tag: image-text-to-text
29
+ tags:
30
+ - multimodal
31
+ library_name: transformers
32
+ ---
33
+
34
+ # Qwen2.5-VL-7B-Instruct
35
+ <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
36
+ <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;"/>
37
+ </a>
38
+
39
+ ## Introduction
40
+
41
+ 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.
42
+
43
+ #### Key Enhancements:
44
+ * **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.
45
+
46
+ * **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.
47
+
48
+ * **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.
49
+
50
+ * **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.
51
+
52
+ * **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.
53
+
54
+
55
+ #### Model Architecture Updates:
56
+
57
+ * **Dynamic Resolution and Frame Rate Training for Video Understanding**:
58
+
59
+ 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.
60
+
61
+ <p align="center">
62
+ <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/>
63
+ <p>
64
+
65
+
66
+ * **Streamlined and Efficient Vision Encoder**
67
+
68
+ 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.
69
+
70
+
71
+ 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).
72
+
73
+
74
+
75
+ ## Evaluation
76
+
77
+ ### Image benchmark
78
+
79
+
80
+ | Benchmark | InternVL2.5-8B | MiniCPM-o 2.6 | GPT-4o-mini | Qwen2-VL-7B |**Qwen2.5-VL-7B** |
81
+ | :--- | :---: | :---: | :---: | :---: | :---: |
82
+ | MMMU<sub>val</sub> | 56 | 50.4 | **60**| 54.1 | 58.6|
83
+ | MMMU-Pro<sub>val</sub> | 34.3 | - | 37.6| 30.5 | 41.0|
84
+ | DocVQA<sub>test</sub> | 93 | 93 | - | 94.5 | **95.7** |
85
+ | InfoVQA<sub>test</sub> | 77.6 | - | - |76.5 | **82.6** |
86
+ | ChartQA<sub>test</sub> | 84.8 | - |- | 83.0 |**87.3** |
87
+ | TextVQA<sub>val</sub> | 79.1 | 80.1 | -| 84.3 | **84.9**|
88
+ | OCRBench | 822 | 852 | 785 | 845 | **864** |
89
+ | CC_OCR | 57.7 | | | 61.6 | **77.8**|
90
+ | MMStar | 62.8| | |60.7| **63.9**|
91
+ | MMBench-V1.1-En<sub>test</sub> | 79.4 | 78.0 | 76.0| 80.7 | **82.6** |
92
+ | MMT-Bench<sub>test</sub> | - | - | - |**63.7** |63.6 |
93
+ | MMStar | **61.5** | 57.5 | 54.8 | 60.7 |63.9 |
94
+ | MMVet<sub>GPT-4-Turbo</sub> | 54.2 | 60.0 | 66.9 | 62.0 | **67.1**|
95
+ | HallBench<sub>avg</sub> | 45.2 | 48.1 | 46.1| 50.6 | **52.9**|
96
+ | MathVista<sub>testmini</sub> | 58.3 | 60.6 | 52.4 | 58.2 | **68.2**|
97
+ | MathVision | - | - | - | 16.3 | **25.07** |
98
+
99
+ ### Video Benchmarks
100
+
101
+ | Benchmark | Qwen2-VL-7B | **Qwen2.5-VL-7B** |
102
+ | :--- | :---: | :---: |
103
+ | MVBench | 67.0 | **69.6** |
104
+ | PerceptionTest<sub>test</sub> | 66.9 | **70.5** |
105
+ | Video-MME<sub>wo/w subs</sub> | 63.3/69.0 | **65.1**/**71.6** |
106
+ | LVBench | | 45.3 |
107
+ | LongVideoBench | | 54.7 |
108
+ | MMBench-Video | 1.44 | 1.79 |
109
+ | TempCompass | | 71.7 |
110
+ | MLVU | | 70.2 |
111
+ | CharadesSTA/mIoU | 43.6|
112
+
113
+ ### Agent benchmark
114
+ | Benchmarks | Qwen2.5-VL-7B |
115
+ |-------------------------|---------------|
116
+ | ScreenSpot | 84.7 |
117
+ | ScreenSpot Pro | 29.0 |
118
+ | AITZ_EM | 81.9 |
119
+ | Android Control High_EM | 60.1 |
120
+ | Android Control Low_EM | 93.7 |
121
+ | AndroidWorld_SR | 25.5 |
122
+ | MobileMiniWob++_SR | 91.4 |
123
+
124
+ ## Requirements
125
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
126
+ ```
127
+ pip install git+https://github.com/huggingface/transformers accelerate
128
+ ```
129
+ or you might encounter the following error:
130
+ ```
131
+ KeyError: 'qwen2_5_vl'
132
+ ```
133
+
134
+
135
+ ## Quickstart
136
+
137
+ Below, we provide simple examples to show how to use Qwen2.5-VL with 🤖 ModelScope and 🤗 Transformers.
138
+
139
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
140
+ ```
141
+ pip install git+https://github.com/huggingface/transformers accelerate
142
+ ```
143
+ or you might encounter the following error:
144
+ ```
145
+ KeyError: 'qwen2_5_vl'
146
+ ```
147
+
148
+
149
+ 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:
150
+
151
+ ```bash
152
+ # It's highly recommanded to use `[decord]` feature for faster video loading.
153
+ pip install qwen-vl-utils[decord]==0.0.8
154
+ ```
155
+
156
+ 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.
157
+
158
+ ### Using 🤗 Transformers to Chat
159
+
160
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
161
+
162
+ ```python
163
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
164
+ from qwen_vl_utils import process_vision_info
165
+
166
+ # default: Load the model on the available device(s)
167
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
168
+ "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto"
169
+ )
170
+
171
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
172
+ # model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
173
+ # "Qwen/Qwen2.5-VL-7B-Instruct",
174
+ # torch_dtype=torch.bfloat16,
175
+ # attn_implementation="flash_attention_2",
176
+ # device_map="auto",
177
+ # )
178
+
179
+ # default processer
180
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
181
+
182
+ # The default range for the number of visual tokens per image in the model is 4-16384.
183
+ # 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.
184
+ # min_pixels = 256*28*28
185
+ # max_pixels = 1280*28*28
186
+ # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
187
+
188
+ messages = [
189
+ {
190
+ "role": "user",
191
+ "content": [
192
+ {
193
+ "type": "image",
194
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
195
+ },
196
+ {"type": "text", "text": "Describe this image."},
197
+ ],
198
+ }
199
+ ]
200
+
201
+ # Preparation for inference
202
+ text = processor.apply_chat_template(
203
+ messages, tokenize=False, add_generation_prompt=True
204
+ )
205
+ image_inputs, video_inputs = process_vision_info(messages)
206
+ inputs = processor(
207
+ text=[text],
208
+ images=image_inputs,
209
+ videos=video_inputs,
210
+ padding=True,
211
+ return_tensors="pt",
212
+ )
213
+ inputs = inputs.to("cuda")
214
+
215
+ # Inference: Generation of the output
216
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
217
+ generated_ids_trimmed = [
218
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
219
+ ]
220
+ output_text = processor.batch_decode(
221
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
222
+ )
223
+ print(output_text)
224
+ ```
225
+ <details>
226
+ <summary>Multi image inference</summary>
227
+
228
+ ```python
229
+ # Messages containing multiple images and a text query
230
+ messages = [
231
+ {
232
+ "role": "user",
233
+ "content": [
234
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
235
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
236
+ {"type": "text", "text": "Identify the similarities between these images."},
237
+ ],
238
+ }
239
+ ]
240
+
241
+ # Preparation for inference
242
+ text = processor.apply_chat_template(
243
+ messages, tokenize=False, add_generation_prompt=True
244
+ )
245
+ image_inputs, video_inputs = process_vision_info(messages)
246
+ inputs = processor(
247
+ text=[text],
248
+ images=image_inputs,
249
+ videos=video_inputs,
250
+ padding=True,
251
+ return_tensors="pt",
252
+ )
253
+ inputs = inputs.to("cuda")
254
+
255
+ # Inference
256
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
257
+ generated_ids_trimmed = [
258
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
259
+ ]
260
+ output_text = processor.batch_decode(
261
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
262
+ )
263
+ print(output_text)
264
+ ```
265
+ </details>
266
+
267
+ <details>
268
+ <summary>Video inference</summary>
269
+
270
+ ```python
271
+ # Messages containing a images list as a video and a text query
272
+ messages = [
273
+ {
274
+ "role": "user",
275
+ "content": [
276
+ {
277
+ "type": "video",
278
+ "video": [
279
+ "file:///path/to/frame1.jpg",
280
+ "file:///path/to/frame2.jpg",
281
+ "file:///path/to/frame3.jpg",
282
+ "file:///path/to/frame4.jpg",
283
+ ],
284
+ },
285
+ {"type": "text", "text": "Describe this video."},
286
+ ],
287
+ }
288
+ ]
289
+
290
+ # Messages containing a local video path and a text query
291
+ messages = [
292
+ {
293
+ "role": "user",
294
+ "content": [
295
+ {
296
+ "type": "video",
297
+ "video": "file:///path/to/video1.mp4",
298
+ "max_pixels": 360 * 420,
299
+ "fps": 1.0,
300
+ },
301
+ {"type": "text", "text": "Describe this video."},
302
+ ],
303
+ }
304
+ ]
305
+
306
+ # Messages containing a video url and a text query
307
+ messages = [
308
+ {
309
+ "role": "user",
310
+ "content": [
311
+ {
312
+ "type": "video",
313
+ "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
314
+ },
315
+ {"type": "text", "text": "Describe this video."},
316
+ ],
317
+ }
318
+ ]
319
+
320
+ #In Qwen 2.5 VL, frame rate information is also input into the model to align with absolute time.
321
+ # Preparation for inference
322
+ text = processor.apply_chat_template(
323
+ messages, tokenize=False, add_generation_prompt=True
324
+ )
325
+ image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
326
+ inputs = processor(
327
+ text=[text],
328
+ images=image_inputs,
329
+ videos=video_inputs,
330
+ fps=fps,
331
+ padding=True,
332
+ return_tensors="pt",
333
+ **video_kwargs,
334
+ )
335
+ inputs = inputs.to("cuda")
336
+
337
+ # Inference
338
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
339
+ generated_ids_trimmed = [
340
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
341
+ ]
342
+ output_text = processor.batch_decode(
343
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
344
+ )
345
+ print(output_text)
346
+ ```
347
+
348
+ 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.
349
+
350
+ | Backend | HTTP | HTTPS |
351
+ |-------------|------|-------|
352
+ | torchvision >= 0.19.0 | ✅ | ✅ |
353
+ | torchvision < 0.19.0 | ❌ | ❌ |
354
+ | decord | ✅ | ❌ |
355
+ </details>
356
+
357
+ <details>
358
+ <summary>Batch inference</summary>
359
+
360
+ ```python
361
+ # Sample messages for batch inference
362
+ messages1 = [
363
+ {
364
+ "role": "user",
365
+ "content": [
366
+ {"type": "image", "image": "file:///path/to/image1.jpg"},
367
+ {"type": "image", "image": "file:///path/to/image2.jpg"},
368
+ {"type": "text", "text": "What are the common elements in these pictures?"},
369
+ ],
370
+ }
371
+ ]
372
+ messages2 = [
373
+ {"role": "system", "content": "You are a helpful assistant."},
374
+ {"role": "user", "content": "Who are you?"},
375
+ ]
376
+ # Combine messages for batch processing
377
+ messages = [messages1, messages2]
378
+
379
+ # Preparation for batch inference
380
+ texts = [
381
+ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
382
+ for msg in messages
383
+ ]
384
+ image_inputs, video_inputs = process_vision_info(messages)
385
+ inputs = processor(
386
+ text=texts,
387
+ images=image_inputs,
388
+ videos=video_inputs,
389
+ padding=True,
390
+ return_tensors="pt",
391
+ )
392
+ inputs = inputs.to("cuda")
393
+
394
+ # Batch Inference
395
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
396
+ generated_ids_trimmed = [
397
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
398
+ ]
399
+ output_texts = processor.batch_decode(
400
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
401
+ )
402
+ print(output_texts)
403
+ ```
404
+ </details>
405
+
406
+ ### 🤖 ModelScope
407
+ We strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
408
+
409
+
410
+ ### More Usage Tips
411
+
412
+ For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
413
+
414
+ ```python
415
+ # You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
416
+ ## Local file path
417
+ messages = [
418
+ {
419
+ "role": "user",
420
+ "content": [
421
+ {"type": "image", "image": "file:///path/to/your/image.jpg"},
422
+ {"type": "text", "text": "Describe this image."},
423
+ ],
424
+ }
425
+ ]
426
+ ## Image URL
427
+ messages = [
428
+ {
429
+ "role": "user",
430
+ "content": [
431
+ {"type": "image", "image": "http://path/to/your/image.jpg"},
432
+ {"type": "text", "text": "Describe this image."},
433
+ ],
434
+ }
435
+ ]
436
+ ## Base64 encoded image
437
+ messages = [
438
+ {
439
+ "role": "user",
440
+ "content": [
441
+ {"type": "image", "image": "data:image;base64,/9j/..."},
442
+ {"type": "text", "text": "Describe this image."},
443
+ ],
444
+ }
445
+ ]
446
+ ```
447
+ #### Image Resolution for performance boost
448
+
449
+ 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.
450
+
451
+ ```python
452
+ min_pixels = 256 * 28 * 28
453
+ max_pixels = 1280 * 28 * 28
454
+ processor = AutoProcessor.from_pretrained(
455
+ "Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
456
+ )
457
+ ```
458
+
459
+ Besides, We provide two methods for fine-grained control over the image size input to the model:
460
+
461
+ 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.
462
+
463
+ 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
464
+
465
+ ```python
466
+ # min_pixels and max_pixels
467
+ messages = [
468
+ {
469
+ "role": "user",
470
+ "content": [
471
+ {
472
+ "type": "image",
473
+ "image": "file:///path/to/your/image.jpg",
474
+ "resized_height": 280,
475
+ "resized_width": 420,
476
+ },
477
+ {"type": "text", "text": "Describe this image."},
478
+ ],
479
+ }
480
+ ]
481
+ # resized_height and resized_width
482
+ messages = [
483
+ {
484
+ "role": "user",
485
+ "content": [
486
+ {
487
+ "type": "image",
488
+ "image": "file:///path/to/your/image.jpg",
489
+ "min_pixels": 50176,
490
+ "max_pixels": 50176,
491
+ },
492
+ {"type": "text", "text": "Describe this image."},
493
+ ],
494
+ }
495
+ ]
496
+ ```
497
+
498
+ ### Processing Long Texts
499
+
500
+ The current `config.json` is set for context length up to 32,768 tokens.
501
+ 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.
502
+
503
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
504
+
505
+ {
506
+ ...,
507
+ "type": "yarn",
508
+ "mrope_section": [
509
+ 16,
510
+ 24,
511
+ 24
512
+ ],
513
+ "factor": 4,
514
+ "original_max_position_embeddings": 32768
515
+ }
516
+
517
+ 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.
518
+
519
+ 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.
520
+
521
+
522
+
523
+
524
+ ## Citation
525
+
526
+ If you find our work helpful, feel free to give us a cite.
527
+
528
+ ```
529
+ @misc{qwen2.5-VL,
530
+ title = {Qwen2.5-VL},
531
+ url = {https://qwenlm.github.io/blog/qwen2.5-vl/},
532
+ author = {Qwen Team},
533
+ month = {January},
534
+ year = {2025}
535
+ }
536
+
537
+ @article{Qwen2VL,
538
+ title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
539
+ 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},
540
+ journal={arXiv preprint arXiv:2409.12191},
541
+ year={2024}
542
+ }
543
+
544
+ @article{Qwen-VL,
545
+ title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
546
+ 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},
547
+ journal={arXiv preprint arXiv:2308.12966},
548
+ year={2023}
549
+ }
550
+ ```
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
config.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Qwen/Qwen2.5-VL-7B-Instruct",
3
+ "architectures": [
4
+ "Qwen2_5_VLModel"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 3584,
11
+ "image_token_id": 151655,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 18944,
14
+ "max_position_embeddings": 128000,
15
+ "max_window_layers": 28,
16
+ "model_type": "qwen2_5_vl",
17
+ "num_attention_heads": 28,
18
+ "num_hidden_layers": 28,
19
+ "num_key_value_heads": 4,
20
+ "quantization_config": {
21
+ "_load_in_4bit": true,
22
+ "_load_in_8bit": false,
23
+ "bnb_4bit_compute_dtype": "bfloat16",
24
+ "bnb_4bit_quant_storage": "uint8",
25
+ "bnb_4bit_quant_type": "nf4",
26
+ "bnb_4bit_use_double_quant": true,
27
+ "llm_int8_enable_fp32_cpu_offload": false,
28
+ "llm_int8_has_fp16_weight": false,
29
+ "llm_int8_skip_modules": null,
30
+ "llm_int8_threshold": 6.0,
31
+ "load_in_4bit": true,
32
+ "load_in_8bit": false,
33
+ "quant_method": "bitsandbytes"
34
+ },
35
+ "rms_norm_eps": 1e-06,
36
+ "rope_scaling": {
37
+ "mrope_section": [
38
+ 16,
39
+ 24,
40
+ 24
41
+ ],
42
+ "rope_type": "default",
43
+ "type": "default"
44
+ },
45
+ "rope_theta": 1000000.0,
46
+ "sliding_window": 32768,
47
+ "tie_word_embeddings": false,
48
+ "torch_dtype": "bfloat16",
49
+ "transformers_version": "4.49.0",
50
+ "use_cache": true,
51
+ "use_sliding_window": false,
52
+ "video_token_id": 151656,
53
+ "vision_config": {
54
+ "hidden_size": 1280,
55
+ "in_chans": 3,
56
+ "model_type": "qwen2_5_vl",
57
+ "spatial_patch_size": 14,
58
+ "tokens_per_second": 2
59
+ },
60
+ "vision_end_token_id": 151653,
61
+ "vision_start_token_id": 151652,
62
+ "vision_token_id": 151654,
63
+ "vocab_size": 152064
64
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71f86c08328ea627da26cf89e31c2954177340e5c53cdf337e2921d2222b5b8e
3
+ size 4457251878
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 131072,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff