Skip to content

Commit 89fe423

Browse files
justinchubyCopilot
andauthored
Add conventional MoE GGUF architecture cohort (#575)
## Summary - add pinned llama.cpp (`8d9af256337d1a501250f9bbf4c0859a654bddd6`) GGUF specs for `olmoe`, `phimoe`, `qwen2moe`, `qwen3moe`, and `granitemoe` - implement exact metadata/config extraction, canonical Qwen aliases, tensor-family closure, routing/norm/scaling semantics, and Granite dense-vs-MoE dispatch - preserve 3-D expert ordering through affine and native quantized imports, split fused Phi QKV tensors, and preserve tied quantized Qwen3/Granite embedding heads - reverse llama.cpp's GraniteMoE Q/K row permutation in both float and packed quantized imports - map pinned expert `.scale`/`.input_scale` suffixes and reject affected files before graph construction because Mobius cannot safely represent NVFP4 scale2/activation-scale sidecars - extend the same suffix-aware preflight to reachable MTP `nextn.eh_proj` scale sidecars before either backbone or MTP graph construction - add generated support docs, negative closure/shape tests, and float/Q4 synthetic save-load-ORT coverage Stacks on #572 (`justinchuby-gguf-dense-transformer-cohort`). ## Real artifact import evidence (runtime deferred) ### GraniteMoE Validated with: - repository: `bartowski/granite-3.0-1b-a400m-instruct-GGUF` - repository revision: `0e1c3cecaa6e49ac0721be91ef441ec72eae62d4` - file: `granite-3.0-1b-a400m-instruct-Q4_K_M.gguf` - size: `821,845,024` bytes - LFS SHA-256: `074f09e13484e54e73c93830d34e9fa9917a6319fb8bae762a22594b9b4da0dc` - source config/tokenizer: `ibm-granite/granite-3.0-1b-a400m-instruct@ffec3c35bdfd97a06f0b4cd5fcc92cd9b1584445` - stored qtypes: 73 F32, 144 Q4_K, 25 Q6_K The pinned integration test verifies exact tensor closure, 24 routers, 2,304 routed expert projections, mixed-qtype routing, 2,401 `MatMulNBits` nodes including the tied quantized head, zero `QMoE` nodes, ONNX save/load, full 49,155-token logits, and repeatable three-token cached decoding. This is deterministic Mobius execution evidence, not independent llama.cpp/HuggingFace parity, so GraniteMoE runtime remains deferred. ## Runtime-DEFERRED All five entries—`olmoe`, `phimoe`, `qwen2moe`, `qwen3moe`, and `granitemoe`—have exact registry/config/tensor support and synthetic float/Q4 ORT execution, but no qualifying independent real-weight cross-runtime evidence. The only compatible Phi representative found was `tripathyShaswata/Phi-tiny-MoE-instruct-GGUF@873ccb08cd3380ee2c08573d45267fac9a6cc81b`, file `Phi-tiny-MoE-instruct-Q8_0.gguf`, size `3,999,171,104` bytes, SHA-256 `297fa09e906e18aaf03850e77d6de8d9ee8e246e00916ac09787ae2cf4bb6019`, sourced from `microsoft/Phi-tiny-MoE-instruct@2fe50e88d0e2a5a132563815686ea0dcc8e252b5`. It was not downloaded because it is not a reasonably sized representative. ## Validation - `504 passed` full focused GGUF/model tests after the Granite/expert-scale fixes - `160 passed` focused MTP/builder/tensor-mapping tests after the MTP scale preflight fix - `1 passed` revised pinned Granite real-artifact integration test - `5585 passed, 52 skipped` broad non-integration suite with `glm_moe_dsa` excluded - full `lintrunner f --output oneline --all-files` The two excluded `glm_moe_dsa` shape-inference/checker failures reproduce unchanged on the stack base and are unrelated to this cohort. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent c6b23e2 commit 89fe423

29 files changed

Lines changed: 1540 additions & 106 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ reason.
159159
| `gemma4` | — | `gemma4_text` | supported | supported |
160160
| `glm-dsa` | `glm_dsa` | `glm_moe_dsa` | tensor_map deferred | unreachable |
161161
| `gpt2` | — | `gpt2` | supported | supported |
162+
| `granitemoe` | — | `granitemoe` | runtime deferred | supported |
162163
| `hunyuan-dense` | `hunyuan_v1_dense` | `hunyuan_v1_dense` | supported | supported |
163164
| `internlm2` | — | `internlm2` | supported | rejected |
164165
| `llama` | `mistral` | `llama` | supported | supported |
@@ -168,13 +169,15 @@ reason.
168169
| `nemotron_h_moe` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected | unreachable |
169170
| `olmo` | — | `olmo` | supported | supported |
170171
| `olmo2` | — | `olmo2` | supported | supported |
172+
| `olmoe` | — | `olmoe` | runtime deferred | supported |
171173
| `phi3` | — | `phi3` | supported | supported |
174+
| `phimoe` | — | `phimoe` | runtime deferred | supported |
172175
| `qwen2` | — | `qwen2` | supported | supported |
173-
| `qwen2moe` | `qwen2_moe` | `qwen2_moe` | supported | supported |
176+
| `qwen2moe` | `qwen2_moe` | `qwen2_moe` | runtime deferred | supported |
174177
| `qwen3` | — | `qwen3` | supported | supported |
175178
| `qwen35` | — | `qwen3_5_text` | supported | supported |
176179
| `qwen35moe` | — | `qwen3_5_moe` | supported | supported |
177-
| `qwen3moe` | `qwen3_moe` | `qwen3_moe` | supported | supported |
180+
| `qwen3moe` | `qwen3_moe` | `qwen3_moe` | runtime deferred | supported |
178181
| `smollm3` | — | `smollm3` | supported | supported |
179182
| `stablelm` | — | `stablelm` | supported | supported |
180183
| `starcoder2` | — | `starcoder2` | supported | supported |
@@ -187,6 +190,30 @@ validated against a vendored census of the 147 architectures llama.cpp defines
187190
at commit `8d9af256337d1a501250f9bbf4c0859a654bddd6`. Aliases are spellings
188191
llama.cpp does not emit but that mobius still accepts.
189192

193+
GraniteMoE has real-weight import and deterministic ORT execution coverage from
194+
`bartowski/granite-3.0-1b-a400m-instruct-GGUF` revision
195+
`0e1c3cecaa6e49ac0721be91ef441ec72eae62d4`,
196+
`granite-3.0-1b-a400m-instruct-Q4_K_M.gguf` (821,845,024 bytes, SHA-256
197+
`074f09e13484e54e73c93830d34e9fa9917a6319fb8bae762a22594b9b4da0dc`).
198+
Its base config and tokenizer are pinned to
199+
`ibm-granite/granite-3.0-1b-a400m-instruct` revision
200+
`ffec3c35bdfd97a06f0b4cd5fcc92cd9b1584445`. The integration test checks all
201+
24 routers and 2,304 expert projections, mixed F32/Q4_K/Q6_K routing, full
202+
49,155-token logits, and deterministic three-token cached decoding. This is not
203+
independent cross-runtime parity evidence, so GraniteMoE runtime support remains
204+
deferred.
205+
206+
Runtime remains deferred for OLMoE, PhiMoE, Qwen2MoE, Qwen3MoE, and GraniteMoE.
207+
The only
208+
compatible Phi-tiny-MoE GGUF found was
209+
`tripathyShaswata/Phi-tiny-MoE-instruct-GGUF` revision
210+
`873ccb08cd3380ee2c08573d45267fac9a6cc81b`,
211+
`Phi-tiny-MoE-instruct-Q8_0.gguf` (3,999,171,104 bytes, SHA-256
212+
`297fa09e906e18aaf03850e77d6de8d9ee8e246e00916ac09787ae2cf4bb6019`);
213+
no trustworthy reasonably sized representative was available. Its source
214+
config and tokenizer were inspected at `microsoft/Phi-tiny-MoE-instruct`
215+
revision `2fe50e88d0e2a5a132563815686ea0dcc8e252b5`.
216+
190217
An architecture outside this table is refused with a message naming its
191218
upstream cohort, so an unsupported input is never mistaken for a broken one.
192219
`clip` files are multimodal projector sidecars: pass them as
@@ -237,16 +264,16 @@ construction.
237264

238265
| Stored qtype | ID | Projection/output route | Direct exactness | Embedding route | Expert-major route | Non-MatMul route | Runtime |
239266
|---|---:|---|---|---|---|---|---|
240-
| `Q4_0` | 2 | affine repack | exact | affine repack | rejected | dequantize to float | deferred |
241-
| `Q4_1` | 3 | affine repack | lossy | affine repack | rejected | dequantize to float | deferred |
242-
| `Q5_0` | 6 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
243-
| `Q5_1` | 7 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
244-
| `Q8_0` | 8 | affine repack | exact | affine repack | rejected | dequantize to float | deferred |
245-
| `Q2_K` | 10 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
246-
| `Q3_K` | 11 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
247-
| `Q4_K` | 12 | affine repack | lossy | affine repack | rejected | dequantize to float | deferred |
248-
| `Q5_K` | 13 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
249-
| `Q6_K` | 14 | affine repack | lossy | affine repack | rejected | dequantize to float | deferred |
267+
| `Q4_0` | 2 | affine repack | exact | affine repack | affine repack | dequantize to float | deferred |
268+
| `Q4_1` | 3 | affine repack | lossy | affine repack | affine repack | dequantize to float | deferred |
269+
| `Q5_0` | 6 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
270+
| `Q5_1` | 7 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
271+
| `Q8_0` | 8 | affine repack | exact | affine repack | affine repack | dequantize to float | deferred |
272+
| `Q2_K` | 10 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
273+
| `Q3_K` | 11 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
274+
| `Q4_K` | 12 | affine repack | lossy | affine repack | affine repack | dequantize to float | deferred |
275+
| `Q5_K` | 13 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
276+
| `Q6_K` | 14 | affine repack | lossy | affine repack | affine repack | dequantize to float | deferred |
250277
| `IQ2_XXS` | 16 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
251278
| `IQ2_XS` | 17 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
252279
| `IQ3_XXS` | 18 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
@@ -256,11 +283,11 @@ construction.
256283
| `IQ2_S` | 22 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
257284
| `IQ4_XS` | 23 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
258285
| `IQ1_M` | 29 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
259-
| `TQ1_0` | 34 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
260-
| `TQ2_0` | 35 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
286+
| `TQ1_0` | 34 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
287+
| `TQ2_0` | 35 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
261288
| `MXFP4` | 39 | native byte-preserved | — | dequantize/requantize | native byte-preserved | dequantize to float | deferred |
262-
| `NVFP4` | 40 | dequantize/requantize | — | dequantize/requantize | rejected | dequantize to float | deferred |
263-
| `Q1_0` | 41 | affine repack | exact | affine repack | rejected | rejected | deferred |
289+
| `NVFP4` | 40 | dequantize/requantize | — | dequantize/requantize | dequantize/requantize | dequantize to float | deferred |
290+
| `Q1_0` | 41 | affine repack | exact | affine repack | affine repack | rejected | deferred |
264291
| `Q2_0` | 42 | rejected | — | rejected | rejected | rejected | deferred |
265292

266293
<!-- END GGUF QUANTIZATION MATRIX -->

‎src/mobius/_registry.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
Phi4MMMultiModalModel,
9999
Phi4SigLIPModel,
100100
PhiCausalLMModel,
101+
PhiMoEGGUFCausalLMModel,
101102
Qwen2MoECausalLMModel,
102103
Qwen2VLCausalLMModel,
103104
Qwen3CausalLMModel,
@@ -577,6 +578,7 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
577578
"mixtral": ModelRegistration(MoECausalLMModel),
578579
"olmoe": ModelRegistration(MoECausalLMModel),
579580
"phimoe": ModelRegistration(Phi3MoECausalLMModel),
581+
"phimoe_gguf": ModelRegistration(PhiMoEGGUFCausalLMModel),
580582
"qwen2_moe": ModelRegistration(Qwen2MoECausalLMModel),
581583
"qwen3_5_moe": ModelRegistration(Qwen35MoECausalLMModel),
582584
"qwen3_moe": ModelRegistration(MoECausalLMModel),
@@ -1024,6 +1026,7 @@ def _create_default_registry() -> ModelRegistry:
10241026
# --- Mixture of Experts ---
10251027
"mixtral": "mistralai/Mixtral-8x7B-v0.1",
10261028
"phimoe": "microsoft/Phi-tiny-MoE-instruct",
1029+
"phimoe_gguf": "microsoft/Phi-tiny-MoE-instruct",
10271030
"qwen2_moe": "Qwen/Qwen1.5-MoE-A2.7B-Chat",
10281031
"qwen3_moe": "Qwen/Qwen3-30B-A3B",
10291032
"qwen3_5_moe": "Qwen/Qwen3.5-MoE-A3B-128K",

‎src/mobius/components/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"QuantizedLinear",
6767
"RadioVisionModel",
6868
"RMSNorm",
69+
"RMSNormBias",
6970
"RmsNorm2d",
7071
"ScaleFreeRMSNorm",
7172
"SelectiveScan",
@@ -302,6 +303,7 @@
302303
OffsetRMSNorm,
303304
PostGatedRMSNorm,
304305
RMSNorm,
306+
RMSNormBias,
305307
ScaleFreeRMSNorm,
306308
apply_rms_norm,
307309
)

