Skip to content

[CK] [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) and tune for M3.1 - #7769

Merged
coderfeli merged 4 commits into
mainfrom
vinayak/a4w4-stage2-ldspa
Nov 14, 2026
Merged

coderfeli merged 4 commits into
mainfrom
vinayak/a4w4-stage2-ldspa

Conversation

@vgokhale

@vgokhale vgokhale commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds _ldspa, a new bf16 scatter epilogue for the FlyDSL A4W4 MoE stage-2 GEMM. The stock epilogue uses one 2-byte store per element, and these stores remove the reused W2 and A tiles from L2.

Changes

  • New epilogue: C goes to LDS as bf16 row pairs and then 16-byte non-temporal row stores to global memory.
  • It is backward compatible because the kernel name suffix _ldspa selects it. Other kernel signatures are unaffected.
  • My current use case is MiniMax-M3.1 TP4 table: the 4 rows for 4096 to 32768 tokens (E=128, top-4) use _ldspa. But any model can use it for prefill.
  • E=129 top-5 rows at 16384 and 32768 tokens also use _ldspa (bitwise; whole MoE call -3.3% at 16384 and -1.5% at 32768 tokens, uniform routing).

Performance

MI355X, M3.1 TP4 MoE (hidden 6144, inter 768), production aiter.fused_moe on main, us, uniform routing:

Tokens GEMM2 old GEMM2 new scatter_reduce old scatter_reduce new stage 2 total (GEMM2 + scatter_reduce) old stage 2 total new Change
4096 129.6 121.0 42.9 42.8 172.5 163.7 -5.1%
8192 200.0 187.4 85.3 81.2 285.3 268.6 -5.9%
16384 364.1 341.6 160.3 161.5 524.4 503.1 -4.1%
32768 650.6 594.6 322.1 325.4 972.6 920.0 -5.4%

Skewed routing: -4.1% to -4.5%. Interleaved runs in one process: -4.2% to -5.5% at 16k to 32k.

Testing

  • New test_flydsl_v2_stage2_scatter_ldspa: bitwise equal to the stock epilogue, 4 tiles. On main (MI355X): 24 of 24 pass. On main, production output is bitwise equal with the old and new table (4 token counts, 2 routings).
  • Stage-2 op tests on main: 167 passed, 13 failed, 1 error. Unmodified main: 143 passed and the same 13 failed, 1 error, all in op_tests/test_flydsl_moe_aux.py (pytest calls its functions without arguments: TypeError).
  • On v0.1.28.post1: production output bitwise equal (old and new table); stage-2 op tests have the same failures with and without this PR.

Limitations

  • The gain occurs only at 4096 tokens and above.
  • The [4M, hidden] bf16 intermediate is still written and read (1.6 GB each direction at 32k tokens).

PR Self-Review

Reviewed revision

5aee658

Behavior and intent

The FlyDSL A4W4 MoE stage-2 GEMM gets an optional bf16 scatter epilogue, _ldspa. It puts C into LDS as bf16 row pairs and writes 16-byte non-temporal rows. The stock epilogue writes one 2-byte element per store, and these stores remove the reused W2 and A tiles from L2. With _ldspa, stage 2 is 4% to 6% faster at 4096 to 32768 tokens. Kernels without the suffix do not change.

Validation and unverified scope

  • On 5aee658 (review fixes: the parser rejects an _ldspa name unless it has an fp4 activation, a bf16 output and the scatter epilogue; the 6 _ldspa rows have measured times), pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa on MI355X: 25 passed.
  • The 6 rows were timed against the stock kernel in one process (whole MoE call, uniform routing, median of 6 alternating rounds, us): E=128 top-4 at 4096 374.7 -> 359.7, 8192 549.1 -> 530.0, 16384 918.7 -> 897.3, 32768 1707.7 -> 1676.6; E=129 top-5 at 16384 1114.1 -> 1077.3, 32768 2046.1 -> 2016.3. The rows store us1 = sort + quant + gemm1 and us2 = gemm2 + scatter_reduce.
  • On 5decfaf (main merged in; main's changes reach aiter/fused_moe.py and gemm_moe_tune.py), pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa on MI355X: 24 passed.
  • pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa on main, MI355X: 24 passed. The _ldspa output is bitwise equal to the stock epilogue for 4 tiles.
  • Production aiter.fused_moe on main: the output is bitwise equal with the old and the new table (4 token counts, uniform and skewed routing). The same is true on v0.1.28.post1.
  • Stage-2 op tests on main: the same 13 failures and 1 error with and without this PR, all in op_tests/test_flydsl_moe_aux.py (pytest calls its functions without arguments).
  • Unverified: other architectures (only gfx950 rows use _ldspa), and other models' shapes (no other table row uses _ldspa).

PR-specific question

Only a kernel name that ends in _ldspa selects the new epilogue. The name parser (mxfp4_kname.py) sets scatter_lds_pairs from that suffix, and every name without it builds the stock epilogue. Only 6 rows of minimax_m3_fp4_tuned_fmoe.csv have the suffix: gfx950 with 256 CUs, bf16 output, MXFP4 weights (per_1x32), hidden 6144, inter 768, E=128 top-4 at 4096 to 32768 tokens and E=129 top-5 at 16384 and 32768 tokens. The epilogue applies only to the A4W4 stage-2 scatter path. The tuner change (gemm_moe_tune.py) only passes the same flag through.

Changed op tests

op_tests/flydsl_tests/test_flydsl_moe.py: the new test_flydsl_v2_stage2_scatter_ldspa runs the _ldspa epilogue and the stock scatter epilogue on the same inputs and requires bitwise equal output for 4 tiles. The new test_ldspa_kernel_names_match_the_generator checks that the parser accepts _ldspa only on the names that get_flydsl_stage2_v2_kernels makes. No other test runs this epilogue.

…) + MiniMax-M3.1 rows

