Skip to content

[FlyDSL] [Bugfix] Fix MoE XCD swizzle on grids not divisible by 8 - #7567

Open
eppaneamd wants to merge 7 commits into
mainfrom
eppaneamd/flydsl-moe-xcd-remainder
Open

eppaneamd wants to merge 7 commits into
mainfrom
eppaneamd/flydsl-moe-xcd-remainder

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the XCD swizzle of the FlyDSL MoE GEMMs (_xcd{N} kernels, stage 1 and stage 2) for grids whose workgroup count is not a multiple of 8. On such grids some tiles ran more than once and as many never ran, which gave wrong MoE output at some token counts.

Motivation

Both MoE stages in mixed_moe_gemm_2stage_common.py remapped workgroups with

wgid = (lin % 8) * (n // 8) + lin // 8

That is a permutation of the n workgroups only when n % 8 == 0. With n ≥ 8 and r = n % 8 != 0, wgids q, 2q, …, r·q (q = n // 8) are produced twice and the last r never; with fewer than 8 workgroups every workgroup computes tile 0:

  • Stage 1 leaves the rows of the skipped tiles unwritten. Split-K stage 1 (_kb{N}) also adds the partial sums of the duplicated tiles twice, since it accumulates atomically.
  • Atomic stage 2 adds the duplicated tiles' expert contributions twice and drops the skipped ones. Reduce stage 2 reads the slots nobody wrote.

n = gx * gy depends on the token count, so an _xcd kernel can be correct at one token count and wrong at the next. Tuned rows are tuned and checked at their bucket's token count, where the grid is often a multiple of 8, so this survives tuning. For example, a stage-2 t32x128x256_atomic_xcd4 kernel that tuning picked for model 2560, inter 512, 513 experts, top-11 (a row not in aiter/configs) is correct at even token counts and wrong at every odd one (9–15).

xcd_remap_bx_by in mfma_preshuffle_pipeline.py already has the remainder term (_clip = min(xcd, n % 8)). Among the FlyDSL XCD remaps, only these two MoE copies lacked it.

Tuned tables on main (f705d6b7a0) that name these kernels (computed from the launch-grid code, not run): 113 rows in aiter/configs name a v1 _xcd MoE kernel with fp8/fp4 activations. For 83 of them, some token count in the row's bucket launches a grid that is not a multiple of 8. 81 of those are stage-1 rows, whose output is wrong only when the skipped last M blocks hold routed rows (a duplicated stage-1 tile stores the same values twice). The other two, in tuned_fhmoe.csv (model 7168, inter 384, 385 experts, top-7; buckets 128 and 256), use _xcd4 in an atomic stage 2, where a duplicated tile adds twice. At 100, 200 and 256 tokens their stage-2 grid is 28 × 407, 28 × 429 and 28 × 441.

Changes

  • aiter/ops/flydsl/kernels/mfma_preshuffle_pipeline.py: new xcd_remap_grid(bx, by, grid_m, grid_n, *, xcd_swizzle, num_xcds=8), the remap xcd_remap_bx_by already did, with the grid size from the caller. xcd_remap_bx_by calls it; a preshuffle and an mxscale GEMM with xcd_swizzle=4 compile to byte-identical ISA before and after.
  • aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py: stage 1 and stage 2 call xcd_remap_grid instead of their own copy of the remap (net −19 lines). The num_xcds = 8 and grid-size lines are unchanged.
  • aiter/ops/flydsl/moe_kernels.py: the stage-2 comment no longer calls xcd_swizzle an ignored argument; it selects the XCD remap.
  • tests/test_flydsl_moe_xcd_swizzle.py (new): test_flydsl_moe_xcd_swizzle_uneven_grid, both stages with xcd_swizzle=4 on a 2 × 18 grid (36 workgroups), 9 tokens routed to 18 distinct experts so every tile holds a routed row. Stage 1 writes into a NaN-filled buffer. It runs only when the running GPU is gfx950 (get_gfx_runtime()), so a multi-arch GPU_ARCHS does not skip it. It is in tests/ because CI runs python3 -m pytest -q tests on pull requests, and op_tests/flydsl_tests/ is not in the sharded op-test plan; it imports its data generator and check from op_tests/flydsl_tests/test_flydsl_moe.py.
  • op_tests/flydsl_tests/test_flydsl_moe.py: _generate_a8w4_gui_data gains distinct_experts (default off) for the new test.

Compiled for gfx950, the stage-1, stage-2 and heterogeneous stage-2 MoE kernels gain 9 instructions and the persistent stage 2 gains 2, with the same VGPR, SGPR, LDS and spill counts.

Performance (if applicable)

MI355X, model 2560, inter 512, 513 experts, top-11, fp4 activations and weights. Each row alternates fresh main and branch processes (main, branch, branch, main, main, branch, branch, main) and gives the median of the four per-process medians, with their range. At 16 tokens both grids are multiples of 8, so main and the branch run the same tiles.

measurement main µs branch µs
stage 1 t64x128x256_w2_xcd4 alone, 16 tokens, 5 × 100 launches 37.34 (36.70–37.47) 36.82 (36.68–37.36)
stage 2 t32x128x256_atomic_xcd4 alone, 16 tokens, 5 × 100 launches 21.83 (21.77–21.84) 21.83 (21.61–22.00)
the same kernels with xcd_swizzle=0 (code unchanged), stage 1 / stage 2 35.20 / 21.03 35.06 / 20.83
fused_moe through the one-row AITER_CONFIG_FMOE described under Validation, run_perftest (20 iterations, 3 per process), 16 tokens 73.33 (72.65–73.65) 73.42 (71.68–73.46)
the same, 9 tokens (main runs the wrong tiles here) 58.58 (57.65–58.81) 58.43 (56.64–58.73)
its stage-2 _xcd4 kernel in a profile of those calls (100 calls, inputs rotated over 20 copies), 16 tokens 21.20 (21.16–21.24) 21.28 (21.08–21.40)

An earlier fused_moe timing run inside an accuracy script, which computed torch references between timings, had the branch 1.4–2.3 % slower at 9 and 16 tokens, while main's own four processes there differed by up to 3.7 %. Neither the kernel profile nor the runs above reproduce the gap.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Tested on MI355X (gfx950) only; see "Validation and unverified scope".

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

xcd_remap_grid has a docstring; no user-facing behavior changes beyond the fix.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

d7ec3d633

Behavior and intent

The remap in _xcd{N} MoE kernels is now a permutation of the grid the kernel computes, for any workgroup count. Before, grids with a workgroup count not divisible by 8 ran some tiles twice and skipped as many, so the output was wrong at some token counts (stage 1 rows unwritten; stage 2 contributions doubled or dropped). The remap is unchanged when the count is divisible by 8. Stage 1 still computes its grid size in the kernel, without the tile2_pad the host adds to its launch; where the two differ, #6598's gpu.grid_dim reads are the fix.

Validation and unverified scope

One MI355X (gfx950), ROCm 7.2, FlyDSL 0.4.2; main at f705d6b7a0 against this branch's first commit, except where stated. The second commit only names arguments and edits a docstring; every kernel below compiles to byte-identical gfx950 ISA under both commits. The third commit only moves the test. The fourth merges main (9c119bb65), which pins FlyDSL 0.5.0 (#7600); this branch merged without conflicts. The fifth only changes the test's skip condition from get_gfx(), which takes the last GPU_ARCHS entry, to get_gfx_runtime(), the running GPU; the test runs below predate it.

  • After the merge of main, on FlyDSL 0.5.0 (the PyPI wheel unpacked ahead of the image's 0.4.2), MI355X, vllm/vllm-openai-rocm nightly 083fbac021 (torch 2.13.0+rocm10.0.0), an empty FlyDSL cache for each run: python3 -m pytest -rA tests/test_flydsl_moe_xcd_swizzle.py fails with main's three kernel files (AssertionError: xcd4_uneven_grid_stage1: output has NaN) and passes with this branch's, 0 skipped, both in CI's layout (the merged source tree with the image's prebuilt .so files copied in) and with the kernel files overlaid on the installed aiter. The whole tests/ directory in CI's layout: main's kernels 4 failed and 355 passed (15 s); this branch's 3 failed and 356 passed (14 s). The 3 common failures are in files this change does not touch: test_all_reduce_config.py::AllReduceConfigTest::test_communicator_reads_explicit_bytes_before_import, test_import_without_gpu.py::test_import_aiter_without_visible_gpu (RuntimeError: No gfx arch found in rocminfo output. in that container) and test_mega_moe_gfx1250_recipe.py::test_layout (an arena-size assertion).
  • Before the merge, on this branch's earlier pin (FlyDSL 0.4.2; amd-aiter 0.1.28.post1 with the three kernel files overlaid, torch 2.13.0+rocm10.0.0, an empty FlyDSL cache for each run): python3 -m pytest -rA tests/test_flydsl_moe_xcd_swizzle.py fails with the merge-base's kernel files (AssertionError: xcd4_uneven_grid_stage1: output has NaN) and passes with this branch's, 0 skipped.
  • Before the merge, FlyDSL 0.4.2, the whole tests/ directory in CI's layout (the source tree, with the image's prebuilt .so files copied in): 13 s with this branch's kernels, 236 passed and 3 failed; with the merge-base's, 235 passed and 4 failed (the moved test). The 3 common failures are in files this change does not touch: test_all_reduce_config.py::AllReduceConfigTest::test_communicator_reads_explicit_bytes_before_import and test_import_without_gpu.py::test_import_aiter_without_visible_gpu (RuntimeError: No gfx arch found in rocminfo output. in that container) and test_mega_moe_gfx1250_recipe.py::test_layout (an arena-size assertion).
  • op_tests/flydsl_tests/test_flydsl_moe.py collected 34 tests after the move (before the merge of main) and they were not run: xcd_swizzle is non-zero only in the moved test. With the test still in that file, main 34 passed and 1 failed (the new test), and the branch 35 passed.
  • Measured with the test in the op test file (same code): it also fails with the stage-1 call reverted to the old remap (stage-1 NaN), with the stage-2 call reverted (xcd4_uneven_grid_stage2: checkAllclose failed (err=0.2665, max=0.05)), and with the remainder term removed from the helper (stage-1 NaN).
  • op_tests/test_fhmoe.py -k production_decode_and_prefill: 17 passed on both. Its 4096-, 8192- and 32768-token rows run _xcd4 stage 1 on grids that are not multiples of 8 (4 × 833, 4 × 833 and 4 × 2561, computed from the launch code), so the new remap runs there. The test routes every token to the same 9 experts, which leaves the skipped last M block empty, so main passes too.
  • Each xcd_swizzle=4 kernel against xcd_swizzle=0 in the same process (a standalone script, not in this PR):
    • stage 2 t32x128x256_atomic, fp4 activations and weights (model 2560, inter 512, 513 experts, top-11), 9–16 tokens: on main, odd counts give rel L2 0.026–0.040 against the torch reference vs 0.005 for xcd_swizzle=0; on the branch every count gives 0.005, with a max abs difference from xcd_swizzle=0 of 0.25–0.44, the scale of two xcd_swizzle=0 runs (0.25–0.38, atomic order).
    • stage 2 t32x256x128_atomic_bnt2, fp8 activations, fp4 weights (model 7168, inter 384, 385 experts, top-7), 100/102/200/256 tokens: on main the (token, N-tile) pairs that differ by more than 4× the xcd_swizzle=0 run-to-run spread are exactly the ones the old remap runs twice or skips (9/0/22/13 pairs); on the branch none differ. This ran the generic stage 2 at that shape, not the heterogeneous kernel the tuned_fhmoe.csv rows name.
  • fused_moe with a one-row AITER_CONFIG_FMOE (token 16, flydsl_moe1_afp4_wfp4_bf16_t32x64x256_w4_kw2_fp4 + flydsl_moe2_afp4_wfp4_bf16_t32x128x256_atomic_xcd4, model 2560, inter 512, 513 experts, top-11), the dispatch log naming both kernels, 9–16 tokens × 3 seeds, against the torch reference with the stage-1 output re-quantized: odd counts rel L2 0.046–0.093 on main vs 0.031–0.044 on the branch; even counts equal to within 0.0001. Main's worst logits_diff is 0.0043, under test_moe_2stage.py's 0.01 gate.
  • The skip condition of the fifth commit, evaluated on MI355X: with GPU_ARCHS unset, gfx950 or gfx942;gfx950, get_gfx() and get_gfx_runtime() both return gfx950; with gfx950;gfx942, get_gfx() returns gfx942, so the earlier condition skipped the test and the new one runs it.
  • CPU compile for gfx950 (aiter.aot.flydsl.dry_run): the two xcd_remap_bx_by callers, a preshuffle and an mxscale GEMM with xcd_swizzle=4, give byte-identical ISA on main and the branch (their xcd_swizzle=0 builds differ, so the comparison sees code changes).

Not verified:

  • MI300X and MI250X were not run.
  • The persistent stage 2 (grid y = CU count) was compiled, not run. On MI355X its workgroup count is a multiple of 8, where the old and new remaps agree.
  • Split-K stage 1 and the reduce stage 2 were not run with _xcd; their failure modes above come from reading the code.
  • CI runs the new test in the Focused regression tests step (python3 -m pytest -q tests, MI35X shard 0), not in the op-test shards (op_tests/flydsl_tests/test_flydsl_moe.py is not in split_tests.sh's plan). The new runs used torch 2.13.0+rocm10.0.0 and a FlyDSL cache emptied for each run; CI's torch differs, and CI starts from the wheel's prebuilt FlyDSL cache.
  • The other tests of op_tests/flydsl_tests/test_flydsl_moe.py do not run in CI; none of them passes xcd_swizzle.

PR-specific question

What the changed op test fails on before this PR, and why existing tests do not cover it:

  • tests/test_flydsl_moe_xcd_swizzle.py::test_flydsl_moe_xcd_swizzle_uneven_grid fails on main at its stage-1 assertion (xcd4_uneven_grid_stage1: output has NaN: the rows of the skipped tiles keep the NaN fill). With only the stage-2 call reverted it fails at stage 2 (xcd4_uneven_grid_stage2: checkAllclose failed (err=0.2665, max=0.05): a duplicated tile adds its contribution twice). It passes on the branch.
  • Existing tests run _xcd kernels only at a tuned row's bucket token count, where the grid is often a multiple of 8 (test_moe_2stage.py's CSV cases, test_fhmoe.py's production rows). Where it is not, test_fhmoe.py routes every token to the same 9 experts, so the skipped last M block holds no routed row and main passes (17 passed on both); test_moe_2stage.py fails a case only when logits_diff exceeds 0.01, and main's worst is 0.0043.
  • The new test routes 9 tokens to 18 distinct experts on a 2 x 18 grid, so every tile holds a routed row, stage 1 writes into a NaN-filled buffer, and a duplicated stage-2 tile changes a sum.

Changed op tests

op_tests/flydsl_tests/test_flydsl_moe.py: only _generate_a8w4_gui_data changes, with a distinct_experts argument (default off) that the new test uses; the new test itself is tests/test_flydsl_moe_xcd_swizzle.py::test_flydsl_moe_xcd_swizzle_uneven_grid. It runs both MoE stages with xcd_swizzle=4 on a grid that is not a multiple of 8, with every tile holding a routed row, fails on main (stage-1 rows left NaN) and passes with the fix. Existing tests run _xcd kernels only as tuned rows at the row's bucket token count (test_moe_2stage.py's CSV cases, test_fhmoe.py's production rows). There the skipped tiles often hold no routed row: test_fhmoe.py routes every token to the same 9 experts, and random routing often leaves the last M blocks empty. test_moe_2stage.py also fails a case only when logits_diff exceeds 0.01, which a few doubled tiles do not reach.

Related

🤖 Generated with Claude Code

eppaneamd and others added 2 commits November 6, 2026 09:08
Both FlyDSL MoE GEMM stages remap their workgroups for XCD locality with

    wgid = (lin % 8) * (n // 8) + lin // 8

which is a permutation of the n workgroups only when n is a multiple of
8. Otherwise n % 8 tiles run twice and n % 8 tiles never run: stage 1
leaves rows of its output unwritten (and split-K stage 1 adds some
partial sums twice), the atomic stage 2 adds some expert contributions
twice and drops others, and the reduce stage 2 reads slots nobody
wrote. n depends on the token count, so an `_xcd` kernel can be right
at one token count and wrong at the next.

xcd_remap_bx_by already has the remainder term. Move its remap into
xcd_remap_grid, which takes the grid size from the caller, and call it
from both MoE stages. Also correct the stage-2 comment that called
xcd_swizzle an ignored argument.

Add test_flydsl_moe_xcd_swizzle_uneven_grid: both stages with
xcd_swizzle=4 on a 2 x 18 grid, every tile holding a routed row.

The same fix was proposed in #4315, closed for inactivity.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The MoE stages put M blocks on grid y and N blocks on grid x, so they
pass grid_y as grid_m; naming the arguments makes that visible. The
docstring now states the helper's xcd_swizzle > 0 precondition, which
xcd_remap_bx_by checks before calling it.

No compiled kernel changes: the gfx950 ISA of both MoE stages, the
persistent and heterogeneous stage 2, and both GEMM callers is
byte-identical to the previous commit's.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 7567 --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.

@eppaneamd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

Copilot AI 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.

🟡 Changes recommended

The new regression is excluded from CI’s test list and requires pytest dispatch, so CI does not execute its assertions.

1 open issue
What changed in this PR

Fixes FlyDSL MoE workgroup mapping on grids not divisible by eight, preventing duplicate and skipped tiles in both GEMM stages.

Changes:

  • Extracts the remainder-aware XCD remap into a shared helper and uses it in both MoE stages.
  • Adds a regression test covering both stages on a 36-workgroup grid, with NaN-filled stage-1 output to detect unwritten rows.
  • Corrects a comment describing stage-2 xcd_swizzle behavior.
File Description
op_tests/​flydsl_tests/​test_flydsl_moe.py Adds distinct-expert routing and an uneven-grid regression test.
aiter/​ops/​flydsl/​moe_kernels.py Clarifies that xcd_swizzle selects the workgroup remap; comment-only change.
aiter/​ops/​flydsl/​kernels/​mixed_moe_gemm_2stage_common.py Replaces both incomplete MoE remaps with the shared helper.
aiter/​ops/​flydsl/​kernels/​mfma_preshuffle_pipeline.py Extracts and exports xcd_remap_grid, preserving the existing GEMM remap behavior.

Review effort: Balanced

@eppaneamd
eppaneamd requested a review from RElbers November 10, 2026 10:21
eppaneamd and others added 2 commits November 10, 2026 04:51
CI runs op_tests/*.py as sharded scripts, and op_tests/flydsl_tests is not in
the plan, so test_flydsl_moe_xcd_swizzle_uneven_grid never ran there. The
Focused regression tests step runs `python3 -m pytest -q tests` on pull
requests (MI35X shard 0), so the test moves, unchanged, to
tests/test_flydsl_moe_xcd_swizzle.py. It imports its data generator, tolerance
check, tile_k helper and gfx950 skip from the op test file, which keeps the
distinct_experts argument of _generate_a8w4_gui_data.

On MI355X (torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2, an empty FlyDSL cache per
run): with the three kernel files of the merge-base the test fails
(xcd4_uneven_grid_stage1: output has NaN), with this commit's it passes, 0
skipped; the whole tests/ directory in CI's layout runs in 13 s.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@eppaneamd
eppaneamd marked this pull request as ready for review November 10, 2026 12:17
@eppaneamd
eppaneamd requested review from a team and a balanced review from Copilot November 10, 2026 12:17
@aiter-bot

aiter-bot commented Nov 10, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision d7ec3d633220 · 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 remap in `_xcd{N}` MoE kernels is now a permutation of the grid the kernel computes, for any workgroup count. Before, grids with a workgroup count not divisible by 8 ran some tiles twice and skipped as many, so the output was wrong at some token counts (stage 1 rows unwritten; stage 2 contributions doubled or dropped). The remap is unchanged when the count is divisible by 8. Stage 1 still computes its grid size in the kernel, without the `tile2_pad` the host adds to its launch; where the two differ, #6598's `gpu.grid_dim` reads are the fix.

Validation and unverified scope

One MI355X (gfx950), ROCm 7.2, FlyDSL 0.4.2; main at `f705d6b7a0` against this branch's first commit, except where stated. The second commit only names arguments and edits a docstring; every kernel below compiles to byte-identical gfx950 ISA under both commits. The third commit only moves the test. The fourth merges main (`9c119bb65`), which pins FlyDSL 0.5.0 (#7600); this branch merged without conflicts. The fifth only changes the test's skip condition from `get_gfx()`, which takes the last `GPU_ARCHS` entry, to `get_gfx_runtime()`, the running GPU; the test runs below predate it.

- After the merge of main, on FlyDSL 0.5.0 (the PyPI wheel unpacked ahead of the image's 0.4.2), MI355X, `vllm/vllm-openai-rocm` nightly `083fbac021` (torch 2.13.0+rocm10.0.0), an empty FlyDSL cache for each run: `python3 -m pytest -rA tests/test_flydsl_moe_xcd_swizzle.py` fails with main's three kernel files (`AssertionError: xcd4_uneven_grid_stage1: output has NaN`) and passes with this branch's, 0 skipped, both in CI's layout (the merged source tree with the image's prebuilt `.so` files copied in) and with the kernel files overlaid on the installed aiter. The whole `tests/` directory in CI's layout: main's kernels 4 failed and 355 passed (15 s); this branch's 3 failed and 356 passed (14 s). The 3 common failures are in files this change does not touch: `test_all_reduce_config.py::AllReduceConfigTest::test_communicator_reads_explicit_bytes_before_import`, `test_import_without_gpu.py::test_import_aiter_without_visible_gpu` (`RuntimeError: No gfx arch found in rocminfo output.` in that container) and `test_mega_moe_gfx1250_recipe.py::test_layout` (an arena-size assertion).
- Before the merge, on this branch's earlier pin (FlyDSL 0.4.2; amd-aiter 0.1.28.post1 with the three kernel files overlaid, torch 2.13.0+rocm10.0.0, an empty FlyDSL cache for each run): `python3 -m pytest -rA tests/test_flydsl_moe_xcd_swizzle.py` fails with the merge-base's kernel files (`AssertionError: xcd4_uneven_grid_stage1: output has NaN`) and passes with this branch's, 0 skipped.
- Before the merge, FlyDSL 0.4.2, the whole `tests/` directory in CI's layout (the source tree, with the image's prebuilt `.so` files copied in): 13 s with this branch's kernels, 236 passed and 3 failed; with the merge-base's, 235 passed and 4 failed (the moved test). The 3 common failures are in files this change does not touch: `test_all_reduce_config.py::AllReduceConfigTest::test_communicator_reads_explicit_bytes_before_import` and `test_import_without_gpu.py::test_import_aiter_without_visible_gpu` (`RuntimeError: No gfx arch found in rocminfo output.` in that container) and `test_mega_moe_gfx1250_recipe.py::test_layout` (an arena-size assertion).
- `op_tests/flydsl_tests/test_flydsl_moe.py` collected 34 tests after the move (before the merge of main) and they were not run: `xcd_swizzle` is non-zero only in the moved test. With the test still in that file, main 34 passed and 1 failed (the new test), and the branch 35 passed.
- Measured with the test in the op test file (same code): it also fails with the stage-1 call reverted to the old remap (stage-1 NaN), with the stage-2 call reverted (`xcd4_uneven_grid_stage2: checkAllclose failed (err=0.2665, max=0.05)`), and with the remainder term removed from the helper (stage-1 NaN).
- `op_tests/test_fhmoe.py -k production_decode_and_prefill`: 17 passed on both. Its 4096-, 8192- and 32768-token rows run `_xcd4` stage 1 on grids that are not multiples of 8 (4 × 833, 4 × 833 and 4 × 2561, computed from the launch code), so the new remap runs there. The test routes every token to the same 9 experts, which leaves the skipped last M block empty, so main passes too.
- Each `xcd_swizzle=4` kernel against `xcd_swizzle=0` in the same process (a standalone script, not in this PR):
  - stage 2 `t32x128x256_atomic`, fp4 activations and weights (model 2560, inter 512, 513 experts, top-11), 9–16 tokens: on main, odd counts give rel L2 0.026–0.040 against the torch

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

What the changed op test fails on before this PR, and why existing tests do not cover it:

- `tests/test_flydsl_moe_xcd_swizzle.py::test_flydsl_moe_xcd_swizzle_uneven_grid` fails on main at its stage-1 assertion (`xcd4_uneven_grid_stage1: output has NaN`: the rows of the skipped tiles keep the NaN fill). With only the stage-2 call reverted it fails at stage 2 (`xcd4_uneven_grid_stage2: checkAllclose failed (err=0.2665, max=0.05)`: a duplicated tile adds its contribution twice). It passes on the branch.
- Existing tests run `_xcd` kernels only at a tuned row's bucket token count, where the grid is often a multiple of 8 (`test_moe_2stage.py`'s CSV cases, `test_fhmoe.py`'s production rows). Where it is not, `test_fhmoe.py` routes every token to the same 9 experts, so the skipped last M block holds no routed row and main passes (17 passed on both); `test_moe_2stage.py` fails a case only when `logits_diff` exceeds 0.01, and main's worst is 0.0043.
- The new test routes 9 tokens to 18 distinct experts on a 2 x 18 grid, so every tile holds a routed row, stage 1 writes into a NaN-filled buffer, and a duplicated stage-2 tile changes a sum.

Changed op tests

`op_tests/flydsl_tests/test_flydsl_moe.py`: only `_generate_a8w4_gui_data` changes, with a `distinct_experts` argument (default off) that the new test uses; the new test itself is `tests/test_flydsl_moe_xcd_swizzle.py::test_flydsl_moe_xcd_swizzle_uneven_grid`. It runs both MoE stages with `xcd_swizzle=4` on a grid that is not a multiple of 8, with every tile holding a routed row, fails on main (stage-1 rows left NaN) and passes with the fix. Existing tests run `_xcd` kernels only as tuned rows at the row's bucket token count (`test_moe_2stage.py`'s CSV cases, `test_fhmoe.py`'s production rows). There the skipped tiles often hold no routed row: `test_fhmoe.py` routes every token to the same 9 experts, and random routing often leaves the last M blocks empty. `test_moe_2stage.py` also fails a case only when `logits_diff` exceeds 0.01, which a few doubled tiles do not reach.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

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.

Copilot AI 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.

🟡 Changes recommended

The regression test uses build-target architecture rather than the running GPU, potentially skipping coverage on gfx950 or enabling a gfx950-only test on gfx942.

2 open issues

Review effort: Balanced

Comment thread tests/test_flydsl_moe_xcd_swizzle.py Resolved
The gfx950 skip imported from the op test uses get_gfx(), which follows
GPU_ARCHS and takes its last entry, so on an MI355X with
GPU_ARCHS='gfx950;gfx942' the regression was skipped. It now checks
get_gfx_runtime(), the running GPU, in the test body, as
op_tests/test_flydsl_pa_decode.py does.

On MI355X with GPU_ARCHS='gfx950;gfx942', get_gfx() returns gfx942 and
get_gfx_runtime() gfx950. Under the other settings tried (unset, 'gfx950',
'gfx942;gfx950') both return gfx950.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:40

Copilot AI 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.

🔵 Needs a closer look

GPU execution was unavailable, leaving correctness and latency unverified across shared-remap paths—including split-K, reduce, persistent, and heterogeneous MoE variants—beyond the focused regression’s coverage.

1 open issue
1 resolved since last review

Review effort: Balanced

Brings in #7774, which ports op_tests/test_flydsl_moe_a16wfp4.py's
stage-2 cache-key test to FlyDSL 0.5.0. The version this branch last
merged imports _jit_function_cache_key, which FlyDSL 0.5.0 does not have,
so that test failed in CI. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rony Leppänen <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 14:26

Copilot AI 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.

🟢 Approval recommended

There are no active review issues for the shared remainder-aware XCD remapping change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced



def test_flydsl_moe_xcd_swizzle_uneven_grid():
"""xcd_swizzle on a 2 x 18 grid in both stages: 36 workgroups, not a multiple

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.

36 workgroups is not a multiple of 8 but is still a multiple of 4. So on a 4-die part the test still passes with the previous code. Changing to topk=3 and token=7 gives a workgroup count of 42, which is divisible by neither.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 16:34

Copilot AI 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.

🔵 Needs a closer look

Shared GPU scheduling changes affect MoE and GEMM, but hardware correctness/performance validation is unavailable, leaving the author’s gfx950 evidence and unexecuted split-K, reduce, and persistent variants for human review.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Dec 4, 2026

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

Labels

FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants