Repository navigation
Description
Part of #493
Context
With the shared MoE FFN primitive (#500) in place, each MoE architecture is a config plus weight-naming delta on top of the primitive. Target set: Mixtral, Qwen2-MoE / Qwen3-MoE, PhiMoE, OLMoE, GLM4-MoE, DeepSeek-V2 / DeepSeek-V3, Dots1, Ernie4.5-MoE, gpt-oss.
Scope
- Add each MoE architecture on the feat: add the MoE FFN graph primitive (router + top-k expert dispatch) #500 primitive via
Config::from_jsonflags andweight_namesordering. - Handle per-family routing details: shared experts, router-weight normalization, expert counts.
- Files:
emitter/config.rs,emitter/model.rs,iree.rs.
Acceptance criteria
- Each listed architecture loads and generates via the CLI
MLXCEL_BACKEND=xlapath and serves viamlxcel-server. - Single-sequence path is token-exact vs an HF fp32 oracle on a real checkpoint.
- Serve path is reference-exact via
xla_batch_bench.
Dependencies
#500 (MoE FFN graph primitive).
Resolution
The shared MoE FFN primitive (#500) plus the qk-norm attention core (#497) cover the MoE families whose routing is softmax-before-top-k and whose attention is standard GQA / qk-norm. Families needing a routing or attention primitive the shared core does not provide are deferred with a specific rejection message and a follow-up under #493 (rather than mis-emitted).
Implemented on the shared primitive and validated:
- Mixtral and Qwen2-MoE (landed in feat: add the MoE FFN graph primitive (router + top-k expert dispatch) #500).
- Qwen3-MoE (this PR): Qwen3 attention (per-head q/k RMSNorm, no bias) + the MoE FFN, no shared expert,
norm_topk_prob.Config::from_jsondetection,weight_specsnaming (mlp.gate.weight,mlp.switch_mlp.{gate,up,down}_proj.weightmatching the mlx-lmswitch_mlpcheckpoint layout), and the emit compose the qk-norm attention with the MoE FFN across every graph kind. - OLMoE (this PR): flat q/k RMSNorm (like OLMo2) on the STANDARD pre-norm block + the MoE FFN, no shared expert, experts use
intermediate_size.clip_qkv(q/k/v clamp) is rejected as a follow-up.
Validation (in-agent):
- Block-level token-exact vs HF fp32 for the routing / dispatch of all four families via
spike/openxla/moe_oracle.py(Qwen3-MoE max block diff ~1.9e-9, OLMoE ~2.2e-8; IREE llvm-cpu). - Byte-exact structural fixtures
qwen3-moe-tinyandolmoe-tinyregistered incrate::validation(per-head vs flat q/k-norm shapes locked; router + stacked-expert args present; no shared-expert / no dense-MLP args), guarding the composed emit forever. - The full-model token-exact run and the
xla_batch_benchserve check require thexla-ireebuild and are deferred to the orchestrator's post-merge gate.
Deferred with a specific message + test (follow-ups under #493):
- DeepSeek-V2 / V3: multi-head latent attention (compressed q/kv LoRA latents, decoupled RoPE), not in the shared attention core.
- PhiMoE: sparsemixer routing (two-step masked top-2), not softmax-before-top-k.
- GLM4-MoE / Dots1: sigmoid expert scoring with grouped (n_group / topk_group) top-k and a score-correction bias.
- ERNIE-4.5-MoE: interleaved (GPT-J-style) RoPE.
- gpt-oss: attention sinks and a clamped, alpha-scaled gated-SwiGLU expert activation.
Activity
feat: add the MoE FFN graph primitive (router + top-k dispatch) (#559)
feat: add Qwen3-MoE and OLMoE on the shared MoE FFN primitive (#563)
feat: add the MoE FFN graph primitive (router + top-k dispatch) (labl…
feat: add Qwen3-MoE and OLMoE on the shared MoE FFN primitive (lablup…