Views
No views yet
1vllm serve zhnagchenchne/Qwen3.6-27B-GPTQ-W4A16 \
2 --reasoning-parser qwen3 \
3 --max-model-len 262144 \
4 --language-model-only1import torch
2from compressed_tensors.utils import save_mtp_tensors_to_checkpoint
3from datasets import load_dataset
4from transformers import AutoProcessor, Qwen3_5ForConditionalGeneration
5
6from llmcompressor import oneshot
7from llmcompressor.modifiers.quantization import QuantizationModifier
8from llmcompressor.utils import load_context
9from llmcompressor.modifiers.gptq import GPTQModifier
10from transformers import AutoModelForCausalLM, AutoTokenizer
11
12# NOTE: This example requires transformers >= v5
13
14MODEL_ID = "Qwen/Qwen3.6-27B"
15
16# Load model.
17model = Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_ID, dtype="auto")
18processor = AutoProcessor.from_pretrained(MODEL_ID)
19tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
20
21
22# No need to include mtp layers as they are not loaded
23# through Qwen3_5MoeForConditionalGeneration
24#recipe = QuantizationModifier(
25recipe = GPTQModifier(
26 targets="Linear",
27 scheme="W4A16",
28 ignore=[
29 "re:.*lm_head",
30 "re:visual.*",
31 "re:model.visual.*",
32 "re:.*mlp.gate$",
33 "re:.*embed_tokens$",
34 "re:.*shared_expert_gate$",
35 "re:.*linear_attn.in_proj_b",
36 "re:.*linear_attn.in_proj_a",
37 ],
38)
39NUM_CALIBRATION_SAMPLES = 256
40MAX_SEQUENCE_LENGTH = 4096
41
42ds = load_dataset(
43 "HuggingFaceH4/ultrachat_200k",
44 split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]",
45)
46ds = ds.select_columns(["messages"])
47ds = ds.shuffle(seed=42)
48
49def preprocess(example):
50 return {
51 "text": tokenizer.apply_chat_template(
52 example["messages"],
53 tokenize=False,
54 )
55 }
56
57ds = ds.map(preprocess)
58
59# Tokenize inputs.
60def tokenize(sample):
61 return tokenizer(
62 sample["text"],
63 padding=False,
64 max_length=MAX_SEQUENCE_LENGTH,
65 truncation=True,
66 add_special_tokens=False,
67 )
68
69ds = ds.map(tokenize, remove_columns=ds.column_names)
70
71# Apply quantization.
72oneshot(
73 model=model,
74 recipe=recipe,
75 dataset=ds,
76 max_seq_length=MAX_SEQUENCE_LENGTH,
77 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
78)
79
80# Save to disk in compressed-tensors format.
81SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-GPTQ-W4A16"
82model.save_pretrained(SAVE_DIR)
83processor.save_pretrained(SAVE_DIR)
84
85# MTP layers are excluded from the model through Qwen3_5MoeForConditionalGeneration
86# Save them as-is from the original checkpoint into the quantized output.
87save_mtp_tensors_to_checkpoint(source_model=MODEL_ID, dest_dir=SAVE_DIR)lm_eval --model local-chat-completions \
--tasks gsm8k_platinum_cot_llama \
--model_args "model=zhnagchenchne/Qwen3.6-27B-GPTQ-W4A16,max_length=96000,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=100,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=3600" \
--num_fewshot 0 \
--apply_chat_template \
--output_path results_mmlu_pro.json \
--seed 0 \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=20,min_p=0.0,presence_penalty=1.5,repetition_penalty=1.0,max_gen_toks=65536,seed=0"
lm_eval --model local-chat-completions \
--tasks mmlu_pro_plus \
--model_args "model=Qwen/Qwen3.6-27B,max_length=96000,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=100,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=3600" \
--num_fewshot 0 \
--apply_chat_template \
--output_path results_mmlu_pro.json \
--seed 0 \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=20,min_p=0.0,presence_penalty=1.5,repetition_penalty=1.0,max_gen_toks=65536,seed=0"| Metric | Qwen/Qwen3.6-27B | zhnagchenchne/Qwen3.6-27B-GPTQ-W4A16 |
|---|---|---|
| gsm8k_platinum_cot_llama | 0.9462 | 0.958 |
| mmlu_pro_plus | 0.6853 | 0.679 |