Skip to content

[JIT] [Build] [Prototype] Route rmsnorm and pertoken_quant through the kernel provider interface - #7123

Closed
zufayu wants to merge 3 commits into
ROCm:mainfrom
zufayu:codex/aklr-day30-route-ops
Closed

zufayu wants to merge 3 commits into
ROCm:mainfrom
zufayu:codex/aklr-day30-route-ops

Conversation

@zufayu

@zufayu zufayu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7086 (the provider interface spike). This branch contains that PR's commits plus one new commit — only Route rmsnorm and pertoken_quant through the kernel provider interface is new here. Review #7086 first; once it merges, this PR's diff automatically reduces to the single new commit.

Summary

  • route the first two production ops through the kernel provider interface ([Prototype] Validate AITER kernel provider interface #7086): aiter.rmsnorm (op rmsnorm, v1) and aiter.pertoken_quant (op pertoken_quant, v1)
  • restore the public op signature on compile_ops wrappers: the guard closure answered inspect.signature() with (*args, **kwargs), which would have made the provider contract vacuous for every JIT op; both ffi branches now point __wrapped__ at the stub
  • default behavior is unchanged: installing a provider never enables it, so both ops stay native until a framework or user opts in (AITER_PLUGIN_ENABLE / AITER_PLUGIN_FORCE)

Why the compile_ops fix is in this PR

The provider contract is captured from the routed function's signature at decoration time. For JIT ops that signature was (*args, **kwargs) — no enforcement, no defaults applied, providers would see raw call style. The one-line-per-branch __wrapped__ fix restores introspection for every compile_ops op (e.g. signature(aiter.smoothquant_fwd) now shows (out, input, x_scale, y_scale)) and is the prerequisite for routing any JIT op, so it belongs with the first one.

What a provider sees for these ops

  • rmsnorm: (out, input, weight, epsilon, gemma_norm=False) — canonicalized, defaults applied, call style normalized
  • pertoken_quant: (x, scale=None, x_scale=None, scale_dtype, quant_dtype, dtypeMax=None), returns (y, y_scale)

Validation

  • pytest -q tests/ — 162 passed, 8 subtests (16 in test_plugin.py, incl. 4 new: contract registration + public signatures, native-by-default on CPU, provider-served rmsnorm without a GPU — a served call never reaches the ROCm kernel — canonicalized provider args)
  • GPU smoke (MI300X-class, gfx942): native rmsnorm matches the bf16-quantized torch reference exactly; provider-served, declined-to-native, and pertoken_quant paths all verified with observable Decision provenance
  • ruff check / black --check / git diff --check clean

Known cost (deferred to the RFC)

Every routed call pays the dispatch check (~4 µs, no-provider path: env reads + empty eligibility + Decision record). For these two ops that is negligible next to kernel time; the 11-op rollout needs the hot-path optimization first (single env read, empty-provider fast path).

Related

  • #7240 — RFC: Versioned Kernel Provider Interface for AITER. The umbrella RFC for this work: ownership model, semantic op contracts, failure boundary, and the two-op initial rollout.

  • RFC: decouple backend names from public op definitions (start with MoE) #7150 — RFC: decouple backend names from public op definitions. The provider interface makes op contracts backend-neutral; that RFC tracks removing backend suffixes from public op names so the rest of the op surface can route the same way.

Author self-review

Reviewed revision

26a37687a658291611ee6f84013c048207dac738

Behavior and intent

Routes the first two production ops through the kernel provider interface (#7086): aiter.rmsnorm (op rmsnorm, v1) and aiter.pertoken_quant (op pertoken_quant, v1). Default behavior is unchanged — installing a provider never enables it, so both ops stay native until a framework or user opts in. Also restores the public signature on compile_ops wrappers (both ffi branches point __wrapped__ at the stub) so the provider contract is not vacuous for JIT ops.

Validation and unverified scope

pytest -q tests/ — 162 passed, 8 subtests (16 in test_plugin.py, incl. 4 new); GPU smoke on MI300X-class (gfx942): native rmsnorm matches the bf16-quantized torch reference exactly, provider-served / declined-to-native / pertoken_quant paths verified with observable Decision provenance; ruff / black / git diff --check clean; standard CI suite green on MI35X. Unverified: multi-GPU (8-GPU) runs, non-MI300X/MI355X targets, and the hot-path dispatch cost at scale (deferred to the RFC before the 11-op rollout).

PR-specific question

What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path? The compile_ops change only sets __wrapped__ on the already-built wrapper — no dependency, cache-key, or compilation-behavior change; JIT compilation and caching are untouched. import aiter now imports the stdlib-only aiter.plugin module via the two routed ops; entry-point discovery stays lazy (first routed call), so import cost is the module itself. Verified against the existing JIT cache: the full suite (162 passed) exercises compile_ops ops with the cache warm, and inspect.signature(aiter.smoothquant_fwd) now shows the public signature. Unverified: cold-cache full-rebuild timing (no cache wipe was performed).

Changed op tests

None — this PR extends tests/test_plugin.py (4 new interface tests); no op_tests/ file changes.

🤖 Generated with Claude Code

zufayu and others added 3 commits October 28, 2026 16:58
Installing a provider never makes it the default: dispatch now serves a
provider only when it is explicitly enabled (AITER_PLUGIN_ENABLE) or
forced (AITER_PLUGIN_FORCE). This makes the ownership boundary concrete:
AITER owns the op contract and execution rules, providers own their
kernels and qualification evidence, frameworks and users own enablement.

- document the ownership boundary in the module docstring
- isolate invalid candidates returned by select(): fall back to native
  with reason "invalid-candidate" instead of raising AttributeError
- document that entry points must target an instance or zero-arg factory
- tests: installed-but-not-enabled is inert (select never called);
  non-candidate select() results fall back to native

Co-Authored-By: Claude Code <[email protected]>
First two production ops on the provider path (Day-30 of the AKLR
integration plan). Default behavior is unchanged: dispatch serves a
provider only when explicitly enabled (AITER_PLUGIN_ENABLE) or forced
(AITER_PLUGIN_FORCE), so these ops stay native until a framework or user
opts in.

compile_ops wrappers destroyed the public op signature: the guard's
closure answers inspect.signature() with (*args, **kwargs), which would
have made the provider contract vacuous for every JIT op. Point
__wrapped__ at the stub in both ffi branches so the public signature is
introspectable again; aiter.plugin.route captures it as the op contract.

- route aiter.rmsnorm (op "rmsnorm", v1) and aiter.pertoken_quant
  (op "pertoken_quant", v1) at their definition sites
- tests: contract registration and public signatures, native-by-default
  on CPU, provider-served calls (rmsnorm provable without a GPU: a
  served call never reaches the ROCm kernel), canonicalized provider
  args with defaults applied
- GPU smoke: native rmsnorm matches the bf16-quantized torch reference
  exactly; provider path, decline fallback, and pertoken_quant verified

Co-Authored-By: Claude Code <[email protected]>
@zufayu
zufayu requested a review from a team October 29, 2026 03:18
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 7123 --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.

@github-actions github-actions Bot changed the title [Prototype] Route rmsnorm and pertoken_quant through the kernel provider interface [JIT] [Build] [Prototype] Route rmsnorm and pertoken_quant through the kernel provider interface Oct 29, 2026
@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 26a37687a658 · 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

Routes the first two production ops through the kernel provider interface (#7086): `aiter.rmsnorm` (op `rmsnorm`, v1) and `aiter.pertoken_quant` (op `pertoken_quant`, v1). Default behavior is unchanged — installing a provider never enables it, so both ops stay native until a framework or user opts in. Also restores the public signature on `compile_ops` wrappers (both ffi branches point `__wrapped__` at the stub) so the provider contract is not vacuous for JIT ops.

Validation and unverified scope

`pytest -q tests/` — 162 passed, 8 subtests (16 in `test_plugin.py`, incl. 4 new); GPU smoke on MI300X-class (gfx942): native `rmsnorm` matches the bf16-quantized torch reference exactly, provider-served / declined-to-native / `pertoken_quant` paths verified with observable `Decision` provenance; `ruff` / `black` / `git diff --check` clean; standard CI suite green on MI35X. Unverified: multi-GPU (8-GPU) runs, non-MI300X/MI355X targets, and the hot-path dispatch cost at scale (deferred to the RFC before the 11-op rollout).

PR-specific question

*What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?* The `compile_ops` change only sets `__wrapped__` on the already-built wrapper — no dependency, cache-key, or compilation-behavior change; JIT compilation and caching are untouched. `import aiter` now imports the stdlib-only `aiter.plugin` module via the two routed ops; entry-point discovery stays lazy (first routed call), so import cost is the module itself. Verified against the existing JIT cache: the full suite (162 passed) exercises `compile_ops` ops with the cache warm, and `inspect.signature(aiter.smoothquant_fwd)` now shows the public signature. Unverified: cold-cache full-rebuild timing (no cache wipe was performed).

Changed op tests

None — this PR extends `tests/test_plugin.py` (4 new interface tests); no `op_tests/` file changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • WAIT — pull request is still a draft

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 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #7484, which carries this work:

  • the @route decorators on rmsnorm and pertoken_quant, unchanged;
  • the __wrapped__ fix in aiter/jit/core.py, with the reasoning for why it is
    a prerequisite rather than a side change: without it a compiled op reports
    (*args, **kwargs), so no per-op binder can be generated and
    apply_defaults() has nothing to apply;
  • the four end-to-end tests, moved to tests/test_plugin_routed_ops.py so the
    interface's own tests stay buildless and can gate every PR without a GPU
    runner ([CI] Run the provider interface tests as a CPU-only gate on every PR #7466);
  • tests/plugin_contracts.json, recording both signatures so that changing
    either without an op_version bump fails CI.

#7484 also states what is actually covered, which this PR did not: rmsnorm
here is the low-level HIP binding rather than a public entry point, so a
provider sees only the _use_hip_common() branch; rmsnorm2d_fwd_with_add —
the residual-add path vLLM-ROCm uses — is not routed at all; and
pertoken_quant is the torch reference implementation, reused by
per_block_quant_wrapper.

Note for whoever revises RFC #7240: its Initial rollout section cites this PR
number, and that reference should move to #7484.

@zufayu zufayu closed this Nov 5, 2026
zufayu added a commit to zufayu/aiter that referenced this pull request Nov 7, 2026
inspect.Signature.bind is generic: it re-derives the parameter mapping on every
call. Measured against the two signatures ROCm#7123 routes, that is 4.57us for
rmsnorm and 6.05us for pertoken_quant -- on its own more than any plausible
dispatch budget, and the step that dominated the hot path.

The signature is already known when route() decorates the op, so the binder is
now generated once, at decoration. The generated function produces exactly what
bind() + apply_defaults() produce, raises the same TypeError on a malformed
call, and costs 0.076us / 0.083us. Defaults travel through the generated
function's namespace rather than through source text, because a default such as
dtypes.fp32 has no parseable repr. Signatures with *args/**kwargs, or with a
parameter that would collide with an injected default, fall back to
Signature.bind.

This sits below the API boundary: providers receive the same canonical
arguments, callers call the same way, and api_version does not move.

tests/test_plugin_overhead.py measures the whole path and prints the numbers,
which is what RFC ROCm#7240's first milestone actually asks for. On a Xeon
Platinum 8480C with Python 3.12.12, overhead over a direct native call:

    provider serves        1.79us
    no provider enabled    1.42us
    AITER_PLUGINS=0        1.19us
    one Signature.bind     4.85us

So the 1us design budget is not met yet, and the per-step projection that
suggested it would be (~0.9us) was optimistic: it omitted the Python call chain
and the per-call bookkeeping that only an end-to-end measurement sees. Decision
construction plus the ContextVar set is 0.787us of what remains, and is now the
largest single item.

The gate asserts what can be defended on unknown hardware: the whole aiter-side
overhead must cost less than one Signature.bind of the same signature, measured
in the same process. That fails the moment generic canonicalization, a per-call
getenv, or a rebuilt provider list returns, on any runner. The 1us budget is
reported rather than asserted until CI runner hardware is characterised.

Co-Authored-By: Claude Code <[email protected]>
zufayu added a commit to zufayu/aiter that referenced this pull request Nov 7, 2026
Reading the RFC itself rather than our proposal answering it turned up three
places where the implementation did not do what the interface describes.

**Routed signatures were never checked for stability.** The RFC lists it among
the checks that block every AITER PR: "verification that routed public
signatures still match their contracts". route() captures the signature at
decoration, so it always agrees with itself -- the check was vacuously true. A
routed op's public signature is its contract, so changing it moved the contract
under every installed provider with no op_version bump and nothing to notice.

tests/test_plugin_contracts.py reads the routed signatures out of the source and
compares them with a committed baseline. It is a static scan rather than an
import: no GPU, no toolchain, and no list of "modules that route ops" for
somebody to forget to extend. A changed signature fails unless version= moved
with it; a removed routed op fails as a contract removal. Validated against the
two ops ROCm#7123 routes, including a non-literal default (dtypes.fp32).

**A provider could only declare one API version.** The RFC says a provider
declares "supported Provider API versions", plural, and lists independent
release cadence among its goals -- which needs one provider release to cover
several AITER versions. Providers now declare api_versions and are served on the
newest version both sides share. The single api_version spelling still works and
says so once, through the same window machinery.

**A duplicate provider name was a tie to break.** Two entry points answering to
one name made AITER_PLUGIN_ENABLE, AITER_PLUGIN_FORCE and every Decision
ambiguous, and let install order decide which served. The second is now skipped
with a reason in status(). Skipped, not raised: the RFC requires that a broken
install never break `import aiter`, which is the opposite of the duplicate
op-name rule, where the ambiguity is in AITER's own code.

Also: falling back to the generic binder now logs once. An op whose signature
cannot be generated against pays roughly sixty times the per-call cost, and
nothing said so.

Deliberately not implemented: the architecture, dtype, layout and shape coverage
declaration the RFC also describes. No form is defined for it, and a declaration
surface is public contract -- easier to add than to undo. A comment on the
Protocol records it; select() answers coverage per call until the form settles.

Co-Authored-By: Claude Code <[email protected]>
zufayu added a commit that referenced this pull request Nov 9, 2026
…y, provenance, observability (#7465)

* Prototype kernel provider interface

* Gate provider dispatch on explicit enablement

Installing a provider never makes it the default: dispatch now serves a
provider only when it is explicitly enabled (AITER_PLUGIN_ENABLE) or
forced (AITER_PLUGIN_FORCE). This makes the ownership boundary concrete:
AITER owns the op contract and execution rules, providers own their
kernels and qualification evidence, frameworks and users own enablement.

- document the ownership boundary in the module docstring
- isolate invalid candidates returned by select(): fall back to native
  with reason "invalid-candidate" instead of raising AttributeError
- document that entry points must target an instance or zero-arg factory
- tests: installed-but-not-enabled is inert (select never called);
  non-candidate select() results fall back to native

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

* Snapshot plugin configuration and honour the enable list order

Dispatch read four environment variables per call and rebuilt a set and a
frozenset each time, costing 2.49us of the hot path (measured). It also stored
enabled providers in a frozenset, which destroyed the enable list order, so
candidates were tried in alphabetical provider-name order instead of the
configured preference order.

Configuration is now an immutable snapshot built at first dispatch. Dispatch
reads one reference per call, so a call always runs against exactly one
generation; configure() and reload_config() build a new snapshot and swap the
reference under the config lock, leaving the hot path lock-free. Measured cost
of the gates drops to 0.048us. The eligible provider list is cached per
(op, config generation), get-or-build, and a build race is benign.

enabled is now an ordered tuple and the eligible list is built by walking it,
so the enable list order is the preference order it was specified to be.

Also:
- configure(*, source, enable, disable): source is required provenance; enable
  replaces the previous framework default, disable unions with the user's. All
  keyword-only, since a required parameter cannot follow a defaulted one.
- reload_config() re-reads the environment deliberately. Mid-process changes
  are not otherwise observed.
- A reload producing an identical snapshot does not bump the generation; a
  no-op bump would flush the eligible cache and churn provider resources.
- An empty environment value counts as unset, so AITER_PLUGIN_ENABLE="" falls
  through to the framework default rather than denying everything.

test_provider_arbitration_is_deterministic asserted that alpha wins from
"alpha, zebra" -- alphabetical order already produced that, so the test passed
against the bug. It is replaced by a case whose enable order contradicts
alphabetical order.

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

* Generate a per-op argument binder and measure dispatch end to end

inspect.Signature.bind is generic: it re-derives the parameter mapping on every
call. Measured against the two signatures #7123 routes, that is 4.57us for
rmsnorm and 6.05us for pertoken_quant -- on its own more than any plausible
dispatch budget, and the step that dominated the hot path.

The signature is already known when route() decorates the op, so the binder is
now generated once, at decoration. The generated function produces exactly what
bind() + apply_defaults() produce, raises the same TypeError on a malformed
call, and costs 0.076us / 0.083us. Defaults travel through the generated
function's namespace rather than through source text, because a default such as
dtypes.fp32 has no parseable repr. Signatures with *args/**kwargs, or with a
parameter that would collide with an injected default, fall back to
Signature.bind.

This sits below the API boundary: providers receive the same canonical
arguments, callers call the same way, and api_version does not move.

tests/test_plugin_overhead.py measures the whole path and prints the numbers,
which is what RFC #7240's first milestone actually asks for. On a Xeon
Platinum 8480C with Python 3.12.12, overhead over a direct native call:

    provider serves        1.79us
    no provider enabled    1.42us
    AITER_PLUGINS=0        1.19us
    one Signature.bind     4.85us

So the 1us design budget is not met yet, and the per-step projection that
suggested it would be (~0.9us) was optimistic: it omitted the Python call chain
and the per-call bookkeeping that only an end-to-end measurement sees. Decision
construction plus the ContextVar set is 0.787us of what remains, and is now the
largest single item.

The gate asserts what can be defended on unknown hardware: the whole aiter-side
overhead must cost less than one Signature.bind of the same signature, measured
in the same process. That fails the moment generic canonicalization, a per-call
getenv, or a rebuilt provider list returns, on any runner. The 1us budget is
reported rather than asserted until CI runner hardware is characterised.

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

* Isolate misbehaving providers, free the kill switch, record the config layer

Three changes that share the dispatch path.

**A misbehaving provider no longer denies service to a well-behaved one.** A
select() exception, and a candidate that is not a KernelCandidate or is owned by
somebody else, both removed the whole op from provider routing: the first one
encountered returned to native and the remaining providers were never asked.
That is correct with one provider and wrong with several. Both are now
pre-execution misbehaviour that removes that provider from this call only.

Native fallback happens when no provider serves. Reason precedence is two tiers:
either provider error outranks provider-declined -- a decline is normal
operation, an error is something someone must fix -- and within the error tier
the first one encountered is recorded, each keeping its own reason string.
Ranking provider-select-error against invalid-candidate would be arbitrary: both
mean the provider is broken, and either ranking still depends on iteration
order.

**The kill switch is now a free path.** With AITER_PLUGINS=0 dispatch checks one
cached flag and calls native, recording nothing: the feature is off, so there is
nothing to observe. Measured overhead over a direct native call drops from
1.19us to 0.141us. A per-op disable still records its Decision -- that op was
routed and deliberately turned off, which is what an operator is watching.

**Decision carries config_source**, naming the layer that produced the route:
"env", "configure:<source>", or "default-deny". An op-disabled route names the
layer that disabled it rather than the enable layer, so disabled_ops is now a
mapping from op name to its source; when both the framework and the user disable
an op, the user's act is the one named.

Measured on a Xeon Platinum 8480C, Python 3.12.12, overhead over a direct native
call: the serving path moves from 1.79us to 1.96us, paying one function call for
the isolation boundary and one more Decision field. The kill-switch path is
8.4x cheaper.

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

* Add the op registry and the four observability reads

RFC #7240 fixes what is observable but not how it is delivered. One record,
four reads: every layer consumes the same frozen Decision, and there are no
separate formats.

    last_decision()    per call        what served this call (already existed)
    status()           introspection   why is, or is not, X routed
    explain(op, ...)   introspection   the same question without executing
    decision_counts()  aggregation     what ran, how often, with what outcome
    on_decision(cb)    aggregation     inline, native routes included
    route-change log   audit trail     did routing flip when config changed

Reporting anything per op presumes routed ops are enumerable, which nothing
made true: Op and the contract lived only in route()'s closure. route() now
registers the op, and a duplicate op name is an error at import. Silent
last-wins would make routing depend on import order, which is exactly what the
enable list exists to avoid, and two routes claiming one name make op_version
unable to describe the contract anyway.

status() reports installed providers including the ones that were skipped and
why -- an installed provider that never serves is the first thing an operator
asks about, and that answer was previously only in the logs.

explain() dry-runs gates, eligibility and selection and returns the Decision the
call would produce plus why each provider declined. It never calls run(), never
records a Decision, and never counts one. It relies on select() being pure,
which is already a provider obligation.

on_decision() callbacks are called inline. A callback exception is swallowed,
logged once per callback rather than once per call, and counted in status(): a
telemetry bug must never break a kernel launch.

The route-change log is scoped to the config generation. Within one generation
the route is a deterministic function of the call arguments, so call-to-call
variation is provider behaviour -- visible in decision_counts() -- and not an
audit event. One line per op per generation, only when the route differs.

Every Decision now goes through a single _record(), so the four reads cannot
drift apart.

Cost, measured on a Xeon Platinum 8480C with Python 3.12.12: the serving path
moves from 1.96us to 2.42us. The layer is 0.46us, of which the counter
increment is the largest single piece at 0.166us, the route-change check 0.063us
and the empty callback loop 0.038us. This is the number the design estimated at
0.110us by counting the increment alone.

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

* Say that decision_counts() counts decisions, not launches

A CUDA graph replay runs no Python, so a captured op contributes one count for
the whole life of the graph however many times it replays. The counts are a
complete record of what was decided; read as a call mix they are wrong by
orders of magnitude for captured decode.

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

* Give the version handshakes a window that names its removal release

RFC #7240's open question 5 asks for deprecation windows. Dispatch had none: a
provider whose api_version did not equal AITER's exactly was skipped, and a
provider declaring an older op_version was simply not eligible. Both failures
were silent about what to do next.

SUPERSEDED_API_VERSIONS maps a still-accepted provider API version to the
release that removes it. A provider inside the window loads and warns once,
naming that release; one outside is skipped with a reason naming the versions
this aiter does accept.

route(supersedes={old_version: release}) does the same for an op contract. A
provider still on the old version serves and warns once, naming the release that
stops accepting it. Only AITER can make that declaration: AITER owns the
contract, so only AITER can say that a provider written against an older version
is still acceptable for calls on this one. A provider cannot grant itself a
grace period, and a contract cannot supersede its own version.

Both warn once per subject rather than once per call, and the warning always
names the removal point, so nobody learns a deadline from a crash.

The policy -- the design proposes two aiter minor releases -- stays with
maintainers. What the mechanism requires is only that the window exists, is
declared, and is named at runtime; the release string is free-form so the
policy can change without the code changing.

status() gains "api_versions_accepted" and "deprecations", so what is on borrowed
time and until when is data, not a log line somebody has to have been watching
for.

One thing deliberately not invented: an enabled provider on an op version this
contract no longer accepts falls back with reason "no-provider", which is
literally true but does not distinguish it from nothing being installed. The
design enumerates no reason for that case; a test records the gap rather than
inventing a string for it.

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

* Cover provider discovery through real packaging metadata

Every other test substitutes _entry_points, so the one seam between this
interface and the outside world -- importlib.metadata, the entry-point group
name, and loading an entry point that names an instance or a zero-argument
factory -- was the least covered part of it. A wheel that declares the group
slightly differently, or a metadata API that changes shape, would have been
caught by nothing.

These tests write real .dist-info directories onto sys.path and let discovery
find them the way it finds an installed wheel: both entry-point targets serve,
an installed provider is still not enabled by default, and an entry point in a
different group is ignored.

CPU-only, no GPU and no actual install.

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

* Close three conformance gaps against RFC #7240

Reading the RFC itself rather than our proposal answering it turned up three
places where the implementation did not do what the interface describes.

**Routed signatures were never checked for stability.** The RFC lists it among
the checks that block every AITER PR: "verification that routed public
signatures still match their contracts". route() captures the signature at
decoration, so it always agrees with itself -- the check was vacuously true. A
routed op's public signature is its contract, so changing it moved the contract
under every installed provider with no op_version bump and nothing to notice.

tests/test_plugin_contracts.py reads the routed signatures out of the source and
compares them with a committed baseline. It is a static scan rather than an
import: no GPU, no toolchain, and no list of "modules that route ops" for
somebody to forget to extend. A changed signature fails unless version= moved
with it; a removed routed op fails as a contract removal. Validated against the
two ops #7123 routes, including a non-literal default (dtypes.fp32).

**A provider could only declare one API version.** The RFC says a provider
declares "supported Provider API versions", plural, and lists independent
release cadence among its goals -- which needs one provider release to cover
several AITER versions. Providers now declare api_versions and are served on the
newest version both sides share. The single api_version spelling still works and
says so once, through the same window machinery.

**A duplicate provider name was a tie to break.** Two entry points answering to
one name made AITER_PLUGIN_ENABLE, AITER_PLUGIN_FORCE and every Decision
ambiguous, and let install order decide which served. The second is now skipped
with a reason in status(). Skipped, not raised: the RFC requires that a broken
install never break `import aiter`, which is the opposite of the duplicate
op-name rule, where the ambiguity is in AITER's own code.

Also: falling back to the generic binder now logs once. An op whose signature
cannot be generated against pays roughly sixty times the per-call cost, and
nothing said so.

Deliberately not implemented: the architecture, dtype, layout and shape coverage
declaration the RFC also describes. No form is defined for it, and a declaration
surface is public contract -- easier to add than to undo. A comment on the
Protocol records it; select() answers coverage per call until the form settles.

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

* Fix four defects found reviewing the series with fresh eyes

**A provider that touches aiter while importing deadlocked the process.**
_provider_lock was a plain Lock and entry_point.load() -- third-party import
code -- ran while holding it, so a provider that called back into dispatch
re-entered and hung the thread. No traceback, no log, stuck inside a kernel
call. Discovery now runs outside the lock, which is taken only to publish the
result, and the lock is reentrant as well. A race only means the same set is
discovered twice; the first to publish wins. A regression test loads a provider
that calls plugin.status() at module scope and fails on a timeout rather than
hanging the suite: it is skipped with a circular-import reason, which is the
right answer where a deadlock is neither visible nor recoverable.

**A malformed wheel belonging to somebody else raised into kernel calls.**
Every entry point's load() was isolated, but the enumeration around them was
not, and metadata.entry_points() reads every installed distribution. One broken
entry_points.txt propagated out of dispatch -- and left _provider_records as
None, so the next call raised again, forever. It is now isolated like the rest,
publishes an empty set, and reports itself in status().

**A superseded op version matched the oldest acceptable one**, because the
supersedes= mapping was walked in literal order. A contract superseding both 1
and 2 told a provider already on 2 that it was on 1, naming a removal release a
cycle too early and asking for a re-validation it had already done. It now takes
the newest acceptable version, the rule discovery already used for API versions.

**explain() diverged from dispatch**, while documenting itself as the Decision
the call would produce: it never named the provider it blamed, and it returned
a "plugins-disabled" reason that dispatch cannot produce. It now names the
provider, and reports no Decision at all under the kill switch -- which is what
dispatch does there. Explanation.decision is therefore Optional.

Also from the same review:

- The contract gate accepted any version difference, so one bump without
  rewriting the baseline licensed every later signature change for that op.
  It now requires the version to move forward *and* the baseline to be
  rewritten with it. Type annotations and the return annotation join the
  fingerprint: a provider implements against those too. Route decorators are
  resolved from the file's imports instead of matched by name suffix, so an
  alias is found and a same-named unrelated decorator is not.
- qualification is optional. The interface says AITER *may* record a
  provider-supplied evidence reference, not that a provider must have one;
  requiring it only produced placeholder strings.
- Provider attribute reads are isolated. The name is read once at discovery and
  cached on the record, so logging inside an except block cannot throw again
  and escape the boundary, and status() reports an unreachable provider instead
  of being the one call that fails when routing has already degraded.
- A dry run no longer spends the one-shot deprecation warning, and -- found by
  the test for it -- no longer caches the quiet result, which would have
  swallowed the warning for every later call.
- AITER_PLUGIN_FORCE is stripped like every other control; ENTRY_POINT_GROUP is
  exported, since a provider author has to know it; two unread fields and a
  redundant sort are gone.

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

* See the routes that rely on the version default

The gate's decorator detection required both op= and version= keywords, so a
route written as @route(op="rmsnorm") was invisible to it. Since version
defaults to 1 and is written only once it has moved, that left the recommended
spelling -- the common one -- entirely unprotected: its signature could change
without the gate noticing.

Detection now keys on op= alone and reads version as 1 when the keyword is
absent, which is what the decorator itself does. The regression test writes a
route without a version and asserts the scan still finds it.

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

* Give enablement one owner, and the environment one switch

Four environment variables had accreted around enablement: AITER_PLUGINS,
AITER_PLUGIN_ENABLE, AITER_PLUGIN_FORCE and AITER_PLUGIN_DISABLE. Each was
defensible alone and the set was never re-examined. Reviewing them together:

- FORCE was redundant. _build_eligible filtered providers by one name with
  _supports(); ENABLE walked a list of names with _supports(). With a
  single-name list the two paths computed the same thing, differing only in
  the reason string reported when nothing matched.
- ENABLE duplicated configure() while losing what makes configure() worth
  having. Enablement is a policy decision, and a decision should name its
  owner; an environment variable cannot say who set it, so a route enabled
  that way reported config_source="env" and nothing more.
- DISABLE named ops while ENABLE and FORCE named providers. Nothing in the
  shared prefix said which, so the obvious gesture for shutting a provider
  off -- AITER_PLUGIN_DISABLE=<provider> -- was accepted and did nothing. A
  control that looks like it worked is worse than no control.

Enablement now has one owner, configure(*, source, enable), so every route
names the framework that asked for it. The environment keeps AITER_PLUGINS=0
alone: it can only take routing away, never grant it. That asymmetry is the
point. Installing a provider makes it available; a wheel arriving as
somebody's transitive dependency must not be able to change which kernels run,
while an operator must be able to stop routing without editing framework code.

ATOM is the precedent: 291 environment variables, none of which activate its
plugin -- activation is _set_framework_backbone(), called by the integration --
and the only plugin-related ones, ATOM_DISABLE_VLLM_PLUGIN*, subtract.

Per-op opt-out goes with DISABLE. If it is wanted again it belongs in the
enable list as a provider:op entry rather than as a second namespace.

Hot path: 2.42us serving (six runs, 2.36-2.51) against 2.50us (2.44-2.54)
before. The ranges overlap, so this is no worse rather than a measured win.

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

* Say why an enabled provider cannot serve, instead of discarding it

A provider that is installed, enabled, and simply declares the wrong op
version was indistinguishable from nothing being installed at all. Both
answered reason="no-provider", and explain() -- the read whose entire job is
saying why a call went native -- returned no declines, because the
eligibility filter dropped the excluded providers without keeping why.

That is the commonest misconfiguration there is: a provider wheel built
against another contract version. The information was in hand and thrown
away, so finding it meant reading op_versions against the contract by eye.

The eligibility build now keeps the exclusions and the reason a native route
should record, in one cached _Eligibility per (op, generation):

- "provider-op-unsupported" when enabled providers are installed but none
  serves this op version, with per-provider detail naming the versions it does
  serve;
- "no-provider" when an enabled name has no installed provider, with
  "enabled but not installed" against that name;
- "provider-not-enabled" unchanged.

status() reports the same detail per routed op, next to the eligible list.

The hot path does not pay for it: eligibility is already cached per (op,
config generation), so the reasons are computed once per generation, and the
native branch now reads one precomputed string instead of re-deriving the
reason from three conditions. Dispatch overhead is unchanged (2.55-2.67us
over four runs, against 2.58-2.68 before).

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

* Pin the asymmetry the environment controls rest on

Removing three environment variables rested on one claim: the environment can
take routing away but never grant it. Nothing tested that claim. Every test
touching enablement was a conversion of an existing one, so reading
AITER_PLUGIN_ENABLE back into _build_config would have left the suite green.

Two tests, one per half:

- setting AITER_PLUGIN_ENABLE, _FORCE and _DISABLE against an installed
  provider leaves the call native with config_source="default-deny", and the
  provider is never asked;
- what configure() turned on, AITER_PLUGINS=0 plus reload_config() turns off,
  asserted by the call going native rather than only by what was recorded.

The second half had no coverage at all: the kill-switch test that existed
never enabled anybody, so it proved "off when never on".

Found by review rather than by writing them alongside the removal, which is
where they belonged.

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

* Name the entry point group for what registers in it

The group was aiter.kernel_providers, the only place a user-facing name said
"provider" rather than "plugin" -- and it is the one line a plugin author
writes, in their pyproject.toml.

Two words were doing one job. They are better as two layers: a kernel plugin
is the unit that ships and registers, KernelProvider is the interface it
implements. That is the pytest relationship, where a plugin implements hooks
the host calls, rather than the vLLM one, where a plugin is loaded and called
for its side effects on the host. Ours is asked and may decline; it patches
nothing. The type names stay as they are, because they name the interface.

The group is aiter.plugins, unqualified. AITER is a kernel library, so a
plugin to it is a kernel plugin; qualifying the group by a kind with no second
member would spend a longer name every time on a distinction that does not
exist. vLLM qualifies its four groups because platforms, model registries, io
processors and stat loggers are genuinely different subsystems. If a second
kind ever appears here it gets its own group, which is additive; renaming this
one would not be.

Many plugins in one group is the expected shape, and already works: several
may be installed and several enabled at once, asked in the order the framework
listed.

Now is the only free moment to settle this. The group name appears in exactly
one place in this tree, and in one line of any plugin's packaging metadata; no
such line has shipped yet.

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

* Test the judgment the rmsnorm bump rests on, instead of arguing it

rmsnorm's contract went to version 2 and deliberately did not list version 1
in supersedes=, because a kernel written for the v1 write-out contract, handed
a v2 call, treats the caller's input tensor as its output buffer. Nothing
catches that: the argument counts line up, both arguments are tensors, and the
signature check only asks whether the call binds, which it does.

That reasoning lived in a commit message. It was the one judgment in this
design supported by argument rather than by a test.

Three tests now hold it:

- a provider declaring only the superseded version is never asked for a
  version-2 call, and the caller's input comes back untouched;
- the counterfactual, where the only change is adding v1 back to supersedes=:
  the same provider is asked, serves, and writes the caller's input. The test
  asserts the corruption rather than describing it, so what the omission buys
  is visible;
- the contract gate now records which versions a contract still accepts and
  fails when that set changes without the baseline being rewritten. Adding a
  version back moves no signature and no fingerprint, so nothing in the gate
  would otherwise have noticed.

The first two model the shape faithfully: both contracts take a mutable
sequence first, which is what makes confusing them silent rather than a
TypeError. An earlier draft used mismatched types and "passed" by raising,
which would have tested nothing.

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

* Write the selection rules once, and test the one nothing covered

explain() exists to say what dispatch would do, and the two were saying it
separately: a Decision built field by field in both places, and one precedence
rule expressed twice -- in dispatch as a first-error tuple, in explain as a
scan back out of the declines dictionary. A comment stood where the shared
function belonged: "Same precedence as dispatch, and the same provider named
with it." Changing one side and forgetting the other makes explain lie, which
is the only thing it is for.

Both now call _selected() for the candidate's Decision and _native_outcome()
for why a native route happened. explain keeps dispatch's bookkeeping rather
than deriving it, so the rule is one object rather than two agreeing ones.
Dispatch allocates nothing new: the declines dictionary stays in explain.
Overhead is unchanged at 2.44us (2.41-2.50 over four runs).

Mutation-checking the result found the rule nobody had tested: keeping the
last error rather than the first left the whole suite green. A test now pins
it on both paths -- a broken provider does not deny the next one its turn, the
first failure is the one reported, and explain names the provider dispatch
named. Breaking either call site turns it red.

Two leftovers from removing the environment controls, both dead:

- test_enable_list_order_is_honoured_through_configure duplicated
  test_enable_list_order_is_the_preference_order once there was no environment
  ordering left to contrast with, and asserted strictly less;
- a reload_config() that reloaded nothing, under a comment explaining that a
  mid-process environment change needs it. configure() swaps the snapshot
  itself, and no environment variable can enable anything now.

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

* Keep the module importable on the Python in between

`_RoutedOp.superseded` defaulted to `MappingProxyType({})` written as a plain
dataclass default. That makes `import aiter` raise

    ValueError: mutable default <class 'mappingproxy'> for field superseded

on every Python 3.11 install, at class creation, before anything of this
interface runs. setup.py declares python_requires=">=3.10", so pip installs
there.

Every gate was green, and the reason is worth stating because it generalises:

- 3.10 rejects only list, dict and set, by type. A mappingproxy passes.
- 3.11 rejects any default whose type declares no __hash__. A mappingproxy
  declares none, so the class is refused.
- 3.12 applies 3.11's rule, but CPython gave mappingproxy a __hash__, so it
  passes again.

CI runs 3.10 and 3.12 — exactly the two versions that accept what 3.11
refuses. No amount of green says anything about the version in between.

`field(default_factory=...)` fixes it: the check reads `f.default`, and with a
factory there is no default to read. Verified on 3.10 and 3.12 here; the
reporting review verified the failure and the fix on 3.11.2.

A test now holds it, and it asks the right question. The obvious spelling —
mirror 3.11 and check whether the type declares __hash__ — passes on 3.12 for
this exact value, so it would have run in CI and caught nothing. It asks
instead whether the default can be hashed, which reads the same on every
version: a mappingproxy declares __hash__ on 3.12 and still raises when hashed.
Mutation-checked by restoring the plain default, which turns it red naming
`_RoutedOp.superseded`.

Two other things the same review raised:

- `_literal()` in the contract gate renders a non-literal default by the source
  that spells it, because the gate reads the tree and never imports it. A
  routed op defaulting to a module constant therefore keeps its fingerprint
  when the constant's value moves — the silent change the gate exists to
  catch. No routed op has such a default today; the gap is now written down
  rather than left for a reader to assume away.
- the testing line said 294; the suite had reached 297 through rebases without
  anyone moving the number. It says 298 now, which is 297 plus the test above.

pytest -q tests/ — 298 passed, 1 skipped, 463 subtests.

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

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
…y, provenance, observability (#7465)

* Prototype kernel provider interface

* Gate provider dispatch on explicit enablement

Installing a provider never makes it the default: dispatch now serves a
provider only when it is explicitly enabled (AITER_PLUGIN_ENABLE) or
forced (AITER_PLUGIN_FORCE). This makes the ownership boundary concrete:
AITER owns the op contract and execution rules, providers own their
kernels and qualification evidence, frameworks and users own enablement.

- document the ownership boundary in the module docstring
- isolate invalid candidates returned by select(): fall back to native
  with reason "invalid-candidate" instead of raising AttributeError
- document that entry points must target an instance or zero-arg factory
- tests: installed-but-not-enabled is inert (select never called);
  non-candidate select() results fall back to native

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

* Snapshot plugin configuration and honour the enable list order

Dispatch read four environment variables per call and rebuilt a set and a
frozenset each time, costing 2.49us of the hot path (measured). It also stored
enabled providers in a frozenset, which destroyed the enable list order, so
candidates were tried in alphabetical provider-name order instead of the
configured preference order.

Configuration is now an immutable snapshot built at first dispatch. Dispatch
reads one reference per call, so a call always runs against exactly one
generation; configure() and reload_config() build a new snapshot and swap the
reference under the config lock, leaving the hot path lock-free. Measured cost
of the gates drops to 0.048us. The eligible provider list is cached per
(op, config generation), get-or-build, and a build race is benign.

enabled is now an ordered tuple and the eligible list is built by walking it,
so the enable list order is the preference order it was specified to be.

Also:
- configure(*, source, enable, disable): source is required provenance; enable
  replaces the previous framework default, disable unions with the user's. All
  keyword-only, since a required parameter cannot follow a defaulted one.
- reload_config() re-reads the environment deliberately. Mid-process changes
  are not otherwise observed.
- A reload producing an identical snapshot does not bump the generation; a
  no-op bump would flush the eligible cache and churn provider resources.
- An empty environment value counts as unset, so AITER_PLUGIN_ENABLE="" falls
  through to the framework default rather than denying everything.

test_provider_arbitration_is_deterministic asserted that alpha wins from
"alpha, zebra" -- alphabetical order already produced that, so the test passed
against the bug. It is replaced by a case whose enable order contradicts
alphabetical order.

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

* Generate a per-op argument binder and measure dispatch end to end

inspect.Signature.bind is generic: it re-derives the parameter mapping on every
call. Measured against the two signatures #7123 routes, that is 4.57us for
rmsnorm and 6.05us for pertoken_quant -- on its own more than any plausible
dispatch budget, and the step that dominated the hot path.

The signature is already known when route() decorates the op, so the binder is
now generated once, at decoration. The generated function produces exactly what
bind() + apply_defaults() produce, raises the same TypeError on a malformed
call, and costs 0.076us / 0.083us. Defaults travel through the generated
function's namespace rather than through source text, because a default such as
dtypes.fp32 has no parseable repr. Signatures with *args/**kwargs, or with a
parameter that would collide with an injected default, fall back to
Signature.bind.

This sits below the API boundary: providers receive the same canonical
arguments, callers call the same way, and api_version does not move.

tests/test_plugin_overhead.py measures the whole path and prints the numbers,
which is what RFC #7240's first milestone actually asks for. On a Xeon
Platinum 8480C with Python 3.12.12, overhead over a direct native call:

    provider serves        1.79us
    no provider enabled    1.42us
    AITER_PLUGINS=0        1.19us
    one Signature.bind     4.85us

So the 1us design budget is not met yet, and the per-step projection that
suggested it would be (~0.9us) was optimistic: it omitted the Python call chain
and the per-call bookkeeping that only an end-to-end measurement sees. Decision
construction plus the ContextVar set is 0.787us of what remains, and is now the
largest single item.

The gate asserts what can be defended on unknown hardware: the whole aiter-side
overhead must cost less than one Signature.bind of the same signature, measured
in the same process. That fails the moment generic canonicalization, a per-call
getenv, or a rebuilt provider list returns, on any runner. The 1us budget is
reported rather than asserted until CI runner hardware is characterised.

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

* Isolate misbehaving providers, free the kill switch, record the config layer

Three changes that share the dispatch path.

**A misbehaving provider no longer denies service to a well-behaved one.** A
select() exception, and a candidate that is not a KernelCandidate or is owned by
somebody else, both removed the whole op from provider routing: the first one
encountered returned to native and the remaining providers were never asked.
That is correct with one provider and wrong with several. Both are now
pre-execution misbehaviour that removes that provider from this call only.

Native fallback happens when no provider serves. Reason precedence is two tiers:
either provider error outranks provider-declined -- a decline is normal
operation, an error is something someone must fix -- and within the error tier
the first one encountered is recorded, each keeping its own reason string.
Ranking provider-select-error against invalid-candidate would be arbitrary: both
mean the provider is broken, and either ranking still depends on iteration
order.

**The kill switch is now a free path.** With AITER_PLUGINS=0 dispatch checks one
cached flag and calls native, recording nothing: the feature is off, so there is
nothing to observe. Measured overhead over a direct native call drops from
1.19us to 0.141us. A per-op disable still records its Decision -- that op was
routed and deliberately turned off, which is what an operator is watching.

**Decision carries config_source**, naming the layer that produced the route:
"env", "configure:<source>", or "default-deny". An op-disabled route names the
layer that disabled it rather than the enable layer, so disabled_ops is now a
mapping from op name to its source; when both the framework and the user disable
an op, the user's act is the one named.

Measured on a Xeon Platinum 8480C, Python 3.12.12, overhead over a direct native
call: the serving path moves from 1.79us to 1.96us, paying one function call for
the isolation boundary and one more Decision field. The kill-switch path is
8.4x cheaper.

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

* Add the op registry and the four observability reads

RFC #7240 fixes what is observable but not how it is delivered. One record,
four reads: every layer consumes the same frozen Decision, and there are no
separate formats.

    last_decision()    per call        what served this call (already existed)
    status()           introspection   why is, or is not, X routed
    explain(op, ...)   introspection   the same question without executing
    decision_counts()  aggregation     what ran, how often, with what outcome
    on_decision(cb)    aggregation     inline, native routes included
    route-change log   audit trail     did routing flip when config changed

Reporting anything per op presumes routed ops are enumerable, which nothing
made true: Op and the contract lived only in route()'s closure. route() now
registers the op, and a duplicate op name is an error at import. Silent
last-wins would make routing depend on import order, which is exactly what the
enable list exists to avoid, and two routes claiming one name make op_version
unable to describe the contract anyway.

status() reports installed providers including the ones that were skipped and
why -- an installed provider that never serves is the first thing an operator
asks about, and that answer was previously only in the logs.

explain() dry-runs gates, eligibility and selection and returns the Decision the
call would produce plus why each provider declined. It never calls run(), never
records a Decision, and never counts one. It relies on select() being pure,
which is already a provider obligation.

on_decision() callbacks are called inline. A callback exception is swallowed,
logged once per callback rather than once per call, and counted in status(): a
telemetry bug must never break a kernel launch.

The route-change log is scoped to the config generation. Within one generation
the route is a deterministic function of the call arguments, so call-to-call
variation is provider behaviour -- visible in decision_counts() -- and not an
audit event. One line per op per generation, only when the route differs.

Every Decision now goes through a single _record(), so the four reads cannot
drift apart.

Cost, measured on a Xeon Platinum 8480C with Python 3.12.12: the serving path
moves from 1.96us to 2.42us. The layer is 0.46us, of which the counter
increment is the largest single piece at 0.166us, the route-change check 0.063us
and the empty callback loop 0.038us. This is the number the design estimated at
0.110us by counting the increment alone.

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

* Say that decision_counts() counts decisions, not launches

A CUDA graph replay runs no Python, so a captured op contributes one count for
the whole life of the graph however many times it replays. The counts are a
complete record of what was decided; read as a call mix they are wrong by
orders of magnitude for captured decode.

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

* Give the version handshakes a window that names its removal release

RFC #7240's open question 5 asks for deprecation windows. Dispatch had none: a
provider whose api_version did not equal AITER's exactly was skipped, and a
provider declaring an older op_version was simply not eligible. Both failures
were silent about what to do next.

SUPERSEDED_API_VERSIONS maps a still-accepted provider API version to the
release that removes it. A provider inside the window loads and warns once,
naming that release; one outside is skipped with a reason naming the versions
this aiter does accept.

route(supersedes={old_version: release}) does the same for an op contract. A
provider still on the old version serves and warns once, naming the release that
stops accepting it. Only AITER can make that declaration: AITER owns the
contract, so only AITER can say that a provider written against an older version
is still acceptable for calls on this one. A provider cannot grant itself a
grace period, and a contract cannot supersede its own version.

Both warn once per subject rather than once per call, and the warning always
names the removal point, so nobody learns a deadline from a crash.

The policy -- the design proposes two aiter minor releases -- stays with
maintainers. What the mechanism requires is only that the window exists, is
declared, and is named at runtime; the release string is free-form so the
policy can change without the code changing.

status() gains "api_versions_accepted" and "deprecations", so what is on borrowed
time and until when is data, not a log line somebody has to have been watching
for.

One thing deliberately not invented: an enabled provider on an op version this
contract no longer accepts falls back with reason "no-provider", which is
literally true but does not distinguish it from nothing being installed. The
design enumerates no reason for that case; a test records the gap rather than
inventing a string for it.

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

* Cover provider discovery through real packaging metadata

Every other test substitutes _entry_points, so the one seam between this
interface and the outside world -- importlib.metadata, the entry-point group
name, and loading an entry point that names an instance or a zero-argument
factory -- was the least covered part of it. A wheel that declares the group
slightly differently, or a metadata API that changes shape, would have been
caught by nothing.

These tests write real .dist-info directories onto sys.path and let discovery
find them the way it finds an installed wheel: both entry-point targets serve,
an installed provider is still not enabled by default, and an entry point in a
different group is ignored.

CPU-only, no GPU and no actual install.

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

* Close three conformance gaps against RFC #7240

Reading the RFC itself rather than our proposal answering it turned up three
places where the implementation did not do what the interface describes.

**Routed signatures were never checked for stability.** The RFC lists it among
the checks that block every AITER PR: "verification that routed public
signatures still match their contracts". route() captures the signature at
decoration, so it always agrees with itself -- the check was vacuously true. A
routed op's public signature is its contract, so changing it moved the contract
under every installed provider with no op_version bump and nothing to notice.

tests/test_plugin_contracts.py reads the routed signatures out of the source and
compares them with a committed baseline. It is a static scan rather than an
import: no GPU, no toolchain, and no list of "modules that route ops" for
somebody to forget to extend. A changed signature fails unless version= moved
with it; a removed routed op fails as a contract removal. Validated against the
two ops #7123 routes, including a non-literal default (dtypes.fp32).

**A provider could only declare one API version.** The RFC says a provider
declares "supported Provider API versions", plural, and lists independent
release cadence among its goals -- which needs one provider release to cover
several AITER versions. Providers now declare api_versions and are served on the
newest version both sides share. The single api_version spelling still works and
says so once, through the same window machinery.

**A duplicate provider name was a tie to break.** Two entry points answering to
one name made AITER_PLUGIN_ENABLE, AITER_PLUGIN_FORCE and every Decision
ambiguous, and let install order decide which served. The second is now skipped
with a reason in status(). Skipped, not raised: the RFC requires that a broken
install never break `import aiter`, which is the opposite of the duplicate
op-name rule, where the ambiguity is in AITER's own code.

Also: falling back to the generic binder now logs once. An op whose signature
cannot be generated against pays roughly sixty times the per-call cost, and
nothing said so.

Deliberately not implemented: the architecture, dtype, layout and shape coverage
declaration the RFC also describes. No form is defined for it, and a declaration
surface is public contract -- easier to add than to undo. A comment on the
Protocol records it; select() answers coverage per call until the form settles.

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

* Fix four defects found reviewing the series with fresh eyes

**A provider that touches aiter while importing deadlocked the process.**
_provider_lock was a plain Lock and entry_point.load() -- third-party import
code -- ran while holding it, so a provider that called back into dispatch
re-entered and hung the thread. No traceback, no log, stuck inside a kernel
call. Discovery now runs outside the lock, which is taken only to publish the
result, and the lock is reentrant as well. A race only means the same set is
discovered twice; the first to publish wins. A regression test loads a provider
that calls plugin.status() at module scope and fails on a timeout rather than
hanging the suite: it is skipped with a circular-import reason, which is the
right answer where a deadlock is neither visible nor recoverable.

**A malformed wheel belonging to somebody else raised into kernel calls.**
Every entry point's load() was isolated, but the enumeration around them was
not, and metadata.entry_points() reads every installed distribution. One broken
entry_points.txt propagated out of dispatch -- and left _provider_records as
None, so the next call raised again, forever. It is now isolated like the rest,
publishes an empty set, and reports itself in status().

**A superseded op version matched the oldest acceptable one**, because the
supersedes= mapping was walked in literal order. A contract superseding both 1
and 2 told a provider already on 2 that it was on 1, naming a removal release a
cycle too early and asking for a re-validation it had already done. It now takes
the newest acceptable version, the rule discovery already used for API versions.

**explain() diverged from dispatch**, while documenting itself as the Decision
the call would produce: it never named the provider it blamed, and it returned
a "plugins-disabled" reason that dispatch cannot produce. It now names the
provider, and reports no Decision at all under the kill switch -- which is what
dispatch does there. Explanation.decision is therefore Optional.

Also from the same review:

- The contract gate accepted any version difference, so one bump without
  rewriting the baseline licensed every later signature change for that op.
  It now requires the version to move forward *and* the baseline to be
  rewritten with it. Type annotations and the return annotation join the
  fingerprint: a provider implements against those too. Route decorators are
  resolved from the file's imports instead of matched by name suffix, so an
  alias is found and a same-named unrelated decorator is not.
- qualification is optional. The interface says AITER *may* record a
  provider-supplied evidence reference, not that a provider must have one;
  requiring it only produced placeholder strings.
- Provider attribute reads are isolated. The name is read once at discovery and
  cached on the record, so logging inside an except block cannot throw again
  and escape the boundary, and status() reports an unreachable provider instead
  of being the one call that fails when routing has already degraded.
- A dry run no longer spends the one-shot deprecation warning, and -- found by
  the test for it -- no longer caches the quiet result, which would have
  swallowed the warning for every later call.
- AITER_PLUGIN_FORCE is stripped like every other control; ENTRY_POINT_GROUP is
  exported, since a provider author has to know it; two unread fields and a
  redundant sort are gone.

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

* See the routes that rely on the version default

The gate's decorator detection required both op= and version= keywords, so a
route written as @route(op="rmsnorm") was invisible to it. Since version
defaults to 1 and is written only once it has moved, that left the recommended
spelling -- the common one -- entirely unprotected: its signature could change
without the gate noticing.

Detection now keys on op= alone and reads version as 1 when the keyword is
absent, which is what the decorator itself does. The regression test writes a
route without a version and asserts the scan still finds it.

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

* Give enablement one owner, and the environment one switch

Four environment variables had accreted around enablement: AITER_PLUGINS,
AITER_PLUGIN_ENABLE, AITER_PLUGIN_FORCE and AITER_PLUGIN_DISABLE. Each was
defensible alone and the set was never re-examined. Reviewing them together:

- FORCE was redundant. _build_eligible filtered providers by one name with
  _supports(); ENABLE walked a list of names with _supports(). With a
  single-name list the two paths computed the same thing, differing only in
  the reason string reported when nothing matched.
- ENABLE duplicated configure() while losing what makes configure() worth
  having. Enablement is a policy decision, and a decision should name its
  owner; an environment variable cannot say who set it, so a route enabled
  that way reported config_source="env" and nothing more.
- DISABLE named ops while ENABLE and FORCE named providers. Nothing in the
  shared prefix said which, so the obvious gesture for shutting a provider
  off -- AITER_PLUGIN_DISABLE=<provider> -- was accepted and did nothing. A
  control that looks like it worked is worse than no control.

Enablement now has one owner, configure(*, source, enable), so every route
names the framework that asked for it. The environment keeps AITER_PLUGINS=0
alone: it can only take routing away, never grant it. That asymmetry is the
point. Installing a provider makes it available; a wheel arriving as
somebody's transitive dependency must not be able to change which kernels run,
while an operator must be able to stop routing without editing framework code.

ATOM is the precedent: 291 environment variables, none of which activate its
plugin -- activation is _set_framework_backbone(), called by the integration --
and the only plugin-related ones, ATOM_DISABLE_VLLM_PLUGIN*, subtract.

Per-op opt-out goes with DISABLE. If it is wanted again it belongs in the
enable list as a provider:op entry rather than as a second namespace.

Hot path: 2.42us serving (six runs, 2.36-2.51) against 2.50us (2.44-2.54)
before. The ranges overlap, so this is no worse rather than a measured win.

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

* Say why an enabled provider cannot serve, instead of discarding it

A provider that is installed, enabled, and simply declares the wrong op
version was indistinguishable from nothing being installed at all. Both
answered reason="no-provider", and explain() -- the read whose entire job is
saying why a call went native -- returned no declines, because the
eligibility filter dropped the excluded providers without keeping why.

That is the commonest misconfiguration there is: a provider wheel built
against another contract version. The information was in hand and thrown
away, so finding it meant reading op_versions against the contract by eye.

The eligibility build now keeps the exclusions and the reason a native route
should record, in one cached _Eligibility per (op, generation):

- "provider-op-unsupported" when enabled providers are installed but none
  serves this op version, with per-provider detail naming the versions it does
  serve;
- "no-provider" when an enabled name has no installed provider, with
  "enabled but not installed" against that name;
- "provider-not-enabled" unchanged.

status() reports the same detail per routed op, next to the eligible list.

The hot path does not pay for it: eligibility is already cached per (op,
config generation), so the reasons are computed once per generation, and the
native branch now reads one precomputed string instead of re-deriving the
reason from three conditions. Dispatch overhead is unchanged (2.55-2.67us
over four runs, against 2.58-2.68 before).

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

* Pin the asymmetry the environment controls rest on

Removing three environment variables rested on one claim: the environment can
take routing away but never grant it. Nothing tested that claim. Every test
touching enablement was a conversion of an existing one, so reading
AITER_PLUGIN_ENABLE back into _build_config would have left the suite green.

Two tests, one per half:

- setting AITER_PLUGIN_ENABLE, _FORCE and _DISABLE against an installed
  provider leaves the call native with config_source="default-deny", and the
  provider is never asked;
- what configure() turned on, AITER_PLUGINS=0 plus reload_config() turns off,
  asserted by the call going native rather than only by what was recorded.

The second half had no coverage at all: the kill-switch test that existed
never enabled anybody, so it proved "off when never on".

Found by review rather than by writing them alongside the removal, which is
where they belonged.

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

* Name the entry point group for what registers in it

The group was aiter.kernel_providers, the only place a user-facing name said
"provider" rather than "plugin" -- and it is the one line a plugin author
writes, in their pyproject.toml.

Two words were doing one job. They are better as two layers: a kernel plugin
is the unit that ships and registers, KernelProvider is the interface it
implements. That is the pytest relationship, where a plugin implements hooks
the host calls, rather than the vLLM one, where a plugin is loaded and called
for its side effects on the host. Ours is asked and may decline; it patches
nothing. The type names stay as they are, because they name the interface.

The group is aiter.plugins, unqualified. AITER is a kernel library, so a
plugin to it is a kernel plugin; qualifying the group by a kind with no second
member would spend a longer name every time on a distinction that does not
exist. vLLM qualifies its four groups because platforms, model registries, io
processors and stat loggers are genuinely different subsystems. If a second
kind ever appears here it gets its own group, which is additive; renaming this
one would not be.

Many plugins in one group is the expected shape, and already works: several
may be installed and several enabled at once, asked in the order the framework
listed.

Now is the only free moment to settle this. The group name appears in exactly
one place in this tree, and in one line of any plugin's packaging metadata; no
such line has shipped yet.

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

* Test the judgment the rmsnorm bump rests on, instead of arguing it

rmsnorm's contract went to version 2 and deliberately did not list version 1
in supersedes=, because a kernel written for the v1 write-out contract, handed
a v2 call, treats the caller's input tensor as its output buffer. Nothing
catches that: the argument counts line up, both arguments are tensors, and the
signature check only asks whether the call binds, which it does.

That reasoning lived in a commit message. It was the one judgment in this
design supported by argument rather than by a test.

Three tests now hold it:

- a provider declaring only the superseded version is never asked for a
  version-2 call, and the caller's input comes back untouched;
- the counterfactual, where the only change is adding v1 back to supersedes=:
  the same provider is asked, serves, and writes the caller's input. The test
  asserts the corruption rather than describing it, so what the omission buys
  is visible;
- the contract gate now records which versions a contract still accepts and
  fails when that set changes without the baseline being rewritten. Adding a
  version back moves no signature and no fingerprint, so nothing in the gate
  would otherwise have noticed.

The first two model the shape faithfully: both contracts take a mutable
sequence first, which is what makes confusing them silent rather than a
TypeError. An earlier draft used mismatched types and "passed" by raising,
which would have tested nothing.

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

* Write the selection rules once, and test the one nothing covered

explain() exists to say what dispatch would do, and the two were saying it
separately: a Decision built field by field in both places, and one precedence
rule expressed twice -- in dispatch as a first-error tuple, in explain as a
scan back out of the declines dictionary. A comment stood where the shared
function belonged: "Same precedence as dispatch, and the same provider named
with it." Changing one side and forgetting the other makes explain lie, which
is the only thing it is for.

Both now call _selected() for the candidate's Decision and _native_outcome()
for why a native route happened. explain keeps dispatch's bookkeeping rather
than deriving it, so the rule is one object rather than two agreeing ones.
Dispatch allocates nothing new: the declines dictionary stays in explain.
Overhead is unchanged at 2.44us (2.41-2.50 over four runs).

Mutation-checking the result found the rule nobody had tested: keeping the
last error rather than the first left the whole suite green. A test now pins
it on both paths -- a broken provider does not deny the next one its turn, the
first failure is the one reported, and explain names the provider dispatch
named. Breaking either call site turns it red.

Two leftovers from removing the environment controls, both dead:

- test_enable_list_order_is_honoured_through_configure duplicated
  test_enable_list_order_is_the_preference_order once there was no environment
  ordering left to contrast with, and asserted strictly less;
- a reload_config() that reloaded nothing, under a comment explaining that a
  mid-process environment change needs it. configure() swaps the snapshot
  itself, and no environment variable can enable anything now.

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

* Keep the module importable on the Python in between

`_RoutedOp.superseded` defaulted to `MappingProxyType({})` written as a plain
dataclass default. That makes `import aiter` raise

    ValueError: mutable default <class 'mappingproxy'> for field superseded

on every Python 3.11 install, at class creation, before anything of this
interface runs. setup.py declares python_requires=">=3.10", so pip installs
there.

Every gate was green, and the reason is worth stating because it generalises:

- 3.10 rejects only list, dict and set, by type. A mappingproxy passes.
- 3.11 rejects any default whose type declares no __hash__. A mappingproxy
  declares none, so the class is refused.
- 3.12 applies 3.11's rule, but CPython gave mappingproxy a __hash__, so it
  passes again.

CI runs 3.10 and 3.12 — exactly the two versions that accept what 3.11
refuses. No amount of green says anything about the version in between.

`field(default_factory=...)` fixes it: the check reads `f.default`, and with a
factory there is no default to read. Verified on 3.10 and 3.12 here; the
reporting review verified the failure and the fix on 3.11.2.

A test now holds it, and it asks the right question. The obvious spelling —
mirror 3.11 and check whether the type declares __hash__ — passes on 3.12 for
this exact value, so it would have run in CI and caught nothing. It asks
instead whether the default can be hashed, which reads the same on every
version: a mappingproxy declares __hash__ on 3.12 and still raises when hashed.
Mutation-checked by restoring the plain default, which turns it red naming
`_RoutedOp.superseded`.

Two other things the same review raised:

- `_literal()` in the contract gate renders a non-literal default by the source
  that spells it, because the gate reads the tree and never imports it. A
  routed op defaulting to a module constant therefore keeps its fingerprint
  when the constant's value moves — the silent change the gate exists to
  catch. No routed op has such a default today; the gap is now written down
  rather than left for a reader to assume away.
- the testing line said 294; the suite had reached 297 through rebases without
  anyone moving the number. It says 298 now, which is 297 plus the test above.

pytest -q tests/ — 298 passed, 1 skipped, 463 subtests.

Co-Authored-By: Claude Opus 5 (1M context) <[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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants