feat: add tract_moe_ffn operator for Mixture-of-Experts FFN#2084
Open
JulienBalianSonos wants to merge 11 commits into
Open
feat: add tract_moe_ffn operator for Mixture-of-Experts FFN#2084JulienBalianSonos wants to merge 11 commits into
JulienBalianSonos wants to merge 11 commits into
Conversation
9f96279 to
4e1671e
Compare
Implements the tract_moe_ffn operator in the tract_transformers extension, enabling inference of MoE-based models (Mixtral, GPT-OSS, Qwen MoE) exported via torch_to_nnef. The operator encapsulates the full MoE FFN block: - Router: x @ wg.T -> top-k expert selection with softmax gating - Token grouping: batch tokens per expert for efficient GEMM - Expert FFN: SwiGLU (silu(x@w1) * (x@w3)) @ w2 with BLAS-backed matmul - Weighted scatter-add of expert outputs Real conditional compute: unused experts are fully skipped. Handles both 2D [T,D] and 3D [B,S,D] input shapes. Verified bit-exact against PyTorch on TitanML/tiny-mixtral (8 experts, top-2, 246M params).
…clamped-swiglu act_alpha/act_limit; codegen keeps biased/clamped path on reference eval)
…n (no router_logits, no rank-align unsqueeze)
…ax_all|sigmoid|raw); fix stale op unit tests (single-output + gate); regen harness asset
… native dtype, cast output back); compute router in f32 to stabilize top-k selection vs PyTorch; f16-faithful weighted scatter
…rch CPU f32 matmul accumulation; native-f16 accumulation derailed greedy decoding
dccfa06 to
c547fe8
Compare
|
🔴 Bench vs main — 1 speed regression(s) Reference: main nightly, latest 2026-07-09 (0d old) · PR Speed — evaltime · prefill · decode
lower is better except prefill/decode (tok/s) · adaptive thresholds (max(floor, k×noise) vs the series' own history) · single-shot vs nightly reference · full report → run |
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.
Implements the
tract_moe_ffnoperator in thetract_transformersextension, enabling inference of routed Mixture-of-Experts FFN blocks exported viatorch_to_nnef.The operator encapsulates the full MoE FFN block:
x @ wg.Tfollowed by top-k expert selection.activation(x @ w1) * (x @ w3)followed by@ w2for SwiGLU-style experts.Real conditional compute: unused experts are fully skipped. The op handles both 2D
[T,D]and 3D[B,S,D]input shapes.Model Coverage
The implemented semantics cover the routed FFN variants used by:
Current validation:
TitanML/tiny-mixtral(8 experts, top-2, 246M params).Granite MoE Benchmark
Local release measurements on Apple Silicon. The benchmark artifact is not included in this PR.
77.68 tok/s78.66 tok/s73.86 tok/s74.47 tok/s65.04 tok/s65.35 tok/s40.63 tok/sAdditional steady-state Metal harness results on the same model family:
1280.3 tok/s123.5 tok/s1254.6 tok/s122.0 tok/s1128.2 tok/s119.4 tok/s