Repository navigation
[Triton/Gluon] Add MoE weight-gradient kernel - #5339
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
a628163 to
033bbbe
Compare
c406a72 to
ae7f0b3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Top-k routes cannot apply distinct gating gradients, and benchmark padding is uninitialized.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a Triton MoE weight-gradient kernel using sorted routing metadata.
Changes:
- Adds the kernel and public wrapper.
- Exports
moe_wgrad. - Adds correctness tests and benchmarks.
File summaries
| File | Description |
|---|---|
aiter/ops/triton/_triton_kernels/moe/moe_wgrad.py |
Implements atomic weight-gradient accumulation. |
aiter/ops/triton/moe/moe_wgrad.py |
Adds the public launch wrapper. |
aiter/ops/triton/moe/__init__.py |
Exports the new operation. |
op_tests/triton_tests/moe/test_moe_wgrad.py |
Adds correctness tests. |
op_tests/op_benchmarks/triton/bench_moe_wgrad.py |
Adds representative benchmarks. |
Review details
Suppressed comments (1)
aiter/ops/triton/_triton_kernels/moe/moe_wgrad.py:61
- This is a new launchable Triton kernel without the required config-aware
repr. The autotune key controls winner caching but does not make trace names identifyBLOCK_SIZE_N,BLOCK_SIZE_K, or launch parameters. Because the comment reports an execution issue when combining decorators, resolve that incompatibility through a safe dispatch/workaround rather than omitting the repository-required representation.
# NOTE: repr= is intentionally omitted here. Combining @triton.autotune with
# @triton.jit(repr=...) corrupts the kernel execution on current Triton versions.
# The autotune key ["N", "K"] already encodes the compiled variant identity.
@triton.jit
- Files reviewed: 5/5 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
7e2b2b9 to
f654080
Compare
Split from ROCm#5310 (per reviewer request). Adds _moe_wgrad_kernel and moe_wgrad wrapper: computes the weight gradient for a MoE expert block using the moe_align_block_size sorting interface. Independent of the mxfp8/per_token PRs — no shared dependencies, can be reviewed and merged in any order.
a90faf4 to
f943912
Compare
Split from ROCm#5310 (per reviewer request). Adds _moe_wgrad_kernel and moe_wgrad wrapper: computes the weight gradient for a MoE expert block using the moe_align_block_size sorting interface. Independent of the mxfp8/per_token PRs — no shared dependencies, can be reviewed and merged in any order. Signed-off-by: Xiake Sun <xiake.sun@amd.com>
Split from #5310 (per reviewer request). Adds _moe_wgrad_kernel and moe_wgrad wrapper: computes the weight gradient for a MoE expert block using the moe_align_block_size sorting interface. Independent of the mxfp8/per_token PRs — no shared dependencies, can be reviewed and merged in any order.
Split from #5310 (per reviewer request). Adds _moe_wgrad_kernel and moe_wgrad wrapper: computes the weight gradient for a MoE expert block using the moe_align_block_size sorting interface. Independent of the mxfp8/per_token PRs — no shared dependencies, can be reviewed and merged in any order.
Split from #5310 (per reviewer request to separate kernels into individual PRs).
Summary
Adds
moe_wgrad: a Triton kernel that computes the weight gradient for aMoE expert block, using the
moe_align_block_sizesorting interface(
sorted_token_ids,expert_ids,num_tokens_post_padded).Independent of the mxfp8/per_token PRs — no shared dependencies,
can be reviewed and merged in any order.
Key design points
gradmust incorporate per-route gating weights fortop_k > 1;the kernel accumulates as-is without applying gating internally
sorted_token_idsmust be initialized to a sentinel>= num_valid_tokens * top_kso the token mask treats them as invalidTests
op_tests/triton_tests/moe/test_moe_wgrad.py: constant-input verification,linearity check, zero-padded-token edge case