1from vllm.assets.image import ImageAsset
2from vllm import LLM, SamplingParams
3
4# prepare model
5llm = LLM(
6 model="neuralmagic/Pixtral-Large-Instruct-2411-hf-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 requests
2import torch
3from PIL import Image
4from transformers import AutoProcessor
5from llmcompressor.modifiers.quantization import GPTQModifier
6from llmcompressor.transformers import oneshot
7from llmcompressor.transformers.tracing import TraceableLlavaForConditionalGeneration
8
9# Load model.
10model_id = "neuralmagic/Pixtral-Large-Instruct-2411-hf"
11model = TraceableLlavaForConditionalGeneration.from_pretrained(
12 model_id, device_map="auto", torch_dtype="auto"
13)
14processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
15
16# Oneshot arguments
17DATASET_ID = "flickr30k"
18DATASET_SPLIT = {"calibration": "test[:512]"}
19NUM_CALIBRATION_SAMPLES = 512
20MAX_SEQUENCE_LENGTH = 2048
21
22
23# Define a oneshot data collator for multimodal inputs.
24def data_collator(batch):
25 assert len(batch) == 1
26 return {
27 "input_ids": torch.LongTensor(batch[0]["input_ids"]),
28 "attention_mask": torch.tensor(batch[0]["attention_mask"]),
29 "pixel_values": torch.tensor(batch[0]["pixel_values"]),
30 }
31
32
33# Recipe
34recipe = [
35 GPTQModifier(
36 targets="Linear",
37 scheme="W8A8",
38 sequential_targets=["MistralDecoderLayer"],
39 ignore=["re:.*lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
40 ),
41]
42
43SAVE_DIR==f"{model_id.split('/')[1]}-quantized.w8a8"
44
45# Perform oneshot
46oneshot(
47 model=model,
48 tokenizer=model_id,
49 dataset=DATASET_ID,
50 splits=DATASET_SPLIT,
51 recipe=recipe,
52 max_seq_length=MAX_SEQUENCE_LENGTH,
53 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
54 trust_remote_code_model=True,
55 data_collator=data_collator,
56 output_dir=SAVE_DIR
57)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 | neuralmagic/Pixtral-Large-Instruct-2411-hf | neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w8a8 | Recovery (%) |
|---|---|---|---|---|
| Vision | MMMU (val, CoT) explicit_prompt_relaxed_correctness | 63.56 | 63.89 | 100.52% |
| VQAv2 (val) vqa_match | 79.03 | 79.12 | 100.11% | |
| DocVQA (val) anls | 89.55 | 89.80 | 100.28% | |
| ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness | 82.24 | 80.44 | 97.81% | |
| Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness | 67.3 | 66.50 | 98.81% | |
| Average Score | 76.34 | 75.95 | 99.49% | |
| Text | MGSM (CoT) | 76.05 | 74.76 | 98.30% |
| MMLU (5-shot) | 82.8 | 82.9 | 100.12% |
| 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) | Queries Per Dollar | Latency (s) | Queries Per Dollar |
| A100 | 4 | neuralmagic/Pixtral-Large-Instruct-2411-hf | 7.5 | 67 | 6.5 | 77 | 6.4 | 79 | |
| 2 | neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w8a8 | 1.86 | 8.1 | 124 | 7.1 | 142 | 6.8 | 148 | |
| 2 | neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w4a16 | 2.52 | 6.9 | 147 | 5.1 | 199 | 4.5 | 221 | |
| H100 | 4 | neuralmagic/Pixtral-Large-Instruct-2411-hf | 4.4 | 67 | 3.9 | 74 | 3.7 | 79 | |
| 2 | neuralmagic/Pixtral-Large-Instruct-2411-hf-FP8-Dynamic | 1.82 | 4.7 | 120 | 4.1 | 137 | 3.9 | 145 | |
| 2 | neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w4a16 | 1.87 | 4.7 | 120 | 3.9 | 144 | 3.8 | 149 |
| 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 | neuralmagic/Pixtral-Large-Instruct-2411-hf | 0.4 | 222 | 0.7 | 341 | 0.8 | 399 | |
| neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w8a8 | 1.70 | 0.8 | 383 | 1.1 | 571 | 1.3 | 674 | |
| neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w4a16 | 1.48 | 0.5 | 276 | 1.0 | 505 | 1.4 | 680 | |
| H100x4 | neuralmagic/Pixtral-Large-Instruct-2411-hf | 1.0 | 284 | 1.6 | 465 | 1.8 | 511 | |
| neuralmagic/Pixtral-Large-Instruct-2411-hf-FP8-Dynamic | 1.61 | 1.7 | 467 | 2.6 | 726 | 3.2 | 908 | |
| neuralmagic/Pixtral-Large-Instruct-2411-hf-quantized.w4a16 | 1.33 | 1.4 | 393 | 2.2 | 726 | 2.7 | 764 |