Skip to content

[Plugin] Register the routed ops that can be, and gate the rest - #7881

Merged
zufayu merged 1 commit into
mainfrom
codex/route-register-all
Nov 13, 2026
Merged

zufayu merged 1 commit into
mainfrom
codex/route-register-all

Conversation

@zufayu

@zufayu zufayu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

route(..., fake=...) landed in #7850, and is opt-in per op. One op in the tree passes it.

That default is the problem this PR is about: an op added without fake= behaves exactly as before and starts splitting a caller's compiled graph only once someone enables a provider for it — far from where the omission happened, and in the configuration this interface exists for. Nothing fails, nothing warns, and the omission costs nothing to make.

What is registered here

Two ops, chosen because neither touches a contract:

op why it is safe to register fake
rmsnorm_with_add returns None; every result is an in-place write, so there is no value a fake can get wrong trivial
gemm_a8w8_blockscale reuses gemm_a8w8_blockscale_fake, which its own torch_compile_guard already runs in production as gen_fake= existing

tests/plugin_contracts.json is unchanged: adding fake= is a decorator argument, not a signature, so no fingerprint moves. A diff there would have meant something went wrong.

What is gated

Every routed op must now be in exactly one of three states, or test_every_routed_op_is_registered_or_says_why_not fails:

  1. it passes fake=;
  2. a torch_compile_guard sits outside its @route, so a caller already reaches an opaque op — detected from decorator order, never listed, so it cannot go stale;
  3. it is named in _NOT_REGISTERED with the reason.

The twelve in (3) fall into three reasons, each measured rather than asserted:

"out-buffer in the contract"

pa_fwd, pa_decode_bf16, mla_sparse_prefill, mla_sparse_prefill_v41, gemm_a8w8_blockscale_bpreshuffle, inverse_rope_group_quant.

These take an optional output tensor and return it. Registered, that is an op returning one of its own arguments. Measured on a probe op:

result
eager, buffer passed returns the buffer — as the caller expects
compiled, buffer passed compiles fine, and the buffer is never written; the return value is correct, so a caller reading its own buffer afterwards reads stale data
opcheck Argument out is not defined to alias output but was aliasing

The silent case is why these wait. Fixing it means dropping the buffer from the contract, which moves the signature and so needs an op_version decision. #7875 shows the shape of that fix for a contract new enough not to need the bump.

"unannotated contract"

pertoken_quant, rmsnorm, sp_qkv_fused, mla_decode_fwd_v4_nm, mla_decode_fwd_v4_nm_ps.

Their contracts render without types (x:positional, not x:positional:Tensor). infer_schema needs annotations, and adding them moves the rendered signature and therefore the fingerprint — indistinguishable, to the gate, from a real contract change. Same op_version decision, and it should be made once for all five rather than per PR.

pertoken_quant carries a second reason worth recording, because it is the one op where registration has a cost rather than only a benefit: its body is pure torch, and inductor fuses it with its neighbours today — measured, one reduction kernel for silu + amax + divide + the consumer, against two inductor kernels plus the op's own launches once registered. Registration happens at import aiter and AITER_PLUGINS=0 does not undo it (measured), so that cost would fall on every compiling caller, including those with no provider at all. Worth paying when a provider serves it; not before.

"no schema can express it"

pa_persistent_fwd takes a QuantType.

Validation

On gfx942, torch 2.9.1:

  • op_tests/test_rmsnorm2d.py run against this tree and against its base: both exit 0, and the full logs are identical once timings are excluded;
  • rmsnorm_with_add output is bit-identical to base, reproducibly (alternating runs);
  • both ops register — OpOverloadPacket under torch.ops.aiter_routed;
  • 144 plugin tests pass, 1 skipped; dispatch overhead unchanged at 0.60 of one Signature.bind;
  • black, ruff check clean;
  • tests/plugin_contracts.json untouched.

The gate was mutation-checked rather than assumed:

mutation result
remove fake= from rmsnorm_with_add fails: routed ops that are neither registered nor explained: rmsnorm_with_add
add fake= to pa_fwd, leaving it listed fails: ops listed as not registered that now pass fake=: pa_fwd

Unverified: gemm_a8w8_blockscale could not be exercised numerically here — module_gemm_a8w8_blockscale fails to JIT-build on this box, identically on the base tree, so the failure is the environment and not this change. Its evidence is that registration succeeds and that its fake is the one already shipping behind its own guard. ci:all is set so a runner that can build it exercises it.

🤖 Generated with Claude Code

PR Self-Review

Reviewed revision

bd24c81e35e027500cec33c323e14537d1922af1

Behavior and intent

#7850 made registration available; it is opt-in per op, and one op opted in. The behaviour that is insufficient is the default: an op routed without fake= is indistinguishable from a correct one until a provider is enabled, at which point the plugin's dispatch splits the caller's graph — a failure that surfaces far from the omission and that nothing today reports. This PR registers the two ops that can be registered without touching a contract, and adds a gate so the omission costs a written sentence instead of nothing.

Validation and unverified scope

Verified on gfx942, torch 2.9.1:

  • op_tests/test_rmsnorm2d.py on this tree and on its base: both exit 0, full logs identical once timings are excluded;
  • rmsnorm_with_add is bit-identical to base across alternating runs;
  • both ops are OpOverloadPacket under torch.ops.aiter_routed;
  • 144 plugin tests pass, 1 skipped; overhead unchanged at 0.60 of one Signature.bind;
  • tests/plugin_contracts.json untouched, which is the invariant for this change: fake= is a decorator argument, not a signature;
  • black, ruff check clean.

Unverified: gemm_a8w8_blockscale is not exercised numerically here — module_gemm_a8w8_blockscale fails to JIT-build on this box, identically on the base tree, so the failure is environmental. Its fake is the one its own torch_compile_guard already ships as gen_fake=. ci:all is set.

The boundary this introduces, and what covers it

The gate's own correctness, since a gate that cannot fail is worse than none. Both failure directions were mutation-checked rather than assumed: removing fake= from a registered op makes it fail and name that op; adding fake= to a listed op makes the vacuity test fail and name the stale entry. The gate also refuses an empty reason, refuses to name an op that is not routed, and refuses to be satisfied by exceptions alone.

The "shielded by an outer guard" state is detected from decorator order rather than listed, specifically so it cannot outlive the decorator it describes.

PR-specific question

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

No configuration or tuning keys change, and no selection logic is touched. Both ops keep their bodies unchanged; fake= adds a meta implementation used only under tracing, and the fake for gemm_a8w8_blockscale is the one already in use behind its guard. Shape-dependent dispatch — gemm_a8w8_blockscale's config-first backend choice, rmsnorm_with_add's kernel selection — runs on the same inputs through the same code.

The evidence that unrelated shapes keep their selection is the op_tests/test_rmsnorm2d.py A/B: the same sweep on both trees produces byte-identical logs, which covers each shape the suite exercises rather than arguing from the diff.

Changed op tests

None. op_tests/test_rmsnorm2d.py was run against both trees; it is not modified.

route(..., fake=...) landed in #7850 but is opt-in per op, and the default
-- no fake -- is the state that splits a caller's graph the day a provider
is enabled. One op in the tree passed it.

Two more can be registered without touching any contract: rmsnorm_with_add
returns nothing, and gemm_a8w8_blockscale reuses the fake its own
torch_compile_guard already runs in production.

The rest cannot, for three measured reasons, and the new gate makes each
one cost a written sentence rather than nothing: a contract carrying an
output buffer the op returns (opcheck rejects it, and under compile the
buffer is silently left unwritten), a contract rendered without type
annotations (adding them moves the fingerprint), and a parameter no schema
can express.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu requested a review from a team November 12, 2026 13:45
@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 7881 --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.

@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision bd24c81e35e0 · 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

#7850 made registration available; it is opt-in per op, and one op opted in. The behaviour that is insufficient is the *default*: an op routed without `fake=` is indistinguishable from a correct one until a provider is enabled, at which point the plugin's dispatch splits the caller's graph — a failure that surfaces far from the omission and that nothing today reports. This PR registers the two ops that can be registered without touching a contract, and adds a gate so the omission costs a written sentence instead of nothing.

Validation and unverified scope

Verified on gfx942, torch 2.9.1:

- `op_tests/test_rmsnorm2d.py` on this tree and on its base: both exit 0, full logs identical once timings are excluded;
- `rmsnorm_with_add` is bit-identical to base across alternating runs;
- both ops are `OpOverloadPacket` under `torch.ops.aiter_routed`;
- 144 plugin tests pass, 1 skipped; overhead unchanged at `0.60 of one Signature.bind`;
- `tests/plugin_contracts.json` untouched, which is the invariant for this change: `fake=` is a decorator argument, not a signature;
- `black`, `ruff check` clean.

**Unverified:** `gemm_a8w8_blockscale` is not exercised numerically here — `module_gemm_a8w8_blockscale` fails to JIT-build on this box, identically on the base tree, so the failure is environmental. Its fake is the one its own `torch_compile_guard` already ships as `gen_fake=`. `ci:all` is set.

PR-specific question

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

No configuration or tuning keys change, and no selection logic is touched. Both ops keep their bodies unchanged; `fake=` adds a meta implementation used only under tracing, and the fake for `gemm_a8w8_blockscale` is the one already in use behind its guard. Shape-dependent dispatch — `gemm_a8w8_blockscale`'s config-first backend choice, `rmsnorm_with_add`'s kernel selection — runs on the same inputs through the same code.

The evidence that unrelated shapes keep their selection is the `op_tests/test_rmsnorm2d.py` A/B: the same sweep on both trees produces byte-identical logs, which covers each shape the suite exercises rather than arguing from the diff.

Changed op tests

None. `op_tests/test_rmsnorm2d.py` was run against both trees; it is not modified.

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 added the ci:all label Nov 12, 2026
zufayu added a commit that referenced this pull request Nov 13, 2026
… cannot be shielded

The other two ops this PR routes, `mhc_pre` and `mhc_post`, carry a
`torch_compile_guard` outside their `@route`, so a caller already reaches
an opaque op and the plugin's dispatch cannot enter its graph.
`per_group_quant` does not: the route sits on `_per_group_quant_routed`,
while the guard sits on `per_group_quant_hip`, a different function. A
decorator-order scan therefore cannot see it as shielded, and it passed no
`fake=`, which leaves it in the state that splits a caller's graph the day a
provider is enabled.

The fake reports shapes only. Both results are freshly allocated in the
native body, so neither aliases an argument and `infer_schema` renders
`-> (Tensor, Tensor)` with nothing to declare about aliasing.
`transpose_scale` shuffles the scale's contents inside the kernel without
moving its shape, so it does not appear in the fake.

