Skip to content

[RFC #7240] Document every routed contract, and gate that it stays documented - #7787

Merged
zufayu merged 5 commits into
mainfrom
codex/plugin-contract-sheets
Nov 11, 2026
Merged

zufayu merged 5 commits into
mainfrom
codex/plugin-contract-sheets

Conversation

@zufayu

@zufayu zufayu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Why

tests/plugin_contracts.json pins 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 main had no docstring at all:

  • pertoken_quant
  • rmsnorm v2 (_rms_norm_fwd_dispatch — thorough comments above the decorator explaining why it is routed there, nothing stating the contract itself)
  • rmsnorm_with_add
  • gemm_a8w8_blockscale_bpreshuffle

The 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:

op output discipline now stated
pertoken_quant returns (y, y_scale); nothing written in place. Also: the reduction is over the last axis (which is what lets per_block_quant_wrapper reuse it), x_scale is 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 NaN
rmsnorm v2 allocates its own output; input is read-only — v1 wrote into it, which is why a v1 kernel is not offered a v2 call
rmsnorm_with_add writes both out and residual_out; residual_out may alias residual_in but not out
gemm_a8w8_blockscale returns a new [M, N]; there is no caller-owned buffer on this contract
gemm_a8w8_blockscale_bpreshuffle optional out= 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 address

fused_qk_norm_rope_cache_quant_shuffle is documented here too — in place, q/k rewritten, K/V scattered into the paged caches, a negative slot_mapping entry skipping the cache write while still rewriting q/k. It is not routed on main; #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_route scanner:

  1. test_every_routed_op_documents_its_contract — a routed op with no docstring ships a contract nobody outside this tree can read.
  2. 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 to gemm_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 real gemm_a8w8_blockscale gap above; it was not written to pass.
  3. 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:

mutation caught by
delete a routed op's docstring gate 1
reword a docstring so it never says return/write gate 2 (named pertoken_quant)
break the shared scanner so it finds nothing gate 3 — though in practice the pre-existing baseline tests fire on that too, since the scanner is shared

tests/test_plugin.py + tests/test_plugin_contracts.py: 102 passed. ruff check clean. No functional change — docstrings and tests only.

One scope note: aiter/ops/fused_qk_norm_rope_cache_quant.py does not satisfy ruff format on main today (an assert at :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.md sheet 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

…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]>
@zufayu
zufayu requested a review from a team November 11, 2026 03:15
@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 7787 --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 11, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 1d86aeed301c · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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]>
@zufayu

zufayu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

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 fused_qk_norm_rope_cache_quant_shuffle does not: it has no docstring on that branch. Its prose is in this PR, deliberately, so #7728 did not have to carry documentation work as well as routing.

The consequence is one-directional:

order result
#7728 → this PR fine. On merge, main has twelve routed ops; the six from #7728 pass both gates already, and this PR supplies the other six
this PR → #7728 #7728 goes red. It would be adding a routed op with no docstring to a tree that now forbids exactly that

#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 fused_qk_norm_rope_cache_quant_shuffle does.

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]>
zufayu and others added 2 commits November 11, 2026 15:11
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]>
@zufayu
zufayu merged commit 342aa1d into main Nov 11, 2026
@zufayu
zufayu deleted the codex/plugin-contract-sheets branch November 11, 2026 12:34
zufayu added a commit that referenced this pull request Nov 11, 2026
#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]>
zufayu added a commit that referenced this pull request Nov 11, 2026
#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]>
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
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants