Repository navigation
[RFC #7240] Document every routed contract, and gate that it stays documented - #7787
Conversation
…documented `plugin_contracts.json` pins a routed op's signature, which is names and arity. It cannot say what a parameter MEANS -- and the pair whose meanings differ is routinely the pair whose signatures look alike. An out-of-tree provider implements against the prose or against nothing. Four of the five routed ops on main had no docstring at all (`pertoken_quant`, `rmsnorm` v2, `rmsnorm_with_add`, `gemm_a8w8_blockscale_bpreshuffle`), and the fifth, `gemm_a8w8_blockscale`, documented its backend dispatch at length without ever saying what it returns. All five now state parameter meanings, shapes and -- the fact a signature cannot carry -- whether the op returns a new tensor or writes into the caller's. `fused_qk_norm_rope_cache_quant_shuffle` is documented here too. It is not routed on main; #7728 routes it, and this way that PR does not also have to carry the prose. Three gates keep it that way: every routed op has a docstring; every docstring says what it returns or writes; and the scan is pinned against the contract baseline so neither gate can pass by finding nothing. 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 |
The gate asserted `>= 10` routed ops -- a number taken from a tree where #7728 had already landed its seven. On `main` there are five, so the gate failed on the very thing it was added to protect. A count was the wrong pin anyway: it has to be revised every time an op is routed, and it is a weaker statement than the one already available. The cross-check against `plugin_contracts.json` is what actually proves the scan is live, so a non-empty scan plus that equality is the whole invariant. Also applies Black, which the repo's style gate runs and which disagrees with `ruff format` on how to wrap this file's asserts. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Merge order: this PR must land after #7728, not before. The gates here require every routed op to carry a docstring that states its output discipline. #7728 routes seven more contracts, and six of them already satisfy both gates — but The consequence is one-directional:
#7728 is approved and green-but-for-its-last-shards as of this comment, so the natural order is already the safe one. Flagging it only so that this PR getting an approval first does not invite the wrong one. Verified by scanning both trees: on #7728's head, the five ops already routed on main fail the gates (which is what this PR fixes), and of its own seven, only |
The previous run's merge commit was computed before #7774 landed, so it still carried the FlyDSL 0.5.0 test breakage. Nothing in this branch changes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Retry for a bit-exactness flake in test_flydsl_hgemm's graph replay (mismatch 0.00044), which this branch cannot have caused -- it adds docstrings and contract tests and touches no kernel. The run could not be re-run through the API, so this takes a fresh one and picks up main. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#7787 appended three gates to tests/test_plugin_contracts.py and this branch appends one, so the two collide at the end of the file. Both kept: main's gates first, this PR's sparse-prefill contract check after. Baseline regenerated with routed_contracts(): 13 contracts, main's 12 plus mla_sparse_prefill, none lost. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#7787 added three gates to tests/test_plugin_contracts.py and this branch adds four; git interleaved them because _routed_docstrings and _routed_function_names open with near-identical bodies, and the automatic resolution was not valid Python. Taken main's file whole and re-appended this PR's additions after it, rather than reconciling markers that cut through two functions at once. Baseline regenerated: 15 contracts, main's 12 plus the three attention entry points, none lost, and none carrying backend or kernelName. 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]>
…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]>
Why
tests/plugin_contracts.jsonpins a routed op's signature: parameter names, kinds, defaults, arity. That is the right thing for the contract gate to compare — but it cannot say what a parameter means, and meaning is where the damage is. Two entry points with identical arity and different meanings pass every check in the tree, and a provider bound to the wrong one returns a plausible wrong answer rather than failing.An out-of-tree provider implements against the prose, or against nothing.
Four of the five routed ops on
mainhad no docstring at all:pertoken_quantrmsnormv2 (_rms_norm_fwd_dispatch— thorough comments above the decorator explaining why it is routed there, nothing stating the contract itself)rmsnorm_with_addgemm_a8w8_blockscale_bpreshuffleThe fifth,
gemm_a8w8_blockscale, documents its config-first backend dispatch at length and never says what it returns.What each one gained
Parameter meanings and shapes, and the one fact a signature cannot carry — whether the op returns a new tensor or writes into the caller's:
pertoken_quant(y, y_scale); nothing written in place. Also: the reduction is over the last axis (which is what letsper_block_quant_wrapperreuse it),x_scaleis a smoothquant input rather than the output scale, and a zero-amax row's scale is forced to 1 so an all-zero row quantizes to zeros instead of NaNrmsnormv2inputis read-only — v1 wrote into it, which is why a v1 kernel is not offered a v2 callrmsnorm_with_addoutandresidual_out;residual_outmay aliasresidual_inbut notoutgemm_a8w8_blockscale[M, N]; there is no caller-owned buffer on this contractgemm_a8w8_blockscale_bpreshuffleout=so the result lands at a fixed address (what lets the consumer be captured into a cudagraph without a per-step copy); the triton fallbacks cannot honour it and assert rather than silently returning a different addressfused_qk_norm_rope_cache_quant_shuffleis documented here too — in place,q/krewritten, K/V scattered into the paged caches, a negativeslot_mappingentry skipping the cache write while still rewritingq/k. It is not routed onmain; #7728 routes it, and this way that PR does not also have to carry the prose.Semantics were read out of the implementations, and for the fused op out of its torch reference in
op_tests/test_fused_qk_norm_rope_cache_quant.py— not inferred from the names.The gates
Prose rots unless something fails when it goes missing. Three tests in
tests/test_plugin_contracts.py, reusing the existing_route_spellings/_is_routescanner:test_every_routed_op_documents_its_contract— a routed op with no docstring ships a contract nobody outside this tree can read.test_every_routed_op_says_whether_it_returns_or_writes— the docstring must state the output discipline. The worked example in the test comes from RFC: decouple backend names from public op definitions (start with MoE) #7150:gemm_a8w8_ck(XQ, WQ, x_scale, w_scale, Out, bias=None, splitK=0)next togemm_a8w8(XQ, WQ, x_scale, w_scale, bias=None, dtype=bf16, splitK=None)— seven parameters each, and the fifth is an output buffer in one and a bias in the other. Neither the names nor the arity catch it. This gate caught the realgemm_a8w8_blockscalegap above; it was not written to pass.test_the_documentation_gate_is_not_vacuous— both gates above pass trivially if the scan finds nothing, so this pins the scan against the contract baseline rather than against a hard-coded count.Mutation-checked:
pertoken_quant)tests/test_plugin.py+tests/test_plugin_contracts.py: 102 passed.ruff checkclean. No functional change — docstrings and tests only.One scope note:
aiter/ops/fused_qk_norm_rope_cache_quant.pydoes not satisfyruff formatonmaintoday (anassertat:497, untouched here). This PR deliberately leaves that alone rather than folding an unrelated reformat into a docs change.Related: #7240 (the interface), #7728 (routes seven more contracts, which these gates will then require prose for), #7150 (where the arity-identical / meaning-different trap was worked through), #6689 (the
CONTRACT.mdsheet this follows in spirit — that op moved its implementation out of tree and needed a standalone sheet; these keep their native in-tree, so a docstring beside the code is the version that cannot drift from it).🤖 Generated with Claude Code