Commit 3b43ed7
committed
[Qwen3.6] Stack per-expert MoE tensors during mlx_lm sanitize
Qwen-org Qwen3.6 MoE checkpoints (e.g. Qwen/Qwen3.6-35B-A3B-FP8) ship
expert MLPs as one tensor per expert per projection:
model.language_model.layers.{L}.mlp.experts.{E}.{gate,up,down}_proj.weight
mlx_lm.qwen3_5_moe.Model.sanitize expects the combined-format layout
(experts.gate_up_proj / experts.down_proj) produced by mlx_lm.convert and
shipped by mlx-community redistributions. Loading a Qwen-org checkpoint
fails strict load_weights with thousands of unexpected keys (30720 for the
35B-A3B variant: 256 experts x 40 layers x 3 projections).
Extend the existing FP8 sanitize compat shim with a pre-step that detects
per-expert MoE tensors, validates the index range is contiguous from 0,
and stacks them (mx.stack along axis 0) into the combined experts.gate_up_proj
+ experts.down_proj form upstream sanitize already handles. Pre-stacked
checkpoints are unaffected (helper short-circuits when no per-expert keys
are present).
This is the downstream complement to ml-explore/mlx-lm#1224, which adds
the same stacking logic inline in qwen3_5_moe.Model.sanitize. When that
lands and vllm-metal's mlx-lm pin bumps past it, this shim can be removed.
Files:
- vllm_metal/compat.py: add _stack_qwen36_moe_per_expert_weights helper,
chained after FP8 dequant in the patched sanitize.
- docs/supported_models.md: update Qwen3.6 row note.
- tests/test_qwen36_smoke.py: opt-in e2e smoke gated on
QWEN36_MOE_FP8_PATH env var (pytest skips by default; runs in 25s
against a local Qwen3.6 MoE FP8 checkpoint).
Verified end-to-end on Qwen/Qwen3.6-35B-A3B-FP8: greedy decode of
"The capital of France is" returns " Paris, a city renowned for its iconic
landmarks such" with the hybrid SDPA + GDN linear attention path on Apple
Silicon Metal. Existing Qwen3.5 golden-token smoke (test_qwen35_smoke.py)
unchanged: 5/5 pass.1 parent 992c797 commit 3b43ed7
3 files changed
Lines changed: 152 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
134 | 207 | | |
135 | 208 | | |
136 | 209 | | |
| |||
177 | 250 | | |
178 | 251 | | |
179 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
180 | 258 | | |
181 | 259 | | |
182 | 260 | | |
183 | 261 | | |
184 | | - | |
| 262 | + | |
185 | 263 | | |
186 | 264 | | |
187 | 265 | | |
| |||
0 commit comments