from transformers import Qwen3_5MoeForConditionalGeneration, AutoProcessor, AutoTokenizerfrom datasets import load_datasetfrom llmcompressor import oneshotfrom llmcompressor.modifiers.quantization import QuantizationModifier MODEL_ID = "Qwen/Qwen3.6-35B-A3B" model = Qwen3_5MoeForConditionalGeneration.from_pretrained(MODEL_ID, dtype="auto", trust_remote_code=True)processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True) recipe = QuantizationModifier( targets="Linear", scheme="NVFP4", ignore=["lm_head", "re:.*visual.*", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"],) ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft[:512]")ds = ds.shuffle(seed=42) def preprocess(example): return {"text": tokenizer.apply_chat_template(example["messages"], tokenize=False)}ds = ds.map(preprocess) def tokenize(sample): return tokenizer(sample["text"], padding=False, max_length=2048, truncation=True, add_special_tokens=False)ds = ds.map(tokenize, remove_columns=ds.column_names) oneshot(model=model, dataset=ds, recipe=recipe, max_seq_length=2048, num_calibration_samples=512, moe_calibrate_all_experts=True) model.save_pretrained("Qwen3.6-35B-A3B-NVFP4", save_compressed=True)processor.save_pretrained("Qwen3.6-35B-A3B-NVFP4")tokenizer.save_pretrained("Qwen3.6-35B-A3B-NVFP4")