Repository navigation
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]>
🏷️ 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.
🟢 Approval recommended
No active review issues are reported for the preshuffled-scale bounds correction and accompanying regression coverage.
No open issues 🎉
What changed in this PR
This PR corrects preshuffled e8m0 scale reads in AITER’s gfx950 8-wave MXFP8 GEMM so partial final 32-row groups are covered, while leaving the row-major scale path unchanged.
Changes:
- Extends the scale-buffer bound to include rows padded to 256, matching the launcher’s existing size requirement.
- Adds regression coverage to the existing GEMM op test, checking both scale layouts against an FP32 reference and requiring bit-for-bit agreement.
- Adds 24 default shapes covering aligned and ragged dimensions, with a configurable
-mnk_preshuffledshape list.
| File | Description |
|---|---|
op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py |
Adds preshuffled-scale regression checks, shape selection, and result summaries. |
aiter/ops/flydsl/kernels/mxfp8_gemm_8wave.py |
Pads the scale-buffer row bound to 256-row alignment. |
Review effort: Balanced
DRAFT — evaluation pausedPR Self-ReviewRevision This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes. |
|
Replaced by #9040 (cherry-picked onto the current main, no conflicts; commit author kept). |
Draft. 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
8d508da
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).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