Repository navigation
[CK] [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows - #8032
cpersson-amd wants to merge 11 commits into
Conversation
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]>
FP8 route rows were only reachable through AITER_FLYDSL_STAGE2_FP8=1, which applies to every reduce tile and converts atomic tiles to reduce. Rows where BF16 is faster could not opt out, and the tuner never timed the FP8 variant of v2 stage 2. Kernel names now carry the choice: a `_fp8` suffix on v1 reduce names (stage-2 params get route_out_dtype="fp8"; out_dtype stays the final dtype) and `fp8` in the v2 out field. Both wrappers, the route-output sizing, the topk_weights hand-off and the MXFP4 AOT builder follow the name. The env flag remains a global override. gemm_moe_tune.py gains --flydsl-stage2-fp8, which adds the FP8 reduce variants as candidates (v1 and v2) under the existing cosine gate. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
Resolve conflicts with the fused shared expert (ROCm#7773), the MXFP4 route-output intermediate (ROCm#7706) and the scatter LDS pairs option: keep the per-kernel-name FP8 route-out selection, with the MXFP4 intermediate as the fallback when FP8 is not selected. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
mjkvaak-amd
left a comment
There was a problem hiding this comment.
Checked on Qwen (MI355X, v0.1.30 with and without this PR's diff, 3 interleaved repeats). I found no regressions: every row picks the same kernels.
FP8 names on the 31 Qwen reduce rows are bit-exact with AITER_FLYDSL_STAGE2_FP8=1 and give the same trade-off as on DSv4.1, so the per-row choice fits Qwen too:
| Model | Reduce rows | FP8 vs BF16 (geomean) | Range |
|---|---|---|---|
| qwen3.5-397b | 17 | 1.17x | 0.94x (32 tok) – 1.41x (32k) |
| qwen3.8-2.4T | 7 | 1.23x | 1.11x – 1.33x |
| qwen3.8-flash | 6 | 1.17x | 1.06x – 1.28x |
Rel L1 vs BF16 is ~2.5%. FP8 also lets 2.4T's 32768-token row run, which exceeds the 32-bit buffer limit in BF16.
BTW the description says dsv41_fp8_tuned_fmoe.csv is retuned, but no commit here touches it. Was the table commit not pushed?
| "fp8" | ||
| if v2_g2["epilog"] == "reduce" and stage2_fp8_route_out | ||
| if v2_g2["epilog"] == "reduce" | ||
| and (stage2_fp8_route_out or v2_g2["out_dtype"] == "fp8") |
There was a problem hiding this comment.
With AITER_MXFP4_INTERMEDIATE=1, a v2 row named fp8 still takes the FP4 branch below: line 289 checks only stage2_fp8_route_out, the env flag. Could you check if this causes issues?
There was a problem hiding this comment.
Good catch, it did. With AITER_MXFP4_INTERMEDIATE=1 the runtime launches an fp8-named v2 reduce row with FP8 route rows, but this builder only checked the env flag, so it compiled the FP4 variant. Fixed in 1528986, which checks the out dtype resolved from the kernel name instead.
Checked on MI355X with AITER_MXFP4_INTERMEDIATE=1 against the kernels the runtime replay (aiter.aot.flydsl.moe) builds for the DSv4.1 table. Before the fix, the standalone mxfp4_moe build missed 5 of the 48 v2 stage-2 kernels (the FP8 variants) and 2 of the 4 reductions. After the fix it covers all of them. The usual aiter.aot.flydsl.moe prebuild was not affected, since it compiles whatever the runtime launches.
Resolve gemm_moe_tune.py against the EP tuning options (--ep-size, --ep-seed): keep both CLI options, and pass both the FP8 route-out arguments and the EP arguments to the v2 stage-2 launch and reduction.
…NTERMEDIATE The runtime launches a v2 reduce row named fp8 with FP8 route rows even when AITER_MXFP4_INTERMEDIATE=1, but the AOT builder only checked the AITER_FLYDSL_STAGE2_FP8 env flag before switching reduce to FP4, so it compiled the FP4 variant and the FP8 kernel was JIT-built at first use. Check the resolved out dtype instead. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
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]>
…40 rows 13 of the 32 (5120, 640) rows, gfx950: - E=384 top-6, 4096-32768 and E=128 top-3, 2048, 8192-32768: same stage 1 and block_m, stage 2 switches to the FP8 version of the same kernel. - E=128, 1024 and 4096: retuned with --flydsl-stage2-fp8, FP8 stage 2. - E=128, 8 and 256, E=384, 4: retuned, BF16 stage 2. A row changes only where fused_moe is at least ~3% faster at both token counts it serves. The E=384 32-128 rows are left to ROCm#8665. fused_moe on MI355X, CUDA graph, two runs, no env flag (E=384 with routing captured from vLLM, E=128 uniform): E=384 -6% at 3072 to -14% at 32768; E=128 -10% at 5-8, -6% at 129-256, -4% at 513-2048, -9% at 2049-4096 and -7% to -13% from 6144 up. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
The EP tuning mode added on main passes expert_mask and topk_ids to the v2 stage-2 reduction; FP8 route rows have not been validated with them. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
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 |
Summary
AITER_FLYDSL_STAGE2_FP8=1makes every reduce stage 2 write FP8 route rows. That is faster for prefill but slower for small batches. This PR makes FP8 route output a per-row choice through the tuned kernel name, adds a tuner option for the FP8 variants, and retunes 13 DSv4.1 TP4 a8w4 rows. Without the env flag,fused_moeis 6–13% faster for target prefill (3072+ tokens) and up to 13% faster for the draft.Motivation
With the env flag, DSv4.1
fused_moeis 6–13% faster from 3072 tokens up but 2–4% slower at 24–128 tokens. A global flag can't keep both, and the tuner never timed the FP8 variants, so the tuned rows couldn't select them.#8669 added a second row table that applies only with the env flag. This PR lets the main tables pick FP8 per row without it. The env flag and the #8669 table behave as before.
Changes
_fp8suffix (..._reduce_fp8,..._reduce_fp8_sbm64).fp8in the out field (flydsl_moe2_layout_afp8_wfp4_fp8_t64x256x128_reduce_sbm64).topk_weightsfor it. The env flag stays a global override.--flydsl-stage2-fp8adds the FP8 variant of every reduce candidate (v1 and v2), gated by the existingerrRatiocheck. It is rejected withAITER_FLYDSL_STAGE2_FP8=1and with--ep-size.fp8compile the FP8 variant, also withAITER_MXFP4_INTERMEDIATE=1(as the runtime launches them).dsv41_fp8_tuned_fmoe.csv: 13 of the 32 inter-640 rows. A row changes only wherefused_moeis at least ~3% faster at both token counts it serves (lookup rounds up to a power of two), in two runs.Performance
MI355X,
fused_moeunder CUDA-graph replay, no env flag, mean of two runs (each within 1.5 points of the mean). Before: the current rows on the same build. Target (E=384, top-6) uses routing captured from vLLM serving; draft (E=128, top-3) uses uniform random routing. Two token counts per changed row:Blank cells are token counts whose row this PR does not change for that model. Unchanged rows measure within noise. From 3072 tokens up, the target rows match forcing the env flag on, without its 2–4% loss at 24–128 tokens.
Serving, DeepSeek-V4.1-Flash TP4 on 4x MI355X, vLLM main 9b38c833e (
--max-num-batched-tokens 16384), mean of 3 runs, no env flag. Both arms use the same build and differ only in this CSV. Prefill time to first token drops ~3% with and without speculative decoding; the decode-heavy run is unchanged within noise:The 8k/1k runs vary ±3% between repeats.
Testing
Unit tests added or updated
Performance benchmarks run
Tested on MI250X
Tested on MI300X
op_tests/flydsl_tests/test_flydsl_moe.py:tile_n128 and 256) and v2 wrappers: the FP8-named kernel is bit-exact against the env flag, differs from BF16, and is close to the reference.Also run:
op_tests/test_moe_stage2_fp8_rows.py([CK] [FlyDSL] [JIT] [MoE] Add a stage2 FP8 row table for AITER_FLYDSL_STAGE2_FP8=1 #8669), the FP8 route-out test inop_tests/test_fhmoe.py, the v2 stage-2 tests andtest_config_shape_collision.py.Tuner:
--flydsl-stage2-fp8on all 32 DSv4.1 inter-640 shapes; no failed shapes.AOT: the table compiles (96 kernels); every row then runs with
FLYDSL_RUNTIME_RUN_ONLY=1.Accuracy on the serving runs above:
The gsm8k differences are within one standard error (±0.007).
Documentation
Dependencies
Breaking Changes
None. Existing names and the env flag behave as before.
PR Self-Review
Reviewed revision
4bb34f0e3Behavior and intent
FP8 route output in FlyDSL reduce stage 2 was only reachable through the global
AITER_FLYDSL_STAGE2_FP8flag, which speeds up prefill but slows small batches, so tuned rows could not use it selectively. The kernel name now selects it per row, the tuner can time the FP8 variants, and 13 DSv4.1 TP4 rows use them.Validation and unverified scope
On MI355X:
pytest op_tests/flydsl_tests/test_flydsl_moe.py(FP8 route-out and v2 stage-2 tests),op_tests/test_moe_stage2_fp8_rows.pyandtest_config_shape_collision.pypassed; the AOT build of the table passed and every row ran withFLYDSL_RUNTIME_RUN_ONLY=1;fused_moeand vLLM serving numbers and gsm8k/NIAH are above. Not run: MI250X/MI300X (FlyDSL MoE is gfx950-only), FP8 route-out with EP (--ep-sizeis rejected), and models other than DSv4.1, which have no FP8-named rows.PR-specific question
FP8 route output is chosen only by name: a v1 FlyDSL reduce stage-2 name ending in
_fp8, or a v2 name withfp8in the out field and thereduceepilog; the v2 wrapper raises forfp8with any other epilog or withouttopk_weights. Only the 13 gfx950 rows ofdsv41_fp8_tuned_fmoe.csv(cu_num 256, 5120x640, E=384 top-6 or E=128 top-3, FP8 activations, FP4 weights) carry these names, so every other shape and name keeps BF16 route rows unless the env flag is set, as before.Changed op tests
op_tests/flydsl_tests/test_flydsl_moe.py: the FP8-name tests fail before this PR because the names do not parse and the wrappers ignore them; no existing test covers the per-name selection (test_fhmoe.py covers the FP8 epilogue only through the env flag). This file is not collected by CI; it was run locally on MI355X.AI disclosure: written with Claude Opus 5.5 (Cursor); reviewed and run by the author.