perf(moe): fuse router weight multiply with Triton kernel - #3800
Open
piyushumate wants to merge 1 commit into
Open
perf(moe): fuse router weight multiply with Triton kernel#3800piyushumate wants to merge 1 commit into
piyushumate wants to merge 1 commit into
Conversation
Signed-off-by: piyushumate <piyushumate@users.noreply.github.com>
piyushumate
force-pushed
the
piyushumate/perf/fused-moe-router-weight-mul
branch
from
September 3, 2026 07:40
300d1ae to
09f6827
Compare
Contributor
|
Thank you @piyushumate ! I am wondering if you have any speed comparisons? |
Author
|
@HuiyingLi yes, i ran a benchmark and numerical parity audit on H100 , comparing chunked autograd implementation currently on mainline against this PR 1. Forward Pass
2. End-to-End Training (Forward + Backward)
|
Author
|
@HuiyingLi any suggestions (/next steps) based on the benchmark numbers? |
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.
What does this PR do ?
Implements a fused Triton forward and backward kernel for MoE router-weight multiply (
_apply_router_weight_fp32), replacing the CPU Python chunking loop with in-register FP32 computation and reduction to eliminate kernel launch overhead and intermediate HBM memory traffic.Changelog
nemo_automodel/components/moe/optimized_ops.py:_router_weight_fwd_kernelcomputingout = (x * prob).to(out_dtype)in-register in FP32._router_weight_bwd_kernelcomputinggrad_xandgrad_p(in-register reduction along hidden dimension) in a single pass._TritonRouterWeightMulFunctionwith support forsave_x=Falseoptimization whenprobsrequires no gradient._apply_router_weight_fp32to dispatch to Triton on CUDA and safely fall back to chunked custom autograd on CPU/non-CUDA.safe_import("triton")andsafe_import("triton.language")per repository review guidelines.tests/unit_tests/moe/test_router_weight_mul.py:save_x=Falsebehavior whenprobs.requires_grad=False._TritonRouterWeightMulFunctionand_RouterWeightMulFunction.1. Forward Pass
[tokens, hidden]main)[16384, 4096][16384, 7168][65536, 7168]2. End-to-End Training (Forward + Backward)
[tokens, hidden]main)main[16384, 4096][16384, 7168][65536, 7168]Before your PR is "Ready for review"
Pre checks:
Additional Information