Skip to content

[FlyDSL] grouped_moe_gfx1250: fold two launches into the MegaMoE A-preshuffle route - #8157

Merged
JiaoliangYu merged 4 commits into
ROCm:mainfrom
JiaoliangYu:jiaolyu/moe-route-fold
Nov 23, 2026
Merged

JiaoliangYu merged 4 commits into
ROCm:mainfrom
JiaoliangYu:jiaolyu/moe-route-fold

Conversation

@JiaoliangYu

@JiaoliangYu JiaoliangYu commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The gfx1250 MegaMoE EP A-preshuffle path spent two extra launches before grouped GEMM1: initializing the grouped-row inverse map and building a g2l LUT.

Change

With AITER_TDM_APRE_ROUTE_FOLD=1 (default), the eligible LDS route initializes row_to_token and uses the aligned contiguous rank expert mask directly. Its separate persistent counter is cleared by the A-preshuffle scatter after the psum remap, its final reader. The opt-out, plain, non-A-preshuffle and compact routes retain their existing routing strategy.

Validation

Current candidate 4b4401e62c155053b9db4fee08b4c8e3ab2d09f5 was tested against main e1648cc122b940aa63f504ae39a6024b2c97def6 on one four-GPU gfx1250 node with FlyDSL 0.5.0, PyTorch 2.11.0/ROCm build, Triton 3.9.0 and MoRI 47df0dadd.

  • Route/psum/A-scatter passed independent count, rowmap, packed payload, scale and sentinel oracles at receive bounds 2560/6144/16384, tile M=128/256, fold/unfold/LDS-off/direct-off, changing device receive counts, 30 eager calls and 50 graph replays per mode. The E=512 last-counter-word reset case passed.
  • Canonical aux passed on both trees. EP4 GEMM1/GEMM2/communication pairings passed on both trees with fold=0/1, using the existing oracles and no errors or skips.
  • Three fixed-clock ABBA rounds of 24 default-CSV cases passed accuracy and found no case with a >2% regression in at least two rounds. The actual default-CSV A-preshuffle gate was off, so this is regression coverage for the inactive route, not a folded-route speedup measurement.
  • A separate forced-A-preshuffle tpr640/fp4 mechanism check passed accuracy on both trees. Every rank trace changed from 19 to 17 GPU launches per replay, removing the LUT and inverse-map fill without another standalone reset launch. This single pair is not a formal performance gain measurement.

Raw results are retained in the validation archive (SHA256 4ebfcc1e405ee6b96d6c0348f50a7aad11f45287d6ea67cdf28940620f200501). The diagnostics add snapshots/sentinels and are not used as production timings.

Remaining limitations

E=513 failed in the EP-specialized prefix scan. Independent probes on both trees left starts[512] and psum[512] unwritten; both use the same scan source blob 181ef2a55b6bb063a31ad762d4d438275627dd80. The route selects its non-LDS fallback, but that does not make the later EP scan support more than 512 local experts. This pre-existing limitation is retained as a failed case, not attributed to the new fold. Baseline evidence for E=513 is the prefix scan only, not a full fallback/scatter/GEMM run.

Formal three-round timings with the folded route actually active, and current-candidate complete DeepSeek-R1 accuracy/16-repeat validation, remain unverified. Historical roughly 3 us/layer and 80.7885 accuracy came from a7a7c99e2 plus an ATOM stack containing several other changes. Recovered historical logs show aggregate VALID/completed samples but also IPCBuffer cleanup assertion tracebacks, so the earlier zero-error claim is withdrawn. These historical results are not current-head full-model evidence.

PR Self-Review

Reviewed revision

eaa68f2037eeffac8b356810dcb5ec869e6dfe82

Behavior and intent

For the gfx1250 MegaMoE EP A-preshuffle path with LDS routing, fold the grouped-row inverse-map initialization into the route launch and use the aligned contiguous rank expert mask directly instead of launching a g2l LUT builder. A separate persistent counter is reset by the A-preshuffle scatter after the psum remap, its final reader. The opt-out AITER_TDM_APRE_ROUTE_FOLD=0, plain routing, non-A-preshuffle and compact paths retain their existing routing strategy. The default-on path removes two launch costs from each eligible layer.

Validation and unverified scope

This head only merges main into the previously reviewed 4b4401e62c155053b9db4fee08b4c8e3ab2d09f5; none of the PR's files changed in the merge, so the answers below still apply. The GPU results below were taken before the merge and were not repeated on this head.

On 4b4401e, a standalone route/scatter GPU check (not part of this PR) passed receive bounds 2560/6144/16384 for tile 128/256, all four routing modes, dynamic 0/1/half/full receive counts, 30 eager and 50 graph calls per mode, independent rowmap/payload/scales/sentinel oracles and E=512 counter reset. op_tests/test_flydsl_moe_aux.py and op_tests/multigpu_tests/test_mega_moe_gfx1250.py --world 4 passed on main/candidate, fold=0/1, with actual GEMM2/communication and no skips. Both import paths and full SHAs were recorded on the four-GPU gfx1250 node; FlyDSL was the requirements pin 0.5.0.

Three fixed-clock ABBA rounds cover 24 default-CSV cases and inactive-path regressions. Actual receive bounds, tile choices and gate=off were checked. A forced-A-preshuffle tpr640/fp4 trace confirms 19 to 17 launches on all ranks and both-tree accuracy, but it is only a mechanism pair. Formal active-fold gain, current-head full-model accuracy and zero-error 16-repeat remain unverified.

E=513 is a failed validation boundary: both trees' EP prefix-scan probe leaves expert 512 unwritten, and the scan blob is identical. Main's probe does not cover full E=513 fallback/scatter/GEMM, and no full PASS is claimed. Historical model commands and logs have been recovered; their different surrounding sources/dependencies and cleanup assertion errors prevent treating them as a fresh current-head, zero-error reproduction.

Host AST/Black/Ruff/whitespace checks passed. Main sync merged e1648cc122b940aa63f504ae39a6024b2c97def6 without changing the original five PR files. CI passes at this head. MI35X tests cannot substitute for gfx1250 coverage.

PR-specific question

The existing test_route_g2l changes the LDS launch's optional tail from (ep_ptr, ep_cap) to (ep_ptr, ep_cap, row_to_token_ptr, row_to_token_len), passing null/zero for the new inverse map. Its eager/graph bucket, dropped-route and weight-cast checks continue to exercise the public launcher ABI. This compatibility call does not prove non-null inverse-map fill or production counter reset; the separate current-head machine diagnostics cover those behaviors at E=64 and the E=512 boundary.

Changed op tests

op_tests/test_flydsl_moe_aux.py: preserves the existing canonical test_route_g2l LDS call after extending the launcher signature, while retaining the plain fallback signature. The new optional inverse-map pointer is null in this test, so its coverage remains launcher ABI compatibility; non-null fill/reset evidence is from the separate machine diagnostics.

…route

The A-preshuffle EP decode/prefill path ran three extra things before
every grouped GEMM1: a torch .fill_(-1) of the grouped-row -> token map
(the FillFunctor launch), the separate moe_g2l_lut launch that builds a
global expert LUT the route kernel then reads, and left the shared
route counter dirty for whoever reads it next.

Behind AITER_TDM_APRE_ROUTE_FOLD (on by default, matching
AITER_FLYDSL_ROUTE_G2L_LDS), when apre, EP scatter and the LDS route
path are all in play:
- the LDS route kernel takes row_to_token and -1-fills it itself, so the
  standalone fill goes away;
- it routes on MegaMoE's aligned per-rank expert mask directly instead
  of a built LUT, so moe_g2l_lut goes away for this path;
- the counter this needs is a separate one from the LUT path's shared
  counter (the LUT path leaves it dirty), and the apre scatter zeroes it
  after the psum remap, its last reader, so the next route starts clean
  without a dedicated reset launch.

Measured about 3 us/layer (about 0.17 ms/decode step) on a DeepSeek-R1
EP4 shape at a recv bound of 6144.

Bit-exact: psum, ep_rowmap, the FC1 A payload and scales, and the final
GEMM2 output match the unfolded path per route, checked at recv bounds
6144 and 16384 (the folded path) and 2560 (the LUT path, unchanged) with
30 eager calls and 50 graph replays mixing both. test_route_g2l (lds and
plain variants) in op_tests/test_flydsl_moe_aux.py covers the new
row_to_token tail; extended here to pass it through.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8157 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@JiaoliangYu
JiaoliangYu marked this pull request as ready for review November 18, 2026 13:01
@JiaoliangYu
JiaoliangYu requested a review from a team November 18, 2026 13:01
@github-actions github-actions Bot changed the title grouped_moe_gfx1250: fold two launches into the MegaMoE A-preshuffle route [FlyDSL] grouped_moe_gfx1250: fold two launches into the MegaMoE A-preshuffle route Nov 18, 2026
@aiter-bot

aiter-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision eaa68f2037ee · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

