clonefy commited on
Commit
9b0956d
·
verified ·
1 Parent(s): 58f8ed7

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. LICENSE +51 -0
  2. README.md +304 -0
LICENSE ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Qwen LICENSE AGREEMENT
2
+
3
+ Qwen LICENSE AGREEMENT Release Date: September 19, 2024
4
+
5
+ By clicking to agree or by using or distributing any portion or element of the Qwen Materials, you will be deemed to have recognized and accepted the content of this Agreement, which is effective immediately.
6
+
7
+ 1. Definitions
8
+ a. This Qwen LICENSE AGREEMENT (this "Agreement") shall mean the terms and conditions for use, reproduction, distribution and modification of the Materials as defined by this Agreement.
9
+ b. "We" (or "Us") shall mean Alibaba Cloud.
10
+ c. "You" (or "Your") shall mean a natural person or legal entity exercising the rights granted by this Agreement and/or using the Materials for any purpose and in any field of use.
11
+ d. "Third Parties" shall mean individuals or legal entities that are not under common control with us or you.
12
+ e. "Qwen" shall mean the large language models, and software and algorithms, consisting of trained model weights, parameters (including optimizer states), machine-learning model code, inference-enabling code, training-enabling code, fine-tuning enabling code and other elements of the foregoing distributed by us.
13
+ f. "Materials" shall mean, collectively, Alibaba Cloud's proprietary Qwen and Documentation (and any portion thereof) made available under this Agreement.
14
+ g. "Source" form shall mean the preferred form for making modifications, including but not limited to model source code, documentation source, and configuration files.
15
+ h. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
16
+
17
+ 2. Grant of Rights
18
+ You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Alibaba Cloud's intellectual property or other rights owned by us embodied in the Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the Materials.
19
+
20
+ 3. Redistribution
21
+ You may distribute copies or make the Materials, or derivative works thereof, available as part of a product or service that contains any of them, with or without modifications, and in Source or Object form, provided that you meet the following conditions:
22
+ a. You shall give any other recipients of the Materials or derivative works a copy of this Agreement;
23
+ b. You shall cause any modified files to carry prominent notices stating that you changed the files;
24
+ c. You shall retain in all copies of the Materials that you distribute the following attribution notices within a "Notice" text file distributed as a part of such copies: "Qwen is licensed under the Qwen LICENSE AGREEMENT, Copyright (c) Alibaba Cloud. All Rights Reserved."; and
25
+ d. You may add your own copyright statement to your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of your modifications, or for any such derivative works as a whole, provided your use, reproduction, and distribution of the work otherwise complies with the terms and conditions of this Agreement.
26
+
27
+ 4. Restrictions
28
+ If you are commercially using the Materials, and your product or service has more than 100 million monthly active users, you shall request a license from us. You cannot exercise your rights under this Agreement without our express authorization.
29
+
30
+ 5. Rules of use
31
+ a. The Materials may be subject to export controls or restrictions in China, the United States or other countries or regions. You shall comply with applicable laws and regulations in your use of the Materials.
32
+ b. If you use the Materials or any outputs or results therefrom to create, train, fine-tune, or improve an AI model that is distributed or made available, you shall prominently display “Built with Qwen” or “Improved using Qwen” in the related product documentation.
33
+
34
+ 6. Intellectual Property
35
+ a. We retain ownership of all intellectual property rights in and to the Materials and derivatives made by or for us. Conditioned upon compliance with the terms and conditions of this Agreement, with respect to any derivative works and modifications of the Materials that are made by you, you are and will be the owner of such derivative works and modifications.
36
+ b. No trademark license is granted to use the trade names, trademarks, service marks, or product names of us, except as required to fulfill notice requirements under this Agreement or as required for reasonable and customary use in describing and redistributing the Materials.
37
+ c. If you commence a lawsuit or other proceedings (including a cross-claim or counterclaim in a lawsuit) against us or any entity alleging that the Materials or any output therefrom, or any part of the foregoing, infringe any intellectual property or other right owned or licensable by you, then all licenses granted to you under this Agreement shall terminate as of the date such lawsuit or other proceeding is commenced or brought.
38
+
39
+ 7. Disclaimer of Warranty and Limitation of Liability
40
+ a. We are not obligated to support, update, provide training for, or develop any further version of the Qwen Materials or to grant any license thereto.
41
+ b. THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. WE MAKE NO WARRANTY AND ASSUME NO RESPONSIBILITY FOR THE SAFETY OR STABILITY OF THE MATERIALS AND ANY OUTPUT THEREFROM.
42
+ c. IN NO EVENT SHALL WE BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE MATERIALS OR ANY OUTPUT OF IT, NO MATTER HOW IT’S CAUSED.
43
+ d. You will defend, indemnify and hold harmless us from and against any claim by any third party arising out of or related to your use or distribution of the Materials.
44
+
45
+ 8. Survival and Termination.
46
+ a. The term of this Agreement shall commence upon your acceptance of this Agreement or access to the Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein.
47
+ b. We may terminate this Agreement if you breach any of the terms or conditions of this Agreement. Upon termination of this Agreement, you must delete and cease use of the Materials. Sections 7 and 9 shall survive the termination of this Agreement.
48
+
49
+ 9. Governing Law and Jurisdiction.
50
+ a. This Agreement and any dispute arising out of or relating to it will be governed by the laws of China, without regard to conflict of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement.
51
+ b. The People's Courts in Hangzhou City shall have exclusive jurisdiction over any dispute arising out of this Agreement.
README.md ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ license: apache-2.0
4
+ language:
5
+ - en
6
+ pipeline_tag: image-text-to-text
7
+ tags:
8
+ - multimodal
9
+ library_name: transformers
10
+ ---
11
+
12
+ # Qwen2.5-VL-7B-Instruct-AWQ
13
+ <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
14
+ <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;"/>
15
+ </a>
16
+
17
+ ## Introduction
18
+
19
+ 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.
20
+
21
+ #### Key Enhancements:
22
+ * **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.
23
+
24
+ * **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.
25
+
26
+ * **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.
27
+
28
+ * **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.
29
+
30
+ * **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.
31
+
32
+
33
+ #### Model Architecture Updates:
34
+
35
+ * **Dynamic Resolution and Frame Rate Training for Video Understanding**:
36
+
37
+ 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.
38
+
39
+ <p align="center">
40
+ <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/>
41
+ <p>
42
+
43
+
44
+ * **Streamlined and Efficient Vision Encoder**
45
+
46
+ 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.
47
+
48
+
49
+ We have three models with 3, 7 and 72 billion parameters. This repo contains the instruction-tuned 7B Qwen2.5-VL model with AWQ. For more information, visit our [Blog](https://qwenlm.github.io/blog/qwen2.5-vl/) and [GitHub](https://github.com/QwenLM/Qwen2.5-VL).
50
+
51
+
52
+
53
+ ## Evaluation
54
+
55
+
56
+
57
+ ## Requirements
58
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
59
+ ```
60
+ pip install git+https://github.com/huggingface/transformers accelerate
61
+ ```
62
+ or you might encounter the following error:
63
+ ```
64
+ KeyError: 'qwen2_5_vl'
65
+ ```
66
+
67
+
68
+ ## Quickstart
69
+
70
+ Below, we provide simple examples to show how to use Qwen2.5-VL with 🤖 ModelScope and 🤗 Transformers.
71
+
72
+ The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:
73
+ ```
74
+ pip install git+https://github.com/huggingface/transformers accelerate
75
+ ```
76
+ or you might encounter the following error:
77
+ ```
78
+ KeyError: 'qwen2_5_vl'
79
+ ```
80
+
81
+
82
+ 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:
83
+
84
+ ```bash
85
+ # It's highly recommanded to use `[decord]` feature for faster video loading.
86
+ pip install qwen-vl-utils[decord]==0.0.8
87
+ ```
88
+
89
+ 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.
90
+
91
+ ### Using 🤗 Transformers to Chat
92
+
93
+ Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
94
+
95
+ ```python
96
+ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
97
+ from qwen_vl_utils import process_vision_info
98
+
99
+ # default: Load the model on the available device(s)
100
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
101
+ "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto"
102
+ )
103
+
104
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
105
+ # model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
106
+ # "Qwen/Qwen2.5-VL-7B-Instruct",
107
+ # torch_dtype=torch.bfloat16,
108
+ # attn_implementation="flash_attention_2",
109
+ # device_map="auto",
110
+ # )
111
+
112
+ # default processer
113
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
114
+
115
+ # The default range for the number of visual tokens per image in the model is 4-16384.
116
+ # 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.
117
+ # min_pixels = 256*28*28
118
+ # max_pixels = 1280*28*28
119
+ # processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
120
+
121
+ messages = [
122
+ {
123
+ "role": "user",
124
+ "content": [
125
+ {
126
+ "type": "image",
127
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
128
+ },
129
+ {"type": "text", "text": "Describe this image."},
130
+ ],
131
+ }
132
+ ]
133
+
134
+ # Preparation for inference
135
+ text = processor.apply_chat_template(
136
+ messages, tokenize=False, add_generation_prompt=True
137
+ )
138
+ image_inputs, video_inputs = process_vision_info(messages)
139
+ inputs = processor(
140
+ text=[text],
141
+ images=image_inputs,
142
+ videos=video_inputs,
143
+ padding=True,
144
+ return_tensors="pt",
145
+ )
146
+ inputs = inputs.to("cuda")
147
+
148
+ # Inference: Generation of the output
149
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
150
+ generated_ids_trimmed = [
151
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
152
+ ]
153
+ output_text = processor.batch_decode(
154
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
155
+ )
156
+ print(output_text)
157
+ ```
158
+
159
+
160
+ ### 🤖 ModelScope
161
+ We strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
162
+
163
+
164
+ ### More Usage Tips
165
+
166
+ For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
167
+
168
+ ```python
169
+ # You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
170
+ ## Local file path
171
+ messages = [
172
+ {
173
+ "role": "user",
174
+ "content": [
175
+ {"type": "image", "image": "file:///path/to/your/image.jpg"},
176
+ {"type": "text", "text": "Describe this image."},
177
+ ],
178
+ }
179
+ ]
180
+ ## Image URL
181
+ messages = [
182
+ {
183
+ "role": "user",
184
+ "content": [
185
+ {"type": "image", "image": "http://path/to/your/image.jpg"},
186
+ {"type": "text", "text": "Describe this image."},
187
+ ],
188
+ }
189
+ ]
190
+ ## Base64 encoded image
191
+ messages = [
192
+ {
193
+ "role": "user",
194
+ "content": [
195
+ {"type": "image", "image": "data:image;base64,/9j/..."},
196
+ {"type": "text", "text": "Describe this image."},
197
+ ],
198
+ }
199
+ ]
200
+ ```
201
+ #### Image Resolution for performance boost
202
+
203
+ 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.
204
+
205
+ ```python
206
+ min_pixels = 256 * 28 * 28
207
+ max_pixels = 1280 * 28 * 28
208
+ processor = AutoProcessor.from_pretrained(
209
+ "Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
210
+ )
211
+ ```
212
+
213
+ Besides, We provide two methods for fine-grained control over the image size input to the model:
214
+
215
+ 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.
216
+
217
+ 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
218
+
219
+ ```python
220
+ # min_pixels and max_pixels
221
+ messages = [
222
+ {
223
+ "role": "user",
224
+ "content": [
225
+ {
226
+ "type": "image",
227
+ "image": "file:///path/to/your/image.jpg",
228
+ "resized_height": 280,
229
+ "resized_width": 420,
230
+ },
231
+ {"type": "text", "text": "Describe this image."},
232
+ ],
233
+ }
234
+ ]
235
+ # resized_height and resized_width
236
+ messages = [
237
+ {
238
+ "role": "user",
239
+ "content": [
240
+ {
241
+ "type": "image",
242
+ "image": "file:///path/to/your/image.jpg",
243
+ "min_pixels": 50176,
244
+ "max_pixels": 50176,
245
+ },
246
+ {"type": "text", "text": "Describe this image."},
247
+ ],
248
+ }
249
+ ]
250
+ ```
251
+
252
+ ### Processing Long Texts
253
+
254
+ The current `config.json` is set for context length up to 32,768 tokens.
255
+ 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.
256
+
257
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
258
+
259
+ {
260
+ ...,
261
+ "type": "yarn",
262
+ "mrope_section": [
263
+ 16,
264
+ 24,
265
+ 24
266
+ ],
267
+ "factor": 4,
268
+ "original_max_position_embeddings": 32768
269
+ }
270
+
271
+ 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.
272
+
273
+ 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.
274
+
275
+
276
+
277
+
278
+ ## Citation
279
+
280
+ If you find our work helpful, feel free to give us a cite.
281
+
282
+ ```
283
+ @misc{qwen2.5-VL,
284
+ title = {Qwen2.5-VL},
285
+ url = {https://qwenlm.github.io/blog/qwen2.5-vl/},
286
+ author = {Qwen Team},
287
+ month = {January},
288
+ year = {2025}
289
+ }
290
+
291
+ @article{Qwen2VL,
292
+ title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
293
+ 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},
294
+ journal={arXiv preprint arXiv:2409.12191},
295
+ year={2024}
296
+ }
297
+
298
+ @article{Qwen-VL,
299
+ title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
300
+ 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},
301
+ journal={arXiv preprint arXiv:2308.12966},
302
+ year={2023}
303
+ }
304
+ ```