Repository navigation
[Plugin] Register the routed ops that can be, and gate the rest - #7881
Conversation
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]>
🏷️ 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 |
… 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]>
…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]>
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]>
…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]>
…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]>
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:
rmsnorm_with_addNone; every result is an in-place write, so there is no value a fake can get wronggemm_a8w8_blockscalegemm_a8w8_blockscale_fake, which its owntorch_compile_guardalready runs in production asgen_fake=tests/plugin_contracts.jsonis unchanged: addingfake=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_notfails:fake=;torch_compile_guardsits outside its@route, so a caller already reaches an opaque op — detected from decorator order, never listed, so it cannot go stale;_NOT_REGISTEREDwith 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:
opcheckArgument out is not defined to alias output but was aliasingThe silent case is why these wait. Fixing it means dropping the buffer from the contract, which moves the signature and so needs an
op_versiondecision. #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, notx:positional:Tensor).infer_schemaneeds annotations, and adding them moves the rendered signature and therefore the fingerprint — indistinguishable, to the gate, from a real contract change. Sameop_versiondecision, and it should be made once for all five rather than per PR.pertoken_quantcarries 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 forsilu+amax+ divide + the consumer, against two inductor kernels plus the op's own launches once registered. Registration happens atimport aiterandAITER_PLUGINS=0does 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_fwdtakes aQuantType.Validation
On gfx942, torch 2.9.1:
op_tests/test_rmsnorm2d.pyrun against this tree and against its base: both exit 0, and the full logs are identical once timings are excluded;rmsnorm_with_addoutput is bit-identical to base, reproducibly (alternating runs);OpOverloadPacketundertorch.ops.aiter_routed;0.60 of one Signature.bind;black,ruff checkclean;tests/plugin_contracts.jsonuntouched.The gate was mutation-checked rather than assumed:
fake=fromrmsnorm_with_addrouted ops that are neither registered nor explained: rmsnorm_with_addfake=topa_fwd, leaving it listedops listed as not registered that now pass fake=: pa_fwdUnverified:
gemm_a8w8_blockscalecould not be exercised numerically here —module_gemm_a8w8_blockscalefails 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:allis set so a runner that can build it exercises it.🤖 Generated with Claude Code
PR Self-Review
Reviewed revision
bd24c81e35e027500cec33c323e14537d1922af1Behavior 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.pyon this tree and on its base: both exit 0, full logs identical once timings are excluded;rmsnorm_with_addis bit-identical to base across alternating runs;OpOverloadPacketundertorch.ops.aiter_routed;0.60 of one Signature.bind;tests/plugin_contracts.jsonuntouched, which is the invariant for this change:fake=is a decorator argument, not a signature;black,ruff checkclean.Unverified:
gemm_a8w8_blockscaleis not exercised numerically here —module_gemm_a8w8_blockscalefails to JIT-build on this box, identically on the base tree, so the failure is environmental. Its fake is the one its owntorch_compile_guardalready ships asgen_fake=.ci:allis 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; addingfake=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 forgemm_a8w8_blockscaleis 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.pyA/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.pywas run against both trees; it is not modified.