Add the _ldspa variant of the FlyDSL layout-v2 GEMM2 bf16 scatter epilogue.
The epilogue writes C to LDS as bf16 row pairs over the A slots. Each thread
then writes 16-byte row chunks with non-temporal buffer stores, in place of
one 2-byte store per element. The output is bitwise equal to the stock
epilogue.

The kernel name suffix _ldspa selects the variant. Other names do not change.
The stage-2 wrapper, the AOT precompile and the tuners pass the flag. The
MiniMax-M3.1 TP4 rows (E=128, top-4, inter_dim 768, 4096 to 32768 tokens) use
it.

Signed-off-by: Vinayak Gokhale <[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 7769 --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.

@vgokhale vgokhale changed the title [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) + MiniMax-M3.1 rows [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) and tune for M3.1 Nov 10, 2026
@vgokhale
vgokhale marked this pull request as ready for review November 10, 2026 21:50
@vgokhale
vgokhale requested a review from a team November 10, 2026 21:50
@vgokhale vgokhale changed the title [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) and tune for M3.1 [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue and tune for M3.1 Nov 10, 2026
@github-actions github-actions Bot changed the title [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue and tune for M3.1 [CK] [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) and tune for M3.1 Nov 10, 2026
@vgokhale
vgokhale requested a review from coderfeli November 10, 2026 21:54
The fused shared-expert rows (E=129, top-5, inter_dim 768) at 16384 and
32768 tokens use the _ldspa scatter epilogue. Stage 2 is 4.5% to 6.8% faster
and the output is bitwise equal.

Signed-off-by: Vinayak Gokhale <[email protected]>
@ROCm ROCm deleted a comment from aiter-bot Nov 12, 2026
@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 5aee65837a90 · 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

The FlyDSL A4W4 MoE stage-2 GEMM gets an optional bf16 `scatter` epilogue, `_ldspa`. It puts C into LDS as bf16 row pairs and writes 16-byte non-temporal rows. The stock epilogue writes one 2-byte element per store, and these stores remove the reused W2 and A tiles from L2. With `_ldspa`, stage 2 is 4% to 6% faster at 4096 to 32768 tokens. Kernels without the suffix do not change.

Validation and unverified scope

- On 5aee65837 (review fixes: the parser rejects an `_ldspa` name unless it has an fp4 activation, a bf16 output and the scatter epilogue; the 6 `_ldspa` rows have measured times), `pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa` on MI355X: 25 passed.
- The 6 rows were timed against the stock kernel in one process (whole MoE call, uniform routing, median of 6 alternating rounds, us): E=128 top-4 at 4096 374.7 -> 359.7, 8192 549.1 -> 530.0, 16384 918.7 -> 897.3, 32768 1707.7 -> 1676.6; E=129 top-5 at 16384 1114.1 -> 1077.3, 32768 2046.1 -> 2016.3. The rows store us1 = sort + quant + gemm1 and us2 = gemm2 + scatter_reduce.
- On 5decfafc0 (main merged in; main's changes reach `aiter/fused_moe.py` and `gemm_moe_tune.py`), `pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa` on MI355X: 24 passed.
- `pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspa` on main, MI355X: 24 passed. The `_ldspa` output is bitwise equal to the stock epilogue for 4 tiles.
- Production `aiter.fused_moe` on main: the output is bitwise equal with the old and the new table (4 token counts, uniform and skewed routing). The same is true on v0.1.28.post1.
- Stage-2 op tests on main: the same 13 failures and 1 error with and without this PR, all in `op_tests/test_flydsl_moe_aux.py` (pytest calls its functions without arguments).
- Unverified: other architectures (only gfx950 rows use `_ldspa`), and other models' shapes (no other table row uses `_ldspa`).

PR-specific question

Only a kernel name that ends in `_ldspa` selects the new epilogue. The name parser (`mxfp4_kname.py`) sets `scatter_lds_pairs` from that suffix, and every name without it builds the stock epilogue. Only 6 rows of `minimax_m3_fp4_tuned_fmoe.csv` have the suffix: gfx950 with 256 CUs, bf16 output, MXFP4 weights (per_1x32), hidden 6144, inter 768, E=128 top-4 at 4096 to 32768 tokens and E=129 top-5 at 16384 and 32768 tokens. The epilogue applies only to the A4W4 stage-2 scatter path. The tuner change (`gemm_moe_tune.py`) only passes the same flag through.

Changed op tests

`op_tests/flydsl_tests/test_flydsl_moe.py`: the new `test_flydsl_v2_stage2_scatter_ldspa` runs the `_ldspa` epilogue and the stock scatter epilogue on the same inputs and requires bitwise equal output for 4 tiles. The new `test_ldspa_kernel_names_match_the_generator` checks that the parser accepts `_ldspa` only on the names that `get_flydsl_stage2_v2_kernels` makes. No other test runs this epilogue.

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.

Comment thread aiter/ops/flydsl/moe_kernels.py Resolved
… rows

- parse_flydsl_v2_gemm2_kernel raises ValueError for an _ldspa name
  unless it has an fp4 activation, a bf16 output and the scatter
  epilogue. get_flydsl_stage2_v2_kernels makes _ldspa only for these.
- minimax_m3_fp4_tuned_fmoe.csv: the 6 _ldspa rows now have times
  measured with _ldspa (MI355X, uniform routing, median of 6 rounds that
  alternate with the stock kernel in one process). us1 is sort + quant +
  gemm1, us2 is gemm2 + scatter_reduce, us is the sum. tflops and bw are
  scaled by the time change. Before, the rows kept the stock times.
- New test: test_ldspa_kernel_names_match_the_generator.

Signed-off-by: Vinayak Gokhale <[email protected]>
@coderfeli
coderfeli merged commit 524dd9a into main Nov 14, 2026
@coderfeli
coderfeli deleted the vinayak/a4w4-stage2-ldspa branch November 14, 2026 02:43
amd-bishwoadhikari added a commit to amd-bishwoadhikari/aiter that referenced this pull request Nov 18, 2026
…s pending A/B

The 3 rows this branch changes in minimax_m3_fp4_tuned_fmoe.csv (tokens 32, 64 at
inter_dim 768 and token 8192 at inter_dim 384) were tuned before the FlyDSL MoE
kernel changes in ROCm#7769 and ROCm#7773, and tokens 32/64 raise the stage-2 error ratio
from 1.2% to 4.8-4.9%. Restore origin/main's rows; each is re-applied only if a
same-session A/B on current main shows it is faster at a comparable error ratio.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Bishwo Adhikari <[email protected]>
sahirema pushed a commit to sahirema/aiter that referenced this pull request Nov 19, 2026
…096 tokens, check every kernarg precondition

Re-measured against AITER main with ROCm#7769 (_ldspa) on MI355X (gfx950, FlyDSL 0.4.2),
uniform routing, device time of the whole stage 2: the atomic kernels (v2ao) and the flat
kernels below 4096 tokens are not faster than AITER's own gemm2 there (0.80x at M1024,
0.96x-0.99x at 1536-3072; the 1.17x at M2285 is the tuned row of the 4096 bucket:
AITER's atomic_nt kernel takes 184 us where the row's pick takes 215 us). From 4096
tokens the flat and dense kernels are 1.07x-1.37x faster than AITER's best arm, with
bit-identical output. Under strongly skewed routing the flat kernel also wins below
4096, so those calls stay with AITER until a replay on captured routing says which
side real traffic is on.

- pick_kernel: a scatter kernelName2 with block_m 128 and M >= 4096 (dense from 12288).
- Ship the two kernels that can be picked (v2n_bm128, v4g8_bm128). gen_t1g2.py builds
  only those; the code objects are byte-identical to the previous build, the registry
  and build_info.json are regenerated.
- _eligible: one pure function checks every flag, dtype, shape, contiguity and id dtype
  the kernarg ABI depends on (fp4 data, e8m0 scales, int32 ids, float32 weights, bf16
  [M, 6144] moe_out, reverse_sorted present), before any device query.
- check_installed(): raise when the registry or a code object is missing.
- Tests: the output must match AITER's and its error against an fp32 reference must be
  at most 1.1x AITER's (the bound was loose); hot-routing cases; a declined call keeps
  AITER's output; every decline reason on meta tensors.

Signed-off-by: Vorapol Assavasangthong <[email protected]>
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