Skip to content

[FlyDSL] mxfp8 8-wave GEMM: cover the padded rows of preshuffled e8m0 scales - #8588

Closed
Jasen2201 wants to merge 1 commit into
mainfrom
Jasen/m31-pp-mxfp8-8wave-psc-rows
Closed

Jasen2201 wants to merge 1 commit into
mainfrom
Jasen/m31-pp-mxfp8-8wave-psc-rows

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ScalePreshuffledS2R sizes its scale buffer for the rows padded to 256, the size flydsl_mxfp8_8wave_gemm already requires of a 1-D scale. It stopped at rows x K/32 bytes, so the partial group's scale words loaded as 0.
  • Row-major scales, the only kind aiter's own dispatch passes, build the same kernel as before.
  • test_gemm_8wave_preshuffled_scales in op_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 by shuffle_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

Dev record
  • Found: the descriptor bound (rows x K/32 bytes) ignored the 256-row padding of the layout the reader walks. It was found while verifying an ATOM MiniMax-M3.1 TP1 prefill prototype that feeds this kernel preshuffled scales. There, real-weight qkv at M 8191 gave relL2 7.4e-3 and max abs 261, against 1.66e-3 and 8.1 on the row-major path (M 3001: relL2 3.4e-2).
  • Decided: pad to 256 rows, the size the launcher checks (-(-M // 256) * 256 * K // 32 bytes for a 1-D x_scale). A 32-row pad would also be correct: rows past M feed only output rows the store drops.
  • Decided: extend op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py rather than add a suite under op_tests/flydsl_tests/. CI shards run the top-level op_tests/test_*.py files 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.
  • Decided: the preshuffled scales come from 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.
  • Decided: random fp8 values and random e8m0 codes per row and 32-K group instead of the quant kernel, so a scale read for the wrong row or group changes the output. The N 6160 point uses M 1024 so that only the weight-scale side is ragged. M 1 and 17 lie inside one partial 32-row group, and M 37 (K 7168) puts a full and a partial group inside one M tile.
  • Surprised: none.
  • Left undone: the file's existing tuned-shape sweep, unchanged here, ran on two shapes only, not on every gfx950 row.
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 (the requirements.txt pin). 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_layout OK, 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):

M N K row-major us preshuffled us
1000 9856 6144 77.4 72.4
3001 9856 6144 171.5 158.3
8191 9856 6144 438.8 392.0
8192 9856 6144 439.1 391.4
16384 9856 6144 873.8 780.1
1000 6144 8192 85.2 76.8
3001 6144 8192 173.7 161.4
8191 6144 8192 307.3 296.7
8192 6144 8192 306.1 291.7
16384 6144 8192 607.1 578.8
1000 6144 6144 68.4 62.0
3001 6144 6144 137.9 127.5
8191 6144 6144 241.4 228.8
8192 6144 6144 243.1 228.5
16384 6144 6144 477.0 449.7
1000 6144 3072 38.8 36.3
3001 6144 3072 78.2 74.2
8191 6144 3072 140.9 134.8
8192 6144 3072 140.4 135.0
16384 6144 3072 266.9 256.8
1024 6160 3072 39.7 37.6
1 6144 3072 30.2 28.8
17 7168 2048 22.2 21.1
37 2112 7168 61.6 58.0

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:

M N K preshuffled output that differs preshuffled relL2 / max abs row-major relL2 / max abs
1000 9856 6144 rows 992-999 7.6e-2 / 6.28 1.7e-3 / 0.028
3001 9856 6144 rows 2976-3000 4.2e-2 / 4.71 1.7e-3 / 0.031
8191 9856 6144 rows 8160-8190 1.2e-2 / 2.79 1.7e-3 / 0.031
1000 6144 8192 rows 992-999 7.7e-2 / 7.49 1.7e-3 / 0.031
3001 6144 8192 rows 2976-3000 4.5e-2 / 4.65 1.7e-3 / 0.031
8191 6144 8192 rows 8160-8190 1.1e-2 / 2.24 1.7e-3 / 0.031
1000 6144 6144 rows 992-999 7.9e-2 / 6.25 1.7e-3 / 0.028
3001 6144 6144 rows 2976-3000 4.4e-2 / 4.49 1.7e-3 / 0.029
8191 6144 6144 rows 8160-8190 1.1e-2 / 2.32 1.7e-3 / 0.028
1000 6144 3072 rows 992-999 8.0e-2 / 4.97 1.7e-3 / 0.016
3001 6144 3072 rows 2976-3000 4.4e-2 / 3.35 1.7e-3 / 0.016
8191 6144 3072 rows 8160-8190 1.2e-2 / 2.71 1.7e-3 / 0.016
1024 6160 3072 columns 6144-6159 3.6e-2 / 3.93 1.7e-3 / 0.016
1 6144 3072 row 0 1.0 / 3.82 1.7e-3 / 0.0077
17 7168 2048 rows 0-16 7.1e-1 / 3.55 1.7e-3 / 0.016
37 2112 7168 rows 32-36 3.4e-1 / 6.18 1.7e-3 / 0.016

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:

M N K row-major us preshuffled, this PR preshuffled, main's kernel
8192 9856 6144 440.4 391.9 391.5
8192 6144 8192 308.5 293.5 293.2
8192 6144 6144 241.9 229.0 228.9
8192 6144 3072 142.3 136.0 136.3
16384 9856 6144 881.6 787.5 786.4
16384 6144 8192 608.8 573.6 574.5
16384 6144 6144 473.3 450.4 450.3
16384 6144 3072 267.5 257.4 257.3

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

  • Validated on one MI355X (gfx950): python3 op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py -mnk 1000,9856,6144 8191,6144,3072 exits 0, and the new check passes at its 24 default points (err 0, preshuffled equals row-major bit for bit).
  • With the kernel file at main, the 16 ragged points fail and the 8 aligned ones pass. Preshuffled timing is unchanged (median of 4 alternating runs, 8 aligned shapes).
  • Unverified: the existing tuned-shape sweep ran on two shapes only (this PR does not change its row-major path). gfx942 and gfx1250 run only the existing checks, since the 8-wave kernel is gfx950-only.

PR-specific question

Before this PR, test_gemm_8wave_preshuffled_scales fails 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_gemm passes row-major scales through the dispatcher.

Changed op tests

op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py adds test_gemm_8wave_preshuffled_scales (gfx950). It runs the 8-wave kernel with row-major scales and with the same scales preshuffled by aiter.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

… 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]>
@Jasen2201
Jasen2201 requested review from a team and a balanced review from Copilot November 24, 2026 15:20
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8588 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

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

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_preshuffled shape 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

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision 8d508da50b22 · mode shadow

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.

@MengqingCao

Copy link
Copy Markdown
Contributor

Replaced by #9040 (cherry-picked onto the current main, no conflicts; commit author kept).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants