Views
No views yet


1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16"
5number_gpus = 1
6sampling_params = SamplingParams(temperature=0.6, top_p=0.95, top_k=20, min_p=0, max_tokens=256)
7
8messages = [
9 {"role": "user", "content": prompt}
10]
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14messages = [{"role": "user", "content": "Give me a short introduction to large language model."}]
15
16prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
17
18llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
19
20outputs = llm.generate(prompts, sampling_params)
21
22generated_text = outputs[0].outputs[0].text
23print(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
7from llmcompressor.modifiers.quantization import GPTQModifier
8
9# NOTE: Requires a minimum of transformers 4.57.0
10
11MODEL_ID = "Qwen/Qwen3-Next-80B-A3B-Thinking"
12
13# Load model.
14model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
15tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
16
17# Select calibration dataset.
18DATASET_ID = "HuggingFaceH4/ultrachat_200k"
19DATASET_SPLIT = "train_sft"
20
21# Select number of samples. 512 samples is a good place to start.
22# Increasing the number of samples can improve accuracy.
23NUM_CALIBRATION_SAMPLES = 512
24MAX_SEQUENCE_LENGTH = 2048
25
26# Load dataset and preprocess.
27ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
28ds = ds.shuffle(seed=42)
29
30
31def preprocess(example):
32 return {
33 "text": tokenizer.apply_chat_template(
34 example["messages"],
35 tokenize=False,
36 )
37 }
38
39
40ds = ds.map(preprocess)
41
42
43# Tokenize inputs.
44def tokenize(sample):
45 return tokenizer(
46 sample["text"],
47 padding=False,
48 max_length=MAX_SEQUENCE_LENGTH,
49 truncation=True,
50 add_special_tokens=False,
51 )
52
53
54ds = ds.map(tokenize, remove_columns=ds.column_names)
55
56# Configure the quantization algorithm to run.
57# * quantize the weights to 4 bit with GPTQ with a group size 128
58recipe = GPTQModifier(targets="Linear", scheme="W4A16",
59 ignore=[
60 "lm_head",
61 "re:.*mlp.gate$",
62 "re:.*mlp.shared_expert_gate$",
63 "re:.*linear_attn.*",
64 ],
65)
66
67# Apply algorithms.
68oneshot(
69 model=model,
70 dataset=ds,
71 recipe=recipe,
72 max_seq_length=MAX_SEQUENCE_LENGTH,
73 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
74)
75
76# Confirm generations of the quantized model look sane.
77print("\n\n")
78print("========== SAMPLE GENERATION ==============")
79dispatch_for_generation(model)
80sample = tokenizer("Describe Large Language Model", return_tensors="pt")
81sample = {key: value.to(model.device) for key, value in sample.items()}
82output = model.generate(**sample, max_new_tokens=100)
83print(tokenizer.decode(output[0]))
84print("==========================================\n\n")
85
86# Save to disk compressed.
87SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-W4A16-G128"
88model.save_pretrained(SAVE_DIR, save_compressed=True)
89tokenizer.save_pretrained(SAVE_DIR)lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=15000,enable_chunk_prefill=True,tensor_parallel_size=1 \
--tasks openllm \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=15000,enable_chunk_prefill=True,tensor_parallel_size=1 \
--tasks mgsm \
--apply_chat_template\
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=15000,enable_chunk_prefill=True,tensor_parallel_size=1 \
--tasks leaderboard \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto1model_parameters:
2 model_name: RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16
3 dtype: auto
4 gpu_memory_utilization: 0.9
5 max_model_length: 40960
6 generation_parameters:
7 temperature: 0.6
8 top_k: 20
9 min_p: 0.0
10 top_p: 0.95
11 max_new_tokens: 32000lighteval vllm \
--model_args lighteval_model_arguments.yaml \
--tasks lighteval|aime25|0|0 \
--use_chat_template = truelighteval vllm \
--model_args lighteval_model_arguments.yaml \
--tasks lighteval|math_500|0|0 \
--use_chat_template = truelighteval vllm \
--model_args lighteval_model_arguments.yaml \
--tasks lighteval|gpqa:diamond|0|0 \
--use_chat_template = truelighteval vllm \
--model_args lighteval_model_arguments.yaml \
--tasks extended|lcb:codegeneration \
--use_chat_template = true| Category | Metric | Qwen/Qwen3-Next-80B-A3B-Instruct | RedHatAI/Qwen3-Next-80B-A3B-Instruct-quantized.w4a16 | Recovery (%) |
|---|---|---|---|---|
| OpenLLM V1 | ARC-Challenge (Acc-Norm, 25-shot) | 73.29 | 72.70 | 99.19 |
| GSM8K (Strict-Match, 5-shot) | 81.58 | 82.18 | 100.74 | |
| HellaSwag (Acc-Norm, 10-shot) | 63.90 | 63.64 | 99.59 | |
| MMLU (Acc, 5-shot) | 85.56 | 85.03 | 99.38 | |
| TruthfulQA (MC2, 0-shot) | 60.70 | 60.63 | 99.88 | |
| Winogrande (Acc, 5-shot) | 78.30 | 78.37 | 100.09 | |
| Average Score | 73.89 | 73.76 | 99.82 | |
| OpenLLM V2 | IFEval (Inst Level Strict Acc, 0-shot) | 77.46 | 80.70 | 104.18 |
| BBH (Acc-Norm, 3-shot) | 67.78 | 67.33 | 99.34 | |
| Math-Hard (Exact-Match, 4-shot) | 56.04 | 55.36 | 98.79 | |
| GPQA (Acc-Norm, 0-shot) | 28.61 | 28.61 | 100.00 | |
| MUSR (Acc-Norm, 0-shot) | 39.68 | 40.08 | 101.01 | |
| MMLU-Pro (Acc, 5-shot) | 76.35 | 75.48 | 98.86 | |
| Average Score | 57.65 | 57.93 | 100.49 |