‎src/mobius/components/_moe.py‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,18 @@ class TopKGate(nn.Module):
136136
with softmax over the selected experts.
137137
"""
138138

139-
def __init__(self, hidden_size: int, num_experts: int, top_k: int):
139+
def __init__(
140+
self,
141+
hidden_size: int,
142+
num_experts: int,
143+
top_k: int,
144+
*,
145+
routed_scaling_factor: float = 1.0,
146+
):
140147
super().__init__()
141148
self.num_experts = num_experts
142149
self.top_k = top_k
150+
self.routed_scaling_factor = routed_scaling_factor
143151
self.weight = nn.Parameter([num_experts, hidden_size])
144152

145153
def forward(self, op: OpBuilder, hidden_states: ir.Value):
@@ -148,6 +156,8 @@ def forward(self, op: OpBuilder, hidden_states: ir.Value):
148156
k = op.Constant(value_ints=[self.top_k])
149157
routing_weights, selected_experts = op.TopK(router_logits, k, axis=-1, _outputs=2)
150158
routing_weights = op.Softmax(routing_weights, axis=-1)
159+
if self.routed_scaling_factor != 1.0: # noqa: RUF069
160+
routing_weights = op.Mul(routing_weights, self.routed_scaling_factor)
151161
return routing_weights, selected_experts
152162

153163
def qmoe_routing(self, op: OpBuilder, hidden_states: ir.Value):
@@ -174,7 +184,7 @@ def qmoe_routing(self, op: OpBuilder, hidden_states: ir.Value):
174184
# ``input`` (see contrib_defs.cc), so it must match hidden_states'
175185
# dtype rather than a fixed float32.
176186
router_logits = op.CastLike(router_logits, hidden_states)
177-
return router_logits, None, True, 1.0
187+
return router_logits, None, True, self.routed_scaling_factor
178188

179189

180190
class SoftmaxTopKGate(nn.Module):
@@ -185,12 +195,19 @@ class SoftmaxTopKGate(nn.Module):
185195
"""
186196

