---
tags:
- vllm
- vision
- w4a16
license: apache-2.0
license_link: >-
https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md
language:
- en
base_model: Qwen/Qwen2-VL-72B-Instruct
library_name: transformers
---
# Qwen2-VL-72B-Instruct-quantized-w4a16
## Model Overview
- **Model Architecture:** Qwen/Qwen2-VL-72B-Instruct
- **Input:** Vision-Text
- **Output:** Text
- **Model Optimizations:**
- **Weight quantization:** FP8
- **Activation quantization:** FP8
- **Release Date:** 2/24/2025
- **Version:** 1.0
- **Model Developers:** Neural Magic
Quantized version of [Qwen/Qwen2-VL-72B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct).
### Model Optimizations
This model was obtained by quantizing the weights of [Qwen/Qwen2-VL-72B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct) to FP8 data type, ready for inference with vLLM >= 0.5.2.
## Deployment
### Use with vLLM
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
```python
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams
# prepare model
llm = LLM(
model="neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16",
trust_remote_code=True,
max_model_len=4096,
max_num_seqs=2,
)
# prepare inputs
question = "What is the content of this image?"
inputs = {
"prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
"multi_modal_data": {
"image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
},
}
# generate response
print("========== SAMPLE GENERATION ==============")
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print(f"PROMPT : {outputs[0].prompt}")
print(f"RESPONSE: {outputs[0].outputs[0].text}")
print("==========================================")
```
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
## Creation
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.
Model Creation Code
```python
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.transformers import oneshot, wrap_hf_model_class
MODEL_ID = "Qwen/Qwen2-VL-72B-Instruct"
# Load model.
model_class = wrap_hf_model_class(Qwen2VLForConditionalGeneration)
model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
processor = AutoProcessor.from_pretrained(MODEL_ID)
# Configure the quantization algorithm and scheme.
# In this case, we:
# * quantize the weights to fp8 with per channel via ptq
# * quantize the activations to fp8 with dynamic per token
recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_DYNAMIC",
ignore=["re:.*lm_head", "re:visual.*"],
)
# Apply quantization and save to disk in compressed-tensors format.
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-dynamic"
oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
processor.save_pretrained(SAVE_DIR)
# Confirm generations of the quantized model look sane.
print("========== SAMPLE GENERATION ==============")
input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
output = model.generate(input_ids, max_new_tokens=20)
print(processor.decode(output[0]))
print("==========================================")
```
Evaluation Commands
### Vision Tasks
- vqav2
- docvqa
- mathvista
- mmmu
- chartqa
```
vllm serve neuralmagic/pixtral-12b-quantized.w8a8 --tensor_parallel_size 1 --max_model_len 25000 --trust_remote_code --max_num_seqs 8 --gpu_memory_utilization 0.9 --dtype float16 --limit_mm_per_prompt image=7
python -m eval.run eval_vllm \
--model_name neuralmagic/pixtral-12b-quantized.w8a8 \
--url http://0.0.0.0:8000 \
--output_dir ~/tmp \
--eval_name
Category | Metric | Qwen/Qwen2-VL-72B-Instruct | neuralmagic/Qwen2-VL-72B-Instruct-FP8-Dynamic | Recovery (%) |
---|---|---|---|---|
Vision | MMMU (val, CoT) explicit_prompt_relaxed_correctness |
62.11 | 60.67 | 97.68% |
VQAv2 (val) vqa_match |
82.51 | 82.44 | 99.91% | |
DocVQA (val) anls |
95.01 | 95.10 | 100.09% | |
ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness |
83.40 | 83.68 | 100.34% | |
Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness |
66.57 | 67.07 | 100.75% | |
Average Score | 77.12 | 77.39 | 100.35% | |
Text | MGSM (CoT) | 68.60 | 67.78 | 98.80% |
MMLU (5-shot) | 82.70 | 82.60 | 99.88% |
Document Visual Question Answering 1680W x 2240H 64/128 |
Visual Reasoning 640W x 480H 128/128 |
Image Captioning 480W x 360H 0/128 |
|||||||
---|---|---|---|---|---|---|---|---|---|
Hardware | Number of GPUs | Model | Average Cost Reduction | Latency (s) | QPD | Latency (s)th> | QPD | Latency (s) | QPD |
A100 | 4 | Qwen/Qwen2-VL-72B-Instruct | 6.5 | 77 | 4.6 | 110 | 4.4 | 113 | |
2 | neuralmagic/Qwen2-VL-72B-Instruct-quantized.w8a8 | 1.85 | 7.2 | 139 | 4.9 | 206 | 4.8 | 211 | |
1 | neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16 | 3.32 | 10.0 | 202 | 5.0 | 398 | 4.8 | 419 | |
H100 | 4 | Qwen/Qwen2-VL-72B-Instruct | 4.4 | 66 | 3.0 | 97 | 2.9 | 99 | |
2 | neuralmagic/Qwen2-VL-72B-Instruct-FP8-Dynamic | 1.79 | 4.7 | 119 | 3.3 | 173 | 3.2 | 177 | |
1 | neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16 | 2.60 | 6.4 | 172 | 4.3 | 253 | 4.2 | 259 |
Document Visual Question Answering 1680W x 2240H 64/128 |
Visual Reasoning 640W x 480H 128/128 |
Image Captioning 480W x 360H 0/128 |
||||||
---|---|---|---|---|---|---|---|---|
Hardware | Model | Average Cost Reduction | Maximum throughput (QPS) | QPD | Maximum throughput (QPS) | QPD | Maximum throughput (QPS) | QPD |
A100x4 | Qwen/Qwen2-VL-72B-Instruct | 0.3 | 169 | 1.1 | 538 | 1.2 | 595 | |
neuralmagic/Qwen2-VL-72B-Instruct-quantized.w8a8 | 1.84 | 0.6 | 293 | 2.0 | 1021 | 2.3 | 1135 | |
neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16 | 2.73 | 0.6 | 314 | 3.2 | 1591 | 4.0 | 2019 | |
H100x4 | Qwen/Qwen2-VL-72B-Instruct | 0.5 | 137 | 1.2 | 356 | 1.3 | 377 | |
neuralmagic/Qwen2-VL-72B-Instruct-FP8-Dynamic | 1.70 | 0.8 | 236 | 2.2 | 623 | 2.4 | 669 | |
neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16 | 2.35 | 1.3 | 350 | 3.3 | 910 | 3.6 | 994 |