Verified:
  * `infer_schema(native, mutates_args="unknown")` renders a schema.
  * Shapes checked on meta tensors against the native body's two branches:
    default -> (m, n // group_size); `scale_layout_m32k4` ->
    ((m + 31) // 32 * 32, n // 32); `transpose_scale` moves neither.
  * `tests/test_plugin_contracts.py` passes on this branch (16), and the
    contract fingerprint is unchanged -- the contract is taken from the
    native signature, which this does not touch, so no op_version bump.
  * Merged locally with #7881, whose registration gate reports
    `per_group_quant` as unregistered without this commit and passes with
    it (18).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu merged commit 888b1a0 into main Nov 13, 2026
@zufayu
zufayu deleted the codex/route-register-all branch November 13, 2026 05:12
zufayu added a commit that referenced this pull request Nov 13, 2026
…guard (#7854)

* feat(plugin): route the three remaining ops that already have a guard

`per_group_quant_hip`, `mhc_pre` and `mhc_post` are called on the DSV4.1
path by vLLM, SGLang and ATOM, and no provider can serve any of them. All
three are ordinary Python implementations that already carry
`torch_compile_guard`, so routing underneath it costs nothing: the guard
is what Dynamo sees, and the plugin's dispatch never reaches a caller's
compiled graph. They need neither #7850 nor the eager snapshot to be safe.

`per_group_quant` routes on a neutrally named `_per_group_quant_routed`
rather than on `per_group_quant_hip`. That was not the first draft --
test_the_backend_suffix_gate_is_not_vacuous rejected it, correctly: a
route's contract is the decorated function's whole signature, so
decorating a backend-named function writes that name's shape into what
providers implement against. `rmsnorm` sits the same way beneath its two
public spellings.

All three lacked docstrings, which #7787's gate requires of a routed op.
Written from the implementations: `mhc_pre` returns three new tensors and
writes nothing (matching its `mutates_args=[]`), `mhc_post` writes `out`
and returns None (matching `mutates_args=["out"]`), `per_group_quant`
returns `(y, scale)` and writes nothing.

Public signatures are byte-identical to main for all three, checked by
AST. Nineteen contracts, none carrying a backend parameter, none lost.

Left out deliberately: `mla_sparse_prefill_v4`, whose `backend is None`
branch chooses between asm and opus by arch and shape with a fallback,
and whose asm path is gfx1250-only -- not verifiable on the gfx942 box
this was written on, and getting it wrong changes which kernel runs. The
four bare `@compile_ops` stubs need a wrapper each, and the wrapper would
itself be exposed unless it also carries a guard and a fake; those belong
with #7850's mechanism, one at a time.

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

* [OPUS] [Plugin] Register per_group_quant, the one routed op here that cannot be shielded

The other two ops this PR routes, `mhc_pre` and `mhc_post`, carry a
`torch_compile_guard` outside their `@route`, so a caller already reaches
an opaque op and the plugin's dispatch cannot enter its graph.
`per_group_quant` does not: the route sits on `_per_group_quant_routed`,
while the guard sits on `per_group_quant_hip`, a different function. A
decorator-order scan therefore cannot see it as shielded, and it passed no
`fake=`, which leaves it in the state that splits a caller's graph the day a
provider is enabled.

The fake reports shapes only. Both results are freshly allocated in the
native body, so neither aliases an argument and `infer_schema` renders
`-> (Tensor, Tensor)` with nothing to declare about aliasing.
`transpose_scale` shuffles the scale's contents inside the kernel without
moving its shape, so it does not appear in the fake.

Verified:
  * `infer_schema(native, mutates_args="unknown")` renders a schema.
  * Shapes checked on meta tensors against the native body's two branches:
    default -> (m, n // group_size); `scale_layout_m32k4` ->
    ((m + 31) // 32 * 32, n // 32); `transpose_scale` moves neither.
  * `tests/test_plugin_contracts.py` passes on this branch (16), and the
    contract fingerprint is unchanged -- the contract is taken from the
    native signature, which this does not touch, so no op_version bump.
  * Merged locally with #7881, whose registration gate reports
    `per_group_quant` as unregistered without this commit and passes with
    it (18).

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

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: root <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
route(..., fake=...) landed in #7850 but is opt-in per op, and the default
-- no fake -- is the state that splits a caller's graph the day a provider
is enabled. One op in the tree passed it.

Two more can be registered without touching any contract: rmsnorm_with_add
returns nothing, and gemm_a8w8_blockscale reuses the fake its own
torch_compile_guard already runs in production.

The rest cannot, for three measured reasons, and the new gate makes each
one cost a written sentence rather than nothing: a contract carrying an
output buffer the op returns (opcheck rejects it, and under compile the
buffer is silently left unwritten), a contract rendered without type
annotations (adding them moves the fingerprint), and a parameter no schema
can express.

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
…guard (#7854)

* feat(plugin): route the three remaining ops that already have a guard

`per_group_quant_hip`, `mhc_pre` and `mhc_post` are called on the DSV4.1
path by vLLM, SGLang and ATOM, and no provider can serve any of them. All
three are ordinary Python implementations that already carry
`torch_compile_guard`, so routing underneath it costs nothing: the guard
is what Dynamo sees, and the plugin's dispatch never reaches a caller's
compiled graph. They need neither #7850 nor the eager snapshot to be safe.

`per_group_quant` routes on a neutrally named `_per_group_quant_routed`
rather than on `per_group_quant_hip`. That was not the first draft --
test_the_backend_suffix_gate_is_not_vacuous rejected it, correctly: a
route's contract is the decorated function's whole signature, so
decorating a backend-named function writes that name's shape into what
providers implement against. `rmsnorm` sits the same way beneath its two
public spellings.

All three lacked docstrings, which #7787's gate requires of a routed op.
Written from the implementations: `mhc_pre` returns three new tensors and
writes nothing (matching its `mutates_args=[]`), `mhc_post` writes `out`
and returns None (matching `mutates_args=["out"]`), `per_group_quant`
returns `(y, scale)` and writes nothing.

Public signatures are byte-identical to main for all three, checked by
AST. Nineteen contracts, none carrying a backend parameter, none lost.

Left out deliberately: `mla_sparse_prefill_v4`, whose `backend is None`
branch chooses between asm and opus by arch and shape with a fallback,
and whose asm path is gfx1250-only -- not verifiable on the gfx942 box
this was written on, and getting it wrong changes which kernel runs. The
four bare `@compile_ops` stubs need a wrapper each, and the wrapper would
itself be exposed unless it also carries a guard and a fake; those belong
with #7850's mechanism, one at a time.

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

* [OPUS] [Plugin] Register per_group_quant, the one routed op here that cannot be shielded

The other two ops this PR routes, `mhc_pre` and `mhc_post`, carry a
`torch_compile_guard` outside their `@route`, so a caller already reaches
an opaque op and the plugin's dispatch cannot enter its graph.
`per_group_quant` does not: the route sits on `_per_group_quant_routed`,
while the guard sits on `per_group_quant_hip`, a different function. A
decorator-order scan therefore cannot see it as shielded, and it passed no
`fake=`, which leaves it in the state that splits a caller's graph the day a
provider is enabled.

The fake reports shapes only. Both results are freshly allocated in the
native body, so neither aliases an argument and `infer_schema` renders
`-> (Tensor, Tensor)` with nothing to declare about aliasing.
`transpose_scale` shuffles the scale's contents inside the kernel without
moving its shape, so it does not appear in the fake.

Verified:
  * `infer_schema(native, mutates_args="unknown")` renders a schema.
  * Shapes checked on meta tensors against the native body's two branches:
    default -> (m, n // group_size); `scale_layout_m32k4` ->
    ((m + 31) // 32 * 32, n // 32); `transpose_scale` moves neither.
  * `tests/test_plugin_contracts.py` passes on this branch (16), and the
    contract fingerprint is unchanged -- the contract is taken from the
    native signature, which this does not touch, so no op_version bump.
  * Merged locally with #7881, whose registration gate reports
    `per_group_quant` as unregistered without this commit and passes with
    it (18).

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

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: root <[email protected]>
zufayu added a commit that referenced this pull request Nov 13, 2026
…cit mutates_args (#7926)

* [Plugin] Fix auto_functionalized_v2 assert: route() gains explicit mutates_args

#7881 registering fake= for gemm_a8w8_blockscale made the op an opaque
custom op whose schema infers with mutates_args="unknown", so every tensor
arg is declared writable. torch 2.10 inductor then wraps the op in
auto_functionalized_v2 and its post-grad decompose fails to remove it
(torch _inductor/fx_passes/post_grad.py:1337 assertion), failing
op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py::test_public_group32_compile_dynamic_rows
deterministically on main (interim greens were shard-skipped vacuous runs).

- route()/_as_custom_op() take explicit mutates_args, same knob as
  torch_compile_guard; default "unknown" preserves current behavior.
- gemm_a8w8_blockscale writes through no argument -> mutates_args=[].
- rmsnorm_with_add writes out and residual_out -> declare exactly those
  (same latent failure waiting for compile coverage).

Verified locally: tests/test_plugin_contracts.py 18 passed. The GPU
compile test needs MI hardware; CI Triton Shard 0 should flip green.

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

* black: wrap rmsnorm_with_add route decorator (unblocks Black required check)

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

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>
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.

3 participants