Repository navigation
Conversation
The stage-1 launcher sizes the grid to the padded output width, including tile2_pad, but the XCD remap inside the kernel (xcd_swizzle 4) recomputed grid_x from n_in - 2 * inter_dim_pad without it. With inter_dim 640, pad 64 and tile_k 256, the launch has 10 N blocks and the remap spreads only 9. The last N block is never computed, so stage-1 columns 576-639 and their e8m0 scales stay unwritten. The v2-layout stage 2 reads them, and the output can turn non-finite (ROCm#8382, ROCm#8051). Compute the launcher's tile2_pad in compile_mixed_moe_gemm1_common and subtract it from the remap's pad term, so the remap covers every launched N block. When tile2_pad is 0 (including pad 0), the kernel is unchanged. Validated on one MI355X with a 0xFF-filled workspace at the DeepSeek-V4.1 TP4 shape (pad 64): failing calls went from 32 of 32 to 0 of 32, and the output was bit-identical to the non-swizzled kernel. Fixes ROCm#8382 Signed-off-by: Peyman Razaghi <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
NOT 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 |
@aiter-bot Updated the
I ran this repo's Prepared with PR Pundit. |
These failures are This PR changes only A grep of Prepared with PR Pundit. |
These failures are That test uses This PR changes only the FlyDSL MoE stage-1 XCD remap in Prepared with PR Pundit. |
The gate log shows every other prerequisite succeeded ( That comes from the two Standard Tests shards above:
As explained in those replies, neither test reaches the file this PR changes. I did not rerun them in this round. Prepared with PR Pundit. |
…le on 2 * inter_dim The interleaved stage-1 gate/up kernel walks 2 * (inter_dim - inter_dim_pad) on its N axis, and one workgroup writes tile_n // 2 output columns, but the resolver checked inter_dim % tile_n. A tuned 256-wide tile at inter_dim 640/1152 was therefore forced to 128 even though it is legal. Resolve the interleaved tile against the real unpadded N axis, keep the historical rule for separated gate/up, and fall back to the largest supported divisor (256/128/64). Cap the interleaved tile at 128 for k_wave > 1: the k_wave reduction path is only exercised with the 128-wide tile, and the 128-wide k_wave=2 output already differs from k_wave=1 on MI350X (pre-existing, outside this diff). A tile move changes grid_x. Replay the stock XCD remap on the kernel's real y grid - ceil(sorted M blocks / persist_m) - and keep the stock tile when a missing workgroup would leave a fillable (M block, N tile) unwritten. When the caller sets an XCD swizzle and tile2_pad != 0, where the launcher and the in-kernel remap count different N tiles (ROCm#8512/ROCm#6598), keep the stock tile; without a swizzle a padded launch may resolve a smaller legal tile than stock (outputs unchanged). With xcd_swizzle=4 the stock launch on the pad64 shape still drops the last N tile, which is the pre-existing main issue tracked by ROCm#8512 and is not changed or claimed fixed here. The interleaved non-split-K CShuffle epilogue only holds tile_n // 2 columns; take the half budget only when the full-width buffer would not fit the LDS limit, so launches that already fit keep their compiled kernel. Tests: 339 CPU cases in op_tests/test_flydsl_moe_stage1_tile_n.py, including a guard-vs-kernel-remap equivalence sweep over persist_m {1,2,3,4,8} and xcd_swizzle 1..8, and the public-API persist_m=2/xcd_swizzle=4 case. The file runs under `python3 <file>` (aiter_test.sh's path) and is collected by split_tests.sh. Public-API MI350X A/B: 14 changed tuned rows 1.045-1.046x A/A-corrected over two runs, 8-shape focus 1.084x, CShuffle rows neutral; 14/14, 32/32, 9/9, 51/51 outputs SHA-256 equal. A 152-case persist_m x xcd_swizzle x tile_n sweep is SHA-equal to main. The pad64 guard case (resolves 128 on both trees) and the 64-wide fallback (inter_dim=128, inter_dim_pad=32, requested 256 -> 64, SHA-equal to stock 128) were run on MI350X; the pad64 stock 128 path still loses the last N tile on main. Signed-off-by: Arist12 <[email protected]>
…le on 2 * inter_dim The interleaved stage-1 gate/up kernel walks 2 * (inter_dim - inter_dim_pad) on its N axis, and one workgroup writes tile_n // 2 output columns, but the resolver checked inter_dim % tile_n. A tuned 256-wide tile at inter_dim 640/1152 was therefore forced to 128 even though it is legal. Resolve the interleaved tile against the real unpadded N axis, keep the historical rule for separated gate/up, and fall back to the largest supported divisor (256/128/64). Cap the interleaved tile at 128 for k_wave > 1: the k_wave reduction path is only exercised with the 128-wide tile. A tile move changes grid_x. Replay the stock XCD remap on the kernel's real y grid - ceil(sorted M blocks / persist_m) - before accepting an upgrade, and keep the stock tile when a missing workgroup would leave a fillable (M block, N tile) unwritten, or when the launcher pads the N axis (tile2_pad != 0, ROCm#8512/ROCm#6598). A downgrade is always kept. Tests: op_tests/flydsl_tests/test_flydsl_moe_stage1_tile_n.py pins the interleaved axis, the fallback, the k_wave cap and the XCD/pad guards. MI355X (FlyDSL 0.5.5, production use_async_copy=True and sync): of the twelve tuned rows that name 256, dsv41_fp4 M2048/N1152/E385 and dsv41_fp8 M4096/N640/E128 are 1.23x and 1.28x async, every warm round above 1.02x, on the stock split-output path; the other ten are not faster, so their CSV rows name the 128 tile main already ran and compile to main's kernel. Outputs are SHA-256 equal and no other tuned row changes its launch. The two kept rows' us1/TFLOPS/BW are refreshed. Signed-off-by: Arist12 <[email protected]>
Summary
Fixes #8382; the same failure is also reported in #8051 at the 385-expert, top-7 key.
The FlyDSL a8w4 MoE stage-1 kernels with XCD swizzle (
*_bnt0_gui_xcd4_fp8) skip the last launched N block whenintermediate_padis non-zero. That block's padded output columns and their e8m0 scales are never written. Stage 2 then reads them, so whatever the memory held reaches every output row. This PR makes the in-kernel XCD remap count the same N blocks as the launch grid. It is a one-term change incompile_mixed_moe_gemm1_common. At pad 0 the kernel is unchanged.Motivation
On MI355X (gfx950),
aiter.fused_moewith MX-fp8 activations, MXFP4 weights, SiLU and gate/up interleaved can return NaN/Inf rows without raising an error. This happens when stage 1 is one of these kernels:flydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui_xcd4_fp8flydsl_moe1_afp8_wfp4_bf16_t64x256x256_w3_bnt0_gui_xcd4_fp8and the caller passes a non-zero
intermediate_pad.The DeepSeek-V4.1 TP4 shape is affected: 576 real intermediate columns padded to 640,
intermediate_pad=64. The tuned rows inaiter/configs/model_configs/dsv41_fp8_tuned_fmoe.csv(key 5120 / 640 / 384 experts / top-6) select the first kernel at T 8192 and 16384.Cause. The launcher sizes the stage-1 grid to cover the padded output width, including
tile2_pad. The XCD remap inside the kernel (xcd_swizzle4) recomputesgrid_xfromn_in - 2 * inter_dim_padand leaves outtile2_pad. With inter_dim 640, pad 64 and tile_k 256, the launch has 10 N blocks but the remap spreads only 9. No workgroup is ever assigned to the last N block, so stage-1 columns 576-639 and their scales stay unwritten. The v2-layout stage 2 reads all 640 K columns. The non-swizzled kernel (..._w4_bnt0_gui_fp8) does not run the remap, writes every column, and stays finite.Whether a call fails depends on what the reused memory held before the call. That would fit the input-dependent counts in the report, but we did not measure it under the normal allocator.
Changes
aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py: compute the launcher'stile2_padat compile scope. The value is(tile_k/2 - (inter_dim - inter_dim_pad) % (tile_k/2)) % (tile_k/2), and 0 for the gate-only path. Subtract it from the pad term of the remap'sgrid_x, so the remap covers every launched N block.tile2_padis 0 (including pad 0), the generated kernel is unchanged.Relation to open PRs:
grid_x.Performance (if applicable)
Not measured. The change only alters which N blocks the remap hands out, but kernel timings were not taken with or without the patch.
Testing
Validated on MI355X only; see "Validation and unverified scope" below. No unit test is added in this PR; a suggested regression test is described below.
Documentation
This is an internal kernel bug fix. No API, option or documented behavior changes.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
5394390
Behavior and intent
Before this change, the XCD-swizzled stage-1 kernels skipped the last launched N block whenever
tile2_padwas non-zero. Padded intermediate columns were left unwritten and were then consumed by stage 2. After the change, the remap and the launch agree on the N-block count, so every column is written. Whentile2_padis 0, the behavior is identical to before.Validation and unverified scope
Checks on this diff. The patch applies cleanly to
mainat 2bd3416. The repository has no.pre-commit-config.yaml, so no pre-commit hooks ran. No build check was run.GPU setup. GPU results were validated on one MI355X in the vLLM nightly ROCm image of 2026-11-22 (aiter 0.1.29.post1, FlyDSL 0.5.0, torch 2.13 on ROCm 10). The FlyDSL MoE kernel source in that image is byte-identical to aiter
07766baea, the commit in the report. The patch was applied to that copy, not to a build of currentmain.Method.
AITER_CONFIG_FMOEtable and checked against aiter's dispatch log.fused_moewas filled with 0xFF (NaN) before each call.Results.
inter_dim_pad=64andxcd_swizzle=4on every call. Failures went from 32 of 32 to 0 of 32, and calls with unwritten columns went from 32 of 32 to 0 of 32. The patched xcd4 output was bit-identical to the non-swizzled kernel's on all 16 inputs.Reproducer. A reduced reproducer (one 1024-token batch, xcd4 vs non-swizzled, pad 64, 0xFF workspace) gives 32 of 32 against 0 of 32, and it did so again on a rerun. It can be shared on request. Without it: call
fused_moeon the shape above withintermediate_pad=64, force the xcd4 stage 1, and fill the stage-1 output buffer with 0xFF beforehand. Columns 576-639 of the stage-1 output keep 0xFF.Not tested:
intermediate_pad=0. No failure was reproduced there, and the report's script was not posted, so its pad setting is unknown. If the report's failures happen at pad 0, they have another cause that this PR does not address.gemm_moe_tune.py) reporting 0% error for these kernels is a separate problem and is not addressed here.Points raised in review of this diff, not addressed here:
tile2_padformula is duplicated at compile scope instead of being shared with the launcher's copy in_launch_mixed_moe_gemm1. If one copy changes without the other, the mismatch returns.workgroups_per_xcd = num_workgroups // 8with no remainder handling. Even with the correctedgrid_x, it is a one-to-one mapping only whengrid_x * grid_yis a multiple of 8. This is a separate concern that this PR does not change and did not test.inter_dim - pad .. inter_dimare written, forxcd_swizzle0 and 4 and pad 0, 32, 64 and 96.PR-specific question
Question (from the PR Self-Review comment): What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
Boundary: the remap must count exactly the N blocks the launcher launches. The change subtracts the compile-time
tile2_padfrom the remap's pad term. The remap and the launcher compute this value separately; the launcher's copy is in_launch_mixed_moe_gemm1.Failure mode if the copies diverge. If the two formulas ever differ, the mismatch returns:
Scope of the change.
tile2_padis 0, includingintermediate_pad=0, the generated kernel is unchanged.tile2_pad=0.xcd_swizzle0 do not run the remap.Evidence.
Not covered.
grid_x * grid_ynot divisible by 8.These are listed under "Validation and unverified scope".
Changed op tests
None.