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.5-VL-72B-Instruct-quantized.w8a8",
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("==========================================")1import base64
2from io import BytesIO
3import torch
4from datasets import load_dataset
5from qwen_vl_utils import process_vision_info
6from transformers import AutoProcessor
7from llmcompressor.modifiers.quantization import GPTQModifier
8from llmcompressor.transformers import oneshot
9from llmcompressor.transformers.tracing import (
10 TraceableQwen2_5_VLForConditionalGeneration,
11)
12
13# Load model.
14model_id = "Qwen/Qwen2.5-VL-72B-Instruct"
15model = TraceableQwen2_5_VLForConditionalGeneration.from_pretrained(
16 model_id,
17 device_map="auto",
18 torch_dtype="auto",
19)
20processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
21
22# Oneshot arguments
23DATASET_ID = "lmms-lab/flickr30k"
24DATASET_SPLIT = {"calibration": "test[:512]"}
25NUM_CALIBRATION_SAMPLES = 512
26MAX_SEQUENCE_LENGTH = 2048
27
28# Load dataset and preprocess.
29ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
30ds = ds.shuffle(seed=42)
31
32dampening_frac=0.01
33
34# Apply chat template and tokenize inputs.
35def preprocess_and_tokenize(example):
36 # preprocess
37 buffered = BytesIO()
38 example["image"].save(buffered, format="PNG")
39 encoded_image = base64.b64encode(buffered.getvalue())
40 encoded_image_text = encoded_image.decode("utf-8")
41 base64_qwen = f"data:image;base64,{encoded_image_text}"
42 messages = [
43 {
44 "role": "user",
45 "content": [
46 {"type": "image", "image": base64_qwen},
47 {"type": "text", "text": "What does the image show?"},
48 ],
49 }
50 ]
51 text = processor.apply_chat_template(
52 messages, tokenize=False, add_generation_prompt=True
53 )
54 image_inputs, video_inputs = process_vision_info(messages)
55
56 # tokenize
57 return processor(
58 text=[text],
59 images=image_inputs,
60 videos=video_inputs,
61 padding=False,
62 max_length=MAX_SEQUENCE_LENGTH,
63 truncation=True,
64 )
65
66ds = ds.map(preprocess_and_tokenize, remove_columns=ds["calibration"].column_names)
67
68# Define a oneshot data collator for multimodal inputs.
69def data_collator(batch):
70 assert len(batch) == 1
71 return {key: torch.tensor(value) for key, value in batch[0].items()}
72
73
74# Recipe
75recipe = [
76 GPTQModifier(
77 targets="Linear",
78 scheme="W8A8",
79 sequential_targets=["Qwen2_5_VLDecoderLayer"],
80 ignore=["lm_head", "re:visual.*"],
81 ),
82]
83
84SAVE_DIR==f"{model_id.split('/')[1]}-quantized.w8a8"
85
86# Perform oneshot
87oneshot(
88 model=model,
89 tokenizer=model_id,
90 dataset=ds,
91 recipe=recipe,
92 max_seq_length=MAX_SEQUENCE_LENGTH,
93 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
94 trust_remote_code_model=True,
95 data_collator=data_collator,
96 output_dir=SAVE_DIR
97)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.5-VL-72B-Instruct | neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w8a8 | Recovery (%) |
|---|---|---|---|---|
| Vision | MMMU (val, CoT) explicit_prompt_relaxed_correctness | 64.33 | 67.56 | 105.02% |
| VQAv2 (val) vqa_match | 81.94 | 81.91 | 99.96% | |
| DocVQA (val) anls | 94.71 | 94.71 | 100.00% | |
| ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness | 88.96 | 89.40 | 100.49% | |
| Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness | 78.18 | 78.38 | 100.26% | |
| Average Score | 81.62 | 82.00 | 100.46% | |
| Text | MGSM (CoT) | 75.45 | 74.29 | 98.46% |
| MMLU (5-shot) | 86.16 | 85.65 | 99.41% |
| 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) | Queries Per Dollar | Latency (s)th> | Queries Per Dollar | Latency (s) | Queries Per Dollar |
| A100 | 4 | Qwen/Qwen2.5-VL-72B-Instruct | 6.4 | 78 | 4.5 | 111 | 4.4 | 113 | |
| 2 | neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w8a8 | 1.85 | 7.0 | 143 | 4.9 | 205 | 4.8 | 211 | |
| 1 | neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w4a16 | 3.33 | 9.4 | 213 | 5.1 | 396 | 4.8 | 420 | |
| H100 | 4 | Qwen/Qwen2.5-VL-72B-Instruct | 4.3 | 68 | 3.0 | 97 | 2.9 | 100 | |
| 2 | neuralmagic/Qwen2.5-VL-72B-Instruct-FP8-Dynamic | 1.79 | 4.6 | 122 | 3.3 | 173 | 3.2 | 177 | |
| 1 | neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w4a16 | 5.66 | 4.3 | 252 | 4.4 | 251 | 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) | Queries Per Dollar | Maximum throughput (QPS) | Queries Per Dollar | Maximum throughput (QPS) | Queries Per Dollar |
| A100x4 | Qwen/Qwen2.5-VL-72B-Instruct | 0.4 | 180 | 1.1 | 539 | 1.2 | 595 | |
| neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w8a8 | 1.80 | 0.6 | 289 | 2.0 | 1020 | 2.3 | 1133 | |
| neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w4a16 | 2.75 | 0.7 | 341 | 3.2 | 1588 | 4.1 | 2037 | |
| H100x4 | Qwen/Qwen2.5-VL-72B-Instruct | 0.5 | 134 | 1.2 | 357 | 1.3 | 379 | |
| neuralmagic/Qwen2.5-VL-72B-Instruct-FP8-Dynamic | 1.73 | 0.9 | 247 | 2.2 | 621 | 2.4 | 669 | |
| neuralmagic/Qwen2.5-VL-72B-Instruct-quantized.w4a16 | 8.27 | 3.3 | 913 | 3.3 | 898 | 3.6 | 991 |