Repository navigation
perf(moe): wire minimax to the fused decode-MoE kernel - #390
Merged
Merged
Conversation
Wire minimax's SparseMoeBlock to the shared forward_fused_kernel path (#268 series, default-on since #285), following the one-branch pattern from qwen2_moe / dots1. For single-token decode with MLXCEL_FUSED_MOE enabled, the block now calls experts.forward_fused_kernel; for prefill or when the env gate is off, it falls through to experts.forward + moe_weighted_sum unchanged. minimax experts are SwiGLU (SiLU), so the kernel runs with the default swiglu act=0 template with no additional activation variant required. Routing uses sigmoid with an e_score_correction_bias that biases expert selection; the fused path receives the normalized unbiased scores, matching exactly what moe_weighted_sum received on the non-fused path. The kernel auto-falls-back for any unsupported quant config (non-affine, 3-bit, etc). Also expose fused_moe_enabled_from as pub(crate) so that per-model test files can assert the gating conditions without touching process-global env state (the function is already documented as a testing seam). Runtime validation is hardware-blocked: MiniMax-Text-01 at ~456B does not fit 128 GB unified memory, so greedy temp-0 throughput and output-parity measurements are deferred until a smaller variant or larger-memory machine is available. The PR body documents this explicitly. Changes: - src/models/minimax.rs: add fused dispatch branch in SparseMoeBlock::forward - src/models/switch_layers.rs: fused_moe_enabled_from fn -> pub(crate) - src/models/minimax_tests.rs: new config + dispatch gate unit tests - src/models/mod.rs: register minimax_tests module - docs/benchmark_results/fused-moe-decode-kernel-design.md: update models covered
Member
Author
Implementation Review SummaryIntentWire minimax Findings AddressedNone. No CRITICAL/HIGH/MEDIUM/LOW issues found in the independent review or in a supplementary automated review; no auto-fix was required and the working tree is unmodified. Parity verification (the load-bearing check)
Verification
Remaining Items
|
The bonus smoke loaded minimax-m2-3bit with the new dispatch wiring and generated 16 coherent tokens at 17.6 tok/s on M1 Ultra. Because 3-bit quant is not a supported fused-kernel input, forward_fused_kernel returned None and decode fell back to gather_qmm cleanly (no crash, no OOM). This confirms the wiring is non-breaking via the fallback path. Fused-path throughput and output-parity validation remain blocked on a fitting 4-bit or 8-bit minimax checkpoint.
Member
Author
PR Finalization CompleteSummary
All checks passing. Ready for merge. |
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
* perf(moe): wire minimax to the fused decode-MoE kernel Wire minimax's SparseMoeBlock to the shared forward_fused_kernel path (lablup#268 series, default-on since lablup#285), following the one-branch pattern from qwen2_moe / dots1. For single-token decode with MLXCEL_FUSED_MOE enabled, the block now calls experts.forward_fused_kernel; for prefill or when the env gate is off, it falls through to experts.forward + moe_weighted_sum unchanged. minimax experts are SwiGLU (SiLU), so the kernel runs with the default swiglu act=0 template with no additional activation variant required. Routing uses sigmoid with an e_score_correction_bias that biases expert selection; the fused path receives the normalized unbiased scores, matching exactly what moe_weighted_sum received on the non-fused path. The kernel auto-falls-back for any unsupported quant config (non-affine, 3-bit, etc). Also expose fused_moe_enabled_from as pub(crate) so that per-model test files can assert the gating conditions without touching process-global env state (the function is already documented as a testing seam). Runtime validation is hardware-blocked: MiniMax-Text-01 at ~456B does not fit 128 GB unified memory, so greedy temp-0 throughput and output-parity measurements are deferred until a smaller variant or larger-memory machine is available. The PR body documents this explicitly. Changes: - src/models/minimax.rs: add fused dispatch branch in SparseMoeBlock::forward - src/models/switch_layers.rs: fused_moe_enabled_from fn -> pub(crate) - src/models/minimax_tests.rs: new config + dispatch gate unit tests - src/models/mod.rs: register minimax_tests module - docs/benchmark_results/fused-moe-decode-kernel-design.md: update models covered * docs(moe): record minimax-m2-3bit auto-fallback smoke on M1 Ultra The bonus smoke loaded minimax-m2-3bit with the new dispatch wiring and generated 16 coherent tokens at 17.6 tok/s on M1 Ultra. Because 3-bit quant is not a supported fused-kernel input, forward_fused_kernel returned None and decode fell back to gather_qmm cleanly (no crash, no OOM). This confirms the wiring is non-breaking via the fallback path. Fused-path throughput and output-parity validation remain blocked on a fitting 4-bit or 8-bit minimax checkpoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wire minimax's
SparseMoeBlock::forwardto the sharedforward_fused_kernelpath (#268 series, default-on since #285). For single-token decode withMLXCEL_FUSED_MOEenabled (default), the MoE block now dispatches the fused kernel; prefill and the disabled-env path fall through toexperts.forward+moe_weighted_sumunchanged.What changed
src/models/minimax.rs: replaced the single-path expert dispatch with the one-branch fused/fallback pattern matching qwen2_moe and dots1. The inputs toforward_fused_kernel(x_flat,topk_indices,norm_scores) are exactly what the fallback path passed toexperts.forwardandmoe_weighted_sum; no routing logic was reordered or recomputed.src/models/switch_layers.rs: promotedfused_moe_enabled_fromfrom private topub(crate). The function was already documented as a unit-testing seam; this makes it reachable from per-model test files without touching process-global env state.src/models/minimax_tests.rs(new): config parsing tests (topology fields, quantization accessors including the gate 8-bit override, RoPE/head_dim) plusfused_dispatch_gate_conditions_for_minimax, which asserts the compound gate (n_tokens == 1 && fused_moe_enabled_from(...)) evaluates correctly for single-token+default-env (kernel attempted), single-token+disabled (kernel skipped), and prefill (kernel skipped).src/models/mod.rs: registeredminimax_testsunder#[cfg(test)].docs/benchmark_results/fused-moe-decode-kernel-design.md: updated "Models covered" count from ten to eleven, added minimax to the wired list with a note that runtime validation is hardware-blocked (see below).Activation template
minimax experts are SwiGLU (SiLU), so the kernel runs with the default swiglu act=0 template. No GeGLU or relu2 variant is needed.
Routing inputs to the fused path
minimax uses sigmoid scoring with an
e_score_correction_biasadded only for expert selection (biased scores determine which experts to call; the selected scores then come from the original unbiased sigmoid output). The normalized unbiased scores (norm_scores) go to bothmoe_weighted_sumon the fallback path andforward_fused_kernelon the fused path. The kernel input triple (x_flat,topk_indices,norm_scores) is identical between the two paths; the fused branch only branches after routing is complete.Verification
Runtime validation (hardware-blocked, deferred)
MiniMax-Text-01 is ~456B parameters; even a 4-bit quantized variant would require 230-260 GB of unified memory, which exceeds the 128 GB available on the test hardware. Greedy temp-0 throughput and output-parity measurements against the
MLXCEL_FUSED_MOE=0baseline are therefore deferred until a smaller MiniMax variant or a larger-memory machine becomes available. This matches the documented treatment of hunyuan-moe-a13b-bf16 in #294 (same does-not-fit-128 GB class). The dispatch wiring and code-path tests land independently of runtime validation.Closes #304