Repository navigation
[FlyDSL] mxfp8 8-wave GEMM: cover the padded rows of preshuffled e8m0 scales - #9040
Conversation
… scales ScalePreshuffledS2R sized its buffer descriptor at rows * K / 32 bytes, but the preshuffled layout it reads (aiter.ops.shuffle.shuffle_scale, flattened) spans the rows padded to 256, as the launcher validates. With M (or N) not a multiple of 32, the scale words of the last, partial 32-row group lie past that bound and load as 0 (2^-127), so those output rows (or columns) come out wrong. Size the descriptor for the padded rows. On gfx950, test_gemm_a8w8_mxfp8_bpreshuffle.py now also runs the 8-wave kernel with scales preshuffled by shuffle_scale and requires the row-major-scale result bit for bit. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 8d508da)
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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 |
Jasen2201
left a comment
There was a problem hiding this comment.
Reviewed at 00715a5.
The fix looks right to me. c_m / c_n are runtime fx.Int32 and ceildiv handles them. The padded bound, ceil(rows / 256) * 256 * K / 32 bytes, is exactly the 1-D scale size flydsl_mxfp8_8wave_gemm already requires (gemm_a8w8_mxfp8_8wave.py:230-246), so the descriptor now covers the whole allocation and nothing past it. n_i32 is built from the same padded rows, so the two lengths in ScalePreshuffledS2R agree. The tail split never runs with preshuffled scales (tail_split_n1 returns None), so no other path hands this reader an unpadded buffer.
CI: the new check ran in Standard Tests shard 3 (MI35X) at this head: 24/24 points, err 0 for both layouts. Shards 6 and 7 are red, but their logs list only passing tests and stop mid-run in tests this PR does not touch (test_per_tensor_quant_exact, test_activation). A re-run should clear them.
No changes requested.
|
Follow-up: I ran aiter's own validator (
Still no changes requested. |
00715a5 to
e1134d0
Compare
…ial-row fix; aiter's shuffle_scale for the w4 copy psc_layout now also needs aiter's 8-wave MXFP8 GEMM to set PRESHUFFLED_SCALE_PARTIAL_ROWS (ROCm/aiter#9040): without that fix a ragged M reads the scales of its last, partial 32-row group as 0 and gets wrong rows. An aiter without the marker keeps row-major scales, logged once. linear.py builds the weight scales' w4 copy with aiter's aiter.ops.shuffle.shuffle_scale(...).view(-1), byte-identical to ATOM's copy (127 pad, same permute), which is dropped; the layout test now pins aiter's. Co-Authored-By: Claude <[email protected]>
…ows, not an aiter marker Replaces the PRESHUFFLED_SCALE_PARTIAL_ROWS gate. An aiter 8-wave MXFP8 GEMM without ROCm/aiter#9040 drops the preshuffled scales of a partial last 32-row group; ATOM now never hands it one. The psc GEMM runs psc_rows(m) = m padded to 32 rows and returns the first m rows. The MXFP8 producers (mx8_quant, norm_mx's MX8 outputs, the SwiGLU w4 quant) write their e4m3 rows into buffers of psc_rows(m) rows, so the GEMM reads them in place; an activation without that storage is copied padded. The w4 scale buffer already covers 256-row padding. psc_layout keys on the real M as before and also needs N % 32 == 0. Co-Authored-By: Claude <[email protected]>
Re-filed from #8588 (author Jasen2201), cherry-picked onto the current
main(6b13649) with no conflicts. The commit keeps its original author; the change is unchanged.Ready for review. No blocking issues.
Why
With preshuffled e8m0 scales, the gfx950 8-wave MXFP8 GEMM loses the scales of the last, partial 32-row group whenever M or N is not a multiple of 32. At M 8191 on a 9856 x 6144 weight, output rows 8160 to 8190 come out wrong: max abs error 2.79 against an fp32 reference, 0.03 with row-major scales.
What changed
ScalePreshuffledS2Rsizes its scale buffer for the rows padded to 256, the sizeflydsl_mxfp8_8wave_gemmalready requires of a 1-D scale. It stopped at rows x K/32 bytes, so the partial group's scale words loaded as 0.test_gemm_8wave_preshuffled_scalesinop_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py(gfx950) feeds the kernel random fp8 data and random scales per row and 32-K group, row-major and preshuffled byshuffle_scale. Both results must match the fp32 reference and each other bit for bit.Review focus
The first two Decided items in the Dev record: the 256-row pad, and the new check living in the existing op test.
Testing
The 24 default points cover the MiniMax-M3.1 TP1 qkv, o_proj and shared-expert shapes at ragged and aligned M, plus N 6160 for the weight scales and M 1, 17 and 37 inside one M tile. All pass bit for bit, and main's kernel fails every ragged point.
branch @ 8d508da on MI355X: 24/24 pass, err 0; main's kernel: 16/24 fail. CPU pre-checks 154 passed, as on main. black, ruff 0.16.0 clean.
Follow-ups
kernels/gemm/mxfp8_gemm_8wave.py, which this kernel was ported from, has the same rows x K/32 bound.Dev record
-(-M // 256) * 256 * K // 32bytes for a 1-D x_scale). A 32-row pad would also be correct: rows past M feed only output rows the store drops.op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.pyrather than add a suite underop_tests/flydsl_tests/. CI shards run the top-levelop_tests/test_*.pyfiles as scripts, and this file already tests the 1x32 MXFP8 bpreshuffle GEMM. The check runs after the existing sweep, on gfx950 only, and has its own shape list (-mnk_preshuffled) and summary table.aiter.ops.shuffle.shuffle_scale, flattened to 1-D. It is the producer aiter ships for this layout, so the kernel is checked against it rather than a test-local copy.Evidence
Setup: rocm/atom-dev:nightly_202611211511 (torch 2.10.0+rocm7.2.4) with aiter replaced by this branch (8d508da on main 526972d, fresh
AITER_JIT_DIR) and FlyDSL 0.5.3 (therequirements.txtpin). One MI355X (gfx950, 256 CUs).Fixed:
python3 op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py -mnk 1000,9856,6144 8191,6144,3072, exit 0.test_w_scale_layoutOK, the existing sweep passed on both shapes, and the new check printed (err 0 for both layouts at every point; the bit-identity assert passed):Revert-red: the same tree with the kernel file at main, each default point run alone. The 8 points with M and N multiples of 32 pass; the other 16 fail the fp32 check. Outputs that differ from the row-major path, and the error against fp32:
Speed: the fix does not change the preshuffled kernel's time. Median of 4 alternating runs each, M and N multiples of 32, where both kernels are right:
With this fix, that ATOM prototype matched ATOM's row-major path bit for bit on 99/99 GEMM points (M 2048-32768, real checkpoint weights) and 112/112 linear points (M 1024-32768, ragged 1025-16383 included). The integrated build's 48/48 linear checks (6 real-weight shapes x M 1000-16384) include M 3001 and 8191.
CPU:
python3 -m pytest -q tests/test_plugin.py tests/test_plugin_contracts.py tests/test_plugin_discovery.py tests/test_plugin_overhead.py: 154 passed on this branch and on main 526972d, no FAILED on either.PR Self-Review
Reviewed revision
e1134d0
Behavior and intent
With preshuffled (1-D) e8m0 scales, the gfx950 8-wave MXFP8 GEMM now reads the scale words of a partial last 32-row group of A or B. Its buffer descriptor stopped at rows x K/32 bytes, so those words loaded as 0. The rows (M % 32 != 0) or columns (N % 32 != 0) of that group came out wrong. Row-major scales build the same kernel as before.
Validation and unverified scope
python3 op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py -mnk 1000,9856,6144 8191,6144,3072exits 0, and the new check passes at its 24 default points (err 0, preshuffled equals row-major bit for bit).op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.pyalso passed on one MI355X.PR-specific question
Before this PR,
test_gemm_8wave_preshuffled_scalesfails at every point whose M or N is not a multiple of 32 (16 of 24). There, the rows or columns of the last partial 32-row group are off the fp32 reference. No existing test feeds the 8-wave kernel preshuffled scales:test_gemmpasses row-major scales through the dispatcher.Changed op tests
op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.pyaddstest_gemm_8wave_preshuffled_scales(gfx950). It runs the 8-wave kernel with row-major scales and with the same scales preshuffled byaiter.ops.shuffle.shuffle_scale, on random e8m0 codes per row and 32-K group. Both must match the fp32 reference and each other bit for bit. The file's existing sweep covers row-major scales only.🤖 Generated with Claude Code