187197
def __init__(
188-
self, hidden_size: int, num_experts: int, top_k: int, *, norm_topk_prob: bool = True
198+
self,
199+
hidden_size: int,
200+
num_experts: int,
201+
top_k: int,
202+
*,
203+
norm_topk_prob: bool = True,
204+
routed_scaling_factor: float = 1.0,
189205
):
190206
super().__init__()
191207
self.num_experts = num_experts
192208
self.top_k = top_k
193209
self.norm_topk_prob = norm_topk_prob
210+
self.routed_scaling_factor = routed_scaling_factor
194211
self.weight = nn.Parameter([num_experts, hidden_size])
195212

196213
def forward(self, op: OpBuilder, hidden_states: ir.Value):
@@ -204,6 +221,8 @@ def forward(self, op: OpBuilder, hidden_states: ir.Value):
204221
# Renormalize selected weights to sum to 1
205222
weight_sum = op.ReduceSum(routing_weights, [-1], keepdims=True)
206223
routing_weights = op.Div(routing_weights, weight_sum)
224+
if self.routed_scaling_factor != 1.0: # noqa: RUF069
225+
routing_weights = op.Mul(routing_weights, self.routed_scaling_factor)
207226
return routing_weights, selected_experts
208227

209228
def qmoe_routing(self, op: OpBuilder, hidden_states: ir.Value):
@@ -227,7 +246,12 @@ def qmoe_routing(self, op: OpBuilder, hidden_states: ir.Value):
227246
# dtype rather than a fixed float32.
228247
router_logits = op.CastLike(router_logits, hidden_states)
229248
routing_probs = op.Softmax(router_logits, axis=-1)
230-
return router_logits, routing_probs, self.norm_topk_prob, 1.0
249+
return (
250+
router_logits,
251+
routing_probs,
252+
self.norm_topk_prob,
253+
self.routed_scaling_factor,
254+
)
231255

