Repository navigation
[FlyDSL] MoE stage 2: fix the fp8 route-out scale group for tile_n=128 - #7949
Conversation
🏷️ 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 |
|
This likely also fixes FHMoE |
|
Nit: the Changes section and the self-review say |
|
For reference: #8174 adds a per-call |
The fp8 route-out epilogue quantizes one fragment to e4m3 and stores a single e8m0 byte per 8-column group, but the fragment width is min(tile_n // 32, 8), i.e. 4 for tile_n=128. Two fragments then write different scales to the same byte and half of every group is dequantized with the wrong scale (~44% relative error with AITER_FLYDSL_STAGE2_FP8=1 on the v1 tiles). Use 8-wide fragments for fp8 output and shrink the CShuffle N lanes to match. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
Fails before the scale-group fix (tile_n=128), passes after. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
AITER_FLYDSL_STAGE2_FP8=1 moves every fp4/fp8 atomic tile to reduce. With AITER_FLYDSL_STAGE2_FP8_KEEP_ATOMIC=1 atomic tiles stay atomic and only tiles tuned for reduce use FP8 route rows. The default is unchanged. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
…-in" Forced and keep-atomic modes measured the same on DeepSeek-V4.1-Flash serving (TTFT, decode throughput, gsm8k), so the extra switch is not needed. This reverts commit 1ad8079. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
…es rows Runs DSv4 FHMoE with AITER_FLYDSL_STAGE2_FP8=1 at the tuned t32x128x128_reduce_persist row (4 tokens) and the t32x256x128_reduce_bnt2_persist row (8 tokens), whose shared expert runs as two 128-column halves, against the fp32 reference and the BF16 route-row output. Before the scale-group fix the relative error is 0.426 and 0.207; after it, 0.031 and 0.033. Unlike flydsl_tests/test_flydsl_moe.py, test_fhmoe.py runs in CI. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
9613075 to
09a4d37
Compare
|
Thanks for the review @msaffari-amd! All addressed in 09a4d37 (rebased on current main):
|
|
Is |
test_flydsl_moe.py is not collected by CI, and test_dsv4_fhmoe_fp8_route_out_matches_fp32 in test_fhmoe.py covers the same epilogue: 128-column routed and shared bodies at 4 tokens, and 256-column routed bodies at 8 tokens. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
|
@Bernard-Liu Agreed, it isn't needed. Dropped in 867a206, so the PR now adds only the CI-run test. The FHMoE test covers both parametrizations of the direct case: at 4 tokens the routed and shared tiles both run with a 128-column body, and at 8 tokens the routed tiles keep a 256-column body (the path where the 8-wide fragment was already correct) while the shared expert runs as two 128-column halves. Description updated to match. |
ROCm#7949 dropped this test on main: test_fhmoe.py covers the tile_n 128 and 256 FP8 route-out epilogue. test_flydsl_stage2_fp8_route_out_name still checks that the FP8 name is bit-exact with AITER_FLYDSL_STAGE2_FP8=1 and close to the reference. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
Summary
Fixes the v1 FlyDSL stage-2 fp8 route-out epilogue when the tile body is 128
columns wide:
tile_n=128tiles, and FHMoEtile_n=256tiles whose sharedexpert runs as two 128-column halves. With
AITER_FLYDSL_STAGE2_FP8=1thesegave 20–44% relative error.
Motivation
The fp8 epilogue quantizes one CShuffle fragment and writes one e8m0 byte per
8-column group, but the fragment is
min(body_tile_n // 32, 8)= 4 columnswide when
body_tile_nis 128. Two fragments then write different scales tothe same byte, and half of every group is dequantized with the wrong scale.
body_tile_nis 128 for:tile_n=128tiles: atomic tiles the flag moves to reduce (e.g. DSv4.1 TP4t16x128x128_atomic_bnt2, T=17-128 and 1025-2048) and rows already tunedas reduce (e.g. in
tuned_fhmoe.csv,minimax_m3_mxfp8,dsv4_fp8fp4; notchecked row by row);
tile_n=256tiles with a shared expert:serial_shared_nruns theshared expert as two 128-column halves (e.g.
tuned_fhmoe.csvt32x256x128_reduce_bnt2_persist). Found by @msaffari-amd.Non-shared
tile_n=256tiles and the layout (v2) kernels are not affected.Changes
mixed_moe_gemm_2stage_common.py: for fp8 output, use 8-wide fragments andcshuffle_nlane = min(32, body_tile_n // 8), so one fragment is one MXFP8group.
body_tile_ncovers the FHMoE halves, and themin(32, ...)keepstile_n=512valid. Non-fp8 epilogues are unchanged.op_tests/test_fhmoe.py:test_dsv4_fhmoe_fp8_route_out_matches_fp32, whichCI runs. DSv4 FHMoE with the flag at the tuned
tile_n=128row (4 tokens)and the
tile_n=256shared-halves row (8 tokens), against the fp32reference and the BF16 route-row output.
Performance
Not applicable: correctness fix. The epilogue issues the same stores with a
different fragment width, only for fp8 output with a 128-column body.
Testing
Documentation
Internal kernel fix.
Dependencies
Breaking Changes
None
PR Self-Review
Reviewed revision
867a206
Behavior and intent
With
AITER_FLYDSL_STAGE2_FP8=1, v1 FlyDSL stage-2 tiles whose body is 128columns now write correct fp8 route rows. Before, the epilogue quantized
4-column CShuffle fragments (
min(body_tile_n // 32, 8)) but stored one e8m0byte per 8-column MXFP8 group, so two fragments wrote different scales to the
same byte and half of every group was dequantized with the wrong scale. This
hits
tile_n=128tiles (about 44% relative error) and FHMoEtile_n=256tiles with a shared expert, whose shared halves are 128 columns (about 21%).
Non-shared
tile_n=256, the v2 kernels and non-fp8 epilogues are unchanged.Validation and unverified scope
All on MI355X (gfx950), FlyDSL 0.5.3, rebased on main 930e954.
pytest op_tests/test_fhmoe.py -k "fp8_route_out or dsv4_production_reduce":the new test, relative L2 error against the fp32 reference with FP8 route
rows:
t32x128x128_reduce_persistt32x256x128_reduce_bnt2_persist(shared halves)"Before" is this branch with only the kernel file taken from main.
Full
pytest op_tests/test_fhmoe.py(as CI runs it): 121 passed.DSv4.1 TP4
fused_moewith the flag, T = 1..16384, both MoE shapes (384experts top-6, 128 experts top-3): worst relative error against BF16 route
rows is 2.7% after the fix (about 44% before).
vLLM DSv4.1-Flash TP4 with the flag: gsm8k (full, 5-shot) 0.9265-0.9272
(BF16 route rows 0.9189-0.9295); niah_single_2 32k/64k 1.0/1.0.
Unverified: the serving run used a branch with other MoE changes (inter-dim
padding, XCD remap, [FlyDSL] Fix LDS race in MoE sorting p23 kernel #7349). Other models'
tile_n=128reduce rows were notrun individually. MI250X/MI300X were not run.
PR-specific question
What is the most important boundary or failure mode introduced by this
change, and what evidence covers it?
The boundary is the fragment width in the fp8 epilogue: it must equal the
8-column MXFP8 group for every
body_tile_n, including the 128-column sharedhalves of an FHMoE
tile_n=256tile.test_dsv4_fhmoe_fp8_route_out_matches_fp32covers both 128-column cases through CI on the tuned DSv4 FHMoE rows: before
the fix it fails at 0.426 and 0.207 relative error, after it passes at 0.031
and 0.033, within the 5e-2 bound of the existing DSv4 reduce test. It also
asserts the tuned stage 2 it runs, so a table change that moves these rows
off the 128-column paths fails loudly instead of passing vacuously, and that
FP8 route rows were actually used. The 8-token row's routed tiles keep a
256-column body, where the 8-wide fragment was already correct, so the same
test also guards that path. The other direction,
tile_n=512,is kept valid by
min(32, body_tile_n // 8); no shipped fp8 route-out rowuses it.
Changed op tests
op_tests/test_fhmoe.py: addstest_dsv4_fhmoe_fp8_route_out_matches_fp32[4|8],the only CI test that runs the v1 fp8 route-out epilogue against a
reference, at a
tile_n=128row and atile_n=256shared-halves row. Theexisting FHMoE tests leave the flag unset (BF16 route rows), and
test_flydsl_stage2_classification_covers_plain_and_fhmoe_wrappersonlychecks dispatch.
AI disclosure: written with Claude Opus 5.5 (Cursor); reviewed and run by the
author.