For the gfx1250 MegaMoE EP A-preshuffle path with LDS routing, fold the grouped-row inverse-map initialization into the route launch and use the aligned contiguous rank expert mask directly instead of launching a g2l LUT builder. A separate persistent counter is reset by the A-preshuffle scatter after the psum remap, its final reader. The opt-out `AITER_TDM_APRE_ROUTE_FOLD=0`, plain routing, non-A-preshuffle and compact paths retain their existing routing strategy. The default-on path removes two launch costs from each eligible layer.

Validation and unverified scope

This head only merges main into the previously reviewed `4b4401e62c155053b9db4fee08b4c8e3ab2d09f5`; none of the PR's files changed in the merge, so the answers below still apply. The GPU results below were taken before the merge and were not repeated on this head.

On `4b4401e`, a standalone route/scatter GPU check (not part of this PR) passed receive bounds 2560/6144/16384 for tile 128/256, all four routing modes, dynamic 0/1/half/full receive counts, 30 eager and 50 graph calls per mode, independent rowmap/payload/scales/sentinel oracles and E=512 counter reset. `op_tests/test_flydsl_moe_aux.py` and `op_tests/multigpu_tests/test_mega_moe_gfx1250.py --world 4` passed on main/candidate, fold=0/1, with actual GEMM2/communication and no skips. Both import paths and full SHAs were recorded on the four-GPU gfx1250 node; FlyDSL was the requirements pin 0.5.0.

Three fixed-clock ABBA rounds cover 24 default-CSV cases and inactive-path regressions. Actual receive bounds, tile choices and gate=off were checked. A forced-A-preshuffle tpr640/fp4 trace confirms 19 to 17 launches on all ranks and both-tree accuracy, but it is only a mechanism pair. Formal active-fold gain, current-head full-model accuracy and zero-error 16-repeat remain unverified.

E=513 is a failed validation boundary: both trees' EP prefix-scan probe leaves expert 512 unwritten, and the scan blob is identical. Main's probe does not cover full E=513 fallback/scatter/GEMM, and no full PASS is claimed. Historical model commands and logs have been recovered; their different surrounding sources/dependencies and cleanup assertion errors prevent treating them as a fresh current-head, zero-error reproduction.

Host AST/Black/Ruff/whitespace checks passed. Main sync merged `e1648cc122b940aa63f504ae39a6024b2c97def6` without changing the original five PR files. CI passes at this head. MI35X tests cannot substitute for gfx1250 coverage.

PR-specific question

The existing `test_route_g2l` changes the LDS launch's optional tail from `(ep_ptr, ep_cap)` to `(ep_ptr, ep_cap, row_to_token_ptr, row_to_token_len)`, passing null/zero for the new inverse map. Its eager/graph bucket, dropped-route and weight-cast checks continue to exercise the public launcher ABI. This compatibility call does not prove non-null inverse-map fill or production counter reset; the separate current-head machine diagnostics cover those behaviors at E=64 and the E=512 boundary.

Changed op tests

`op_tests/test_flydsl_moe_aux.py`: preserves the existing canonical `test_route_g2l` LDS call after extending the launcher signature, while retaining the plain fallback signature. The new optional inverse-map pointer is null in this test, so its coverage remains launcher ABI compatibility; non-null fill/reset evidence is from the separate machine diagnostics.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

@zufayu zufayu self-assigned this Nov 19, 2026
@JiaoliangYu

JiaoliangYu commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

The original route-fold implementation was validated on gfx1250 in the November 17 DSR1 optimization runs, and that evidence was checked against this PR.

  • The existing test_route_g2l passed on the original implementation.
  • Against PR head 4b4401e62c155053b9db4fee08b4c8e3ab2d09f5: the changes in the four production files match the original patch, including the LDS route/scatter core; surrounding source and dependencies differ.
  • The November 17 MLPerf trace recorded about 0.18 ms less per decode step for the route-fold component. This is a historical component trace, not a new-head measurement or a standalone end-to-end gain.
  • The combined optimization stack, including this patch, completed DSR1 accuracy at 80.788514% (threshold 80.545%, 4,388 samples) and the 16-repeat / 70,208-request performance run at 89,787.1 output tokens/s, with one aggregate LoadGen VALID result. These are combined-stack results and are not attributed to this PR alone. Both logs contain 16 IPCBuffer cleanup assertions after processing; completion and scoring are established, but a zero-error run is not claimed.

No new complete-model A/B was run to reproduce these results.

@JiaoliangYu
JiaoliangYu merged commit 43d5afd into ROCm:main Nov 23, 2026
73 checks passed
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.

3 participants