Views
No views yet
vllm serve RedHatAI/Qwen3-VL-32B-Instruct-NVFP4 --tensor_parallel_size 21from openai import OpenAI
2
3# Modify OpenAI's API key and API base to use vLLM's API server.
4openai_api_key = "EMPTY"
5openai_api_base = "http://<your-server-host>:8000/v1"
6
7client = OpenAI(
8 api_key=openai_api_key,
9 base_url=openai_api_base,
10)
11
12model = "RedHatAI/Qwen3-VL-32B-Instruct-NVFP4"
13
14messages = [
15 {
16 "role": "user",
17 "content": [
18 {
19 "type": "image_url",
20 "image_url": {"url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"},
21 },
22 {"type": "text", "text": "Describe this image."},
23 ],
24 }
25]
26
27outputs = client.chat.completions.create(
28 model=model,
29 messages=messages,
30)
31
32generated_text = outputs.choices[0].message.content
33print(generated_text)1import torch
2from datasets import load_dataset
3from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
4
5from llmcompressor import oneshot
6from llmcompressor.modifiers.quantization import QuantizationModifier
7from llmcompressor.utils import dispatch_for_generation
8
9MODEL_ID = "Qwen/Qwen3-VL-32B-Instruct"
10
11# Load model.
12model = Qwen3VLForConditionalGeneration.from_pretrained(MODEL_ID, torch_dtype="auto")
13processor = AutoProcessor.from_pretrained(MODEL_ID)
14
15DATASET_ID = "neuralmagic/calibration"
16NUM_CALIBRATION_SAMPLES = 20
17MAX_SEQUENCE_LENGTH = 8192
18
19ds = load_dataset(DATASET_ID, name="LLM", split=f"train[:{NUM_CALIBRATION_SAMPLES}]")
20
21
22def preprocess_function(example):
23 messgages = []
24 for message in example["messages"]:
25 messgages.append(
26 {
27 "role": message["role"],
28 "content": [{"type": "text", "text": message["content"]}],
29 }
30 )
31
32 return processor.apply_chat_template(
33 messgages,
34 return_tensors="pt",
35 padding=False,
36 truncation=True,
37 max_length=MAX_SEQUENCE_LENGTH,
38 tokenize=True,
39 add_special_tokens=False,
40 return_dict=True,
41 add_generation_prompt=False,
42 )
43
44
45ds = ds.map(preprocess_function, batched=False, remove_columns=ds.column_names)
46
47
48def data_collator(batch):
49 assert len(batch) == 1
50 return {
51 key: (
52 torch.tensor(value)
53 if key != "pixel_values"
54 else torch.tensor(value, dtype=torch.bfloat16).squeeze(0)
55 )
56 for key, value in batch[0].items()
57 }
58
59
60# Configure the quantization algorithm and scheme.
61# In this case, we:
62# * quantize the weights to fp4 with group-wise quantization
63# * quantize the activations to fp4 with dynamic group activations
64recipe = QuantizationModifier(
65 targets="Linear",
66 scheme="NVFP4",
67 ignore=[
68 "re:.*lm_head",
69 "re:visual.*",
70 "re:model.visual.*",
71 "re:.*mlp.gate$",
72 ],
73)
74
75# Apply quantization.
76oneshot(
77 model=model,
78 recipe=recipe,
79 max_seq_length=MAX_SEQUENCE_LENGTH,
80 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
81 dataset=ds,
82 data_collator=data_collator,
83)
84
85print("========== SAMPLE GENERATION ==============")
86dispatch_for_generation(model)
87input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
88output = model.generate(input_ids, max_new_tokens=20)
89print(processor.decode(output[0]))
90print("==========================================")
91
92
93# Save to disk in compressed-tensors format.
94SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
95model.save_pretrained(SAVE_DIR)
96processor.save_pretrained(SAVE_DIR)lm_eval \
--model vllm-vlm \
--model_args pretrained="RedHatAI/Qwen3-VL-32B-Instruct-NVFP4",dtype=auto,add_bos_token=False,max_model_len=262144,tensor_parallel_size=2,gpu_memory_utilization=0.9,enable_chunked_prefill=True,trust_remote_code=True,max_images=10 \
--tasks chartqa \
--apply_chat_template \
--batch_size autolm_eval \
--model vllm-vlm \
--model_args pretrained="RedHatAI/Qwen3-VL-32B-Instruct-NVFP4",dtype=auto,add_bos_token=False,max_model_len=262144,tensor_parallel_size=2,gpu_memory_utilization=0.9,enable_chunked_prefill=True,trust_remote_code=True,max_images=10 \
--tasks mmlu \
--apply_chat_template \
--batch_size auto| Model | Accuracy | Recovery (%) |
|---|---|---|
| Qwen/Qwen3-VL-32B-Instruct | 61.52 | 100.00 |
| Qwen/Qwen3-VL-32B-Instruct-FP8 | 86.92 | 141.32 |
| RedHatAI/Qwen3-VL-32B-Instruct-FP8-block | 86.60 | 140.82 |
| RedHatAI/Qwen3-VL-32B-Instruct-FP8-dynamic | 86.68 | 140.95 |
| RedHatAI/Qwen3-VL-32B-Instruct-NVFP4 | 86.56 | 140.7 |
| Model | Accuracy | Recovery (%) |
|---|---|---|
| Qwen/Qwen3-VL-32B-Instruct | 78.03 | 100.00 |
| Qwen/Qwen3-VL-32B-Instruct-FP8 | 77.80 | 99.71 |
| RedHatAI/Qwen3-VL-32B-Instruct-FP8-block | 77.72 | 99.60 |
| RedHatAI/Qwen3-VL-32B-Instruct-FP8-dynamic | 77.89 | 99.82 |
| RedHatAI/Qwen3-VL-32B-Instruct-NVFP4 | 76.27 | 97.74 |