Views
No views yet
vllm serve RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w8a8 --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-Next-80B-A3B-Instruct-quantized.w8a8"
13
14messages = [
15 {"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
16]
17
18
19outputs = client.chat.completions.create(
20 model=model,
21 messages=messages,
22)
23
24generated_text = outputs.choices[0].message.content
25print(generated_text)1from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.quantization import QuantizationModifier
6from llmcompressor.utils import dispatch_for_generation
7
8# NOTE: Requires a minimum of transformers 4.57.0
9
10MODEL_ID = "Qwen/Qwen3-Next-80B-A3B-Instruct"
11
12
13# Select calibration dataset.
14DATASET_ID = "garage-bAInd/Open-Platypus"
15DATASET_SPLIT = "train"
16
17# Select number of samples. 512 samples is a good place to start.
18# Increasing the number of samples can improve accuracy.
19NUM_CALIBRATION_SAMPLES = 1024
20MAX_SEQUENCE_LENGTH = 8192
21
22# Load model.
23model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
24tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
25
26# Configure the quantization algorithm and scheme.
27# In this case, we:
28# * quantize the weights to int8 with per channel via ptq
29# * quantize the activations to int8 with dynamic per token
30recipe = QuantizationModifier(
31 targets="Linear", scheme="W8A8", ignore=[
32 "lm_head",
33 "re:.*mlp.gate$",
34 "re:.*mlp.shared_expert_gate$",
35 "re:.*linear_attn.*",
36 ],
37)
38
39# Load calibration dataset.
40ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
41ds = ds.shuffle(seed=42)
42
43def preprocess(example):
44 messages = [
45 {"role": "user", "content": example["instruction"]},
46 {"role": "assistant", "content": example["output"]},
47 ]
48 return {
49 "text": tokenizer.apply_chat_template(
50 messages,
51 tokenize=False,
52 )
53 }
54
55ds = ds.map(preprocess)
56
57def tokenize(sample):
58 return tokenizer(
59 sample["text"],
60 padding=False,
61 max_length=MAX_SEQUENCE_LENGTH,
62 truncation=True,
63 add_special_tokens=False,
64 )
65
66ds = ds.map(tokenize, remove_columns=ds.column_names)
67
68# Apply quantization.
69oneshot(
70 model=model,
71 dataset=ds,
72 recipe=recipe,
73 max_seq_length=MAX_SEQUENCE_LENGTH,
74 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
75)
76
77# Confirm generations of the quantized model look sane.
78print("========== SAMPLE GENERATION ==============")
79dispatch_for_generation(model)
80input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
81 model.device
82)
83output = model.generate(input_ids, max_new_tokens=20)
84print(tokenizer.decode(output[0]))
85print("==========================================")
86
87# Save to disk in compressed-tensors format.
88SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-quantized.w8a8"
89model.save_pretrained(SAVE_DIR)
90tokenizer.save_pretrained(SAVE_DIR)vllm serve RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w8a8 --tensor_parallel_size 21lm_eval --model local-chat-completions \
2 --tasks mmlu_pro_chat \
3 --model_args "model=RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w8a8,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,timeout=600,tokenizer_backend=None" \
4 --apply_chat_template \
5 --num_fewshot 5 \
6 --fewshot_as_multiturn \
7 --output_path mmlu_pro_qwen3_next_w8a8 \
8 --gen_kwargs "do_sample=True,temperature=0.7,top_p=0.8,top_k=20,max_gen_toks=16000"1lm_eval --model local-chat-completions \
2 --tasks ifeval \
3 --model_args "model=RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w8a8,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,timeout=600,tokenizer_backend=None" \
4 --apply_chat_template \
5 --output_path ifeval_qwen3_next_w8a8 \
6 --gen_kwargs "do_sample=True,temperature=0.7,top_p=0.8,top_k=20,max_gen_toks=16000"1lm_eval --model local-chat-completions \
2 --tasks gsm8k \
3 --model_args "model=RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w8a8,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,timeout=600,tokenizer_backend=None" \
4 --apply_chat_template \
5 --num_fewshot 5 \
6 --fewshot_as_multiturn \
7 --output_path gsm8k_qwen3_next_w8a8 \
8 --gen_kwargs "do_sample=True,temperature=0.7,top_p=0.8,top_k=20,max_gen_toks=16000"1model_parameters:
2 provider: "hosted_vllm"
3 model_name: "hosted_vllm/RedHatAI/Phi-4-reasoning-FP8-dynamic"
4 base_url: "http://0.0.0.0:8000/v1"
5 api_key: ""
6 timeout: 600
7 concurrent_requests: 128
8 generation_parameters:
9 temperature: 0.7
10 top_k: 20
11 top_p: 0.8
12 max_new_tokens: 160001lighteval endpoint litellm litellm_config.yaml \
2 gpqa:diamond|0,math_500|0,aime25|0 \
3 --output-dir qwen3_next_w8a8 \
4 --save-details| Benchmark | Qwen3-Next-80B-A3B-Instruct | Qwen3-Next-80B-A3B-Instruct-quantized.w8a8 (this model) | Recovery |
| AIME25 | 62.78 | 65.00 | 103.5% |
| GPQA Diamond | 74.58 | 75.17 | 100.8% |
| Math 500 | 89.73 | 90.57 | 100.9% |
| MMLU-Pro | 78.62 | 78.85 | 100.3% |
| IFEval | 91.45 | 91.51 | 100.1% |
| GSM8k | 69.71 | 69.74 | 100.0% |