Views
No views yet
1from vllm.assets.image import ImageAsset
2from vllm import LLM, SamplingParams
3
4# prepare model
5llm = LLM(
6 model="neuralmagic/pixtral-12b-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("==========================================")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
8from compressed_tensors.quantization import QuantizationArgs, QuantizationType, QuantizationStrategy, ActivationOrdering, QuantizationScheme
9
10# Load model.
11model_id = "mgoin/pixtral-12b"
12model = TraceableLlavaForConditionalGeneration.from_pretrained(
13 model_id, device_map="auto", torch_dtype="auto"
14)
15processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
16
17# Oneshot arguments
18DATASET_ID = "flickr30k"
19DATASET_SPLIT = {"calibration": "test[:512]"}
20NUM_CALIBRATION_SAMPLES = 512
21MAX_SEQUENCE_LENGTH = 2048
22dampening_frac=0.01
23
24# Define a oneshot data collator for multimodal inputs.
25def data_collator(batch):
26 assert len(batch) == 1
27 return {
28 "input_ids": torch.LongTensor(batch[0]["input_ids"]),
29 "attention_mask": torch.tensor(batch[0]["attention_mask"]),
30 "pixel_values": torch.tensor(batch[0]["pixel_values"]),
31 }
32
33recipe = GPTQModifier(
34 targets="Linear",
35 config_groups={
36 "config_group": QuantizationScheme(
37 targets=["Linear"],
38 weights=QuantizationArgs(
39 num_bits=4,
40 type=QuantizationType.INT,
41 strategy=QuantizationStrategy.GROUP,
42 group_size=128,
43 symmetric=True,
44 dynamic=False,
45 actorder=ActivationOrdering.WEIGHT,
46 ),
47 ),
48 },
49 sequential_targets=["MistralDecoderLayer"],
50 ignore=["re:.*lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
51 update_size=NUM_CALIBRATION_SAMPLES,
52 dampening_frac=dampening_frac,
53)
54
55SAVE_DIR = f"{model_id.split('/')[1]}-quantized.w4a16"
56
57# Perform oneshot
58oneshot(
59 model=model,
60 tokenizer=model_id,
61 dataset=DATASET_ID,
62 splits=DATASET_SPLIT,
63 recipe=recipe,
64 max_seq_length=MAX_SEQUENCE_LENGTH,
65 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
66 trust_remote_code_model=True,
67 data_collator=data_collator,
68 output_dir=SAVE_DIR
69)
70vllm 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.w4a16 \
--url http://0.0.0.0:8000 \
--output_dir ~/tmp
--eval_name <vision_task_name>lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/pixtral-12b-quantized.w4a16 ",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 \
python3 codegen/generate.py \
--model neuralmagic/pixtral-12b-quantized.w4a16 \
--bs 16 \
--temperature 0.2 \
--n_samples 50 \
--root "." \
--dataset humanevalpython3 evalplus/sanitize.py \
humaneval/neuralmagic/pixtral-12b-quantized.w4a16_vllm_temp_0.2evalplus.evaluate \
--dataset humaneval \
--samples humaneval/neuralmagic/pixtral-12b-quantized.w4a16_vllm_temp_0.2-sanitized| Category | Metric | mgoin/pixtral-12b | neuralmagic/pixtral-12b-quantized.w4a16 | Recovery (%) |
|---|---|---|---|---|
| Vision | MMMU (val, CoT) explicit_prompt_relaxed_correctness | 48.00 | 44.67 | 93.06% |
| VQAv2 (val) vqa_match | 78.71 | 77.04 | 97.88% | |
| DocVQA (val) anls | 89.47 | 89.02 | 99.50% | |
| ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness | 81.68 | 82.12 | 100.54% | |
| Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness | 56.50 | 54.40 | 96.28% | |
| Average Score | 70.07 | 69.05 | 98.54% | |
| Text | HumanEval pass@1 | 71.40 | 63.80 | 89.37% |
| MMLU (5-shot) | 68.40 | 65.56 | 95.86% |
| 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 | Latency (s) | Queries Per Dollar | Latency (s) | Queries Per Dollar | Latency (s) | Queries Per Dollar | |
| A6000x1 | mgoin/pixtral-12b | 5.7 | 796 | 4.8 | 929 | 4.7 | 964 | ||
| neuralmagic/pixtral-12b-quantized.w8a8 | 1.55 | 3.7 | 1220 | 3.1 | 1437 | 3.0 | 1511 | ||
| neuralmagic/pixtral-12b-quantized.w4a16 | 2.16 | 3.2 | 1417 | 2.1 | 2093 | 1.9 | 2371 | ||
| A100x1 | mgoin/pixtral-12b | 3.0 | 676 | 2.4 | 825 | 2.3 | 859 | ||
| neuralmagic/pixtral-12b-quantized.w8a8 | 1.38 | 2.2 | 904 | 1.7 | 1159 | 1.7 | 1201 | ||
| neuralmagic/pixtral-12b-quantized.w4a16 | 1.83 | 1.8 | 1096 | 1.3 | 1557 | 1.2 | 1702 | ||
| H100x1 | mgoin/pixtral-12b | 1.8 | 595 | 1.5 | 732 | 1.4 | 764 | ||
| neuralmagic/pixtral-12b-FP8-Dynamic | 1.35 | 1.4 | 767 | 1.1 | 1008 | 1.0 | 1056 | ||
| neuralmagic/pixtral-12b-quantized.w4a16 | 1.37 | 1.4 | 787 | 1.1 | 1018 | 1.0 | 1065 |
| 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 |
| A6000x1 | mgoin/pixtral-12b | 0.6 | 2632 | 0.9 | 4108 | 1.1 | 4774 | |
| neuralmagic/pixtral-12b-quantized.w8a8 | 1.50 | 0.9 | 3901 | 1.4 | 6160 | 1.6 | 7292 | |
| neuralmagic/pixtral-12b-quantized.w4a16 | 1.41 | 0.6 | 2890 | 1.3 | 5758 | 1.8 | 8312 | |
| A100x1 | mgoin/pixtral-12b | 1.1 | 2291 | 1.8 | 3670 | 2.1 | 4284 | |
| neuralmagic/pixtral-12b-quantized.w8a8 | 1.38 | 1.5 | 3096 | 2.5 | 5076 | 3.0 | 5965 | |
| neuralmagic/pixtral-12b-quantized.w4a16 | 1.40 | 1.4 | 2728 | 2.6 | 5133 | 3.5 | 6943 | |
| H100x1 | BF16 | 2.6 | 2877 | 4.0 | 4372 | 4.7 | 5095 | |
| neuralmagic/pixtral-12b-FP8-Dynamic | 1.33 | 3.4 | 3753 | 5.4 | 5862 | 6.3 | 6917 | |
| neuralmagic/pixtral-12b-quantized.w4a16 | 1.22 | 2.8 | 3115 | 5.0 | 5511 | 6.2 | 6777 |