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
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-3B-Instruct
12
+ library_name: transformers
13
+ ---
14
+
15
+ # Qwen2.5-VL-3B-Instruct-quantized-w8a8
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Qwen/Qwen2.5-VL-3B-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-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct).
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights of [Qwen/Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-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-3B-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 = args["model_id"]
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=args["dampening_frac"]
111
+
112
+ save_name = f"{model_id.split('/')[1]}-W8A8-samples{NUM_CALIBRATION_SAMPLES}-df{dampening_frac}"
113
+ save_path = os.path.join(args["save_dir"], save_name)
114
+
115
+ print("Save Path will be:", save_path)
116
+
117
+ # Apply chat template and tokenize inputs.
118
+ def preprocess_and_tokenize(example):
119
+ # preprocess
120
+ buffered = BytesIO()
121
+ example["image"].save(buffered, format="PNG")
122
+ encoded_image = base64.b64encode(buffered.getvalue())
123
+ encoded_image_text = encoded_image.decode("utf-8")
124
+ base64_qwen = f"data:image;base64,{encoded_image_text}"
125
+ messages = [
126
+ {
127
+ "role": "user",
128
+ "content": [
129
+ {"type": "image", "image": base64_qwen},
130
+ {"type": "text", "text": "What does the image show?"},
131
+ ],
132
+ }
133
+ ]
134
+ text = processor.apply_chat_template(
135
+ messages, tokenize=False, add_generation_prompt=True
136
+ )
137
+ image_inputs, video_inputs = process_vision_info(messages)
138
+
139
+ # tokenize
140
+ return processor(
141
+ text=[text],
142
+ images=image_inputs,
143
+ videos=video_inputs,
144
+ padding=False,
145
+ max_length=MAX_SEQUENCE_LENGTH,
146
+ truncation=True,
147
+ )
148
+
149
+ ds = ds.map(preprocess_and_tokenize, remove_columns=ds["calibration"].column_names)
150
+
151
+ # Define a oneshot data collator for multimodal inputs.
152
+ def data_collator(batch):
153
+ assert len(batch) == 1
154
+ return {key: torch.tensor(value) for key, value in batch[0].items()}
155
+
156
+
157
+ # Recipe
158
+ recipe = [
159
+ GPTQModifier(
160
+ targets="Linear",
161
+ scheme="W8A8",
162
+ sequential_targets=["Qwen2_5_VLDecoderLayer"],
163
+ ignore=["lm_head", "re:visual.*"],
164
+ ),
165
+ ]
166
+
167
+ SAVE_DIR==f"{model_id.split('/')[1]}-quantized.w8a8"
168
+
169
+ # Perform oneshot
170
+ oneshot(
171
+ model=model,
172
+ tokenizer=model_id,
173
+ dataset=ds,
174
+ recipe=recipe,
175
+ max_seq_length=MAX_SEQUENCE_LENGTH,
176
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
177
+ trust_remote_code_model=True,
178
+ data_collator=data_collator,
179
+ output_dir=SAVE_DIR
180
+ )
181
+ ```
182
+ </details>
183
+
184
+ ## Evaluation
185
+
186
+ 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:
187
+
188
+ <details>
189
+ <summary>Evaluation Commands</summary>
190
+
191
+ ```
192
+ ```
193
+
194
+ </details>
195
+
196
+ ### Accuracy
197
+
198
+ ## Inference Performance
199
+
200
+
201
+ 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.
202
+ 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).
203
+
204
+ <details>
205
+ <summary>Benchmarking Command</summary>
206
+ ```
207
+ guidellm --model neuralmagic/Qwen2.5-VL-3B-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
208
+ ```
209
+
210
+ </details>
211
+
212
+ ### Single-stream performance (measured with vLLM version 0.7.2)
213
+
214
+ <table border="1" class="dataframe">
215
+ <thead>
216
+ <tr>
217
+ <th></th>
218
+ <th></th>
219
+ <th></th>
220
+ <th style="text-align: center;" colspan="2" >Document Visual Question Answering<br>1680W x 2240H<br>64/128</th>
221
+ <th style="text-align: center;" colspan="2" >Visual Reasoning <br>640W x 480H<br>128/128</th>
222
+ <th style="text-align: center;" colspan="2" >Image Captioning<br>480W x 360H<br>0/128</th>
223
+ </tr>
224
+ <tr>
225
+ <th>Hardware</th>
226
+ <th>Model</th>
227
+ <th>Average Cost Reduction</th>
228
+ <th>Latency (s)</th>
229
+ <th>QPD</th>
230
+ <th>Latency (s)th>
231
+ <th>QPD</th>
232
+ <th>Latency (s)</th>
233
+ <th>QPD</th>
234
+ </tr>
235
+ </thead>
236
+ <tbody style="text-align: center">
237
+ <tr>
238
+ <th rowspan="3" valign="top">A6000x1</th>
239
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
240
+ <td></td>
241
+ <td>3.1</td>
242
+ <td>1454</td>
243
+ <td>1.8</td>
244
+ <td>2546</td>
245
+ <td>1.7</td>
246
+ <td>2610</td>
247
+ </tr>
248
+ <tr>
249
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8</th>
250
+ <td>1.27</td>
251
+ <td>2.6</td>
252
+ <td>1708</td>
253
+ <td>1.3</td>
254
+ <td>3340</td>
255
+ <td>1.3</td>
256
+ <td>3459</td>
257
+ </tr>
258
+ <tr>
259
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
260
+ <td>1.57</td>
261
+ <td>2.4</td>
262
+ <td>1886</td>
263
+ <td>1.0</td>
264
+ <td>4409</td>
265
+ <td>1.0</td>
266
+ <td>4409</td>
267
+ </tr>
268
+ <tr>
269
+ <th rowspan="3" valign="top">A100x1</th>
270
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
271
+ <td></td>
272
+ <td>2.2</td>
273
+ <td>920</td>
274
+ <td>1.3</td>
275
+ <td>1603</td>
276
+ <td>1.2</td>
277
+ <td>1636</td>
278
+ </tr>
279
+ <tr>
280
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8</th>
281
+ <td>1.09</td>
282
+ <td>2.1</td>
283
+ <td>975</td>
284
+ <td>1.2</td>
285
+ <td>1743</td>
286
+ <td>1.1</td>
287
+ <td>1814</td>
288
+ </tr>
289
+ <tr>
290
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
291
+ <td>1.20</td>
292
+ <td>2.0</td>
293
+ <td>1011</td>
294
+ <td>1.0</td>
295
+ <td>2015</td>
296
+ <td>1.0</td>
297
+ <td>2012</td>
298
+ </tr>
299
+ <tr>
300
+ <th rowspan="3" valign="top">H100x1</th>
301
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
302
+ <td>1.5</td>
303
+ <td>740</td>
304
+ <td>0.9</td>
305
+ <td>1221</td>
306
+ <td>0.9</td>
307
+ <td>1276</td>
308
+ </tr>
309
+ <tr>
310
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-FP8-Dynamic</th>
311
+ <td>1.06</td>
312
+ <td>1.4</td>
313
+ <td>768</td>
314
+ <td>0.9</td>
315
+ <td>1276</td>
316
+ <td>0.8</td>
317
+ <td>1399</td>
318
+ </tr>
319
+ <tr>
320
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
321
+ <td>1.24</td>
322
+ <td>0.9</td>
323
+ <td>1219</td>
324
+ <td>0.9</td>
325
+ <td>1270</td>
326
+ <td>0.8</td>
327
+ <td>1304</td>
328
+ </tr>
329
+ </tbody>
330
+ </table>
331
+
332
+
333
+
334
+ ### Multi-stream asynchronous performance (measured with vLLM version 0.7.2)
335
+
336
+ <table border="1" class="dataframe">
337
+ <thead>
338
+ <tr>
339
+ <th></th>
340
+ <th></th>
341
+ <th></th>
342
+ <th style="text-align: center;" colspan="2" >Document Visual Question Answering<br>1680W x 2240H<br>64/128</th>
343
+ <th style="text-align: center;" colspan="2" >Visual Reasoning <br>640W x 480H<br>128/128</th>
344
+ <th style="text-align: center;" colspan="2" >Image Captioning<br>480W x 360H<br>0/128</th>
345
+ </tr>
346
+ <tr>
347
+ <th>Hardware</th>
348
+ <th>Model</th>
349
+ <th>Average Cost Reduction</th>
350
+ <th>Maximum throughput (QPS)</th>
351
+ <th>QPD</th>
352
+ <th>Maximum throughput (QPS)</th>
353
+ <th>QPD</th>
354
+ <th>Maximum throughput (QPS)</th>
355
+ <th>QPD</th>
356
+ </tr>
357
+ </thead>
358
+ <tbody style="text-align: center">
359
+ <tr>
360
+ <th rowspan="3" valign="top">A6000x1</th>
361
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
362
+ <td></td>
363
+ <td>0.5</td>
364
+ <td>2405</td>
365
+ <td>2.6</td>
366
+ <td>11889</td>
367
+ <td>2.9</td>
368
+ <td>12909</td>
369
+ </tr>
370
+ <tr>
371
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8</th>
372
+ <td>1.26</td>
373
+ <td>0.6</td>
374
+ <td>2725</td>
375
+ <td>3.4</td>
376
+ <td>15162</td>
377
+ <td>3.9</td>
378
+ <td>17673</td>
379
+ </tr>
380
+ <tr>
381
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
382
+ <td>1.39</td>
383
+ <td>0.6</td>
384
+ <td>2548</td>
385
+ <td>3.9</td>
386
+ <td>17437</td>
387
+ <td>4.7</td>
388
+ <td>21223</td>
389
+ </tr>
390
+ <tr>
391
+ <th rowspan="3" valign="top">A100x1</th>
392
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
393
+ <td></td>
394
+ <td>0.8</td>
395
+ <td>1663</td>
396
+ <td>3.9</td>
397
+ <td>7899</td>
398
+ <td>4.4</td>
399
+ <td>8924</td>
400
+ </tr>
401
+ <tr>
402
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8</th>
403
+ <td>1.06</td>
404
+ <td>0.9</td>
405
+ <td>1734</td>
406
+ <td>4.2</td>
407
+ <td>8488</td>
408
+ <td>4.7</td>
409
+ <td>9548</td>
410
+ </tr>
411
+ <tr>
412
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
413
+ <td>1.10</td>
414
+ <td>0.9</td>
415
+ <td>1775</td>
416
+ <td>4.2</td>
417
+ <td>8540</td>
418
+ <td>5.1</td>
419
+ <td>10318</td>
420
+ </tr>
421
+ <tr>
422
+ <th rowspan="3" valign="top">H100x1</th>
423
+ <th>Qwen/Qwen2.5-VL-3B-Instruct</th>
424
+ <td></td>
425
+ <td>1.1</td>
426
+ <td>1188</td>
427
+ <td>4.3</td>
428
+ <td>4656</td>
429
+ <td>4.3</td>
430
+ <td>4676</td>
431
+ </tr>
432
+ <tr>
433
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-FP8-Dynamic</th>
434
+ <td>1.15</td>
435
+ <td>1.4</td>
436
+ <td>1570</td>
437
+ <td>4.3</td>
438
+ <td>4676</td>
439
+ <td>4.8</td>
440
+ <td>5220</td>
441
+ </tr>
442
+ <tr>
443
+ <th>neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16</th>
444
+ <td>1.96</td>
445
+ <td>4.2</td>
446
+ <td>4598</td>
447
+ <td>4.1</td>
448
+ <td>4505</td>
449
+ <td>4.4</td>
450
+ <td>4838</td>
451
+ </tr>
452
+ </tbody>
453
+ </table>