Skip to content

[CK] [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows - #8032

Open
cpersson-amd wants to merge 11 commits into
ROCm:mainfrom
cpersson-amd:moe-s2-fp8-route-out-tuned
Open

cpersson-amd wants to merge 11 commits into
ROCm:mainfrom
cpersson-amd:moe-s2-fp8-route-out-tuned

Conversation

@cpersson-amd

@cpersson-amd cpersson-amd commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AITER_FLYDSL_STAGE2_FP8=1 makes 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_moe is 6–13% faster for target prefill (3072+ tokens) and up to 13% faster for the draft.

Motivation

With the env flag, DSv4.1 fused_moe is 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

  • Kernel names:
    • v1 reduce names take a _fp8 suffix (..._reduce_fp8, ..._reduce_fp8_sbm64).
    • v2 names put fp8 in the out field (flydsl_moe2_layout_afp8_wfp4_fp8_t64x256x128_reduce_sbm64).
  • Runtime: the v1 and v2 stage-2 wrappers pick FP8 route output from the name and forward topk_weights for it. The env flag stays a global override.
  • Tuner: --flydsl-stage2-fp8 adds the FP8 variant of every reduce candidate (v1 and v2), gated by the existing errRatio check. It is rejected with AITER_FLYDSL_STAGE2_FP8=1 and with --ep-size.
  • AOT: v2 rows named fp8 compile the FP8 variant, also with AITER_MXFP4_INTERMEDIATE=1 (as the runtime launches them).
  • dsv41_fp8_tuned_fmoe.csv: 13 of the 32 inter-640 rows. A row changes only where fused_moe is at least ~3% faster at both token counts it serves (lookup rounds up to a power of two), in two runs.

Performance

MI355X, fused_moe under 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:

Tokens Target before (µs) after (µs) Change Draft before (µs) after (µs) Change
3 / 5 30.6 29.5 -3.4% 30.6 27.4 -10.6%
4 / 8 33.3 31.6 -5.0% 34.8 32.2 -7.3%
192 124.2 115.5 -7.0%
256 126.5 119.1 -5.8%
768 145.7 138.8 -4.7%
1024 159.2 153.7 -3.5%
1536 173.1 165.9 -4.2%
2048 186.2 179.4 -3.7%
3072 564.0 531.5 -5.8% 259.9 236.0 -9.2%
4096 662.0 618.3 -6.6% 286.6 259.9 -9.3%
6144 800.6 734.0 -8.3% 459.2 429.0 -6.6%
8192 970.5 876.9 -9.6% 561.5 520.8 -7.2%
12288 1282.8 1152.3 -10.2% 642.5 576.3 -10.3%
16384 1617.5 1433.7 -11.4% 813.0 721.5 -11.2%
24576 2287.8 2008.8 -12.2% 1158.6 1025.3 -11.5%
32768 2982.8 2599.2 -12.9% 1519.2 1323.8 -12.9%

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:

Workload No spec before after Change DSpark k5 before after Change
8k in / 1 out, c64, mean TTFT (ms) 4164 4029 -3.3% 4301 4151 -3.5%
60k in / 1 out, c16, mean TTFT (ms) 7888 7638 -3.2% 8124 7894 -2.8%
8k in / 1k out, c64, mean TTFT (ms) 744 734 -1.2% 827 809 -2.1%
8k in / 1k out, c64, output tok/s 3235 3211 -0.7% 3693 3684 -0.2%
8k in / 1k out, c64, median TPOT (ms) 17.93 17.94 +0.1% 15.74 15.67 -0.4%

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:

    • name parsing and sizing for the FP8 names;
    • v1 (tile_n 128 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 in op_tests/test_fhmoe.py, the v2 stage-2 tests and test_config_shape_collision.py.

  • Tuner: --flydsl-stage2-fp8 on 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:

No spec before after DSpark k5 before after
gsm8k 5-shot, full, strict / flexible 0.921 / 0.921 0.927 / 0.925 0.930 / 0.930 0.922 / 0.923
niah_single_2 32k / 64k 1.0 / 1.0 1.0 / 1.0 1.0 / 1.0 1.0 / 1.0

The gsm8k differences are within one standard error (±0.007).

Documentation

  • No documentation change is needed: the new names follow the existing kernel-name scheme, and the tuner option has CLI help.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. Existing names and the env flag behave as before.

PR Self-Review

Reviewed revision

4bb34f0e3

Behavior and intent

FP8 route output in FlyDSL reduce stage 2 was only reachable through the global AITER_FLYDSL_STAGE2_FP8 flag, 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.py and test_config_shape_collision.py passed; the AOT build of the table passed and every row ran with FLYDSL_RUNTIME_RUN_ONLY=1; fused_moe and vLLM serving numbers and gsm8k/NIAH are above. Not run: MI250X/MI300X (FlyDSL MoE is gfx950-only), FP8 route-out with EP (--ep-size is 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 with fp8 in the out field and the reduce epilog; the v2 wrapper raises for fp8 with any other epilog or without topk_weights. Only the 13 gfx950 rows of dsv41_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.

cpersson-amd and others added 5 commits November 13, 2026 12:38
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]>
@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 8032 --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.

@cpersson-amd cpersson-amd changed the title # [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows Nov 16, 2026
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 mjkvaak-amd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@cpersson-amd cpersson-amd Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

cpersson-amd and others added 5 commits November 30, 2026 11:20
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]>
@cpersson-amd
cpersson-amd marked this pull request as ready for review November 30, 2026 14:25
@cpersson-amd
cpersson-amd requested a review from a team November 30, 2026 14:25
@github-actions github-actions Bot changed the title [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows [CK] [FlyDSL] MoE stage 2: pick FP8 route output per tuned row; DSv4.1 TP4 rows Nov 30, 2026
@aiter-bot

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 4bb34f0e30ec · 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

FP8 route output in FlyDSL reduce stage 2 was only reachable through the global `AITER_FLYDSL_STAGE2_FP8` flag, 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.py` and `test_config_shape_collision.py` passed; the AOT build of the table passed and every row ran with `FLYDSL_RUNTIME_RUN_ONLY=1`; `fused_moe` and vLLM serving numbers and gsm8k/NIAH are above. Not run: MI250X/MI300X (FlyDSL MoE is gfx950-only), FP8 route-out with EP (`--ep-size` is 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 with `fp8` in the out field and the `reduce` epilog; the v2 wrapper raises for `fp8` with any other epilog or without `topk_weights`. Only the 13 gfx950 rows of `dsv41_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.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants