bluelike commited on
Commit
c742902
·
verified ·
1 Parent(s): 2bd5d53

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +309 -0
README.md ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ license: other
4
+ license_name: qwen
5
+ license_link: https://huggingface.co/Qwen/Qwen2.5-VL-72B-Instruct-AWQ/blob/main/LICENSE
6
+ language:
7
+ - en
8
+ pipeline_tag: image-text-to-text
9
+ tags:
10
+ - multimodal
11
+ library_name: transformers
12
+ base_model:
13
+ - Qwen/Qwen2.5-VL-72B-Instruct
14
+ ---
15
+
16
+ # Qwen2.5-VL-72B-Instruct-AWQ
17
+ <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
18
+ <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;"/>
19
+ </a>
20
+
21
+ ## Introduction
22
+
23
+ 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.
24
+
25
+ #### Key Enhancements:
26
+ * **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.
27
+
28
+ * **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.
29
+
30
+ * **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.
31
+
32
+ * **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.
33
+
34
+ * **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.
35
+
36
+
37
+ #### Model Architecture Updates:
38
+
39
+ * **Dynamic Resolution and Frame Rate Training for Video Understanding**:
40
+
41
+ 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.
42
+
43
+ <p align="center">
44
+ <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/>
45
+ <p>
46
+
47
+ * **Streamlined and Efficient Vision Encoder**
48
+
49
+ 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.
50
+
51
+
52
+ We have three models with 3, 7 and 72 billion parameters. This repo contains the instruction-tuned 72B 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).
53
+
54
+
55
+
56
+ ## Evaluation
57
+
58
+
59
+ ## Requirements
60
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
61
+ ```
62
+ pip install git+https://github.com/huggingface/transformers accelerate
63
+ ```
64
+ or you might encounter the following error:
65
+ ```
66
+ KeyError: 'qwen2_5_vl'
67
+ ```
68
+
69
+
70
+ ## Quickstart
71
+
72
+ Below, we provide simple examples to show how to use Qwen2.5-VL with 🤖 ModelScope and 🤗 Transformers.
73
+
74
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
75
+ ```
76
+ pip install git+https://github.com/huggingface/transformers accelerate
77
+ ```
78
+ or you might encounter the following error:
79
+ ```
80
+ KeyError: 'qwen2_5_vl'
81
+ ```
82
+
83
+
84
+ 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:
85
+
86
+ ```bash
87
+ # It's highly recommanded to use `[decord]` feature for faster video loading.
88
+ pip install qwen-vl-utils[decord]==0.0.8
89
+ ```
90
+
91
+ 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.
92
+
93
+ ### Using 🤗 Transformers to Chat
94
+
95
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
96
+
97
+ ```python
98
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
99
+ from qwen_vl_utils import process_vision_info
100
+
101
+ # default: Load the model on the available device(s)
102
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
103
+ "Qwen/Qwen2.5-VL-72B-Instruct", torch_dtype="auto", device_map="auto"
104
+ )
105
+
106
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
107
+ # model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
108
+ # "Qwen/Qwen2.5-VL-72B-Instruct",
109
+ # torch_dtype=torch.bfloat16,
110
+ # attn_implementation="flash_attention_2",
111
+ # device_map="auto",
112
+ # )
113
+
114
+ # default processer
115
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct")
116
+
117
+ # The default range for the number of visual tokens per image in the model is 4-16384.
118
+ # 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.
119
+ # min_pixels = 256*28*28
120
+ # max_pixels = 1280*28*28
121
+ # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
122
+
123
+ messages = [
124
+ {
125
+ "role": "user",
126
+ "content": [
127
+ {
128
+ "type": "image",
129
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
130
+ },
131
+ {"type": "text", "text": "Describe this image."},
132
+ ],
133
+ }
134
+ ]
135
+
136
+ # Preparation for inference
137
+ text = processor.apply_chat_template(
138
+ messages, tokenize=False, add_generation_prompt=True
139
+ )
140
+ image_inputs, video_inputs = process_vision_info(messages)
141
+ inputs = processor(
142
+ text=[text],
143
+ images=image_inputs,
144
+ videos=video_inputs,
145
+ padding=True,
146
+ return_tensors="pt",
147
+ )
148
+ inputs = inputs.to("cuda")
149
+
150
+ # Inference: Generation of the output
151
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
152
+ generated_ids_trimmed = [
153
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
154
+ ]
155
+ output_text = processor.batch_decode(
156
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
157
+ )
158
+ print(output_text)
159
+ ```
160
+
161
+
162
+
163
+
164
+ ### 🤖 ModelScope
165
+ We strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
166
+
167
+
168
+ ### More Usage Tips
169
+
170
+ For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
171
+
172
+ ```python
173
+ # You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
174
+ ## Local file path
175
+ messages = [
176
+ {
177
+ "role": "user",
178
+ "content": [
179
+ {"type": "image", "image": "file:///path/to/your/image.jpg"},
180
+ {"type": "text", "text": "Describe this image."},
181
+ ],
182
+ }
183
+ ]
184
+ ## Image URL
185
+ messages = [
186
+ {
187
+ "role": "user",
188
+ "content": [
189
+ {"type": "image", "image": "http://path/to/your/image.jpg"},
190
+ {"type": "text", "text": "Describe this image."},
191
+ ],
192
+ }
193
+ ]
194
+ ## Base64 encoded image
195
+ messages = [
196
+ {
197
+ "role": "user",
198
+ "content": [
199
+ {"type": "image", "image": "data:image;base64,/9j/..."},
200
+ {"type": "text", "text": "Describe this image."},
201
+ ],
202
+ }
203
+ ]
204
+ ```
205
+ #### Image Resolution for performance boost
206
+
207
+ 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.
208
+
209
+ ```python
210
+ min_pixels = 256 * 28 * 28
211
+ max_pixels = 1280 * 28 * 28
212
+ processor = AutoProcessor.from_pretrained(
213
+ "Qwen/Qwen2.5-VL-72B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
214
+ )
215
+ ```
216
+
217
+ Besides, We provide two methods for fine-grained control over the image size input to the model:
218
+
219
+ 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.
220
+
221
+ 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
222
+
223
+ ```python
224
+ # min_pixels and max_pixels
225
+ messages = [
226
+ {
227
+ "role": "user",
228
+ "content": [
229
+ {
230
+ "type": "image",
231
+ "image": "file:///path/to/your/image.jpg",
232
+ "resized_height": 280,
233
+ "resized_width": 420,
234
+ },
235
+ {"type": "text", "text": "Describe this image."},
236
+ ],
237
+ }
238
+ ]
239
+ # resized_height and resized_width
240
+ messages = [
241
+ {
242
+ "role": "user",
243
+ "content": [
244
+ {
245
+ "type": "image",
246
+ "image": "file:///path/to/your/image.jpg",
247
+ "min_pixels": 50176,
248
+ "max_pixels": 50176,
249
+ },
250
+ {"type": "text", "text": "Describe this image."},
251
+ ],
252
+ }
253
+ ]
254
+ ```
255
+
256
+ ### Processing Long Texts
257
+
258
+ The current `config.json` is set for context length up to 32,768 tokens.
259
+ 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.
260
+
261
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
262
+
263
+ ```json
264
+ {
265
+ ...,
266
+ "type": "yarn",
267
+ "mrope_section": [
268
+ 16,
269
+ 24,
270
+ 24
271
+ ],
272
+ "factor": 4,
273
+ "original_max_position_embeddings": 32768
274
+ }
275
+ ```
276
+
277
+ 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.
278
+
279
+ 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.
280
+
281
+
282
+
283
+ ## Citation
284
+
285
+ If you find our work helpful, feel free to give us a cite.
286
+
287
+ ```
288
+ @misc{qwen2.5-VL,
289
+ title = {Qwen2.5-VL},
290
+ url = {https://qwenlm.github.io/blog/qwen2.5-vl/},
291
+ author = {Qwen Team},
292
+ month = {January},
293
+ year = {2025}
294
+ }
295
+
296
+ @article{Qwen2VL,
297
+ title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
298
+ 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},
299
+ journal={arXiv preprint arXiv:2409.12191},
300
+ year={2024}
301
+ }
302
+
303
+ @article{Qwen-VL,
304
+ title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
305
+ 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},
306
+ journal={arXiv preprint arXiv:2308.12966},
307
+ year={2023}
308
+ }
309
+ ```