Repository navigation
[FlyDSL] grouped_moe_gfx1250: fold two launches into the MegaMoE A-preshuffle route - #8157
Conversation
…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.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
The original route-fold implementation was validated on gfx1250 in the November 17 DSR1 optimization runs, and that evidence was checked against this PR.
No new complete-model A/B was run to reproduce these results. |
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 initializesrow_to_tokenand 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
4b4401e62c155053b9db4fee08b4c8e3ab2d09f5was tested against maine1648cc122b940aa63f504ae39a6024b2c97def6on one four-GPU gfx1250 node with FlyDSL 0.5.0, PyTorch 2.11.0/ROCm build, Triton 3.9.0 and MoRI47df0dadd.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]andpsum[512]unwritten; both use the same scan source blob181ef2a55b6bb063a31ad762d4d438275627dd80. 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
a7a7c99e2plus 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
eaa68f2037eeffac8b356810dcb5ec869e6dfe82Behavior 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.pyandop_tests/multigpu_tests/test_mega_moe_gfx1250.py --world 4passed 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
e1648cc122b940aa63f504ae39a6024b2c97def6without 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_g2lchanges 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 canonicaltest_route_g2lLDS 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.