Skip to content

[ASM] [RFC #7240] Drop the output buffer from six routed contracts - #8291

Merged
fangche123 merged 4 commits into
mainfrom
opus/aklr-drop-out-buffers
Nov 20, 2026
Merged

fangche123 merged 4 commits into
mainfrom
opus/aklr-drop-out-buffers

Conversation

@zufayu

@zufayu zufayu commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Six routed contracts took an optional output buffer and returned it. That shape cannot be registered as a custom op, so those six split a caller's graph the day a provider is enabled. This removes the buffer from the contract -- not from the public API -- and registers them.

_NOT_REGISTERED goes from 24 entries to 18; registered routed ops from 10 to 16.

Why the buffer blocks registration

Registered, an op that returns a buffer it was handed is an op returning one of its own arguments, while the schema it registers under declares that results do not alias inputs. opcheck rejects it, and under compile both ways of resolving the contradiction are wrong. The silent one is what matters: a fake that allocates leaves the caller's buffer unwritten while still returning the right value -- no error, stale buffer, nothing says so.

def native(x: Tensor, out_: Tensor | None = None) -> Tensor:
    out = out_ if out_ is not None else torch.empty_like(x)
    out.copy_(x * 2)
    return out                      # returns its own argument when out_ is given

infer_schema          -> (Tensor(a0!) x, Tensor(a1!)? out_=None) -> Tensor   # passes
opcheck(op, (x,))     -> passes                                              # no buffer, no aliasing
opcheck(op, (x, buf)) -> Argument out_ is not defined to alias output but was aliasing

Note the middle line: opcheck is silent unless the buffer is passed. A check that only exercises the default path reports success on exactly the call that fails.

What changes

Each public spelling keeps its buffer argument and its signature. Naming a buffer bypasses routing and runs AITER's own kernel -- which is what naming it asked for. The routed contract carries no buffer and allocates, so a provider serves the allocating form only. This is the shape #7875 established; nothing here is new design.

op version
gemm_a8w8_blockscale_bpreshuffle 1 → 2
mla_sparse_prefill 1 → 2
mla_sparse_prefill_v41 2 → 3
inverse_rope_group_quant 1 → 2
pa_decode_bf16 1 → 2
pa_fwd 1 → 2

Each declares the older version in supersedes=. The only change is removing an optional buffer, so a provider built for the older shape sees None and allocates -- which is the newer semantics exactly. (rmsnorm v1 was left out of its own supersedes for the opposite reason: a v1 kernel handed a v2 call writes the caller's input.)

No caller in this repository passes any of these buffers except pa_fwd, so for the first five the change is internal forwarding rather than an API move.

pa_fwd

pa_fwd is the one with callers that do pass out_ -- five sites, all in op_tests. After the change those keep working and keep running AITER's kernel, but they stop exercising the routed path, so the coverage has to be put back deliberately rather than assumed. It carries its own regression tests here (+126 lines in tests/test_plugin_routed_ops.py):

  • both public spellings route. pa_fwd_asm looks like a backend pin and is not -- it predates the neutral name, so an ordinary call through it routes. Only kernelName pins a kernel, and only that bypasses on its own.
  • out_ bypasses from either spelling.
  • the buffered form returns the caller's buffer, asserted on data_ptr rather than on value: a fake that allocates returns the right numbers into the wrong allocation, and only the pointer tells those apart.

pa_fwd takes mutates_args=[], unlike pa_decode_bf16 in this same PR, and the code says why: dropping out leaves pa_fwd with nothing it writes through, while pa_decode_bf16 still hands split_o, split_lse and work_info to the asm binding as split-KV scratch.

Testing

  • tests/test_plugin_contracts.py, tests/test_plugin_routed_ops.py, op_tests/test_mla_sparse_prefill_v41_asm.py -- 116 passed
  • All six appear in torch.ops.aiter_routed after a real import aiter, so they register rather than silently staying traced
  • gemm_a8w8_blockscale_bpreshuffle and inverse_rope_group_quant on gfx942: opcheck(..., test_utils=("test_faketensor",)) passes, and the public spelling with a buffer returns the same data_ptr -- the bypass is exercised, not just assumed
  • black, ruff clean

After the review round, on gfx942:

pytest tests/test_plugin_contracts.py tests/test_plugin_routed_ops.py \
       op_tests/test_mla_sparse_prefill_v41_asm.py \
       op_tests/test_gemm_host_dispatch_cache.py
  -> 137 passed, 145 skipped

torch.ops.aiter exposes the same three names as an unpatched main tree, so
the registration the guard move had dropped is back; four of the five routed
schemas now read (Tensor XQ, ...) rather than (Tensor(a0!) XQ, ...), and
pa_decode_bf16 keeps the conservative default with its reason in the code.

Unverified

The remaining four are arch-gated here: mla_sparse_prefill, mla_sparse_prefill_v41, pa_decode_bf16 and pa_fwd cannot reach a kernel on gfx942 (op_tests/test_mla_sparse_prefill.py is 38 skipped; op_tests/test_pa_decode_bf16_asm.py exits on anything but gfx1250). What this PR changes about them is the dispatch branch and the fake -- both pure Python -- so both were verified by stubbing the native layer:

pa_decode_bf16          out=None -> native receives out=None (through the registered op)
                        out=buf  -> native receives that same buffer (bypass)
                        fake     -> (2, 8, 64) bf16
mla_sparse_prefill      same three
mla_sparse_prefill_v41  routed form passes out=None to the opus path; fake -> (8, 16, 512) bf16

What remains unverified is only that their kernels still produce the same numbers -- and no kernel body is touched here; only the forwarding moved. A run on gfx950/gfx1250 would close that last step.

opcheck's test_schema is not usable for the fp8 ops here: it performs arithmetic on inputs to detect mutation, and mul_cuda is not implemented for Float8_e4m3fnuz. test_faketensor -- which is what checks the fake against the real output -- does run.

Test update included

op_tests/test_mla_sparse_prefill_v41_asm.py::test_provider_path_preserves_v2_contract pinned both the version and the v2 argument count. It is renamed to ..._v3_contract and now asserts version == 3, the contract arg tuple without the out slot, and len(bound) == 13. The test was doing its job; a contract bump is supposed to break it.

Documentation

  • The reasoning lives next to each change: why the buffer bypasses routing, and why the older version stays acceptable.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None to callers: every public signature is unchanged, and a call that passes a buffer behaves exactly as before. Providers implementing the older versions keep being offered these calls, by supersedes=.

PR Self-Review

Reviewed revision

d3d0e37c7a

Behavior and intent

Six routed contracts took an optional output buffer and returned it, which cannot be registered as a torch custom op: the schema declares that results do not alias inputs, so opcheck rejects the shape, and under compile a fake that allocates leaves the caller's buffer unwritten while still returning the right value. Unregistered, those six stay traced Python inside a caller's graph and split it the day a provider is enabled -- which is the point of RFC #7240.

The existing behaviour is insufficient only in that one respect: the kernels are correct, and nothing is wrong today with no provider installed. What changes is that the routed contract no longer carries the buffer, so the op registers. Every public spelling keeps its signature; naming a buffer now bypasses routing and runs AITER's own kernel, which is what naming it asked for. _NOT_REGISTERED goes 24 -> 18.

Validation and unverified scope

Ran on this branch, gfx942 (MI300X), ROCm/torch from the container image:

pytest tests/test_plugin_contracts.py tests/test_plugin_routed_ops.py \
       op_tests/test_mla_sparse_prefill_v41_asm.py
  -> 116 passed, 129 skipped
black --check / ruff check on the changed files -> clean

Registration is real rather than inferred from the AST gate: after import aiter, all six appear under torch.ops.aiter_routed.

After folding pa_fwd in, on the same machine:

pytest tests/test_plugin.py tests/test_plugin_routed_ops.py \
       tests/test_plugin_contracts.py tests/test_ar_rmsnorm_routing.py \
       op_tests/test_mla_sparse_prefill_v41_asm.py \
       op_tests/test_gemm_host_dispatch_cache.py
  -> 301 passed, 145 skipped

On GPU, two of the five were exercised end to end:

opcheck(torch.ops.aiter_routed.gemm_a8w8_blockscale_bpreshuffle, ..., test_utils=("test_faketensor",))  pass
opcheck(torch.ops.aiter_routed.inverse_rope_group_quant,         ..., test_utils=("test_faketensor",))  pass
public spelling with a buffer -> returned tensor has the same data_ptr as the buffer (bypass confirmed)

The remaining four are arch-gated here: mla_sparse_prefill, mla_sparse_prefill_v41, pa_decode_bf16 and pa_fwd cannot reach a kernel on gfx942 (op_tests/test_mla_sparse_prefill.py is 38 skipped; op_tests/test_pa_decode_bf16_asm.py exits on anything but gfx1250). What this PR changes about them is the dispatch branch and the fake -- both pure Python -- so both were verified by stubbing the native layer:

pa_decode_bf16          out=None -> native receives out=None (through the registered op)
                        out=buf  -> native receives that same buffer (bypass)
                        fake     -> (2, 8, 64) bf16
mla_sparse_prefill      same three
mla_sparse_prefill_v41  routed form passes out=None to the opus path; fake -> (8, 16, 512) bf16

What remains unverified is only that their kernels still produce the same numbers -- and no kernel body is touched here; only the forwarding moved. A run on gfx950/gfx1250 would close that last step.

opcheck's test_schema is not usable for the fp8 ops here: it performs arithmetic on inputs to detect mutation, and mul_cuda is not implemented for Float8_e4m3fnuz. test_faketensor, which checks the fake against the real output, does run.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

No tuned-configuration file changes in this PR; no workload key consumes anything new. The only "configuration" that moves is the contract version recorded in tests/plugin_contracts.json, whose consumer is a plugin provider, not a shape-keyed tuning table. Backend selection is untouched: each public spelling forwards the same arguments to the same native path it did before, and the added branch only chooses between the registered contract (no buffer) and that native path (buffer). Evidence that unrelated shapes keep their previous selection is that no selection code was edited -- the diff in aiter/ops/* is a rename plus a dispatcher, with the kernel-choosing bodies moved verbatim.

Changed op tests

op_tests/test_mla_sparse_prefill_v41_asm.py -- test_provider_path_preserves_v2_contract pinned both the op version and the v2 argument count of what a provider is handed. Bumping mla_sparse_prefill_v41 to v3 and dropping the buffer necessarily breaks both assertions, so the test is renamed ..._v3_contract and now asserts version == 3, the argument tuple without the out slot, and len(bound) == 13.

op_tests/test_gemm_host_dispatch_cache.py -- it patched op._eager_body to intercept the nested gemm_a8w8_blockscale -> ..._bpreshuffle call. That call now targets the native body directly, because with no buffer named the public spelling routes, and a provider serving it there would be a second dispatch of the op the caller is already inside. The patch target moves to gemm_op_a8w8._gemm_a8w8_blockscale_bpreshuffle_native in both places. It is not redundant with the plugin tests: those check that the contract registers, this one checks that the host-side dispatch caches still answer identically, and its _eager_body.__name__ assertion is kept deliberately as the guard that the public spelling stays registered under its own name.

No op_tests/ file changed for pa_fwd: its five out_ call sites keep working unchanged, and the coverage they stop providing -- that the routed path is exercised -- is added in tests/test_plugin_routed_ops.py instead, where the routing is what is under test.

@zufayu
zufayu requested a review from a team November 19, 2026 09:04
@github-actions github-actions Bot changed the title [RFC #7240] Drop the output buffer from five routed contracts [ASM] [RFC #7240] Drop the output buffer from five routed contracts Nov 19, 2026
@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 8291 --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 added the ASM label Nov 19, 2026
@aiter-bot

aiter-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision d3d0e37c7a13 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Six routed contracts took an optional output buffer and returned it, which cannot be registered as a torch custom op: the schema declares that results do not alias inputs, so `opcheck` rejects the shape, and under compile a fake that allocates leaves the caller's buffer unwritten while still returning the right value. Unregistered, those six stay traced Python inside a caller's graph and split it the day a provider is enabled -- which is the point of RFC #7240.

The existing behaviour is insufficient only in that one respect: the kernels are correct, and nothing is wrong today with no provider installed. What changes is that the routed contract no longer carries the buffer, so the op registers. Every public spelling keeps its signature; naming a buffer now bypasses routing and runs AITER's own kernel, which is what naming it asked for. `_NOT_REGISTERED` goes 24 -> 18.

Validation and unverified scope

Ran on this branch, gfx942 (MI300X), ROCm/torch from the container image:

```
pytest tests/test_plugin_contracts.py tests/test_plugin_routed_ops.py \
       op_tests/test_mla_sparse_prefill_v41_asm.py
  -> 116 passed, 129 skipped
black --check / ruff check on the changed files -> clean
```

Registration is real rather than inferred from the AST gate: after `import aiter`, all six appear under `torch.ops.aiter_routed`.

After folding `pa_fwd` in, on the same machine:

```
pytest tests/test_plugin.py tests/test_plugin_routed_ops.py \
       tests/test_plugin_contracts.py tests/test_ar_rmsnorm_routing.py \
       op_tests/test_mla_sparse_prefill_v41_asm.py \
       op_tests/test_gemm_host_dispatch_cache.py
  -> 301 passed, 145 skipped
```

On GPU, two of the five were exercised end to end:

```
opcheck(torch.ops.aiter_routed.gemm_a8w8_blockscale_bpreshuffle, ..., test_utils=("test_faketensor",))  pass
opcheck(torch.ops.aiter_routed.inverse_rope_group_quant,         ..., test_utils=("test_faketensor",))  pass
public spelling with a buffer -> returned tensor has the same data_ptr as the buffer (bypass confirmed)
```

The remaining four are arch-gated here: `mla_sparse_prefill`, `mla_sparse_prefill_v41`, `pa_decode_bf16` and `pa_fwd` cannot reach a kernel on gfx942 (`op_tests/test_mla_sparse_prefill.py` is 38 skipped; `op_tests/test_pa_decode_bf16_asm.py` exits on anything but gfx1250). What this PR changes about them is the dispatch branch and the fake -- both pure Python -- so both were verified by stubbing the native layer:

```
pa_decode_bf16          out=None -> native receives out=None (through the registered op)
                        out=buf  -> native receives that same buffer (bypass)
                        fake     -> (2, 8, 64) bf16
mla_sparse_prefill      same three
mla_sparse_prefill_v41  routed form passes out=None to the opus path; fake -> (8, 16, 512) bf16
```

**What remains unverified is only that their kernels still produce the same numbers** -- and no kernel body is touched here; only the forwarding moved. A run on gfx950/gfx1250 would close that last step.

`opcheck`'s `test_schema` is not usable for the fp8 ops here: it performs arithmetic on inputs to detect mutation, and `mul_cuda` is not implemented for `Float8_e4m3fnuz`. `test_faketensor`, which checks the fake against the real output, does run.

PR-specific question

*Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?*

No tuned-configuration file changes in this PR; no workload key consumes anything new. The only "configuration" that moves is the contract version recorded in `tests/plugin_contracts.json`, whose consumer is a plugin provider, not a shape-keyed tuning table. Backend selection is untouched: each public spelling forwards the same arguments to the same native path it did before, and the added branch only chooses between the registered contract (no buffer) and that native path (buffer). Evidence that unrelated shapes keep their previous selection is that no selection code was edited -- the diff in `aiter/ops/*` is a rename plus a dispatcher, with the kernel-choosing bodies moved verbatim.

Changed op tests

`op_tests/test_mla_sparse_prefill_v41_asm.py` -- `test_provider_path_preserves_v2_contract` pinned both the op version and the v2 argument count of what a provider is handed. Bumping `mla_sparse_prefill_v41` to v3 and dropping the buffer necessarily breaks both assertions, so the test is renamed `..._v3_contract` and now asserts `version == 3`, the argument tuple without the `out` slot, and `len(bound) == 13`.

`op_tests/test_gemm_host_dispatch_cache.py` -- it patched `op._eager_body` to intercept the nested `gemm_a8w8_blockscale -> ..._bpreshuffle` call. That call now targets the native body directly, because with no buffer named the public spelling routes, and a provider serving it there would be a second dispatch of the op the caller is already inside. The patch target moves to `gemm_op_a8w8._gemm_a8w8_blockscale_bpreshuffle_native` in both places. It is not redundant with the plugin tests: those check that the contract registers, this one checks that the *host-side dispatch caches* still answer identically, and its `_eager_body.__name__` assertion is kept deliberately as the guard that the public spelling stays registered under its own name.

No `op_tests/` file changed for `pa_fwd`: its five `out_` call sites keep working unchanged, and the coverage they stop providing -- that the *routed* path is exercised -- is added in `tests/test_plugin_routed_ops.py` instead, where the routing is what is under test.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 1 review(s); expect to start in about 28 min. 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 #8291 — [ASM] [RFC #7240] Drop the output buffer from five routed contracts

Review (advisory): 🔴 HIGH RISK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the one touched test target is op_tests/test_mla_sparse_prefill_v41_asm.py
Perf (advisory): NOT RUN — the touched test target exposes no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the PR makes no perf claim and moves no kernel math
Size: 660 lines / 7 files
Design (advisory): a caller-named output buffer bypasses routing and runs AITER's native kernel; the provider contract carries only the allocating form (buffer-free v2/v3 with supersedes=)
Human: recommend Sergey Shlyapnikov review whether a caller-named out= buffer bypassing routing (never offered to a provider) and declaring each older version acceptable via supersedes= is the right semantics for the five contracts this PR bumps, given the rmsnorm v1 counterexample

🔴 [verified] aiter/ops/gemm_op_a8w8.py moves @torch_compile_guard off the public gemm_a8w8_blockscale_bpreshuffle onto the renamed _gemm_a8w8_blockscale_bpreshuffle_native, and the guard registers under the decorated function's own name — so torch.ops.aiter.gemm_a8w8_blockscale_bpreshuffle and the public spelling's _eager_body attribute both disappear, and op_tests/test_gemm_host_dispatch_cache.py:160 (op._eager_body, a CPU test with no skip marker) and :208 (torch.ops.aiter.gemm_a8w8_blockscale_bpreshuffle, runs wherever the group32 GEMM exists, gfx950/gfx1250) now raise AttributeError — confirmed on the patched merge-target tree, where the old registered name is gone and only _gemm_a8w8_blockscale_bpreshuffle_native resolves. Author must keep the public name registered (or update the test to the new registration) before merge.

⚠️ [verified] the five new @_route registrations in aiter/ops/gemm_op_a8w8.py, aiter/ops/attention.py, aiter/ops/inverse_rope_group_quant.py and aiter/ops/mla_sparse_prefill.py pass fake= but not mutates_args=[], so every registered schema marks every tensor input mutated — on the patched tree aiter_routed::gemm_a8w8_blockscale_bpreshuffle resolves as (Tensor(a0!) XQ, Tensor(a1!) WQ, Tensor(a2!) x_scale, Tensor(a3!) w_scale, ScalarType dtype=15) -> Tensor — and under torch.compile these nodes get the auto_functionalized_v2 wrap that route()'s own docstring names as the price of the default, on ops whose unguarded public spellings previously traced through. The repo's own pattern for a contract that writes through no argument (gemm_a8w8_blockscale at gemm_op_a8w8.py:1552, and _mhc_fused_post_pre_routed) passes mutates_args=[]. Author must pass mutates_args=[] on the contracts whose own new docstrings say they write through no argument, and state the per-argument decision for pa_decode_bf16's split_o/split_lse/work_info work buffers.

@torch_compile_guard(mutates_args=[], gen_fake=gemm_a8w8_blockscale_fake)

⚠️ [verified] the re-routed contract paths for three of the five ops — _mla_sparse_prefill_contract and the v3 _mla_sparse_prefill_v41_routed in aiter/ops/mla_sparse_prefill.py, and _pa_decode_bf16_contract in aiter/ops/attention.py — have never executed on a GPU (the PR's own Unverified section: their op_tests skip on gfx942 and need gfx950/gfx1250), and the PR carries no ci: label, so the label-gated downstream jobs (ATOM/SGLang/vLLM) whose compiled graphs now stop at these new opaque nodes run nothing before merge. Author must run the three contracts on gfx950/gfx1250 before merge, add ci:all or the minimal label set, and get the attention.py/gemm_op_a8w8.py owners' sign-off on the contract bump.

📝 [verified] the _eager_body unwrap in gemm_a8w8_blockscale's group32 path (aiter/ops/gemm_op_a8w8.py:1607) silently stops unwrapping — the new public spelling carries no _eager_body — so the nested gemm_a8w8_blockscale_bpreshuffle call now dispatches through the aiter_routed contract and becomes provider-offerable where it used to call AITER's own body directly, and the comment at gemm_op_a8w8.py:1602-1605 still describes the old behaviour. Reviewer should ask whether the nested call is meant to be provider-served now, and have the stale comment updated either way.

bpreshuffle = getattr(bpreshuffle, "_eager_body", bpreshuffle)

# tensors: tracing uses gemm_a8w8_blockscale_fake), so the nested
# op's body is called directly instead of dispatching
# torch.ops.aiter.gemm_a8w8_blockscale_bpreshuffle a second time.
# A rebound module attribute (e.g. monkeypatched) is still called.

📝 [verified] nothing asserts the five ops actually appear under torch.ops.aiter_routed after import: tests/test_plugin_contracts.py checks only that fake= was passed (AST-level) and tests/test_plugin_routed_ops.py:73 checks the plugin's internal registry, while _as_custom_op returns None silently on any failure — so a torch change that breaks infer_schema would silently un-register all five, no test would fail, and the PR's entire purpose would be gone. Author must add a test asserting the five names resolve under torch.ops.aiter_routed.

@aiter-bot

Copy link
Copy Markdown

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

@zufayu zufayu added the ci:all label Nov 19, 2026
@zufayu

zufayu commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 1 review(s); expect to start in about 28 min. 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 #8291 — [ASM] [RFC #7240] Drop the output buffer from five routed contracts

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0) and no unique test target to name (two candidates: op_tests/test_gemm_host_dispatch_cache.py, op_tests/test_mla_sparse_prefill_v41_asm.py); all 8 GPUs on this box carry resident workloads (95–96% VRAM), so no run could happen here — an environment gap, not a PR defect
Perf (advisory): NOT RUN — no unique test target to derive a harness from (two candidates), and neither touched target ships a benchmark entry point (no --scenario bench, no perftest/@benchmark harness), so the per-call cost of the added routing dispatch has nothing to measure it with
Size: 782 lines / 9 files
Design (advisory): a caller-named output buffer bypasses routing and runs AITER's own kernel; the provider contract carries only the allocating form, with each older version declared acceptable via supersedes=
Human: recommend Sergey Shlyapnikov review whether a caller-named out= buffer bypassing routing (never offered to a provider) and declaring each older contract version acceptable via supersedes= is the right semantics for the five contracts this PR bumps, given mla_sparse_prefill v1 and mla_sparse_prefill_v41 v2 carried out= before num_kv_splits rather than after it

⚠️ [verified] aiter/ops/mla_sparse_prefill.py declares the older mla_sparse_prefill v1 and mla_sparse_prefill_v41 v2 contracts acceptable via supersedes=, but the removed out parameter sat before num_kv_splits, so a provider built for the older shape and handed a call with num_kv_splits=4 receives 4 in its out slot and None in num_kv_splits — the plugin's arity probe passes because both trailing params carried defaults and dispatch calls run positionally with the new contract's canonicalized args, verified by simulation — and the served call then fails inside the provider with no fallback. Author must drop supersedes= from these two contracts (the arity rejection is then the correct outcome, as this file already argues for v41's v1→v2 backend removal) or state why a superseded provider can never be handed a num_kv_splits call.

⚠️ [verified] aiter/ops/attention.py and aiter/ops/gemm_op_a8w8.py are stable downstream-facing contracts whose routed versions this PR bumps (pa_decode_bf16 1→2, gemm_a8w8_blockscale_bpreshuffle 1→2) with no human review on the PR — only the bot has commented — so the semantics change (a caller-named buffer now bypasses routing and is never offered to a provider) could land without the path owners ever seeing it. Reviewer must @-mention the de-facto owners (minmengdie for attention.py, BingYuan.Zhou for gemm_op_a8w8.py, by commit count) and get their explicit sign-off before merge.

📝 [inferred] the four mutates_args=[] declarations assert that no kernel writes through any contract argument, but nothing in the tree can establish that — the Python layer hands kv/q/unified_kv straight to the compiled opus/asm bindings, and attention.py itself declines the declaration for pa_decode_bf16 because split_o/split_lse/work_info are kernel scratch — so if any of those kernels uses an input as scratch, the registered schema lies and inductor behaviour is undefined. Author must cite per contract what establishes that the kernel beneath writes through no argument (a kernel-source reading or a torch.compile run on gfx950/gfx1250), since the docstring's assertion is today the only evidence.

📝 [inferred] every eager caller of the five ops now pays one extra torch.ops.aiter_routed dispatch plus one Python frame per call even with no provider installed (before this PR the contracts were traced functions, because route() without fake= returns the plain dispatch fn), and neither touched test target (op_tests/test_gemm_host_dispatch_cache.py, op_tests/test_mla_sparse_prefill_v41_asm.py) ships a benchmark entry point — so whether the added dispatch costs anything measurable on the decode/prefill hot paths is an open question. Author must measure the no-buffer spelling's per-call overhead on one hot path (e.g. pa_decode_bf16 decode) or point at a harness that does.

📝 [verified] the PR's one red downstream check (Sglang DeepSeek-R1-MXFP4 Accuracy) fails identically on main's latest run of the same workflow (12:12 today, before this head was pushed) with the same NumPy C-API crash at sglang server startup before any model load, and the remaining ci:all jobs (Accuracy DeepSeek-R1-0528, gpt-oss-120b, Sglang DeepSeek-V3.2, Aiter wheel) were still running at review time. Reviewer should ask for the completed ci:all run before merge rather than reading the red as this PR's.

zufayu and others added 3 commits November 20, 2026 01:34
Five contracts carried an optional output buffer and returned it. That shape
cannot be registered as a custom op: the schema declares that results do not
alias inputs, so opcheck rejects it, and under compile a fake that allocates
leaves the caller's buffer unwritten while still returning the right value --
no error, stale buffer, nothing says so.

Each public spelling keeps its buffer argument and bypasses routing when one
is named, as #7875 does. The routed contract drops it and gains a fake, so
the op registers and a caller's graph no longer splits when a provider is
enabled.

  gemm_a8w8_blockscale_bpreshuffle  v1 -> v2
  mla_sparse_prefill                v1 -> v2
  mla_sparse_prefill_v41            v2 -> v3
  inverse_rope_group_quant          v1 -> v2
  pa_decode_bf16                    v1 -> v2

Each declares the older version in supersedes=: the only change is removing
an OPTIONAL buffer, so a provider built for the older shape sees it as None
and allocates, which is the new semantics exactly. (rmsnorm v1 was left out
of its own supersedes for the opposite reason: a v1 kernel handed a v2 call
writes the caller's input.)

_NOT_REGISTERED drops from 12 entries to 7; registered routed ops go from 7
to 12.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…in it

Five findings from the bot review of 5416969, each verified before fixing.

**The public name stopped being registered.** Moving `@torch_compile_guard`
onto the renamed `_gemm_a8w8_blockscale_bpreshuffle_native` moved the
registration with it -- the guard registers under the decorated function's
own name -- so `torch.ops.aiter.gemm_a8w8_blockscale_bpreshuffle` and the
public spelling's `_eager_body` both disappeared, and
`op_tests/test_gemm_host_dispatch_cache.py` used both. The guard now sits on
the public dispatcher, which carries the name. Confirmed by comparing the
registered names against an unpatched main tree: the same three are present
on both.

Worth noting that CI did not catch this. The Aiter Test Gate went green on
the revision where those two attributes were already gone.

**The schemas claimed every input was mutated.** The new routes passed
`fake=` but not `mutates_args=[]`, so each registered as
`(Tensor(a0!) XQ, Tensor(a1!) WQ, ...)` and earned an
`auto_functionalized_v2` wrap under compile -- on ops whose unguarded public
spellings previously traced through. Four of the five now declare `[]`, which
is what their own docstrings say.

`pa_decode_bf16` deliberately does not. Dropping `out` removes the buffer it
RETURNED, but `split_o`, `split_lse` and `work_info` still reach the asm
binding as split-KV scratch and nothing in the tree establishes they are
read-only. `route()` says the conservative default costs a wrap while a
declared list that lies is undefined behaviour, so the wrap is the cheaper of
the two until someone can state it per buffer.

**The nested group32 call became provider-offerable.** `gemm_a8w8_blockscale`
reached its bpreshuffle sibling through `_eager_body` to avoid dispatching a
second time; with the split, that body is the dispatcher, which routes when no
buffer is named -- a second dispatch, and a different kernel inside what the
caller asked AITER to compute. It now targets the native body directly. The
comment and the test's patch target move with it.

**Nothing asserted the contracts reach torch.** The AST gate checks that
`fake=` was passed and the registry check reads the plugin's own dict; neither
calls into torch, and `_as_custom_op` returns None silently on failure. A new
parametrised test resolves each of the five under `torch.ops.aiter_routed` and
compares the registered parameter list against the recorded contract --
against the baseline rather than a list of likely buffer names, because
`x_scale` is an output buffer for one of these ops and an input for another.

**No CI label.** `ci:all` added, so the label-gated downstream jobs run
against the new opaque nodes rather than nothing.

Verified: `tests/test_plugin_contracts.py tests/test_plugin_routed_ops.py
op_tests/test_mla_sparse_prefill_v41_asm.py
op_tests/test_gemm_host_dispatch_cache.py` is 137 passed, 145 skipped on
gfx942. black and ruff clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`test_status_lists_what_is_deprecated_and_when_it_goes` asserted that
`status()["deprecations"]` held exactly the two entries it created, which
held only while no op in the tree declared `supersedes=`. These five now
do, so the test selects its own two subjects instead.

The coverage that assertion really provided -- that a superseded op
version is announced at all -- moves to the contract test, where it is
checked per op against that op's own version.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu force-pushed the opus/aklr-drop-out-buffers branch from 4026299 to 982fc3a Compare November 20, 2026 01:37
…path

`pa_fwd` is the sixth contract with an optional output buffer it returns,
and the last one this series leaves. Registered, that is an op returning one
of its own arguments while its schema declares results do not alias inputs.

v1 -> v2 removes the buffer from the contract. Both public spellings keep
their signatures; naming `out_` bypasses routing and runs AITER's own kernel,
which is what naming it asked for. v1 is declared in `supersedes=`: the only
change is removing an OPTIONAL buffer, so a v1 provider sees `out_=None` and
allocates, which is v2's semantics exactly.

`_NOT_REGISTERED` goes from 19 entries to 18; registered routed ops 15 -> 16.

Unlike the five in the previous commit, this op has callers that pass the
buffer -- five, all in `op_tests` -- so after this change they exercise the
bypass and nothing exercises the routed path. Six tests restore that
coverage, each pinning WHICH path ran rather than that the call returned:

  * both spellings route when no buffer is named. `pa_fwd_asm` reads like a
    backend pin and is not: it predates the neutral name, so an ordinary call
    through it routes. Testing only `pa_fwd` would leave half the callers
    unrouted without anyone noticing.
  * naming `out_` bypasses, from either spelling.
  * `kernelName` bypasses on its own, kept separate from the `out_` reason so
    the two cannot be merged into one.
  * the buffered form returns the caller's buffer, asserted on `data_ptr`.
    A fake that allocates returns the right value while leaving that buffer
    unwritten; comparing values alone cannot see it.

Verified: `tests/test_plugin_contracts.py tests/test_plugin_routed_ops.py`
is 83 passed; `pa_fwd` appears in `torch.ops.aiter_routed` after a real
`import aiter`; `op_tests/test_pa_block_id_truncation.py`, which passes
`out_`, is 56 passed 8 skipped on gfx942. black and ruff clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu zufayu changed the title [ASM] [RFC #7240] Drop the output buffer from five routed contracts [ASM] [RFC #7240] Drop the output buffer from six routed contracts Nov 20, 2026
@fangche123
fangche123 merged commit 5050132 into main Nov 20, 2026
73 of 77 checks passed
@fangche123
fangche123 deleted the opus/aklr-drop-out-buffers branch November 20, 2026 08:12
zufayu added a commit that referenced this pull request Nov 20, 2026
…8339)

One retry budget covered two different situations: not having found the
Checks run yet, and having found it while it is still going. Five
attempts thirty seconds apart is a reasonable budget for the first and
no budget at all for the second -- on a busy day the queue alone holds a
run past 2.5 minutes, and the script then reports "Failed to read
pre-checks status" and exits 1, taking the gate red on a pre-check that
goes on to pass.

Seen on #8291: run 44609631130 was located on attempt 2 and was still
in_progress through attempt 5; its conclusion was success. Every
workflow that gates on this script -- eight of them -- fails the same
way whenever the queue is deep.

So the two are budgeted apart. MAX_RETRIES still bounds locating the
run, because a missing run usually means the event never started one.
Once located, the script polls until the run completes, bounded by
MAX_WAIT_SECONDS (45 minutes) so a genuinely stuck run still ends the
job rather than holding a runner forever.

Exercised against a stubbed `gh` on all four paths: slow-then-success
(exit 0, where the current script exits 1), pre-checks failed (78),
never located (1), and still running at the deadline (1).

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zufayu pushed a commit that referenced this pull request Nov 23, 2026
)

Since #8291, gemm_a8w8_blockscale_bpreshuffle without out= goes through a
routed custom op, and under the AOT dry run's FakeTensors only its fake
runs. The replay jobs never reached the FlyDSL dispatch, so their rows were
reported [UNREACHED] and no kernel was built. Naming out= takes the native
path, which is the one the replay is meant to drive.

Co-authored-by: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 23, 2026
Keeps ROCm#7667's commits as they are and takes main's changes. The only
conflict is the module docstring of op_tests/test_gemm_host_dispatch_cache.py:
main's text for the nested blockscale call (ROCm#8291) plus this branch's `_pl`
bullet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

4 participants