dsikka commited on
Commit
4796e86
·
verified ·
1 Parent(s): a0f3517

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +105 -1
README.md CHANGED
@@ -16,6 +16,108 @@ The model has both weights and activations quantized to NVFP4 format with [vllm-
16
 
17
  It is compatible and tested against vllm main. Deploy it with: `vllm serve RedHatAI/Qwen3.6-35B-A3B-NVFP4 --reasoning-parser qwen3 --moe_backend flashinfer_cutlass`
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Preliminary Evaluations
20
 
21
  1) GSM8K Platinum:
@@ -38,4 +140,6 @@ Recovery:
38
  | Recovery | \- | 100.69% |
39
 
40
 
41
- **Note**: More rigorous evaluations are currently in progress and will be available soon.
 
 
 
16
 
17
  It is compatible and tested against vllm main. Deploy it with: `vllm serve RedHatAI/Qwen3.6-35B-A3B-NVFP4 --reasoning-parser qwen3 --moe_backend flashinfer_cutlass`
18
 
19
+ # Creation Script:
20
+
21
+ Run this script with LLM Compressor main and latest transformers.
22
+
23
+ <details>
24
+
25
+ ```python
26
+ import torch
27
+ from compressed_tensors.utils import save_mtp_tensors_to_checkpoint
28
+ from datasets import load_dataset
29
+ from transformers import AutoProcessor, Qwen3_5MoeForConditionalGeneration
30
+
31
+ from llmcompressor import oneshot
32
+ from llmcompressor.modifiers.quantization import QuantizationModifier
33
+
34
+ # NOTE: This example requires transformers >= v5
35
+
36
+ MODEL_ID = "Qwen/Qwen3.6-35B-A3B"
37
+
38
+ # Load model.
39
+ model = Qwen3_5MoeForConditionalGeneration.from_pretrained(MODEL_ID, dtype="auto")
40
+ processor = AutoProcessor.from_pretrained(MODEL_ID)
41
+
42
+ # No need to include mtp layers as they are not loaded
43
+ # through Qwen3_5MoeForConditionalGeneration
44
+ recipe = QuantizationModifier(
45
+ targets="Linear",
46
+ scheme="NVFP4",
47
+ ignore=[
48
+ "re:.*lm_head",
49
+ "re:visual.*",
50
+ "re:model.visual.*",
51
+ "re:.*mlp.gate$",
52
+ "re:.*embed_tokens$",
53
+ "re:.*shared_expert_gate$",
54
+ "re:.*linear_attn.*",
55
+ ],
56
+ )
57
+
58
+ NUM_CALIBRATION_SAMPLES = 256
59
+ MAX_SEQUENCE_LENGTH = 4096
60
+
61
+ ds = load_dataset(
62
+ "HuggingFaceH4/ultrachat_200k",
63
+ split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]",
64
+ )
65
+ ds = ds.select_columns(["messages"])
66
+ ds = ds.shuffle(seed=42)
67
+
68
+
69
+ def preprocess_function(example):
70
+ messages = [
71
+ {"role": m["role"], "content": [{"type": "text", "text": m["content"]}]}
72
+ for m in example["messages"]
73
+ ]
74
+ return processor.apply_chat_template(
75
+ messages,
76
+ tokenize=True,
77
+ return_dict=True,
78
+ add_generation_prompt=False,
79
+ processor_kwargs={
80
+ "return_tensors": "pt",
81
+ "padding": False,
82
+ "truncation": True,
83
+ "max_length": MAX_SEQUENCE_LENGTH,
84
+ "add_special_tokens": False,
85
+ },
86
+ )
87
+
88
+
89
+ ds = ds.map(preprocess_function, batched=False, remove_columns=ds.column_names)
90
+
91
+
92
+ def data_collator(batch):
93
+ assert len(batch) == 1
94
+ return {key: torch.tensor(value) for key, value in batch[0].items()}
95
+
96
+
97
+ # Apply quantization.
98
+ oneshot(
99
+ model=model,
100
+ recipe=recipe,
101
+ dataset=ds,
102
+ max_seq_length=MAX_SEQUENCE_LENGTH,
103
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
104
+ moe_calibrate_all_experts=True,
105
+ data_collator=data_collator,
106
+ )
107
+
108
+ # Save to disk in compressed-tensors format.
109
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
110
+ model.save_pretrained(SAVE_DIR)
111
+ processor.save_pretrained(SAVE_DIR)
112
+
113
+ # MTP layers are excluded from the model through Qwen3_5MoeForConditionalGeneration
114
+ # Save them as-is from the original checkpoint into the quantized output.
115
+ save_mtp_tensors_to_checkpoint(source_model=MODEL_ID, dest_dir=SAVE_DIR)
116
+
117
+ ```
118
+ </details>
119
+
120
+
121
  # Preliminary Evaluations
122
 
123
  1) GSM8K Platinum:
 
140
  | Recovery | \- | 100.69% |
141
 
142
 
143
+ **Note**: More rigorous evaluations are currently in progress and will be available soon.
144
+
145
+