Skip to content

[Triton/Gluon] Add per-token-scaled grouped MoE GEMM kernel - #5338

Merged
shengnxu merged 2 commits into
ROCm:mainfrom
WuLei-AMD:dev_lumen_pr5_moe_gemm_per_token
Sep 14, 2026
Merged

shengnxu merged 2 commits into
ROCm:mainfrom
WuLei-AMD:dev_lumen_pr5_moe_gemm_per_token

Conversation

@WuLei-AMD

Copy link
Copy Markdown
Contributor

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 applies
per-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_mapping
introduced there).

Key design points

  • TN layout: out[tokens_for_e] = lhs[tokens_for_e] @ rhs[e]^T * x_scale * w_scale
  • m_mask bounded by block_token_ends to prevent cross-expert reads
  • Shares build_block_mapping() from moe_utils (zero .item() calls)

Tests

  • op_tests/triton_tests/moe/test_moe_gemm_per_token.py: correctness + empty-token edge case
  • All tests pass on MI308X

@WuLei-AMD
WuLei-AMD requested a review from a team September 8, 2026 13:13
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5338 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@WuLei-AMD
WuLei-AMD force-pushed the dev_lumen_pr5_moe_gemm_per_token branch 2 times, most recently from 7ddc455 to 72b3efc Compare September 8, 2026 13:36
@ZhangDanyang-AMD
ZhangDanyang-AMD force-pushed the dev_lumen_pr5_moe_gemm_per_token branch 2 times, most recently from 2a82eb8 to 8a434c9 Compare September 8, 2026 14:41
@zufayu
zufayu requested review from a team and Dewei-Wang-sh September 9, 2026 01:24
@Boss2002n
Boss2002n requested a balanced review from Copilot September 9, 2026 02:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@ZhangDanyang-AMD
ZhangDanyang-AMD force-pushed the dev_lumen_pr5_moe_gemm_per_token branch 3 times, most recently from 1b58ff2 to cc781da Compare September 9, 2026 09:57
Dewei-Wang-sh
Dewei-Wang-sh previously approved these changes Sep 10, 2026
…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.
@ZhangDanyang-AMD
ZhangDanyang-AMD force-pushed the dev_lumen_pr5_moe_gemm_per_token branch from 525d985 to 38a63a5 Compare September 11, 2026 14:05
@shengnxu
shengnxu merged commit 804f655 into ROCm:main Sep 14, 2026
95 of 100 checks passed
sammysun0711 pushed a commit to sammysun0711/aiter that referenced this pull request Sep 16, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants