Skip to content

fix: zero-pad XQ to padded weight K for all a8w8 bpreshuffle backends - #6456

Merged
demonsan merged 5 commits into
ROCm:mainfrom
yuychang:fix/a8w8-bpreshuffle-padded-k
Oct 20, 2026
Merged

demonsan merged 5 commits into
ROCm:mainfrom
yuychang:fix/a8w8-bpreshuffle-padded-k

Conversation

@yuychang

@yuychang yuychang commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

shuffle_weight(..., pad_k_to=K_w) preshuffles WQ in blocks laid out over the padded K_w. Every a8w8 bpreshuffle kernel takes a single K for both operands, but only the FlyDSL path zero-padded XQ to K_w. CK, CKTile and the untuned fallbacks therefore read the shuffled weight with the wrong K and returned wrong results.

Technical Details

  • aiter/ops/gemm_op_a8w8.py: zero-pad XQ to w_k once before config dispatch, so every backend runs at K_w. This replaces the two FlyDSL-only pads. Zero padding leaves the dot product unchanged.
  • Tuned-config lookup is unchanged: it still tries logical K first, then falls back to K_w.
  • op_tests/test_gemm_a8w8_bpreshuffle_pad_k.py:
    • The mock dispatch tests now expect the padded XQ shape and a zero tail.
    • New end-to-end reference cases cover untuned, CK, split-K CK, CKTile and FlyDSL. They hit both the logical-K and the padded-K config rows.
    • Each case asserts that dispatch still picks the expected backend.
    • The cases compare against an fp32 reference with assertAllclose (rtol=atol=1e-2, catastrophic_check=True). Split-K uses atol=1.0 because it adds up bf16 partial sums.
    • They are skipped unless the device is a full 256-CU gfx950, because the rows come from the gfx950 cu_num=256 tuned tables.
    • The reference cases are an aiter op test (@benchmark sweep + main()), so the default CI runner (python3 <file>) now executes them; pytest still runs them via a parametrized wrapper.

Test Plan

pytest op_tests/test_gemm_a8w8_bpreshuffle_pad_k.py and python op_tests/test_gemm_a8w8_bpreshuffle_pad_k.py (prints a markdown summary table of us/TFLOPS/TB/s/err and the dispatched backend per shape; -s m,n,k,w_k to pick shapes) on gfx950 (MI355X), with and without the dispatch fix.

Test Result

  • With the fix: 17 passed.
  • Without the fix: 7 of the 8 new reference cases fail. The FlyDSL case passes because that path already padded XQ.

Submission Checklist

- K-padded WQ is preshuffled over K_w and every kernel takes a single K for both operands
- Only FlyDSL padded XQ; CK, CKTile and untuned fallbacks read the shuffled weight with the wrong K
- Pad XQ once before dispatch so all backends run at K_w; zero padding leaves the result unchanged
- Update mock tests to expect padded XQ and add end-to-end reference checks for CK, CKTile, FlyDSL and untuned shapes

Co-authored-by: Copilot <[email protected]>
@yuychang
yuychang requested review from a team and a balanced review from Copilot October 13, 2026 02:21
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6456 --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.

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.

🟡 Changes recommended

The new tests use a mismatched architecture gate and a nonstandard comparison that can miss localized errors.

2 open findings
What changed in this PR

Centralizes activation zero-padding so all A8W8 preshuffle backends correctly consume K-padded weights.

Changes:

  • Pads XQ to the physical weight K before backend dispatch.
  • Adds backend dispatch and numerical regression tests.
File Description
aiter/​ops/​gemm_op_a8w8.py Applies padding consistently across CK, CKTile, FlyDSL, and fallbacks.
op_tests/​test_gemm_a8w8_bpreshuffle_pad_k.py Expands padded-K backend and reference coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 03:54
…ertAllclose

- Skip every reference row unless get_gfx() is gfx950, since dispatch keys the tuned CSV with get_gfx()
- Replace the max-relative-error check with assertAllclose(rtol=atol=1e-2, catastrophic_check=True)
- Loosen atol to 1.0 for the split-K row only, where bf16 partial sums add ~1 ulp on small outputs

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.

🔵 Needs a closer look

The new tests incorrectly run 256-CU-specific tuned cases on other gfx950 CU configurations.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Gate test on gfx950 devices with 256 CUs

op_tests/​test_gemm_a8w8_bpreshuffle_pad_k.py:256

These cases are tied to tuned rows with cu_num=256, but this gate also admits partitioned gfx950 devices with a different CU count. On those devices _padded_k_backend() cannot find the expected tuned rows and the test fails before exercising the kernel. Gate on both gfx950 and 256 CUs (or provide rows for each supported partition).

🧠 Review effort: Balanced

- Tuned lookup keys on (gfx, cu_num) and every gfx950 bpreshuffle row has cu_num=256
- A partitioned gfx950 finds no row, so the backend assertion would fail before running the kernel; skip instead
Copilot AI balanced review requested due to automatic review settings October 13, 2026 04:03
@yuychang

Copy link
Copy Markdown
Contributor Author

Re Copilot "Gate test on gfx950 devices with 256 CUs": valid, since the tuned lookup keys on (gfx, cu_num) and every gfx950 bpreshuffle row has cu_num=256. Fixed in db3c999: the reference cases now skip unless (get_gfx(), get_cu_num()) == ("gfx950", 256). Verified with 17 passed on a 256-CU MI355X, and all 8 reference cases skipped under CU_NUM=80.

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

The centralized fix preserves lookup behavior and is covered across all affected backend paths.

0 open findings

🧠 Review effort: Balanced

… test

- Move the end-to-end case body into a @benchmark sweep fn with a candidate dict, run_perftest and checkAllclose
- Report us, TFLOPS, TB/s and err per candidate plus the dispatched backend and gfx in a markdown summary table
- Split the fp32 dequant reference into an untimed run_torch helper
- Add main() with a gfx942/gfx950 allow-list, -d/--dtype and -s/--mnk (m,n,k,w_k) argparse and itertools.product sweep
- Add a __main__ guard so `python op_tests/test_gemm_a8w8_bpreshuffle_pad_k.py` (the CI runner) executes the sweep
- Keep the pytest wrapper with the gfx950 cu_num=256 skip and expected-backend assertion on top of the sweep fn
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:15

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.

🟡 Changes recommended

End-to-end coverage skips the affected gfx942 backend paths.

1 open finding

🧠 Review effort: Balanced

yuychang added a commit to yuychang/aiter that referenced this pull request Oct 14, 2026
yuychang added a commit to yuychang/aiter that referenced this pull request Oct 14, 2026
yuychang added a commit to yuychang/aiter that referenced this pull request Oct 14, 2026
@demonsan

Copy link
Copy Markdown
Contributor

@aiter-bot review

- Key the end-to-end case table by the (gfx, cu_num) tuned table each row was picked from
- Add gfx942 cu_num=80 rows that reach the CK and CKTile logical-K and padded-K fallback rows
- Run the untuned CKTile-fallback rows on 304-CU gfx942, whose tuned table has no fp8 rows
- Default main() shapes to the current device's table instead of the gfx950 rows
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:02

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.

🔵 Needs a closer look

Cross-backend GPU validation, particularly for the new gfx942 cases, remains necessary before approval.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Validate expected backend for known benchmark shapes

op_tests/​test_gemm_a8w8_bpreshuffle_pad_k.py:395

The default CI invocation (python3 <file>) calls the benchmark helper here, bypassing the expected-backend assertion in the pytest wrapper. If a tuned row changes backend or disappears, the script can still pass numerically while losing the intended CK, CKTile, split-K, or FlyDSL coverage. Check the expected backend for each known shape in the selected device's case table before benchmarking, while leaving arbitrary -s shapes unrestricted.

1 resolved since last review

Review effort: Balanced

@demonsan demonsan 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.

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants