Skip to content

[HIP] [CK] [OPUS] Add opus mxfp4 bpreshuffle nt gemm - #7979

Open
Fyzyukk wants to merge 26 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp4_nt_gemm
Open

Fyzyukk wants to merge 26 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp4_nt_gemm

Conversation

@Fyzyukk

@Fyzyukk Fyzyukk commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add an OPUS backend for MXFP4 x MXFP4 NT GEMM with B preshuffle on gfx950. gemm_a4w4(bpreshuffle=True) interface to select tuned OPUS kernels.

Details

  • 2x2 4-wave pipeline: pre-compiled .co kernels with persistent/splitK/nob.
  • 1x4 small-tile pipeline: JIT-built for M <= 512.
  • Support MXFP4 (fp4x2) inputs, native 1x32 E8M0 scales in the e8m0_shuffle layout, B in the shuffle_weight(16, 16) layout and BF16 output through the existing a4w4 GEMM interface. Tuned rows select OPUS kernels via opus_a4w4_kid, and the a4w4 tuner gets an opus backend.

Speedup Distribution

Of the 1464 gfx950 / CU 256 shapes in aiter/configs/a4w4_blockscale_tuned_gemm.csv, the tuned table selects OPUS for 549. Speedup is base_us / head_us - 1, from the us column of this PR's CSV and of upstream/main's CSV for the same shape.

Speedup range Shapes
0–5% 71
5–10% 59
10–15% 42
15–20% 40
≥20% 337
Total 549

@Fyzyukk
Fyzyukk requested a review from a team November 15, 2026 06:42
@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 7979 --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.

@github-actions github-actions Bot changed the title Add opus mxfp4 bpreshuffle nt gemm [HIP] [CK] [OPUS] Add opus mxfp4 bpreshuffle nt gemm Nov 15, 2026
@aiter-bot

aiter-bot commented Nov 15, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 15b1a08c20f0 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gemm_a4w4.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@Fyzyukk
Fyzyukk force-pushed the fyz/opus_mxfp4_nt_gemm branch 5 times, most recently from 1be6485 to b9bd7da Compare November 15, 2026 13:37
…ackend

Add OPUS MXFP4 x MXFP4 NT GEMM kernels for gfx950 aiter.gemm_a4w4(bpreshuffle=True) inputs (A row-major
fp4x2, B shuffle_weight(16, 16), 1x32 UE8M0 e8m0_shuffle scales, bf16 C):
- 2x2 4-wave pipeline, 18 pre-compiled .co (tiles 128/192/256 x 128/192/256; persistent, one tile per
  block, split-K, no-boundary), registered in gen_co/co_kernels.json under gfx950 and rebuilt
  byte-identically by build_co.py --arch gfx950;
- 1x4 small-tile pipeline (M <= 512), JIT-built with stock ROCm, in-block K split for very small M.
Family a4w4 / gfx950 with local kids 0-5, 10-15, 21-25, 30 (.co) and 410-416 (small), launched through
opus_gemm / opus_bmm (family="a4w4", layout="bpreshuffle"); Python plans split-K and allocates Torch
workspaces. aiter.gemm_a4w4 dispatches tuned rows whose kernelName is the OPUS instance name
(kernelId = local kid), as the a8w8 / bf16 OPUS rows do. The a4w4 tuner gets an opus backend.
a4w4_blockscale_tuned_gemm.csv: 692 of 1464 gfx950 rows switch to OPUS kernels where they beat the best
asm / CK kernel in the same tuning run (MI355X); all other rows unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk and others added 5 commits November 16, 2026 02:10
…igned

get_GEMM_config reuses a row tuned at a padded M for every M that pads up to
it, so a row tuned with the no-bounds-check 256x256x256_nob kernel (needs
M % 256 == 0 and N % 256 == 0) is also returned for e.g. M=1664 via the
M=2048 row. _gemm_a4w4_opus launched it anyway and _a4w4_plan raised
ValueError, failing op_tests/test_gemm_a4w4.py (M=1664, N=8192, K=28672).
Switch to the same tile without _nob in that case (None -> CK/asm fallback
if no twin is registered).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…w4_bpreshuffle/

Gives the bpreshuffle family its own directory (and build_info.json) under
gen_co/gfx950/ instead of sharing the arch root. Files are moved unchanged;
build_co.py's default gfx950 output, the runtime loader and co_image_path
follow the new location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The JSON list key now matches the image directory (A4W4_CO_KEY, relative to
gen_co/), so co_image_path and build_co.py's default output derive from it.
The manifest test checks the arch part of "<arch>/<family>" keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the gfx950 a4w4 bpreshuffle entries out of the shared co_kernels.json
(back to its main content) into gen_co/co_kernels_gfx950_a4w4_bpreshuffle.json;
images stay in gen_co/gfx950/a4w4_bpreshuffle/ (A4W4_CO_DIR). Drops the
previous key rename and its manifest-test change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
opus_co_launch_mxfp4_gfx950.cuh becomes the family-agnostic
opus_co_launch_gfx950.cuh: the launcher passes its image directory under
gen_co/ (co_kernel(symbol, co_dir), cache keyed by co_dir/symbol) and calls
opus_co_launch_gfx950. Read / ELF check / launch logic unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 16, 2026
New a8w8_mxfp8 opus_gemm family: MXFP8 x MXFP8 with 1x32 UE8M0 scales (row-major
x_scale [M, K/32] / w_scale [N, K/32], not shuffled), B in shuffle_weight(16, 16),
bf16 output, in all four operand layouts (NT = gemm_a8w8_mxfp8_bpreshuffle's
inputs; NN: B stored [K, N]; TT: A stored [K, M]; TN: both).

- 2x2-wave pipeline (pre-compiled .co, pin toolchain): tiles 256/192/128 x
  256/192/128, one tile per block / persistent / split-K, M/N boundary
  handling; transposed operands go through LDS k-major and ds_read_tr8.
  Kids 0-16 (co_kernels_gfx950_a8w8_mxfp8_bpreshuffle.json), one image per
  layout in gen_co/gfx950/a8w8_mxfp8_bpreshuffle/.
- Split-K: fp32 partials summed by splitk_reduce_kernel.
- opus layer: _launch_a8w8_mxfp8_gemm picks the layout from the XQ / WQ
  strides (as the a16w16 4-wave family); A stored [K, M] needs M % 16 and B
  stored [K, N] needs N % 32.
- gemm_a8w8_mxfp8_bpreshuffle runs libtype "opus" rows of the tuned CSV (NT),
  falling back to FlyDSL when the tile does not fit; the tuner adds the OPUS
  kids as candidates. No tuned-CSV changes.

Shares the gfx950 pre-compiled .co infrastructure with the MXFP4 NT PR (ROCm#7979):
its code is included here, its kid table, .co images and tuned CSV are not
(they come with ROCm#7979).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk and others added 7 commits November 17, 2026 07:06
…y lookup

- test_gemm_a4w4: tuned_shapes()/baseline use _A4W4_PRESHUFFLE_PREFIXES so the
  OPUS rows run in CI; opus_a4w4_kid_sweep() launches every registered kid
  (off-grid M, forced split_k=2 on split-K and small-tile kids); add padded-M
  shapes that reach OPUS rows; assert only the tuned kernel (the default ASM
  baseline is wrong on some large-M shapes, e.g. M=6528 N=7040 K=5632).
- gemm_a4w4_blockscale_tune: opus_candidates returns {} for a CU count with no
  OPUS a4w4 table instead of aborting the default-backend tune.
- get_GEMM_config: document why OPUS rows also serve a padded M.
- a4w4 traits: the split-K counter block is zeroed by the launcher every launch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…impler dispatch

The a4w4 family now has two layouts; this PR is layout="bpreshuffle" and every
name it adds carries it, so it can coexist with layout="plain" kids.

- Naming: tags a4w4_mxfp4_nt_bpreshuffle_co / a4w4_mxfp4_nt_bpreshuffle_small,
  headers opus_gemm_{pipeline,traits}_a4w4_mxfp4_nt_bpreshuffle[_small]_gfx950.cuh,
  kargs / traits / kernel functions / OPUS_MXFP4_BPRESHUFFLE_* and the
  opus_gemm_common.py constants, .co symbols
  opus_gemm_gfx950_a4w4_mxfp4_nt_bpreshuffle_co_*, tuned CSV kernelNames.
  Kids are unchanged (0-30, 410-416).
- C++ entry opus_gemm_a4w4_bpreshuffle_launch (own e8m0_shuffle scale checks);
  opus_check_a8_family_tensors takes the A/B dtype.
- .co pipeline: 64-bit tile base offsets (batch strides long long, row / column
  offsets widened, host kargs too), buffer ranges bounded to one tile; a Y of
  > 2^31 elements no longer overflows (reachable through the padded-M lookup,
  e.g. M >= 262145, N = 6144, K = 16384 on the M = 8192 row). 18 .co rebuilt,
  kernarg 136 B.
- aiter/ops/opus/gemm_op_a4w4.py follows the a8w8 structure:
  _launch_a4w4_bpreshuffle_gemm / _bmm picked by dispatch, shape checks left to
  the C++ entry, split-K pick folded into _a4w4_bpreshuffle_plan.
- gemm_a4w4: OPUS rows match the "opus_" prefix; _gemm_a4w4_opus maps the
  name to its kid (nob -> bounded twin when M/N are not tile-aligned) and lets
  the C++ entry check shapes; kernelId is no longer threaded through.
- test_gemm_a4w4: > 2^31-element Y through kids 0, 10, 30.

All 692 OPUS rows pass, every kid passes the sweep (incl. split_k=2), and the
large-offset case passes; .co kids are within 0.3% of the previous build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ines

Big pipeline: own namespace (opus_mxfp4_bpreshuffle), constexpr cache policies,
ROW_PAIR / A_SPLIT_PAIR / B_SPLIT_PAIR, async_load_rows / async_load_blocks,
opus layouts for the e8m0_shuffle scale panels (make_layout_gsf / ssf / rsf),
one generic sched_quadrant (the hand-tuned 256x256 schedules are dropped),
mma_quadrant as a function, the odd K tile step with a compile-time stage, and
no split_k < 0 separate-reduce mode (aiter launches S > 0 only).
Small pipeline: g_a / g_b / g_sfa / g_sfb up front with out-of-range K tiles by
offset, wave-dim layouts, one LDS array with restrict read views, tiled MMA +
mma_step / sched_step, KS partials in the ring, nt C stores with an OOB offset;
B and the raw scale dwords stay in the register ring. kargs gain stride_b.
All 18 .co rebuilt; every .co / small / split-K kid gives bitwise the same C as
before (153 cases).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts with ROCm#6696 (gfx950 blockscale MXFP8 .co) and ROCm#6067 (ASM f4gemm _ps):
- opus_co_launch_gfx950.cuh: main's loader with an optional co_dir for
  co_kernel() and an optional kernarg size for opus_co_launch_gfx950 (the
  defaults keep the a8w8 blockscale bpreshuffle images); the a4w4 bpreshuffle
  launcher passes "<name>.co", gfx950/a4w4_bpreshuffle and 136.
- build_co.py: main's builder plus --family a4w4_bpreshuffle
  (build_one_a4w4_bpreshuffle, device-only clang++ on the pin toolchain); it
  rebuilds the 18 committed .co byte-identically.
- opus_gemm_common.py / gen_instances*.py: both families registered.
- a4w4_blockscale_tuned_gemm.csv: for each shape both sides retuned, the row
  with the lower us (121 OPUS, 267 main ASM).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk and others added 2 commits November 26, 2026 01:55
Conflict with ROCm#7883 (ASM a4w4 GEMMs exact past 4 GiB) in op_tests/test_gemm_a4w4.py main():
both sets of gfx950 checks run (main's ASM last-tile / 4 GiB checks, then the OPUS
large-offset check, kid sweep and fallback check).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…tion', no test failure)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
- a4w4_blockscale_tuned_gemm.csv: remove fallbackKernelName / fallbackSplitK
  columns (back to the 12-column schema); the 549 OPUS kernelName selections stay.
- gemm_op_a4w4.py: remove _a4w4_fallback_config / _log_a4w4_fallback; a declined
  preshuffle call now routes to the default ASM path instead of a CSV-recorded kernel.
- validate_tuned_csv.py: restored to origin/main (OPUS rows produce a harmless warning).
- test_gemm_a4w4.py: drop check_opus_fallback and the baseline fallback candidate.

gen_instances.py keeps the opus_ exclusion; its fallback block is now inert (the CSV
no longer has the column) so it is left untouched.

Co-Authored-By: Claude <[email protected]>
@Fyzyukk
Fyzyukk force-pushed the fyz/opus_mxfp4_nt_gemm branch from 12c8b3b to 20cc8f9 Compare November 27, 2026 09:48
Fyzyukk and others added 2 commits November 27, 2026 10:02
…line test

The previous commit removed _a4w4_fallback_config / _log_a4w4_fallback, the
triton_/flydsl_ padded-M fallback and the test's baseline candidate. Those are
upstream code from ROCm#7317 (the narrow-N CSV still carries the fallback columns),
not part of the OPUS change, so they are back exactly as on upstream/main.
OPUS rows have no fallback columns and still fall through to the default ASM path.

a4w4_blockscale_tuned_gemm.csv: two ASM rows (2048x16384x4096 and
32768x16384x53248) are back to upstream's rows; the diff against upstream is
now the 549 OPUS rows only.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@demonsan

Copy link
Copy Markdown
Contributor

Advisory review with the repo's .claude/skills/review-pr skill, run locally against head 6423b1b1e. All 8 gates passed and an independent reader refuted each finding before it was kept. [verified] means the finding was checked against the code; [inferred] means it is a question for the author to confirm.

Verdict: ⚠️ NEEDS WORK

  1. ⚠️ [inferred] aiter/ops/gemm_op_a4w4.py _gemm_a4w4_opus now sends 549 default tuned gfx950 shapes of gemm_a4w4 through the JIT-built module_deepgemm_opus and the .co images, while _opus_a4w4_kid raises ValueError and compile errors propagate instead of falling back to the previous CK/ASM kernel and the only switch is replacing the CSV — worth checking whether a missing .co or failed JIT build now breaks every MXFP4 caller of those shapes. Author must add a fallback to the prior kernel or an env gate for the opus_ rows.
  2. ⚠️ [inferred] aiter/ops/gemm_op_a4w4.py get_GEMM_config (head lines 143-146) keeps exact-M qualification for triton_/flydsl_ rows ("New backends are qualified at exact M") but omits opus_, so a row tuned at M=4 (kid 415) also serves M=3 and the PR's timings exist only at the tuned M — worth checking whether padded-M calls still beat the old CK/ASM choice. Author must add opus_ to that tuple or report base-vs-head timing for the padded-M shapes it adds to op_tests/test_gemm_a4w4.py, for example (3, 512, 4096) and (97, 51200, 5120).
  3. ⚠️ [verified] The PR body speedup table (219+102+53+34+284) sums to 692 while the body says OPUS is selected for 549 shapes, aiter/configs/a4w4_blockscale_tuned_gemm.csv holds 549 opus_ rows, and its base-vs-head us columns give 337 rows at ≥20% instead of 284, so the headline number is untraceable (the body also says small-tile is for M <= 512 while three CSV rows use it at M=1024). Author must regenerate the table from the CSV with the baseline command and hardware stated.

Size / design: SPLIT — (1) pre-compiled 2x2 .co kids with build_co.py and the JSON/build_info; (2) JIT small-tile 1x4 pipeline and traits; (3) opus_gemm launcher, pybind and aiter/ops/opus/gemm_op_a4w4.py with dispatch.py; (4) gemm_a4w4 routing, the 549-row CSV retune and the tuner opus backend as the last stacked layer

@Fyzyukk

Fyzyukk commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author
  1. The opus_ rows follow the same policy as the existing triton_/flydsl_ rows in _gemm_a4w4_preshuffle: a call the kernel cannot serve returns None and goes through _a4w4_fallback_config to the default ASM path; compile and kernel errors propagate, as that function's docstring already states for the other backends. The CK/ASM path depends on a JIT-built module and .co files under hsa/ in the same way, so a broken build is not specific to the OPUS rows.

  2. Serving padded M is intentional: a nob tile switches to its bounded twin when M or N is not a whole tile. Back-to-back device time (run_perftest, MI355X, upstream/main selection → this PR) for the four padded-M shapes added to op_tests/test_gemm_a4w4.py: (3, 512, 4096) 5.79 → 4.97 us; (65, 32768, 512) 6.17 → 6.21 us; (97, 51200, 5120) 33.81 → 26.79 us; (129, 32768, 512) 8.64 → 9.16 us.

  3. The table was stale. Regenerated from the us columns of this PR's CSV and upstream/main's CSV (549 OPUS rows, 337 at ≥20%), with hardware and the tuner command stated. Also corrected the small-tile range to M <= 1024.

@demonsan

demonsan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 16 review(s); expect to start in about 4.6 h. The box reviews one PR at a time.

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the runner environment (gh, token, git), not with this PR.

fetch produced no WORK dir -- check gh auth/token, network, git and disk on the runner

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

@yzhou103

yzhou103 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

ci green.

)
for split_k in splits:
y = torch.empty((M, N), dtype=dtype)
opus_gemm(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch>1 opus_bmm and the _nob switch have no test, please add a batch=2 case with 3d scales and one padded-M call that lands on a _nob row

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • check_opus_bmm: every a4w4 kid through opus_bmm with 3D [B, rows, K/32] scales and different data per batch. It runs at B=2/3/4, on whole tiles (256×256) and on partial tiles (300×272, skipped for the nob kid). The small-tile kids also run split_k=2. 189/189 pass on gfx950.
  • check_opus_nob_padded_m: M=2047 pads up to the tuned 2048 _nob row. It asserts that the bounded twin runs instead of the nob kid and checks the result against torch. Passes.

Fyzyukk and others added 2 commits December 3, 2026 03:19
…ob switch

check_opus_bmm_batch2: every a4w4 kid through opus_bmm at batch 2 with 3D
[B, rows, K/32] scales (small-tile kids also at split_k=2).
check_opus_nob_padded_m: M=2047 pads up to the tuned 2048 _nob row; assert
gemm_a4w4 launches the bounded twin and matches the reference.

Co-Authored-By: Claude <[email protected]>
@Fyzyukk
Fyzyukk requested a review from valar-cop December 3, 2026 03:30
@demonsan

demonsan commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the runner environment (gh, token, git), not with this PR.

fetch produced no WORK dir -- check gh auth/token, network, git and disk on the runner

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

zufayu added a commit that referenced this pull request Dec 4, 2026
…runcated watchdog read, size the agent timeouts for the 4-lane pool (#9201)

* [CI] review-bot: read WORK out of a binary fetch log, retry a stalled watchdog read, size the agent timeouts for the 4-lane pool

Three failure modes from the 2026-12-04 outage (6 failed runs, 01:24-03:02):

- run_one.sh extracted WORK= from the tee'd fetch log with a bare grep, so a PR
  with binary artifacts (OPUS .co blobs put NULs in that log) made grep answer
  "binary file matches" instead of the match -- a fetch that SUCCEEDED was
  reported as "fetch produced no WORK dir" on every retry (#8283/#7979/#7983).
  grep -a reads the log as text.

- watchdog.py caught only HTTPError, so a 30s socket timeout crashed the
  watchdog with a bare TimeoutError and failed a run whose review had already
  published a green card (#9178). A stalled GET is now retried (3 attempts,
  5s backoff); a POST is never retried, because a retried comment can land
  twice, and a failed POST degrades to 0, which the caller already warns about.

- AITER_AGENT_TIMEOUT=2400s was sized for one review at a time; the 4-lane
  pool serves four through the same GLM endpoint and workers measured 25-40+
  min under that load, so 2400s timed out live while the backend answered
  normally (#8983/#8541). Defaults now 3300s/agent and 6900s/run (115 min,
  still under the job's timeout-minutes of 120; check_prompts.py asserts it).

watchdog_test.py gains real-socket transport checks (the retry lives below the
_get/_post seam its fakes replace) with a mutation guard; _fetchfail_test.sh
gains the binary-log case. selftest: 156 green / 0 red.

Co-Authored-By: Claude Code <[email protected]>

* watchdog: retry a truncated response body, not just a stalled read

A response that dies mid-body raises http.client.IncompleteRead -- an
HTTPException, not an OSError -- so the OSError-only retry net added for
the 2026-12-04 stall let it escape unretried and unnamed: the same
bare-traceback crash one layer up, and _post's RuntimeError guard could
not degrade it either. Name the family in the catch so a truncated GET is
retried like a stalled one and a truncated POST degrades to 0.

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>
@zufayu

zufayu commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 3 review(s); expect to start in about 39 min. The box reviews up to 4 PRs at a time.

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #7979 — [HIP] [CK] [OPUS] Add opus mxfp4 bpreshuffle nt gemm

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled on this runner (REVIEW_AUTO_VALIDATE=0) and no gfx950 GPU present (8× MI300X gfx942, all busy); target op_tests/test_gemm_a4w4.py, correctness and perf triage both REQUIRED — environment gap, not a PR defect
Perf (advisory): NOT RUN — no gfx950 GPU on this box (8× gfx942, all at 97–98% use); the PR's own evidence is the retuned CSV's us columns vs upstream/main's (recomputed here: 71/59/42/40/337 over 549 rows, min +0.1%, no negative row) plus the author's four back-to-back padded-M timings on MI355X
Size: 5255 lines / 41 files — over the review bar
Design (advisory): SPLIT — (1) pre-compiled 2x2 .co kids + build_co a4w4 family + images; (2) JIT 1x4 small-tile pipeline; (3) host launch chain (launchers, checked C++ entry, pybind, registry, co loader); (4) aiter routing + tuner opus backend + the 549-row CSV retune as the last stacked layer
Human: recommend valar-cop review whether switching 549 default gfx950 gemm_a4w4 shapes to OPUS with no env gate, and the .co split-K reduction's relaxed-atomic synchronization, are the right contract for this op

⚠️ [verified] aiter/ops/gemm_op_a4w4.py:37 keeps a4w4_fallback_config's guard at ("triton", "flydsl_") although this PR adds opus_ as a third preshuffle backend that the guard exists to keep out of the fallback column — a future tuner row writing fallbackKernelName=opus_… would pass the guard and reach gemm_a4w4_blockscale (the CK/ASM entry) with a kernel name it cannot serve. Author must add "opus_" to the guard tuple.

def _log_a4w4_fallback(m, n, k, dtype, selected, fallback):

📝 [verified] The PR description still says "1x4 small-tile pipeline: JIT-built for M <= 512" while three tuned rows in aiter/configs/a4w4_blockscale_tuned_gemm.csv select small-tile kids at M=1024 ((1024,512,4096) and (1024,512,7168) on kid 410, (1024,800,5120) on kid 412), and the author's Nov 30 comment claims the range was corrected to M <= 1024 — the correction never landed in the body. Author must fix the description line.

📝 [verified] The author's own back-to-back padded-M timings (Nov 30 PR comment, MI355X) show two of the four padded-M shapes added to op_tests/test_gemm_a4w4.py slower at head — (65,32768,512) 6.17→6.21 µs and (129,32768,512) 8.64→9.16 µs (+6%) — so the padded-M dispatch buys the 549-row win at a small cost on those rows. Reviewer should ask whether those two rows should keep the previous kernel via the exact-M qualification the triton_/flydsl_ rows already have.

1 finding(s) posted inline, on the lines they are about:

  • csrc/opus_gemm/include/gfx950/opus_gemm_pipeline_a4w4_mxfp4_nt_bpreshuffle_gfx950.cuh:985-997 — The .co split-K reduction in…

Comment on lines +985 to +997
// No agent-scope fences (on gfx950 they write back / invalidate the whole L2): the partials use system-coherent
// stores / loads that bypass the non-coherent L2, so vmcnt(0) before the relaxed device-scope counter is enough.
s_waitcnt_vmcnt(0_I);
sync_threads();
if (thread_id_x() == 0) {
const int arrived = __scoped_atomic_fetch_add(&counters[tile_id], 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE);
const int last = arrived == split_k - 1;
if (last) __scoped_atomic_store_n(&counters[tile_id], 0, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE);
*sk_last_p = last;
}
s_waitcnt_lgkmcnt(0_I);
sync_threads();
if (!*sk_last_p) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [inferred] The .co split-K reduction in csrc/opus_gemm/include/gfx950/opus_gemm_pipeline_a4w4_mxfp4_nt_bpreshuffle_gfx950.cuh:985-997 orders the cross-block partial reduction with a RELAXED device-scope atomic and no fence, where the family's existing gfx950 split-K (opus_gemm_pipeline_a8w8_mxscale_flatmm_splitk_gfx950.cuh:2558) uses an agent-scope release fence plus an ACQ_REL atomic — if the relaxed counter does not order the system-coherent partial loads, a reducing block reads stale partials and silently corrupts that tile's output. Author must cite the ISA/memory-model basis (or a stress validation) proving the relaxed counter orders the partial loads.

@demonsan

demonsan commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Shape-coverage check of this PR's kernel selection at head 15b1a08c2. I ran a CPU-only sweep that drives the public entry points with meta tensors up to the raw launch (the launch is intercepted). For every case it checks the selected kid against its own Python predicate and against a Python mirror of the generated C++ launcher checks. The grid covers odd and edge M/N/K (1, 7, 15, 17, 127, 129, 1025, 65537, ...), every layout, zero sizes, and >4 GiB / >INT32 sizes. Numerical correctness of in-kernel tail handling needs a GPU and is not claimed here.

Routing coverage:

  • All 549 tuned rows (plus 880 padded-M reuses) select a valid OPUS kid on 256 CUs.
  • There is no OPUS heuristic for untuned shapes; they go to CK / ASM. The CSV has only cu_num=256 rows, so on 128 CUs every shape goes to ASM.
  • Several partial-N shapes therefore land on the ASM f4gemm kernels, e.g. (1, 16, 256), or (3, 8192, 7168) on 128 CUs. [ASM] [Bugfix] a4w4: skip f4gemm kernels wrong at a partial N tile (full_n_tile table flag) #8847 found ASM kernels there that are wrong when N % tile_N != 0. Please make sure such shapes avoid them, or add an OPUS untuned path.

Gaps:

  1. The tuned splitK is ignored. (4, 48, 768) with splitK=2 launches with split=1 (gemm_op_a4w4.py:392).
  2. Exact-M qualification (get_GEMM_config, :143) covers triton_ / flydsl_ rows but not opus_. A row tuned at M=4 also serves M=3.
  3. Multi-GPU: get_gfx() / get_cu_num() use device 0, not A.device (:381, :580).
  4. K == 0 raises ZeroDivisionError, e.g. (1, 16, 0) (:530). Also, _a4w4_fallback_config accepts opus_* names (:29), and opus_candidates accepts M=0 (gemm_a4w4_blockscale_tune.py:129).
  5. A wrong-K B (A:[1,2048], B:[512,128]) bypasses the Python decline and is caught only by the C++ check (gemm_op_a4w4.py:362, opus_gemm.cu:538).
  6. Shared small-tile split-K int32 overflow above 4 GiB: (32768, 16384, 512) with S=2 (splitk_reduce_gfx950.cuh:135-152).

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants