Views
No views yet
vllm serve mlj-solutions/Qwen3.6-35B-A3B-NVFP4 --reasoning-parser qwen3 --moe_backend flashinfer_cutlass1import torch
2from compressed_tensors.utils import save_mtp_tensors_to_checkpoint
3from datasets import load_dataset
4from transformers import AutoProcessor, Qwen3_5MoeForConditionalGeneration
5
6from llmcompressor import oneshot
7from llmcompressor.modifiers.quantization import QuantizationModifier
8
9# NOTE: This example requires transformers >= v5
10
11MODEL_ID = "Qwen/Qwen3.6-35B-A3B"
12
13# Load model.
14model = Qwen3_5MoeForConditionalGeneration.from_pretrained(MODEL_ID, dtype="auto")
15processor = AutoProcessor.from_pretrained(MODEL_ID)
16
17# No need to include mtp layers as they are not loaded
18# through Qwen3_5MoeForConditionalGeneration
19recipe = QuantizationModifier(
20 targets="Linear",
21 scheme="NVFP4",
22 ignore=[
23 "re:.*lm_head",
24 "re:visual.*",
25 "re:model.visual.*",
26 "re:.*mlp.gate$",
27 "re:.*embed_tokens$",
28 "re:.*shared_expert_gate$",
29 "re:.*linear_attn.*",
30 ],
31)
32
33NUM_CALIBRATION_SAMPLES = 256
34MAX_SEQUENCE_LENGTH = 4096
35
36ds = load_dataset(
37 "HuggingFaceH4/ultrachat_200k",
38 split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]",
39)
40ds = ds.select_columns(["messages"])
41ds = ds.shuffle(seed=42)
42
43
44def preprocess_function(example):
45 messages = [
46 {"role": m["role"], "content": [{"type": "text", "text": m["content"]}]}
47 for m in example["messages"]
48 ]
49 return processor.apply_chat_template(
50 messages,
51 tokenize=True,
52 return_dict=True,
53 add_generation_prompt=False,
54 processor_kwargs={
55 "return_tensors": "pt",
56 "padding": False,
57 "truncation": True,
58 "max_length": MAX_SEQUENCE_LENGTH,
59 "add_special_tokens": False,
60 },
61 )
62
63
64ds = ds.map(preprocess_function, batched=False, remove_columns=ds.column_names)
65
66
67def data_collator(batch):
68 assert len(batch) == 1
69 return {key: torch.tensor(value) for key, value in batch[0].items()}
70
71
72# Apply quantization.
73oneshot(
74 model=model,
75 recipe=recipe,
76 dataset=ds,
77 max_seq_length=MAX_SEQUENCE_LENGTH,
78 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
79 moe_calibrate_all_experts=True,
80 data_collator=data_collator,
81)
82
83# Save to disk in compressed-tensors format.
84SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
85model.save_pretrained(SAVE_DIR)
86processor.save_pretrained(SAVE_DIR)
87
88# MTP layers are excluded from the model through Qwen3_5MoeForConditionalGeneration
89# Save them as-is from the original checkpoint into the quantized output.
90save_mtp_tensors_to_checkpoint(source_model=MODEL_ID, dest_dir=SAVE_DIR)
91lm_eval --model local-chat-completions \
--tasks gsm8k_platinum_cot_llama \
--model_args "model=mlj-solutions/Qwen3.6-35B-A3B-NVFP4,max_length=262144,base_url=http://0.0.0.0:8000/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 0 \
--apply_chat_template \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,top_k=20,min_p=0.0,max_gen_toks=64000,presence_penalty=1.5,repetition_penalty=1.0,seed=5678"
| Qwen/Qwen3.6-35B-A3B | mlj-solutions/Qwen3.6-35B-A3B-NVFP4 (this model) | |
|---|---|---|
| Accuracy | 95.62 | 96.28 |
| Recovery | - | 100.69% |