Views
No views yet
1from vllm.assets.image import ImageAsset
2from vllm import LLM, SamplingParams
3
4# prepare model
5llm = LLM(
6 model="neuralmagic/Qwen2-VL-72B-Instruct-quantized.w4a16",
7 trust_remote_code=True,
8 max_model_len=4096,
9 max_num_seqs=2,
10)
11
12# prepare inputs
13question = "What is the content of this image?"
14inputs = {
15 "prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
16 "multi_modal_data": {
17 "image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
18 },
19}
20
21# generate response
22print("========== SAMPLE GENERATION ==============")
23outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
24print(f"PROMPT : {outputs[0].prompt}")
25print(f"RESPONSE: {outputs[0].outputs[0].text}")
26print("==========================================")1from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
2
3from llmcompressor.modifiers.quantization import QuantizationModifier
4from llmcompressor.transformers import oneshot, wrap_hf_model_class
5
6MODEL_ID = "Qwen/Qwen2-VL-72B-Instruct"
7
8# Load model.
9model_class = wrap_hf_model_class(Qwen2VLForConditionalGeneration)
10model = model_class.from_pretrained(MODEL_ID, device_map="auto", torch_dtype="auto")
11processor = AutoProcessor.from_pretrained(MODEL_ID)
12
13# Configure the quantization algorithm and scheme.
14# In this case, we:
15# * quantize the weights to fp8 with per channel via ptq
16# * quantize the activations to fp8 with dynamic per token
17recipe = QuantizationModifier(
18 targets="Linear",
19 scheme="FP8_DYNAMIC",
20 ignore=["re:.*lm_head", "re:visual.*"],
21)
22
23# Apply quantization and save to disk in compressed-tensors format.
24SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-dynamic"
25oneshot(model=model, recipe=recipe, output_dir=SAVE_DIR)
26processor.save_pretrained(SAVE_DIR)
27
28# Confirm generations of the quantized model look sane.
29print("========== SAMPLE GENERATION ==============")
30input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
31output = model.generate(input_ids, max_new_tokens=20)
32print(processor.decode(output[0]))
33print("==========================================")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 <vision_task_name>lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=<n>,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
--tasks mmlu \
--num_fewshot 5 \
--batch_size auto \
--output_path output_dir
lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,max_model_len=4096,max_gen_toks=2048,max_num_seqs=128,tensor_parallel_size=<n>,gpu_memory_utilization=0.9 \
--tasks mgsm_cot_native \
--apply_chat_template \
--num_fewshot 0 \
--batch_size auto \
--output_path output_dir
| 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 |