feat: add tract_moe_ffn operator for Mixture-of-Experts FFN#2084
Open
JulienBalianSonos wants to merge 2 commits intomainfrom
Open
feat: add tract_moe_ffn operator for Mixture-of-Experts FFN#2084JulienBalianSonos wants to merge 2 commits intomainfrom
JulienBalianSonos wants to merge 2 commits intomainfrom
Conversation
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).
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_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:
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).