Repository navigation
[ASM] [RFC #7240] Drop the output buffer from six routed contracts - #8291
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 28 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
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.
aiter/aiter/ops/gemm_op_a8w8.py
Line 1552 in 5416969
📝 [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.
aiter/aiter/ops/gemm_op_a8w8.py
Line 1607 in 5416969
aiter/aiter/ops/gemm_op_a8w8.py
Lines 1602 to 1605 in 5416969
📝 [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 — queued behind 1 review(s); expect to start in about 28 min. The box reviews one PR at a time. |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 28 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8291 — [ASM] [RFC #7240] Drop the output buffer from five routed contracts
Review (advisory):
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
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.
📝 [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.
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]>
4026299 to
982fc3a
Compare
…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]>
…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]>
) 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]>
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]>
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_REGISTEREDgoes 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.
opcheckrejects 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.Note the middle line:
opcheckis 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.
gemm_a8w8_blockscale_bpreshufflemla_sparse_prefillmla_sparse_prefill_v41inverse_rope_group_quantpa_decode_bf16pa_fwdEach declares the older version in
supersedes=. The only change is removing an optional buffer, so a provider built for the older shape seesNoneand allocates -- which is the newer semantics exactly. (rmsnormv1 was left out of its ownsupersedesfor 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_fwdpa_fwdis the one with callers that do passout_-- five sites, all inop_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 intests/test_plugin_routed_ops.py):pa_fwd_asmlooks like a backend pin and is not -- it predates the neutral name, so an ordinary call through it routes. OnlykernelNamepins a kernel, and only that bypasses on its own.out_bypasses from either spelling.data_ptrrather than on value: a fake that allocates returns the right numbers into the wrong allocation, and only the pointer tells those apart.pa_fwdtakesmutates_args=[], unlikepa_decode_bf16in this same PR, and the code says why: droppingoutleavespa_fwdwith nothing it writes through, whilepa_decode_bf16still handssplit_o,split_lseandwork_infoto 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 passedtorch.ops.aiter_routedafter a realimport aiter, so they register rather than silently staying tracedgemm_a8w8_blockscale_bpreshuffleandinverse_rope_group_quanton gfx942:opcheck(..., test_utils=("test_faketensor",))passes, and the public spelling with a buffer returns the samedata_ptr-- the bypass is exercised, not just assumedAfter the review round, on gfx942:
torch.ops.aiterexposes the same three names as an unpatched main tree, sothe registration the guard move had dropped is back; four of the five routed
schemas now read
(Tensor XQ, ...)rather than(Tensor(a0!) XQ, ...), andpa_decode_bf16keeps 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_bf16andpa_fwdcannot reach a kernel on gfx942 (op_tests/test_mla_sparse_prefill.pyis 38 skipped;op_tests/test_pa_decode_bf16_asm.pyexits 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: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'stest_schemais not usable for the fp8 ops here: it performs arithmetic on inputs to detect mutation, andmul_cudais not implemented forFloat8_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_contractpinned both the version and the v2 argument count. It is renamed to..._v3_contractand now assertsversion == 3, the contract arg tuple without theoutslot, andlen(bound) == 13. The test was doing its job; a contract bump is supposed to break it.Documentation
Dependencies
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
d3d0e37c7aBehavior 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
opcheckrejects 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_REGISTEREDgoes 24 -> 18.Validation and unverified scope
Ran on this branch, gfx942 (MI300X), ROCm/torch from the container image:
Registration is real rather than inferred from the AST gate: after
import aiter, all six appear undertorch.ops.aiter_routed.After folding
pa_fwdin, on the same machine:On GPU, two of the five were exercised end to end:
The remaining four are arch-gated here:
mla_sparse_prefill,mla_sparse_prefill_v41,pa_decode_bf16andpa_fwdcannot reach a kernel on gfx942 (op_tests/test_mla_sparse_prefill.pyis 38 skipped;op_tests/test_pa_decode_bf16_asm.pyexits 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: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'stest_schemais not usable for the fp8 ops here: it performs arithmetic on inputs to detect mutation, andmul_cudais not implemented forFloat8_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 inaiter/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_contractpinned both the op version and the v2 argument count of what a provider is handed. Bumpingmla_sparse_prefill_v41to v3 and dropping the buffer necessarily breaks both assertions, so the test is renamed..._v3_contractand now assertsversion == 3, the argument tuple without theoutslot, andlen(bound) == 13.op_tests/test_gemm_host_dispatch_cache.py-- it patchedop._eager_bodyto intercept the nestedgemm_a8w8_blockscale -> ..._bpreshufflecall. 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 togemm_op_a8w8._gemm_a8w8_blockscale_bpreshuffle_nativein 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 forpa_fwd: its fiveout_call sites keep working unchanged, and the coverage they stop providing -- that the routed path is exercised -- is added intests/test_plugin_routed_ops.pyinstead, where the routing is what is under test.