Repository navigation
[Triton/Gluon] Add per-token-scaled grouped MoE GEMM kernel - #5338
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
7ddc455 to
72b3efc
Compare
2a82eb8 to
8a434c9
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Padded programs can perform out-of-bounds expert reads, and the implementation also bypasses required tuned configuration handling.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a Triton grouped MoE GEMM with per-token activation scaling and per-expert weight scaling.
Changes:
- Adds the kernel, wrapper, mapping utility, and public export.
- Adds correctness tests and a benchmark.
File summaries
| File | Description |
|---|---|
aiter/ops/triton/_triton_kernels/moe/moe_gemm_per_token.py |
Implements the Triton kernel. |
aiter/ops/triton/moe/moe_gemm_per_token.py |
Provides the public wrapper and launch logic. |
aiter/ops/triton/moe/moe_utils.py |
Builds block-to-expert mappings. |
aiter/ops/triton/moe/__init__.py |
Exports the new operation. |
op_tests/triton_tests/moe/test_moe_gemm_per_token.py |
Adds correctness and empty-input tests. |
op_tests/op_benchmarks/triton/bench_moe_gemm_per_token.py |
Adds performance measurements. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 5
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
1b58ff2 to
cc781da
Compare
cc781da to
90d7f2a
Compare
90d7f2a to
525d985
Compare
…ng utils Split from ROCm#5310 (per reviewer request). Introduces two components: moe_utils.py: build_block_mapping() pre-computes per-M-block expert IDs, token offsets, and valid row ends using pure GPU tensor ops (torch.bucketize + cumsum + torch.where). Zero .item() calls. moe_gemm_per_token: fused grouped MoE GEMM applying per-token FP32 activation scales and per-expert FP32 weight scales after FP8 dot-product accumulation. m_mask bounded by block_token_ends to prevent cross-expert reads.
525d985 to
38a63a5
Compare
…ng utils (ROCm#5338) Split from ROCm#5310 (per reviewer request). Introduces two components: moe_utils.py: build_block_mapping() pre-computes per-M-block expert IDs, token offsets, and valid row ends using pure GPU tensor ops (torch.bucketize + cumsum + torch.where). Zero .item() calls. moe_gemm_per_token: fused grouped MoE GEMM applying per-token FP32 activation scales and per-expert FP32 weight scales after FP8 dot-product accumulation. m_mask bounded by block_token_ends to prevent cross-expert reads. Signed-off-by: Xiake Sun <[email protected]>
Split from #5310 (per reviewer request to separate kernels into individual PRs).
Summary
Adds
moe_gemm_per_token: a fused grouped MoE GEMM kernel that appliesper-token FP32 activation scales and per-expert FP32 weight scales after
FP8 dot-product accumulation.
Depends on: #5310-mxfp8 PR (requires
moe_utils.build_block_mappingintroduced there).
Key design points
out[tokens_for_e] = lhs[tokens_for_e] @ rhs[e]^T * x_scale * w_scalem_maskbounded byblock_token_endsto prevent cross-expert readsbuild_block_mapping()frommoe_utils(zero.item()calls)Tests
op_tests/triton_tests/moe/test_moe_gemm_per_token.py: correctness + empty-token edge case