Repository navigation
Conversation
Given intermediate_pad, get_2stage_cfgs binds a tuned FlyDSL or Opus stage 1 with inter_dim_pad=intermediate_pad. The FlyDSL stage 1 then launches tiles for the unpadded width rounded up to tile_k // 2 (fewer for a small tile_n) and the Opus stage 1 writes exactly the unpadded width; the rest of its torch.empty output stays unwritten. Most stage 2s read more: the v2 layout (flydsl_moe2_layout_*) and CK stage 2 read every column, CK-Tile skips whole 128-column blocks (k_pad_zeros), and the v1 FlyDSL stage 2 whole 128-column blocks of its last K tile. Only the Opus stage 2 reads exactly the unpadded width. An unwritten 0xFF e8m0 scale byte gives NaN (#6565). Stage 1 now gets the trailing columns its stage 2 skips: the pad before the Opus stage 2; the pad rounded down to 128 columns before CK-Tile, and also capped at tile_k before the v1 FlyDSL stage 2; 0 before the v2 layout and CK stage 2. It computes the other padding columns: zero given w1's zero padding, multiplied by w2's zero padding in stage 2. The test checks the stage-1 pad for each stage-2 kind. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
There was a problem hiding this comment.
🟡 Changes recommended
The stage-2 cap uses the registered tile size rather than the resolved size, so a 256-to-128 downgrade can make stage 2 read unwritten stage-1 data and produce NaNs; the dispatch test also needs coverage for this case.
1 open issue
What changed in this PR
This PR adjusts tuned two-stage MoE dispatch so stage 1 initializes the padded columns that stage 2 reads, addressing the uninitialized-data NaNs reported in #6565.
Changes:
- Derives stage-1 padding from the selected stage-2 backend’s padding behavior.
- Adds seven dispatch regression cases covering backend combinations and padding sizes.
| File | Description |
|---|---|
op_tests/test_moe_mxfp4_inter_dim_dispatch.py |
Adds assertions for stage-1 padding across stage-2 backends. |
aiter/fused_moe.py |
Adjusts padding passed to tuned FlyDSL and Opus stage-1 kernels. |
Review effort: Balanced
A v1 FlyDSL stage 2 runs with resolve_flydsl_stage2_tile_k(inter_dim, tile_k), which lowers a tile_k of 256 to 128 when 256 does not divide inter_dim, and it skips at most that many pad columns. The stage-1 pad was capped at the registered tile_k, so at inter_dim 384 with a pad of 256 stage 1 left 256 columns unwritten while stage 2 read 128 of them. The test adds that case (stage-1 pad 128) and one where the cap stays 256 (inter_dim 768, pad 384). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human runtime review is needed because GPU evidence does not cover the exact head or key padded dispatch paths, while the new tests verify only dispatch metadata.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
GPU check of the padded dispatch paths on this head (
The controls' outputs differ before vs after as much as repeated calls do. Not run: stage 1s other than A4W4 and Opus (so no CK-Tile stage 2 with a pad), and a v1 stage 2 at |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
…h-grid remap ROCm#7796 was closed without merging; ROCm#7822 handles the stage-1 padding in the dispatch instead. Drop its padding changes and tests, but keep the remap over the launch grid: stage 1 launches tile2_pad more N columns than the count the remap recomputed, so with intermediate_pad (DSv4.1 TP4: 576 + 64) an xcd_swizzle stage 1 left the padded columns unwritten. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
|
Serving check on a key whose 16 tuned rows pad 128 columns and use a v2-layout stage 2 ( This is the PR's binding block, as on this head, applied to the image's
GSM8K: 1319 questions, SE ≈ 0.005 per launch. Without the binding, all 1319 replies run to the 512-token limit with a
Setup
|
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-backend GPU padding contracts warrant human review because added tests verify only dispatch, leaving finite padded-weight scales and key stage/dtype combinations without GPU validation.
No open issues 🎉
Review effort: Balanced
|
There is a merge conflict with main in |
| ( | ||
| dtypes.fp8, | ||
| INTER_DIM, | ||
| _FP8_STAGE1, | ||
| "opus_moe2_afp8_wfp4_atomic_t32x128x256_sbm32_occ1_cache_b2_ws2", | ||
| 64, | ||
| 64, | ||
| ), |
There was a problem hiding this comment.
On gfx942 this case fails: the Opus stage 2 is gfx950-only, so get_2stage_cfgs discards the tuned row ("Opus stage2 config unsupported (requires gfx950, got gfx942)") and meta.stage1.keywords["kernelName"] is ''. The file's _SKIP allows gfx942, and main's post-merge MI300X run includes this file, so it would go red there (we ran it on gfx942: 33/34 pass, only this case fails). Could you skip this case off gfx950?
| ( | |
| dtypes.fp8, | |
| INTER_DIM, | |
| _FP8_STAGE1, | |
| "opus_moe2_afp8_wfp4_atomic_t32x128x256_sbm32_occ1_cache_b2_ws2", | |
| 64, | |
| 64, | |
| ), | |
| pytest.param( | |
| dtypes.fp8, | |
| INTER_DIM, | |
| _FP8_STAGE1, | |
| "opus_moe2_afp8_wfp4_atomic_t32x128x256_sbm32_occ1_cache_b2_ws2", | |
| 64, | |
| 64, | |
| marks=pytest.mark.skipif( | |
| get_gfx() != "gfx950", reason="the Opus stage 2 runs only on gfx950" | |
| ), | |
| ), |
| else: | ||
| stage1_inter_dim_pad = 0 |
There was a problem hiding this comment.
A small suggestion: for a v2-layout stage 2 this makes stage 1 compute the padding, which the description measures at 1.13–1.32× fused_moe GPU time on the Qwen3.5-397B rows (256 columns instead of 128). #7917 changes the same v2-layout case in get_2stage_cfgs from the other side: the v2 stage 2 skips the padding, so stage 1 can skip it too and the NaN goes away without the extra work. It might be worth keeping pad 0 here only for the CK stage 2, and noting in the description that the v2-layout binding is a stopgap until a stage-2 skip lands.
| # output unwritten, so it gets only the columns its stage 2 skips: the Opus stage | ||
| # 2 reads the unpadded width, the v1 FlyDSL one skips whole 128-column blocks of | ||
| # the last K tile it runs with (resolve_flydsl_stage2_tile_k), CK-Tile whole | ||
| # 128-column blocks, and the v2 layout and CK ones read every column. Stage 1 |
There was a problem hiding this comment.
A small suggestion: the bf16-activation v1 FlyDSL stage 2 (flydsl_moe2_abf16_*) never gets inter_dim_pad and reads every column (the a16w-mix branch of _flydsl_moe_stage2_impl), so "skips whole 128-column blocks" is not true for it. It is safe only because the stage 1s feeding it (the a16w port and the gfx942 _g942 a8w4 kernel) ignore the pad and tile the full width; here they just switch from torch.zeros to torch.empty for pads below 128. It might be worth saying so in the comment, so a later stage 1 that honors the pad does not bring the NaN back.
| # 128-column blocks, and the v2 layout and CK ones read every column. Stage 1 | |
| # 128-column blocks, and the v2 layout and CK ones read every column. The | |
| # bf16-activation v1 FlyDSL stage 2 reads every column too; its stage 1s ignore | |
| # the pad and write the full width. Stage 1 computes the others: zero from w1's | |
| # zero padding, times w2's zero padding. |

Summary
get_2stage_cfgsnow gives a tuned FlyDSL or Opus stage 1 only the padding columns its stage 2 skips, so stage 1writes every column stage 2 reads. This fixes the NaN output of #6565 (its repro: NaN in 28 / 88 calls → 0).
Motivation
Given
intermediate_pad, stage 1 leaves trailing columns of itstorch.emptyoutput and e8m0 scales unwritten, andmost stage 2s read them. An unwritten
0xFFe8m0 scale byte is NaN.tile_k // 2(less for a smalltile_n)flydsl_moe2_layout_*), CK stage 2k_pad_zeros)tile_kit runs withAffected tuned rows:
qwen3_5_397b_fp4_tuned_fmoe.csv, Qwen3.5-397B TP8, 16 rowsminimax_m25_fp4_tuned_fmoe.csv, MiniMax-M2.x TP8, 16 rowsCallers and related PRs:
tile_k // 2for everytile_n. That covers [Issue]: a8w4 fused_moe writes NaN at small token counts on gfx950 (uninitialized padded scratch) #6565, but not Qwen3.5-397B (128 of 256 columns stay unwritten) or the Opus stage 1.[ROCm][Bugfix] Stop declaring the MXFP4 MoE intermediate padding to AITER vllm-project/vllm#61816 dropped it only on vLLM's bias-less W4A16 path, where [Issue]: a8w4 fused_moe writes NaN at small token counts on gfx950 (uninitialized padded scratch) #6565 came from.
[Perf] [AMD] quark: Pad W4A4 MXFP4 MoE to 128 columns for AITER FlyDSL sgl-project/sglang#49852 aligns SGLang's to 128 columns.
Changes
aiter/fused_moe.py,get_2stage_cfgs, the stage-1inter_dim_pad:intermediate_padintermediate_padintermediate_padmin(tile_k, intermediate_pad // 128 * 128),tile_kfromresolve_flydsl_stage2_tile_kintermediate_padintermediate_pad // 128 * 128intermediate_pada pad column.
op_tests/test_moe_mxfp4_inter_dim_dispatch.py:test_padded_stage1_writes_the_columns_stage2_reads.Not changed: kernel selection; calls without a pad; the untuned path (
tile_n128 stage 1, v1 stage 2).It gives stage 1 the full pad. At widths that are multiples of 128 its stage 1 still writes every column its
stage 2 reads for any pad below 256 (derived from both grids, not run); 128 or 256 alignment never pads more.
With [FlyDSL] Fix and efficiently initialize A8W4 MoE stage1 padding #7796: a stage 1 whose epilogue would clear the pad (A8W4, interleaved gate/up, BF16 or FP16 output) computes
those columns instead when stage 2 reads them.
Performance (if applicable)
repro_min.py --rounds 8(a8w4,inter_dim640, pad 64)fused_moe, the 16 Qwen3.5-397B rows, 30 token countsfused_moe, the 16 MiniMax-M2.x rows, 30 token countscolumns instead of 128; a caller that pads to 128 ([ROCm][MXFP4] Align the AITER W4A4 MoE intermediate size to 128 vllm-project/vllm#55104, [Perf] [AMD] quark: Pad W4A4 MXFP4 MoE to 128 columns for AITER FlyDSL sgl-project/sglang#49852) has no pad here.
t32x32x256) leaves columns unwritten (224 of 256 written). Time perbucket 0.986–1.000×.
0xFFfill: Qwen3.5-397B non-finite in 39 / 180 timed cases (≥ 1 of 4 calls) → 0 / 180. Finite outputsmatch the tuner's reference as before (relative L2 median 0.0372).
Setup:
lmsysorg/sglang-rocm:v0.5.23-rocm10-mi35x-20261109(AITER285579b62), as published and with a hunk thatbinds that row as this PR does.
fused_moerows: the same AITER, MoE path as shipped (other patches outside it, [Triton/Gluon] [FlyDSL] [CI] [Bugfix] Never share scratch buffers whose zero fill was recorded into a graph #7126 among them); "after" with ahunk that binds these rows as this PR does (0 before their v2 layout and CK stage 2s).
inter_dimis served, quantized andshuffled with
gemm_moe_tune.py's helpers;intermediate_pad= padded − real.get_padded_Mmaps to it.torch.emptyresult insidefused_moefilled with0xFF(NaN as bf16, fp8 e4m3fnand e8m0).
run_perftest), seeds 0–2; arms alternated twice in one container. Repeat-to-repeatgeomean 1.000, per case 0.96–1.05.
Testing
Documentation
The change is internal to
get_2stage_cfgs; no guide describes how it binds the stage-1 pad.Dependencies
Breaking Changes
None for callers whose padding is zero. Where stage 1 now computes padding columns, w1's padding rows and their e8m0
scales must give finite values (zero weights; any scale byte but
0xFF), as w2's padding already had to be zero.PR Self-Review
Reviewed revision
753b907f4d5366a698c7004b969c35373cbaa402Behavior and intent
With
intermediate_pad> 0, a tuned FlyDSL or Opus stage 1 leaves unwritten only the columns its stage 2 skips, so theoutput no longer depends on what the allocator handed back. Rows with an Opus stage 2 keep the full pad; no key changes
kernels.
Validation and unverified scope
op_tests/test_moe_mxfp4_inter_dim_dispatch.py, 34 passed on this branch (mainat66ec1adad2).main'sfused_moe.py: the 8 cases whose binding changes fail, 26 pass.tile_kcap, CK-Tile 0, v1 FlyDSL the full pad, Opus 0; and forthe
tile_kresolution: none (fails the 384 case), a fixed 128, or resolved with the unpadded width (768).vllm/vllm-openai-rocm:nightly-rocm100-083fbac021348c2c7af8a7bc71ba18199d0dd7a4, FlyDSL 0.5.0 fromPyPI,
GPU_ARCHS=gfx950.285579b62plus a hunk with this PR's bindings for the measuredrows (all 0), not a build of
main.main8c964fa61, with this branch's trees and the JIT modules built from them (oneMI355X, every Python-level
torch.emptyinfused_moefilled with0xFF, 1, 16 and 200 tokens), A4W4: 7 forcedpairs, a v1 FlyDSL stage 2 at pads 64, 128 and 256, the v2 layout one at 64 and 128, the CK one at 64. The 4 whose
stage 1 left columns its stage 2 reads unwritten are non-finite in every row before and in none after. The 3
controls are finite in both, and their outputs before and after differ as much as repeated calls do.
ones are the tables' only FlyDSL or Opus stage 1s before a CK-Tile stage 2, so no CK-Tile stage 2 with a pad either;
a v1 stage 2 at
tile_k256 (the 384-wide case runs at 128); an Opus stage 1 before a v2 stage 2 with a pad(
main's 3 such rows are atinter_dim2304 and 384, widths callers do not pad).PR-specific question
What behavior each changed op test would fail on before this PR, and why existing tests do not cover it:
test_padded_stage1_writes_the_columns_stage2_readsfails onmainin 8 of 9 cases (mainpasses the full pad):tile_k128)tile_k256,inter_dim384, runs as 128)tile_k256,inter_dim768)main)No other test asserts the stage-1 pad: the file's other tests check backend selection and the CK-Tile guard;
op_tests/test_moe_2stage.pychecks outputs, which depend on allocator contents.Changed op tests
op_tests/test_moe_mxfp4_inter_dim_dispatch.py,test_padded_stage1_writes_the_columns_stage2_reads: the stage-1 padof a tuned FlyDSL or Opus stage 1 per stage-2 kind and pad (9 cases).
This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.
🤖 Generated with Claude Code