Skip to content

[FlyDSL][MoE] Fix gfx1250 HERD decode routing and extend it past 512 experts - #7130

Merged
charlieguo1106 merged 3 commits into
mainfrom
cguo/fixherd
Oct 30, 2026
Merged

charlieguo1106 merged 3 commits into
mainfrom
cguo/fixherd

Conversation

@charlieguo1106

@charlieguo1106 charlieguo1106 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three fixes to the gfx1250 HERD path from #6527:

  1. Regression: after [FlyDSL] [CI] [MoE] Enable AITER_FLYDSL_USE_HERD on gfx1250 and add a fused HERD selector for GPT-OSS #6527 merged with [FlyDSL] [Perf] MiniMax-M3 MoE on gfx1250: fused route psum and tuned grouped A8W4 tiles #6668, HERD decode steps took the fused TP route and skipped the HERD drop, which produced wrong MoE output.
  2. fused_moe(herd_topk=...) raised for E > 512 (Kimi-K3, E=896). The drop is now chosen by expert count, and AITER_HERD_FUSED_DROP is removed.
  3. HERD sigmoid candidate selection raised on wave32 GPUs, so two test_flydsl_herd.py cases failed on gfx1250.

1. Keep HERD routes off the fused TP route

With fused drop, fused_moe(herd_topk=K) keeps the K+1 candidate tensors and sets only the scalar topk to K; herd_route_psum_remap drops one candidate per token later. #6668 added _fused_tp_route for TP batches with token_num * topk <= 2048 and E <= 512, and the merge put the HERD route under elif not _fused_tp_route:. That condition holds for the whole HERD window (16..128 tokens) on DeepSeek-V4-Flash (E=256, K=6) and GPT-OSS (E=128, K=4). On those steps:

  • the HERD drop never ran;
  • fused_route_psum_remap read K+1 from the tensor shape, built a K+1-wide route map, and kept every candidate with its raw weight;
  • the activation quant still used source_topk = K, so route r read token r // K, the wrong token for most routes.

On b5078fc, test_fused_moe_outputs_match_router_drop[16] returns NaN rows.

Fix: _fused_tp_route now excludes HERD steps, so they take herd_route_psum_remap. Non-HERD TP batches keep the fused route.

2. Pick the gfx1250 HERD drop by expert count

The fused drop runs in one workgroup with one LDS slot per expert, so herd_route_psum_remap accepts at most 512 experts (_FUSED_ROUTE_PSUM_MAX_EXPERTS). With the default AITER_HERD_FUSED_DROP=1, E > 512 raised there.

fused_moe now decides from E:

  • E <= 512: drop inside the grouped MoE route kernel, the previous default.
  • E > 512: finalize the candidates with herd_finalize_candidates first (1024 threads for E > 512), then take the ordinary route. contiguous_psum_remap scans experts in chunks and supports up to 2048.

Both paths produce the same routes, so the AITER_HERD_FUSED_DROP switch is removed. gfx950 is unchanged: there HERD finishes in the router and never reaches fused_moe(herd_topk).

3. Sigmoid HERD candidates on wave32

The FlyDSL sigmoid selector in herd_topk_candidates ballots over a 64-lane wave and raises on wave32, so test_candidate_scoring[sigmoid] failed on gfx1250. The FFM CI shard runs op_tests/test_flydsl_herd.py. Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.

Tests

op_tests/test_flydsl_herd.py: the three tests that toggled AITER_HERD_FUSED_DROP now run (E, K) = (128, 4) and (896, 16), covering the fused drop and the finalize-first path:

  • test_herd_topk_is_only_for_gfx1250
  • test_fused_moe_outputs_match_router_drop
  • test_fused_moe_herd_skips_pad_rows

ROCm/ATOM#2713 routes Kimi-K3 HERD candidates through fused_moe(herd_topk=16) with E=896, which needs fix 2.

The small-batch TP route (_fused_tp_route) reads topk from the route
tensor, so a HERD step's K+1 candidates went through it undropped while
the quant kernel still used K as the source topk. That mismaps tokens
and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and
GPT-OSS (M*K <= 2048, E <= 512) took this path.

