Skip to content

perf(moe): wire minimax to the fused decode-MoE kernel #304

Closed

Description

@inureyes

Parent epic: #307. Sibling: #286 (qwen2_moe, same pattern).

Background

The fused single-token decode-MoE kernel (#268 series) and the default-on flip (#282, PR #285) are wired into only four model paths: qwen3_moe, qwen3_next, dots1, gemma4. #286 wires qwen2_moe. Several more MoE families reuse a SwitchGLU for the expert matmul but never call forward_fused_kernel, so they always fall back to gather_qmm regardless of MLXCEL_FUSED_MOE. This issue wires minimax.

The canonical one-branch pattern lives in src/models/qwen3_moe.rs, src/models/dots1.rs, and src/models/qwen3_next.rs: gate on single-token decode plus fused_moe_enabled() (src/models/switch_layers.rs:42), call experts.forward_fused_kernel(&x_flat, &topk_indices, &scores) (src/models/switch_layers.rs:276), and fall back to experts.forward(...) plus moe_weighted_sum(...) (src/models/switch_layers.rs:419).

Scope

File: src/models/minimax.rs. It already uses the shared switch_layers::SwitchGLU (import at line 25). SparseMoeBlock::forward is at line 242 (expert call at 283, moe_weighted_sum at 285). Routing: sigmoid plus correction-bias style, with unbiased scores selected, no shared expert. minimax experts are SwiGLU (SiLU), so the kernel runs with the default swiglu activation (act=0); no GeGLU/relu2 template is needed.

Implementation class: Group A (direct one-branch wiring). Because the experts already use the shared SwitchGLU that exposes forward_fused_kernel, the change is the small one-branch dispatch from #286/dots1.

HARDWARE CAVEAT: MiniMax-Text-01 is about 456B params; even 4-bit (roughly 230 to 260 GB) exceeds 128 GB unified memory, so it cannot be runtime-validated locally (same class as hunyuan-moe in #294). The dispatch wiring plus a code-path/unit test can still land, but the greedy temp-0 runtime validation is BLOCKED on a fitting checkpoint or a larger-memory machine. Do NOT claim runtime validation that was not actually run; defer it as a documented follow-up if no checkpoint fits.

Acceptance Criteria

  • minimax's MoE block dispatches the fused kernel for single-token decode when MLXCEL_FUSED_MOE is enabled (default) and the config qualifies; the non-fused fallback path is unchanged.
  • INTEGRATION: the change is wired into the actual minimax forward decode path (not an orphaned helper). Confirm the kernel actually dispatches via a code-path/unit test (runtime dispatch trace if a fitting checkpoint becomes available).
  • Runtime validation is BLOCKED on a fitting checkpoint or a larger-memory machine. Document the hardware blocker explicitly; do not claim an unrun validation. If a fitting checkpoint becomes available, validate greedy temp-0 output byte-identical or within the documented f16 jitter class vs the MLXCEL_FUSED_MOE=0 (gather_qmm) baseline, with no NaN.
  • If validated, measure decode tok/s fused-on vs off; record the gain; confirm no regression. Otherwise note this as deferred.
  • Update the "Models covered" list in docs/benchmark_results/fused-moe-decode-kernel-design.md to reflect the wiring and the hardware-blocked validation state.
  • Add or extend tests where practical (code-path/unit coverage of the dispatch branch).

Technical Considerations / References

Activity

  1. added
    type:performance
    priority:low
    area:models
    area:inference
    platform:macos
    status:blocked
    on Jun 16, 2026
  2. added this to the 0.4 milestone on Jun 21, 2026
  3. added
    status:in-progress
    status:review
    status:done
    and removed
    status:blocked
    status:in-progress
    status:review
    on Jun 21, 2026
  4. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencearea:modelsplatform:macospriority:lowstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions