Skip to content

[CI] [Bugfix] Fix A4W4 mutation schemas under torch.compile - #8474

Open
zufayu wants to merge 4 commits into
ROCm:mainfrom
zufayu:codex/fix-2780-a4w4-mutation-schema
Open

zufayu wants to merge 4 commits into
ROCm:mainfrom
zufayu:codex/fix-2780-a4w4-mutation-schema

Conversation

@zufayu

@zufayu zufayu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Declare the allocating A4W4 GEMM entry points as read-only custom ops so torch.compile does not functionalize inputs they never mutate.

Motivation

torch_compile_guard defaults to mutates_args="unknown". For gemm_a4w4, that marks every tensor input as writable, inserts auto_functionalized_v2, and can fail Inductor post-grad lowering with AssertionError: auto_functionalized_v2 was not removed.

Fixes #2780.

Changes

  • Pass mutates_args=[] for gemm_a4w4 and gemm_a4w4o8; both allocate their outputs and leave inputs unchanged.
  • Add op_tests/test_gemm_a4w4_compile.py: a schema test (runs anywhere, no GPU needed) asserting both ops declare no written arguments, plus torch.compile+Inductor end-to-end tests for each op, gated to the GPU each one actually runs on (gfx950 for gemm_a4w4, gfx1250 for gemm_a4w4o8).
  • Route the new test file through .github/scripts/aiter_test.sh's pytest-collection list.

Testing

  • Unit tests added or updated — op_tests/test_gemm_a4w4_compile.py (see above)
  • Performance benchmarks run (not applicable; schema-only change)
  • Tested on MI250X (op unsupported)
  • Tested on MI300X (op unsupported)
  • git diff --check — passed

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed; this corrects an operator schema contract.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. The new schema matches the existing implementation: neither allocating op mutates its inputs.

PR Self-Review

Reviewed revision

fc069db11d (re-adds the op_tests/test_gemm_a4w4_compile.py regression test and its .github/scripts/aiter_test.sh pytest routing, and adds an equivalent gemm_a4w4o8 compile test).

Behavior and intent

The only runtime contract change is removal of false input mutation aliases from the two allocating A4W4 operators. Eager dispatch, argument values, output allocation, and kernel selection are unchanged. The existing schema is insufficient because mutates_args="unknown" tells PyTorch that every tensor input is written in place, even though these functions only allocate and return new outputs; Inductor then inserts an unnecessary auto_functionalized_v2 node and can fail to remove it.

Validation and unverified scope

The local machine has neither PyTorch nor a ROCm GPU with the right arch, so none of the new tests were exercised locally against real kernels:

  • test_allocating_a4w4_ops_have_read_only_schemas is schema-only (no GPU needed); per aiter-bot's automated review on an earlier revision, hand-run on CPU: 2 failures on the pre-fix revision, 2 passes on this revision (I don't have a working aiter build locally to re-run it myself).
  • test_gemm_a4w4_compiles_with_inductor (gemm_a4w4, gfx950) and test_gemm_a4w4o8_compiles_with_inductor (gemm_a4w4o8, gfx1250) are both skipped outside their target arch, so neither has run anywhere yet; they're gated to run on the PR's MI35X CI runner (gfx950) and, if a gfx1250 runner is in scope for this file, there respectively.
  • The gemm_a4w4 inductor case compiles a bare function (backend="inductor", fullgraph=True), while issue [Issue]: torch_compile_guard defaults to mutates_args="unknown", causing torch.compile crash for gemm_a4w4 #2780's original reproducer compiled a residual-add block under mode="max-autotune-no-cudagraphs"; I can't confirm from here whether this simpler graph reproduces the original auto_functionalized_v2 assertion on the pre-fix revision, or whether Inductor elides it for a graph this small. The schema test is the regression guard I can vouch for; treat the inductor cases as best-effort end-to-end confirmation, not as confirmed repros of the original crash.
  • No performance change is expected because no kernel or dispatch code changed; performance was not benchmarked.

Follow-up (not in this PR)

aiter/ops/quant.py's per_token_quant_hip and per_group_quant_hip are allocating, non-mutating ops still on torch_compile_guard's default mutates_args="unknown", so they can hit the same auto_functionalized_v2 class of failure under torch.compile. Not fixed here; will open a follow-up to sweep remaining default-guard sites.

CI and permissions

This revision touches no workflow, CI script routing logic, runner label, token permission, or secret (only adds one filename to an existing pytest-routing list).

@zufayu
zufayu requested a review from a team November 23, 2026 05:00
@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 8474 --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 Fix A4W4 mutation schemas under torch.compile [CI] Fix A4W4 mutation schemas under torch.compile Nov 23, 2026
@github-actions github-actions Bot added the CI label Nov 23, 2026
@aiter-bot

aiter-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision fc069db11d56 · 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. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  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 ### 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 — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gemm_a4w4_compile.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.

@zufayu zufayu changed the title [CI] Fix A4W4 mutation schemas under torch.compile [CI] [JIT] [Bugfix] Fix A4W4 mutation schemas under torch.compile Nov 23, 2026
@zufayu
zufayu requested a review from demonsan November 24, 2026 01:15
@github-actions github-actions Bot changed the title [CI] [JIT] [Bugfix] Fix A4W4 mutation schemas under torch.compile [Bugfix] Fix A4W4 mutation schemas under torch.compile Nov 27, 2026
@github-actions github-actions Bot removed the CI label Nov 27, 2026
@zufayu
zufayu requested review from dbyoung18 and junhaha666 and removed request for dbyoung18 November 27, 2026 08:45
junhaha666
junhaha666 previously approved these changes Nov 27, 2026
@demonsan

Copy link
Copy Markdown
Contributor

Advisory review with the repo's .claude/skills/review-pr skill, run locally against head 85fe4deef. 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. ⚠️ [verified] aiter/ops/gemm_op_a4w4.py:438,837 changes the torch.compile operator schemas for gemm_a4w4 and gemm_a4w4o8 with no test target added, while the PR Testing section claims existing A4W4 op tests cover it — neither op_tests/test_gemm_a4w4.py nor op_tests/test_f4gemm.py calls torch.compile or inspects torch.ops.aiter schemas (and MI35X CI skips gfx1250-only gemm_a4w4o8), leaving the auto_functionalized_v2 fix and read-only schemas unverified and unguarded against regression in CI. Author must add a test asserting non-mutating schemas on torch.ops.aiter.gemm_a4w4 and torch.ops.aiter.gemm_a4w4o8 plus a torch.compile(backend="inductor", fullgraph=True) case for gemm_a4w4.

zufayu and others added 3 commits December 1, 2026 06:34
Keep the schema fix only; remove op_tests/test_gemm_a4w4_compile.py and
revert the aiter_test.sh pytest routing it required.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Re-adds test_gemm_a4w4_compile.py (dropped in 85fe4de) per review
feedback: op_tests/test_gemm_a4w4.py and test_f4gemm.py never exercise
torch.compile or inspect the aiter schema, so the mutates_args fix in
this PR had no CI guard against the regression it addresses.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@zufayu
zufayu force-pushed the codex/fix-2780-a4w4-mutation-schema branch from 85fe4de to 1251748 Compare December 1, 2026 08:06
@github-actions github-actions Bot changed the title [Bugfix] Fix A4W4 mutation schemas under torch.compile [CI] [Bugfix] Fix A4W4 mutation schemas under torch.compile Dec 1, 2026
@github-actions github-actions Bot added the CI label Dec 1, 2026
@demonsan

demonsan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 7 review(s); expect to start in about 2.0 h. The box reviews one PR 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 #8474 — [CI] [Bugfix] Fix A4W4 mutation schemas under torch.compile

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — target op_tests/test_gemm_a4w4_compile.py existed, but auto-validation was disabled (REVIEW_AUTO_VALIDATE=0) and this box has no ROCm GPU (torch 2.15.0+cpu); the schema half was hand-run on CPU as advisory evidence (fails on base, passes on head)
Perf (advisory): NOT RUN — target op_tests/test_gemm_a4w4_compile.py exposes no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the diff changes no kernel or dispatch code, so no latency delta is expected
Size: 61 lines / 3 files
Design (advisory): declare the two allocating A4W4 entry points read-only (mutates_args=[] on gemm_a4w4/gemm_a4w4o8) rather than changing the torch_compile_guard default for every guarded op
Human: recommend yifehuan-amd review whether declaring gemm_a4w4/gemm_a4w4o8 read-only under torch.compile matches how ATOM and other downstream consumers call them on gfx950/gfx1250, and whether the remaining allocating ops still on the default mutates_args="unknown" (per_token_quant_hip, per_group_quant_hip) should be swept in a follow-up to PR #8474

⚠️ [verified] The PR description describes a stale revision: its Testing section says "Unit tests added or updated (none; schema-only change, covered by the existing A4W4 op tests)" and its Reviewed-revision paragraph says the test and its CI routing "were dropped; only the operator schema change remains", but head 1251748 re-adds op_tests/test_gemm_a4w4_compile.py (55 lines) and the .github/scripts/aiter_test.sh pytest routing, and that test does guard the fix (hand-run on CPU: 2 failed on base, 2 passed on head) — so a reviewer reading the description believes the regression is unguarded in CI when it is guarded, and the self-review gate stays red. Author must refresh the Testing and PR Self-Review sections for head 1251748.

📝 [verified] The inductor compile case is gated _GFX != "gfx950" (op_tests/test_gemm_a4w4_compile.py:73) while gemm_a4w4o8 is gfx1250-only (aiter/ops/gemm_op_a4w4.py:846) and the gfx1250 CI jobs run only the opt-in Triton suite — so the second fixed op is never compiled end-to-end on any runner and only its schema is asserted. Reviewer should ask whether a gfx1250-gated compile case for gemm_a4w4o8 is planned.

📝 [inferred] The e2e case may not reproduce the base crash it targets: issue #2780's reproducer compiles a residual-add Block under mode="max-autotune-no-cudagraphs", while the test compiles a bare function under backend="inductor", fullgraph=True, and Inductor may remove auto_functionalized_v2 cleanly for so simple a graph — leaving the schema assertion (which does fail on base) as the only guard that catches the regression. Author must confirm the inductor case fails on the base revision, or state on the PR that the schema test is the intended regression guard.

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

  • aiter/ops/gemm_op_a4w4.py:438 — The bare @torch_compile_guard() default this PR removes from gemm_a4w4/gemm_a4w4o8…

Comment thread aiter/ops/gemm_op_a4w4.py Resolved
aiter-bot review on this PR flagged that gemm_a4w4o8 (the gfx1250-only
mxfp8-output entry point also fixed by this PR) was never compiled
end-to-end on any runner, since gfx1250 CI only runs the opt-in Triton
suite. Add a compile test for it mirroring the existing gemm_a4w4 case,
gated to gfx1250 so it only runs where the op is actually supported.
@zufayu

zufayu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressing aiter-bot's review:

  1. Stale PR description — fixed in fc069db1's accompanying description update: Testing/Self-Review now correctly reflect that op_tests/test_gemm_a4w4_compile.py is present (it was never actually dropped from this revision, the description just hadn't caught up).

  2. gemm_a4w4o8 never compiled end-to-end on any runner — added test_gemm_a4w4o8_compiles_with_inductor in fc069db1, mirroring the existing gemm_a4w4 compile test but gated to gfx1250. I don't have a gfx1250 box to run it on, so I can't confirm it passes — if this repo's gfx1250 CI lane only runs the opt-in Triton suite, this test still won't execute by default; let me know if it needs wiring into that lane instead, or if a gfx1250 runner can pick it up as-is.

  3. Inductor repro fidelity — can't fully confirm from here. The schema test (test_allocating_a4w4_ops_have_read_only_schemas) is the regression guard I can vouch for; it's schema-only and doesn't need a GPU. The torch.compile end-to-end cases compile a bare function rather than issue [Issue]: torch_compile_guard defaults to mutates_args="unknown", causing torch.compile crash for gemm_a4w4 #2780's original residual-add block under max-autotune-no-cudagraphs, so I can't rule out that Inductor elides auto_functionalized_v2 cleanly for this simpler graph even pre-fix. Treating these as best-effort confirmation rather than a proven repro of the original crash — called out explicitly in the PR description now.

Also replied inline on the quant.py follow-up question.

@zufayu

zufayu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@demonsan — this is ready for review when you have a moment: CI is green, the two aiter-bot review threads are addressed (stale description fixed, added a gemm_a4w4o8 compile test, replied on the quant.py follow-up question), and the one open thread is resolved. Let me know if anything else is needed.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: torch_compile_guard defaults to mutates_args="unknown", causing torch.compile crash for gemm_a4w4

4 participants