232256

233257
class SigmoidTopKGate(nn.Module):

‎src/mobius/components/_rms_norm.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ def forward(self, op: OpBuilder, hidden_states: ir.Value):
2222
return apply_rms_norm(op, hidden_states, self.weight, self.variance_epsilon)
2323

2424

25+
class RMSNormBias(nn.Module):
26+
"""RMS normalization with learned scale and bias."""
27+
28+
def __init__(self, hidden_size: int, eps: float = 1e-6):
29+
super().__init__()
30+
self.weight = nn.Parameter([hidden_size])
31+
self.bias = nn.Parameter([hidden_size])
32+
self.variance_epsilon = eps
33+
34+
def forward(self, op: OpBuilder, hidden_states: ir.Value):
35+
normalized = apply_rms_norm(op, hidden_states, self.weight, self.variance_epsilon)
36+
return op.Add(normalized, self.bias)
37+
38+
2539
class OffsetRMSNorm(nn.Module):
2640
"""RMSNorm with +1 offset on weight: output = norm(x) * (1.0 + weight).
2741

‎src/mobius/integrations/gguf/_arch_registry.py‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,28 @@
144144
# architecture is spelled the way llama.cpp writes it.
145145
aliases=frozenset({"qwen2_moe"}),
146146
tensor_map_recipe=("llama", "moe_extras"),
147+
config_postprocessor="moe",
148+
required_metadata=(
149+
"attention.layer_norm_rms_epsilon",
150+
"expert_count",
151+
"expert_used_count",
152+
),
153+
runtime=Support.DEFERRED,
154+
reason=_RUNTIME_VALIDATION_PENDING,
147155
),
148156
GGUFArchitectureSpec(
149157
gguf_arch="qwen3moe",
150158
model_type="qwen3_moe",
151159
aliases=frozenset({"qwen3_moe"}),
152-
tensor_map_recipe=("llama", "moe_extras"),
160+
tensor_map_recipe=("llama", "moe_qk_norm_extras", "moe_extras"),
161+
config_postprocessor="moe",
162+
required_metadata=(
163+
"attention.layer_norm_rms_epsilon",
164+
"expert_count",
165+
"expert_used_count",
166+
),
167+
runtime=Support.DEFERRED,
168+
reason=_RUNTIME_VALIDATION_PENDING,
153169
),
154170
GGUFArchitectureSpec(
155171
gguf_arch="qwen35",
@@ -257,6 +273,47 @@
257273
config_postprocessor="dense_sliding",
258274
required_metadata=("attention.layer_norm_rms_epsilon",),
259275
),
276+
GGUFArchitectureSpec(
277+
gguf_arch="olmoe",
278+
model_type="olmoe",
279+
tensor_map_recipe=("llama", "moe_qk_norm_extras", "moe_extras"),
280+
config_postprocessor="moe",
281+
required_metadata=(
282+
"attention.layer_norm_rms_epsilon",
283+
"expert_count",
284+
"expert_used_count",
285+
),
286+
runtime=Support.DEFERRED,
287+
reason=_RUNTIME_VALIDATION_PENDING,
288+
),
289+
GGUFArchitectureSpec(
290+
gguf_arch="phimoe",
291+
model_type="phimoe",
292+
module_type="phimoe_gguf",
293+
tensor_map_recipe=("llama", "phi3", "moe_extras"),
294+
config_postprocessor="phimoe",
295+
required_metadata=(
296+
"attention.layer_norm_rms_epsilon",
297+
"expert_count",
298+
"expert_used_count",
299+
),
300+
runtime=Support.DEFERRED,
301+
reason=_RUNTIME_VALIDATION_PENDING,
302+
),
303+
GGUFArchitectureSpec(
304+
gguf_arch="granitemoe",
305+
model_type="granitemoe",
306+
tensor_map_recipe=("llama", "moe_extras"),
307+
config_postprocessor="granitemoe",
308+
required_metadata=(
309+
"attention.layer_norm_rms_epsilon",
310+
"logit_scale",
311+
),
312+
tensor_processor="llama",
313+
llama_qk_permute=True,
314+
runtime=Support.DEFERRED,
315+
reason=_RUNTIME_VALIDATION_PENDING,
316+
),
260317
GGUFArchitectureSpec(
261318
gguf_arch="cohere2",
262319
model_type="cohere2",

0 commit comments

Comments
 (0)