Skip to content

[FlyDSL] [CI] [MoE] gemm2: bound atomic rows by the sort's valid token count - #7294

Merged
JiaoliangYu merged 4 commits into
mainfrom
gbyu/flydsl-gemm2-valid-token-count
Nov 4, 2026
Merged

JiaoliangYu merged 4 commits into
mainfrom
gbyu/flydsl-gemm2-valid-token-count

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem

With num_local_tokens, moe_sorting fills each expert block's tail with the pad sentinel MOE_SORTING_MOCK_ID(tokens, topk), whose token id is the real token count. When the caller's M is padded (e.g. a cudagraph batch), that id is still < M, so the a16w4 (moe_2stage_a16wmix/gemm2.py) and native mxfp4 (mxfp4_gemm2.py) atomic epilogs, which bound rows by token_id < M, scatter every pad slot into row tokens.

Seen in ATOM Kimi-K3 (TP8, bs=100 decode in a 128-row cudagraph): gemm2_a16w4_port went 5.45 → 24.9 ms/step from the atomic pileup into one row.

Fix

Add use_valid_token_count (default False) to both gemm2s, as the v2 dispatcher already has. When it is set, rows are bounded by min(cumsum[1], M), and the kernel name gets a _valid_tokens suffix. When it is off, the compiled kernels are unchanged. It only applies to the atomic epilog (a16w4: non-reduce; mxfp4: epilog == "atomic").

fused_moe_2stages enables it for the flydsl / flydsl-v2 / native-mxfp4 stage2 whenever num_local_tokens is passed.

Test

op_tests/flydsl_tests/test_gemm2_valid_token_count.py (gfx950): M=128 padded with 100 real tokens, blocks padded with the sentinel. For both kernels:

  • flag off reproduces the pileup (row 100 non-zero);
  • flag on gives bit-equal rows [0, 100);
  • pad rows are untouched.
2 passed in 5.80s   (MI355X, rocm/atom-dev:nightly_202610310756, aiter bd4ff1c70 + this patch)

Not yet run end to end (serving / accuracy) with this branch.

🤖 Generated with Claude Code

With num_local_tokens, moe_sorting fills each expert block with the pad
sentinel MOE_SORTING_MOCK_ID(tokens, topk), whose token id is the REAL token
count. When the caller's M is padded (cudagraph), that id is still < M, so
the a16w4 and mxfp4 atomic gemm2 epilogs (bounded by token_id < M) scatter
every pad slot into row `tokens`.

Add use_valid_token_count to both kernels: rows are bounded by
min(cumsum[1], M), as the v2 dispatcher already does. fused_moe_2stages
enables it whenever num_local_tokens is passed. Off by default; the compiled
kernels are unchanged when it is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7294 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision e55e87ebfb65 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/flydsl_tests/test_gemm2_valid_token_count.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@github-actions github-actions Bot changed the title [FlyDSL][MoE] gemm2: bound atomic rows by the sort's valid token count [FlyDSL] [MoE] gemm2: bound atomic rows by the sort's valid token count Nov 2, 2026
@github-actions github-actions Bot added the FlyDSL label Nov 2, 2026
op_tests/flydsl_tests/ is outside split_tests.sh discovery, and the file has
no __main__, so add it to the explicit list and the pytest branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot changed the title [FlyDSL] [MoE] gemm2: bound atomic rows by the sort's valid token count [FlyDSL] [CI] [MoE] gemm2: bound atomic rows by the sort's valid token count Nov 4, 2026
@github-actions github-actions Bot added the CI label Nov 4, 2026
@JiaoliangYu
JiaoliangYu merged commit f60ee45 into main Nov 4, 2026
@JiaoliangYu
JiaoliangYu deleted the gbyu/flydsl-gemm2-valid-token-count branch November 4, 2026 07:00
yuychang added a commit to yuychang/aiter that referenced this pull request Nov 5, 2026
- Resolve fused_moe.py conflict: keep the presort-ignored check and main's AsmMoeMode (ROCm#5988) line
- No presort interaction with ROCm#7294: use_valid_token_count needs num_local_tokens, which disables the presort
LiuYinfeng01 added a commit to LiuYinfeng01/aiter that referenced this pull request Nov 5, 2026
Resolve conflicts with ROCm#6552 (a16wmix SiLU honours swiglu_limit), ROCm#7294
(gemm2 use_valid_token_count) and the a8w8 literal-file CI case:

- gemm1 epilogue: plain silu keeps ROCm#6552's clamp_gate_up; the optional
  activation_bf16 rounding is applied before the activation. situ_params
  is now built for every activation, as on main.
- gemm2 and flydsl_a16w4_gemm2: keep both reuse_lds and
  use_valid_token_count; their kernel-name tags stay distinct.
- moe_kernels: keep the silu_clamped/activation_bf16 validation with
  main's bf16-weight comment.
- aiter_test.sh: keep the pytest case for test_flydsl_moe_a16wfp4.py next
  to main's test_gemm_a8w8.py case.

silu_clamped and ROCm#6552's clamped silu share the same clamp: gate is
upper-bounded and up is clamped to [-limit, limit] before silu(gate) * up.
silu_clamped additionally requires a positive limit and is the only mode
that accepts activation_bf16.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
MHYangAMD added a commit to AFDEAPAC/aiter that referenced this pull request Nov 10, 2026
…942-fp8-mfma

Conflicts in the a16wmix port, resolved by keeping both sides. The fp8
kernels are separate definitions, so two main changes are carried into them:

- gemm1 (ROCm#6552): SiLU clamps before silu_mul_batch, so the fp8 kernel builds
  situ_params for every activation, as the bf16 kernel now does. The fp8
  dequant still runs before the activation.
- gemm2 (ROCm#7294): the fp8 kernel bounds scatter rows by min(cumsum[1], M)
  under use_valid_token_count, as the bf16 kernel does.
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…n count (ROCm#7294)

* [FlyDSL][MoE] gemm2: bound atomic rows by the sort's valid token count

With num_local_tokens, moe_sorting fills each expert block with the pad
sentinel MOE_SORTING_MOCK_ID(tokens, topk), whose token id is the REAL token
count. When the caller's M is padded (cudagraph), that id is still < M, so
the a16w4 and mxfp4 atomic gemm2 epilogs (bounded by token_id < M) scatter
every pad slot into row `tokens`.

Add use_valid_token_count to both kernels: rows are bounded by
min(cumsum[1], M), as the v2 dispatcher already does. fused_moe_2stages
enables it whenever num_local_tokens is passed. Off by default; the compiled
kernels are unchanged when it is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [CI] Shard and run gemm2 valid-token-count test under pytest

op_tests/flydsl_tests/ is outside split_tests.sh discovery, and the file has
no __main__, so add it to the explicit list and the pytest branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: ganyi <[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.

5 participants