Repository navigation
[RFC #7240] Build the plugin config snapshot at import, not on first dispatch - #7848
Conversation
A routed op's first call in a process acquired a lock and read an
environment variable, because the config snapshot was built lazily. Dynamo
can trace neither, so that call graph-breaks: the region compiles as two
graphs instead of one, and a framework that permits a single backend
invocation per compilation is handed a second and asserts.
Measured with a counting backend, each case in its own process:
plain function 1 graph
routed op, snapshot unbuilt 2 graphs <- the break
routed op, snapshot built 1 graph
Nothing else on the dispatch path breaks, so building the snapshot at
import is the whole fix. The hot path was already a plain global read for
every call after the first; this makes the first one no different.
The lazy branch in _config() stays, because _reset_for_testing clears the
snapshot and a test that clears it must not become the call that rebuilds
it inside somebody's graph.
tests/test_plugin_compile.py pins both halves -- one graph per compiled
region, and nothing left to build when dispatch starts -- in subprocesses,
since the breakage is first-call-only and torch._dynamo state is global.
Removing the fix fails both.
This is the coverage #7465 and #7728 lacked: every test of the interface
so far has been eager, and an eager test cannot see a graph boundary.
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: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
Reproduced on GPU, with the failure it was inferred fromThe PR body measures graph counts. On an 8-GPU gfx942 box I reproduced the downstream symptom itself, using the real dispatcher and a backend carrying the same single-invocation constraint ATOM's does: So the defect does not merely split a graph in the abstract — it produces that exact error. The trigger condition, measuredThe break is first-call-only, and that turns out to matter more than it sounds:
A single eager dispatch anywhere before compilation builds the snapshot and protects everything after it. So whether a given deployment hits this depends on where its first routed call lands, not on how many routed ops it uses. That gives a one-line check that needs no new wheel, for anyone currently red: import aiter.plugin
aiter.plugin._config() # or any eager call to a routed opearly in startup. If the failure disappears, this is the cause and that is also an immediate workaround; if it does not, this PR is not the fix for that failure and the search should continue elsewhere. Worth running before a pin-the-wheel A/B, because the answer is binary and arrives in one run. What this PR does not fixWith a provider enabled, dispatch continues past the fast path into
Nobody ships a provider yet, so this is not urgent — but it is the configuration the interface exists for, and it will surface the day one arrives.
The shape that is correct for a mutating op is the one three routed ops already have: registration as a custom op with its mutations declared, i.e. Environmentgfx942, torch 2.9.1, 8 GPUs. The native in the probe is plain torch rather than a kernel: the installed AITER on that box cannot load |
Reproduced with a real routed op, and the reason it is this set of opsEarlier evidence here used synthetic ops because the box could not import AITER. That is fixed (
So the fix holds end to end on a real op, not only on a probe. Why some routed ops were never at riskThe same test with The difference is not the op, it is what a caller reaches:
I had this wrong in my own earlier analysis on #7150 and in the first comment here: I classified exposure by the decorator on the routed function, when what matters is whether a guard sits between the caller and the dispatcher. For That also answers a question I could not answer before — why a deployment using routed ops for weeks only broke recently. The routed ops it was already using were the shielded kind. Schema feasibility on the real opsRelevant to #7850 rather than this PR, measured now that the package imports — of fifteen routed ops, eight infer a schema today and could become opaque given a fake; two more ( Environmentgfx942, torch 2.9.1, AITER at this branch's base with its built kernels. |
#7848 landed the eager config snapshot in the same file this branch rewrites. Merged cleanly; verified both halves survive rather than assuming an absent conflict marker means an intact result -- the snapshot is built at import, _as_custom_op is intact, and the first registered op still comes back as an OpOverloadPacket. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#7850) * feat(plugin): let a routed op be an opaque node instead of traced Python torch.compile traces through the routing wrapper, so a routed op puts this module's dispatch inside the caller's graph. Anything in there that Dynamo cannot follow splits that graph, and a framework permitting one backend invocation per compilation then fails. #7848 removed the one such thing on the fast path; with a provider enabled, dispatch continues into provider selection and the break comes back. `route(..., fake=...)` registers the op with torch instead: one node, and nothing inside it reachable from the caller's graph. Measured, provider enabled, against a counting backend: traced wrapper 2 graphs registered 1 graph, provider's kernel served Registration is opt-in per op and failure to register is an outcome rather than an error. No fake, an unannotated parameter, an argument no schema can express -- each leaves the op exactly as it is today. Nothing regresses for any op at any point, and an op becomes protected the day it acquires what registration needs. No op in the tree passes `fake=` yet, so this change alters the behaviour of nothing; it makes the behaviour available. `mutates_args="unknown"` rather than a per-op list: a list has to be right for every op anyone adds later, and under-declaring is undefined behaviour rather than an error. "unknown" is never wrong, only conservative. It was not observed to change results either way under inductor, and the comment says so rather than claiming it prevents a failure that has been seen. tests/test_plugin_custom_op.py, in subprocesses, pins: one graph for a registered op; an op writing through an argument still correct with the compiled region reading that buffer; a provider still served; and each way of being unregisterable leaving the op traced and correct. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Register the first routed op, and fix a test that proved nothing `fused_qk_norm_rope_cache_quant_shuffle` returns None and writes through its arguments, so its fake is `return None` -- correct by inspection rather than by shape arithmetic, which makes it the right op to be first. Its public name is the routed function with no guard above it, so it was one of the ops whose dispatch a caller's compiled graph could reach. A/B against op_tests/test_fused_qk_norm_rope_cache_quant.py on gfx942: 6 failed, 5 passed, 4 errors both with and without the registration -- identical, so the failures are this box (a gfx950 path) and the change introduces none of them. A deselected test is broken on main: it takes eleven positional arguments pytest never supplies. The test fix matters more than it looks. tests/test_plugin_custom_op.py asked `hasattr(op, "_schema")` to tell a registered op from a Python wrapper. `_schema` is on an OpOverload, not on the OpOverloadPacket that route hands back, so that answered False either way and the assertion that an unregisterable op stays traced passed without checking anything. Now it asks the type, and forcing registration without a fake fails it. 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]>
…ch (#7848) A routed op's first call in a process acquired a lock and read an environment variable, because the config snapshot was built lazily. Dynamo can trace neither, so that call graph-breaks: the region compiles as two graphs instead of one, and a framework that permits a single backend invocation per compilation is handed a second and asserts. Measured with a counting backend, each case in its own process: plain function 1 graph routed op, snapshot unbuilt 2 graphs <- the break routed op, snapshot built 1 graph Nothing else on the dispatch path breaks, so building the snapshot at import is the whole fix. The hot path was already a plain global read for every call after the first; this makes the first one no different. The lazy branch in _config() stays, because _reset_for_testing clears the snapshot and a test that clears it must not become the call that rebuilds it inside somebody's graph. tests/test_plugin_compile.py pins both halves -- one graph per compiled region, and nothing left to build when dispatch starts -- in subprocesses, since the breakage is first-call-only and torch._dynamo state is global. Removing the fix fails both. This is the coverage #7465 and #7728 lacked: every test of the interface so far has been eager, and an eager test cannot see a graph boundary. Co-authored-by: zufayu <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
#7850) * feat(plugin): let a routed op be an opaque node instead of traced Python torch.compile traces through the routing wrapper, so a routed op puts this module's dispatch inside the caller's graph. Anything in there that Dynamo cannot follow splits that graph, and a framework permitting one backend invocation per compilation then fails. #7848 removed the one such thing on the fast path; with a provider enabled, dispatch continues into provider selection and the break comes back. `route(..., fake=...)` registers the op with torch instead: one node, and nothing inside it reachable from the caller's graph. Measured, provider enabled, against a counting backend: traced wrapper 2 graphs registered 1 graph, provider's kernel served Registration is opt-in per op and failure to register is an outcome rather than an error. No fake, an unannotated parameter, an argument no schema can express -- each leaves the op exactly as it is today. Nothing regresses for any op at any point, and an op becomes protected the day it acquires what registration needs. No op in the tree passes `fake=` yet, so this change alters the behaviour of nothing; it makes the behaviour available. `mutates_args="unknown"` rather than a per-op list: a list has to be right for every op anyone adds later, and under-declaring is undefined behaviour rather than an error. "unknown" is never wrong, only conservative. It was not observed to change results either way under inductor, and the comment says so rather than claiming it prevents a failure that has been seen. tests/test_plugin_custom_op.py, in subprocesses, pins: one graph for a registered op; an op writing through an argument still correct with the compiled region reading that buffer; a provider still served; and each way of being unregisterable leaving the op traced and correct. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Register the first routed op, and fix a test that proved nothing `fused_qk_norm_rope_cache_quant_shuffle` returns None and writes through its arguments, so its fake is `return None` -- correct by inspection rather than by shape arithmetic, which makes it the right op to be first. Its public name is the routed function with no guard above it, so it was one of the ops whose dispatch a caller's compiled graph could reach. A/B against op_tests/test_fused_qk_norm_rope_cache_quant.py on gfx942: 6 failed, 5 passed, 4 errors both with and without the registration -- identical, so the failures are this box (a gfx950 path) and the change introduces none of them. A deselected test is broken on main: it takes eleven positional arguments pytest never supplies. The test fix matters more than it looks. tests/test_plugin_custom_op.py asked `hasattr(op, "_schema")` to tell a registered op from a Python wrapper. `_schema` is on an OpOverload, not on the OpOverloadPacket that route hands back, so that answered False either way and the assertion that an unregisterable op stays traced passed without checking anything. Now it asks the type, and forcing registration without a fake fails it. 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]>
What breaks
A routed op's first call in a process acquires a lock and reads an environment variable, because the config snapshot is built lazily:
torch.compile traces through the dispatcher — routing replaces a direct call with a Python wrapper, so whatever that wrapper does becomes part of the trace. That first call therefore graph-breaks, and the compiled region comes out as two graphs instead of one.
A framework that permits one backend invocation per compilation is then handed a second one and asserts. ATOM's is
VllmBackend can only be called once.Measured, not inferred
A counting backend, each case in its own process (the breakage is first-call-only and
torch._dynamostate is global):Nothing else on the dispatch path breaks, so building the snapshot eagerly is the whole fix. Confirmed on the same harness: 2 → 1.
The kill switch does not avoid it
AITER_PLUGINSis read inside the function that breaks, so turning plugins off does not turn this off. Worth knowing before anyone uses it as a control in an A/B: it will not go green, and that is not evidence the plugin is uninvolved.The change
Three lines at the end of the module. The hot path was already a plain global read for every call after the first; this makes the first one no different.
The lazy branch stays in
_config()because_reset_for_testingclears the snapshot, and a test that clears it must not become the call that rebuilds it inside somebody's graph.tests/test_plugin_overhead.pyis unchanged and still passes at0.58 of one Signature.bind.Why not the alternatives
torch.compiler.disableon_dispatchallow_in_graphon the wrappertorch_compile_guardoutside@routeper opThis one is in the interface, so all twelve routed ops are covered at once.
Tests
tests/test_plugin_compile.py, in subprocesses:test_a_routed_op_compiles_into_a_single_graph— one compiled region, one graph.test_the_config_snapshot_exists_before_any_dispatch— read before anything dispatches, since a lazily built snapshot would also be set by the time a model has run. Asking afterwards proves nothing, and the first version of this test made exactly that mistake.Removing the fix fails both. 117 tests pass across the plugin suites;
blackandruffclean.What this does not cover
Only the provider-disabled path is measured. With a provider enabled, dispatch goes on through
_eligibleand_ask_provider, which I have not checked for graph breaks. That does not affect anyone today — nothing ships a provider — but it is the next thing to measure before one does.Provenance
This is the coverage #7465 and #7728 lacked. Every test of this interface so far has been eager, and an eager test cannot see a graph boundary: the op returns the right answer either way. The defect is in the interface (#7465); #7728 is what put a routed op inside a compiled region and exposed it.
It is not established that this is the cause of any particular downstream failure — that needs a run with
TORCH_LOGS=+dynamoon the affected machine, which this PR does not have.🤖 Generated with Claude Code