Route HERD steps through herd_route_psum_remap instead.
@charlieguo1106
charlieguo1106 requested a review from a team October 29, 2026 05:28
@github-actions

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

@github-actions github-actions Bot changed the title [FlyDSL][MoE] Keep HERD routes off the fused TP route [FlyDSL] [MoE] Keep HERD routes off the fused TP route Oct 29, 2026
@charlieguo1106 charlieguo1106 changed the title [FlyDSL] [MoE] Keep HERD routes off the fused TP route [BugFix][FlyDSL] [MoE] Keep HERD routes off the fused TP route Oct 29, 2026
fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE
route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one
workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896)
raised in herd_route_psum_remap.

Drop in the grouped MoE route when E fits that kernel, and finalize the
candidates in fused_moe first otherwise. Both produce the same routes, so
the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged.

The HERD tests that toggled the switch now run E=128 and E=896.
@github-actions github-actions Bot changed the title [BugFix][FlyDSL] [MoE] Keep HERD routes off the fused TP route [FlyDSL] [BugFix] [MoE] Keep HERD routes off the fused TP route Oct 29, 2026
…ave32

herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave
and raises on wave32, so test_candidate_scoring[sigmoid] failed on
gfx1250, where the FFM CI shard runs test_flydsl_herd.py.

Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the
kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference
for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
@charlieguo1106 charlieguo1106 changed the title [FlyDSL] [BugFix] [MoE] Keep HERD routes off the fused TP route [FlyDSL][MoE] Fix gfx1250 HERD decode routing and extend it past 512 experts Oct 29, 2026
@aiter-bot

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 500efa9b08b5 · 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 behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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/test_flydsl_herd.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.

@charlieguo1106
charlieguo1106 merged commit 05dbf34 into main Oct 30, 2026
54 checks passed
@charlieguo1106
charlieguo1106 deleted the cguo/fixherd branch October 30, 2026 03:06
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
…experts (#7130)

* [FlyDSL][MoE] Keep HERD routes off the fused TP route

The small-batch TP route (_fused_tp_route) reads topk from the route
tensor, so a HERD step's K+1 candidates went through it undropped while
the quant kernel still used K as the source topk. That mismaps tokens
and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and
GPT-OSS (M*K <= 2048, E <= 512) took this path.

Route HERD steps through herd_route_psum_remap instead.

* [FlyDSL][MoE] Pick the gfx1250 HERD drop by expert count

fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE
route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one
workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896)
raised in herd_route_psum_remap.

Drop in the grouped MoE route when E fits that kernel, and finalize the
candidates in fused_moe first otherwise. Both produce the same routes, so
the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged.

The HERD tests that toggled the switch now run E=128 and E=896.

* [FlyDSL][MoE] Select sigmoid HERD candidates with the HIP gating on wave32

herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave
and raises on wave32, so test_candidate_scoring[sigmoid] failed on
gfx1250, where the FFM CI shard runs test_flydsl_herd.py.

Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the
kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference
for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…experts (ROCm#7130)

* [FlyDSL][MoE] Keep HERD routes off the fused TP route

The small-batch TP route (_fused_tp_route) reads topk from the route
tensor, so a HERD step's K+1 candidates went through it undropped while
the quant kernel still used K as the source topk. That mismaps tokens
and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and
GPT-OSS (M*K <= 2048, E <= 512) took this path.

Route HERD steps through herd_route_psum_remap instead.

* [FlyDSL][MoE] Pick the gfx1250 HERD drop by expert count

fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE
route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one
workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896)
raised in herd_route_psum_remap.

Drop in the grouped MoE route when E fits that kernel, and finalize the
candidates in fused_moe first otherwise. Both produce the same routes, so
the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged.

The HERD tests that toggled the switch now run E=128 and E=896.

* [FlyDSL][MoE] Select sigmoid HERD candidates with the HIP gating on wave32

herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave
and raises on wave32, so test_candidate_scoring[sigmoid] failed on
gfx1250, where the FFM CI shard runs test_flydsl_herd.py.

Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the
kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference
for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants