shubhrapandit commited on
Commit
f8e6340
·
verified ·
1 Parent(s): c956a1e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +387 -0
README.md ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - vllm
4
+ - vision
5
+ - w8a8
6
+ license: apache-2.0
7
+ license_link: >-
8
+ https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md
9
+ language:
10
+ - en
11
+ base_model: Qwen/Qwen2.5-VL-7B-Instruct
12
+ library_name: transformers
13
+ ---
14
+
15
+ # Qwen2.5-VL-7B-Instruct-quantized-w8a8
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Qwen/Qwen2.5-VL-7B-Instruct
19
+ - **Input:** Vision-Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** INT8
23
+ - **Activation quantization:** INT8
24
+ - **Release Date:** 2/24/2025
25
+ - **Version:** 1.0
26
+ - **Model Developers:** Neural Magic
27
+
28
+ Quantized version of [Qwen/Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct).
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights of [Qwen/Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) to INT8 data type, ready for inference with vLLM >= 0.5.2.
33
+
34
+ ## Deployment
35
+
36
+ ### Use with vLLM
37
+
38
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
39
+
40
+ ```python
41
+ from vllm.assets.image import ImageAsset
42
+ from vllm import LLM, SamplingParams
43
+
44
+ # prepare model
45
+ llm = LLM(
46
+ model="neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8",
47
+ trust_remote_code=True,
48
+ max_model_len=4096,
49
+ max_num_seqs=2,
50
+ )
51
+
52
+ # prepare inputs
53
+ question = "What is the content of this image?"
54
+ inputs = {
55
+ "prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
56
+ "multi_modal_data": {
57
+ "image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
58
+ },
59
+ }
60
+
61
+ # generate response
62
+ print("========== SAMPLE GENERATION ==============")
63
+ outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
64
+ print(f"PROMPT : {outputs[0].prompt}")
65
+ print(f"RESPONSE: {outputs[0].outputs[0].text}")
66
+ print("==========================================")
67
+ ```
68
+
69
+ vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
70
+
71
+ ## Creation
72
+
73
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below as part a multimodal announcement blog.
74
+
75
+ <details>
76
+ <summary>Model Creation Code</summary>
77
+
78
+ ```python
79
+ import base64
80
+ from io import BytesIO
81
+ import torch
82
+ from datasets import load_dataset
83
+ from qwen_vl_utils import process_vision_info
84
+ from transformers import AutoProcessor
85
+ from llmcompressor.modifiers.quantization import GPTQModifier
86
+ from llmcompressor.transformers import oneshot
87
+ from llmcompressor.transformers.tracing import (
88
+ TraceableQwen2_5_VLForConditionalGeneration,
89
+ )
90
+
91
+ # Load model.
92
+ model_id = "Qwen/Qwen2.5-VL-7B-Instruct"
93
+ model = TraceableQwen2_5_VLForConditionalGeneration.from_pretrained(
94
+ model_id,
95
+ device_map="auto",
96
+ torch_dtype="auto",
97
+ )
98
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
99
+
100
+ # Oneshot arguments
101
+ DATASET_ID = "lmms-lab/flickr30k"
102
+ DATASET_SPLIT = {"calibration": "test[:512]"}
103
+ NUM_CALIBRATION_SAMPLES = 512
104
+ MAX_SEQUENCE_LENGTH = 2048
105
+
106
+ # Load dataset and preprocess.
107
+ ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
108
+ ds = ds.shuffle(seed=42)
109
+
110
+ dampening_frac=0.01
111
+
112
+ # Apply chat template and tokenize inputs.
113
+ def preprocess_and_tokenize(example):
114
+ # preprocess
115
+ buffered = BytesIO()
116
+ example["image"].save(buffered, format="PNG")
117
+ encoded_image = base64.b64encode(buffered.getvalue())
118
+ encoded_image_text = encoded_image.decode("utf-8")
119
+ base64_qwen = f"data:image;base64,{encoded_image_text}"
120
+ messages = [
121
+ {
122
+ "role": "user",
123
+ "content": [
124
+ {"type": "image", "image": base64_qwen},
125
+ {"type": "text", "text": "What does the image show?"},
126
+ ],
127
+ }
128
+ ]
129
+ text = processor.apply_chat_template(
130
+ messages, tokenize=False, add_generation_prompt=True
131
+ )
132
+ image_inputs, video_inputs = process_vision_info(messages)
133
+
134
+ # tokenize
135
+ return processor(
136
+ text=[text],
137
+ images=image_inputs,
138
+ videos=video_inputs,
139
+ padding=False,
140
+ max_length=MAX_SEQUENCE_LENGTH,
141
+ truncation=True,
142
+ )
143
+
144
+ ds = ds.map(preprocess_and_tokenize, remove_columns=ds["calibration"].column_names)
145
+
146
+ # Define a oneshot data collator for multimodal inputs.
147
+ def data_collator(batch):
148
+ assert len(batch) == 1
149
+ return {key: torch.tensor(value) for key, value in batch[0].items()}
150
+
151
+
152
+ # Recipe
153
+ recipe = [
154
+ GPTQModifier(
155
+ targets="Linear",
156
+ scheme="W8A8",
157
+ sequential_targets=["Qwen2_5_VLDecoderLayer"],
158
+ ignore=["lm_head", "re:visual.*"],
159
+ ),
160
+ ]
161
+
162
+ SAVE_DIR==f"{model_id.split('/')[1]}-quantized.w8a8"
163
+
164
+ # Perform oneshot
165
+ oneshot(
166
+ model=model,
167
+ tokenizer=model_id,
168
+ dataset=ds,
169
+ recipe=recipe,
170
+ max_seq_length=MAX_SEQUENCE_LENGTH,
171
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
172
+ trust_remote_code_model=True,
173
+ data_collator=data_collator,
174
+ output_dir=SAVE_DIR
175
+ )
176
+ ```
177
+ </details>
178
+
179
+ ## Evaluation
180
+
181
+ The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard), OpenLLM Leaderboard [V2](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/) and on [HumanEval](https://github.com/neuralmagic/evalplus), using the following commands:
182
+
183
+ <details>
184
+ <summary>Evaluation Commands</summary>
185
+
186
+ ```
187
+ ```
188
+
189
+ </details>
190
+
191
+ ### Accuracy
192
+
193
+ ## Inference Performance
194
+
195
+
196
+ This model achieves up to xxx speedup in single-stream deployment and up to xxx speedup in multi-stream asynchronous deployment, depending on hardware and use-case scenario.
197
+ The following performance benchmarks were conducted with [vLLM](https://docs.vllm.ai/en/latest/) version 0.7.2, and [GuideLLM](https://github.com/neuralmagic/guidellm).
198
+
199
+ <details>
200
+ <summary>Benchmarking Command</summary>
201
+ ```
202
+ guidellm --model neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8 --target "http://localhost:8000/v1" --data-type emulated --data prompt_tokens=<prompt_tokens>,generated_tokens=<generated_tokens>,images=<num_images>,width=<image_width>,height=<image_height> --max seconds 120 --backend aiohttp_server
203
+ ```
204
+
205
+ </details>
206
+
207
+ ### Single-stream performance (measured with vLLM version 0.7.2)
208
+
209
+ <table border="1" class="dataframe">
210
+ <thead>
211
+ <tr>
212
+ <th></th>
213
+ <th></th>
214
+ <th></th>
215
+ <th style="text-align: center;" colspan="2" >Document Visual Question Answering<br>1680W x 2240H<br>64/128</th>
216
+ <th style="text-align: center;" colspan="2" >Visual Reasoning <br>640W x 480H<br>128/128</th>
217
+ <th style="text-align: center;" colspan="2" >Image Captioning<br>480W x 360H<br>0/128</th>
218
+ </tr>
219
+ <tr>
220
+ <th>Hardware</th>
221
+ <th>Model</th>
222
+ <th>Average Cost Reduction</th>
223
+ <th>Latency (s)</th>
224
+ <th>QPD</th>
225
+ <th>Latency (s)th>
226
+ <th>QPD</th>
227
+ <th>Latency (s)</th>
228
+ <th>QPD</th>
229
+ </tr>
230
+ </thead>
231
+ <tbody style="text-align: center">
232
+ <tr>
233
+ <th rowspan="3" valign="top">A100x1</th>
234
+ <th>Qwen/Qwen2.5-VL-7B-Instruct</th>
235
+ <td></td>
236
+ <td>2.8</td>
237
+ <td>707</td>
238
+ <td>1.7</td>
239
+ <td>1162</td>
240
+ <td>1.7</td>
241
+ <td>1198</td>
242
+ </tr>
243
+ <tr>
244
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8</th>
245
+ <td>1.24</td>
246
+ <td>2.4</td>
247
+ <td>851</td>
248
+ <td>1.4</td>
249
+ <td>1454</td>
250
+ <td>1.3</td>
251
+ <td>1512</td>
252
+ </tr>
253
+ <tr>
254
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16</th>
255
+ <td>1.49</td>
256
+ <td>2.2</td>
257
+ <td>912</td>
258
+ <td>1.1</td>
259
+ <td>1791</td>
260
+ <td>1.0</td>
261
+ <td>1950</td>
262
+ </tr>
263
+ <tr>
264
+ <th rowspan="3" valign="top">H100x1</th>
265
+ <th>Qwen/Qwen2.5-VL-7B-Instruct</th>
266
+ <td></td>
267
+ <td>2.0</td>
268
+ <td>557</td>
269
+ <td>1.2</td>
270
+ <td>919</td>
271
+ <td>1.2</td>
272
+ <td>941</td>
273
+ </tr>
274
+ <tr>
275
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-FP8-Dynamic</th>
276
+ <td>1.28</td>
277
+ <td>1.6</td>
278
+ <td>698</td>
279
+ <td>0.9</td>
280
+ <td>1181</td>
281
+ <td>0.9</td>
282
+ <td>1219</td>
283
+ </tr>
284
+ <tr>
285
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16</th>
286
+ <td>1.28</td>
287
+ <td>1.6</td>
288
+ <td>686</td>
289
+ <td>0.9</td>
290
+ <td>1191</td>
291
+ <td>0.9</td>
292
+ <td>1228</td>
293
+ </tr>
294
+ </tbody>
295
+ </table>
296
+
297
+
298
+
299
+ ### Multi-stream asynchronous performance (measured with vLLM version 0.7.2)
300
+
301
+ <table border="1" class="dataframe">
302
+ <thead>
303
+ <tr>
304
+ <th></th>
305
+ <th></th>
306
+ <th></th>
307
+ <th style="text-align: center;" colspan="2" >Document Visual Question Answering<br>1680W x 2240H<br>64/128</th>
308
+ <th style="text-align: center;" colspan="2" >Visual Reasoning <br>640W x 480H<br>128/128</th>
309
+ <th style="text-align: center;" colspan="2" >Image Captioning<br>480W x 360H<br>0/128</th>
310
+ </tr>
311
+ <tr>
312
+ <th>Hardware</th>
313
+ <th>Model</th>
314
+ <th>Average Cost Reduction</th>
315
+ <th>Maximum throughput (QPS)</th>
316
+ <th>QPD</th>
317
+ <th>Maximum throughput (QPS)</th>
318
+ <th>QPD</th>
319
+ <th>Maximum throughput (QPS)</th>
320
+ <th>QPD</th>
321
+ </tr>
322
+ </thead>
323
+ <tbody style="text-align: center">
324
+ <tr>
325
+ <th rowspan="3" valign="top">A100x1</th>
326
+ <th>Qwen/Qwen2.5-VL-7B-Instruct-quantized.</th>
327
+ <td></td>
328
+ <td>0.7</td>
329
+ <td>1347</td>
330
+ <td>2.6</td>
331
+ <td>5221</td>
332
+ <td>3.0</td>
333
+ <td>6122</td>
334
+ </tr>
335
+ <tr>
336
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8</th>
337
+ <td>1.27</td>
338
+ <td>0.8</td>
339
+ <td>1639</td>
340
+ <td>3.4</td>
341
+ <td>6851</td>
342
+ <td>3.9</td>
343
+ <td>7918</td>
344
+ </tr>
345
+ <tr>
346
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16</th>
347
+ <td>1.21</td>
348
+ <td>0.7</td>
349
+ <td>1314</td>
350
+ <td>3.0</td>
351
+ <td>5983</td>
352
+ <td>4.6</td>
353
+ <td>9206</td>
354
+ </tr>
355
+ <tr>
356
+ <th rowspan="3" valign="top">H100x1</th>
357
+ <th>Qwen/Qwen2.5-VL-7B-Instruct</th>
358
+ <td></td>
359
+ <td>0.9</td>
360
+ <td>969</td>
361
+ <td>3.1</td>
362
+ <td>3358</td>
363
+ <td>3.3</td>
364
+ <td>3615</td>
365
+ </tr>
366
+ <tr>
367
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-FP8-Dynamic</th>
368
+ <td>1.29</td>
369
+ <td>1.2</td>
370
+ <td>1331</td>
371
+ <td>3.8</td>
372
+ <td>4109</td>
373
+ <td>4.2</td>
374
+ <td>4598</td>
375
+ </tr>
376
+ <tr>
377
+ <th>neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16</th>
378
+ <td>1.28</td>
379
+ <td>1.2</td>
380
+ <td>1298</td>
381
+ <td>3.8</td>
382
+ <td>4190</td>
383
+ <td>4.2</td>
384
+ <td>4573</td>
385
+ </tr>
386
+ </tbody>
387
+ </table>