Repository navigation
[RFC #7240] Let a provider report what a kernel costs, and record it unchanged - #7654
Merged
Merged
Conversation
zufayu
marked this pull request as ready for review
November 9, 2026 12:43
zufayu
force-pushed
the
codex/aklr-provider-latency
branch
2 times, most recently
from
November 9, 2026 14:14
15579e6 to
df66202
Compare
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
zufayu
added a commit
to zufayu/AKLR-1
that referenced
this pull request
Nov 10, 2026
ROCm/aiter#7654 adds one optional field to `KernelCandidate`: how many microseconds this kernel takes *for this call*. AKLR's answer today is that it does not know, and this makes that answer explicit rather than incidental. The dispatcher cannot answer it. `lookup()` returns two fast keys and a runnable; there is no timing anywhere on that path. AKLR does hold timings — `aklr.core.validation`'s `TimingRecord` carries `candidate_milliseconds` against a baseline — and reporting those would be worse than reporting nothing. They are measured offline, on the shapes validation picked, as a ratio against a versus kernel. AITER labels what it records with the conditions of the call in front of it, so a validation number would arrive attached to a shape it never ran on. That is the failure the protocol's "omit rather than extrapolate" rule exists to prevent, and it is the harder kind to catch: a number that looks sourced and is not. What AKLR would need is a read-only accessor on the dispatcher that, given the resolved kernel and the call's shapes, returns the cost it expects from its own tuning table. It does not exist. `_reported_latency_us()` is where it plugs in when it does — one function, one return. The field is passed conditionally, because this adapter has to work against AITER releases on both sides of #7654. Verified both ways: against the branch that has the field, it is constructed and reads back `None`; against the branch that does not, the keyword is omitted and construction succeeds. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A provider hands back a kernel and, optionally, one number: how long that
kernel takes for this call. AITER records it and hands it back. Nothing else.
This is groundwork rather than a feature. There are one or two providers
today, which is too few to choose between — but the shape of this field is
public contract, and once a second and third provider have each implemented
their own reading of it, it cannot be changed. The cost of getting it right
now is one optional field; the cost of getting it wrong is a migration across
every provider that exists by then.
What the number means, which matters more than the number:
for THIS call, how long does this kernel take
Not a tuning result for some other shape. AITER labels what it records with
the conditions of the call the candidate was offered for, so a number measured
elsewhere arrives wearing conditions it was never measured under -- worse than
no number, because it looks sourced. A provider with nothing for the shape in
front of it omits the field rather than extrapolating.
That paragraph lives in `KernelCandidate`'s docstring rather than beside the
field, because a provider author reads `help(KernelCandidate)` or the RFC, not
this file. Semantics that only exist in a source comment are semantics the
people implementing against them never see.
Conditions are AITER's to supply, not the provider's. `select()` already
receives the real arguments, so shape and dtype are readable from them and the
arch is this machine's. Asking a provider to restate them would be redundant
and would invent a question with no good answer: when the declared shape and
the actual call disagree, which one is true?
The field is appended, after `run`, and a test holds it there. `KernelCandidate`
is what every provider constructs, out of tree, where no grep of this repository
can see the call sites — and a field inserted before `run` silently takes
`run`'s argument, so the provider gets `ValueError` about a field it never
passed. Appending is the only backward-compatible place to add one, and the
test is what tells whoever adds the next field. Mutation-checked: moving the
field back ahead of `run` turns it red.
Four things deliberately left out:
- no second metric. tflops, bandwidth, efficiency: all absent. Adding a field
is easy and removing one is not, and every optional field on a public
contract is a future "somebody fills this and nobody reads it";
- no side-by-side path. Dispatch short-circuits at the first provider that can
serve, by design, so normal traffic only ever sees one quote. Collecting all
of them needs a walk that asks everyone, and that cannot live on the hot
path -- it would hand back the 1.9µs this series just removed, doubled;
- no retention. No database, no file, no report;
- no influence on routing. The enable list decides, and it is the one place
that names an owner for that decision. A number a provider picks for itself
must not be able to outrank it. A test holds this with a provider reporting
99999µs winning over one reporting 1µs, because it is earlier in the list.
No new API. The number rides the `Decision`, so `last_decision()`,
`on_decision()` and `explain()` already carry it. `explain()` is the one to
note: it produces a quote without running the kernel, so the side-by-side walk
left out above is a variant of it rather than a second contract change.
Zero, negative, inf and nan are refused at construction. Each looks like data
and carries none, and would be recorded, handed back, and eventually compared
against a real number. There is one way to say "I do not know" and it is
omission.
Known and stated rather than implied: native never reports. Only providers
can, so "is the plugin worth enabling at all" is not a question this protocol
answers — that needs a tune flow on both sides. Comparing provider against
provider is unaffected.
The contract gate does not move, and I expected it to. It fingerprints the
five *routed ops* — their signatures, source and version — and not the
provider-facing dataclasses, so an optional field here is invisible to it.
Correct for a backward-compatible addition, and worth saying out loud because
the same blindness covers a change that would not be: `KernelCandidate` and
`KernelProvider` are what every provider is written against, and nothing in CI
watches their shape. Extending the gate to cover them needs its own fingerprint
and bump rules; raised in ROCm#7240 rather than bolted onto this.
pytest -q tests/ — 328 passed, 1 skipped, 463 subtests. Hot path unchanged:
nothing-enabled 0.153µs against the kill switch's 0.144µs, both gates green.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu
force-pushed
the
codex/aklr-provider-latency
branch
from
November 10, 2026 05:17
df66202 to
00b161a
Compare
junhaha666
approved these changes
Nov 10, 2026
zufayu
added a commit
to zufayu/aiter
that referenced
this pull request
Nov 10, 2026
Three statements in this file were written against a main where the interface existed and nothing used it. ROCm#7484 changed that, and ROCm#7654 adds the cost field, so: - "no op is routed on main today" becomes the actual list of five, with the pointer to tests/plugin_contracts.json as the description that cannot drift; - "nothing checks your run against the contract yet" becomes the arity check that now exists — and keeps the warning that matters more, that arity is not meaning: v4 and v41 both take 15 arguments with a different second one; - a section on `latency_us`: what it means, why an offline validation ratio is not it, and why omitting beats extrapolating. Documentation that describes a main it is not merging into is worse than none, which is why this waits for ROCm#7654 rather than landing in two passes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu
added a commit
that referenced
this pull request
Nov 10, 2026
…l library (#7695) * Write down how to serve an AITER op from out of tree The interface is on main and nothing says how to use it. The next library that wants to serve an op has to read 1200 lines of implementation to find out that installing a provider does nothing until a framework calls configure(), or that `select()` has to be pure because `explain()` calls it without running anything. Deliberately not a second RFC. #7240 holds the rationale, the open questions and the deprecation policy; this holds the smallest provider that works, the entry point declaration, what `select()` must honour, and the four reads that answer "I installed it and nothing happens". Two things stated here that are easy to get wrong by omission: - **no op is routed on main today.** The interface is complete and tested, and the first ops to pass through it arrive in #7484. A provider can be written, installed, enabled and inspected right now, and every call still goes native. Saying so is better than letting someone conclude their provider is broken. - **nothing checks your `run` against the contract yet.** The arity check comes with #7484. Until then a kernel bound to the wrong contract runs silently. The failure section is four things that cost real debugging time on the first provider to use this interface, rather than invented examples: a kernel bound to a layout instead of a contract; matching hardware on `get_device_name()` (which reads "AMD Radeon Graphics" on MI355X under rocm/atom-dev) instead of `gcnArchName`; reporting offline validation timings as if they described the call in hand; and treating a decline as a failure. The arity point is worth the space it takes. Even once #7484 lands, the check compares argument counts, not meaning — `mla_sparse_prefill_v4` and `_v41` both take 15 arguments and their second parameter is `q_rope` in one and `q_scale` in the other. A provider bound to the wrong one reads a scale tensor as a RoPE component with every gate green. Every API name, keyword, status() key and reason string in this file was checked against the module on this commit. The one reference to something that does not exist on main yet (`contract-mismatch`) is marked as arriving with #7484. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Bring the guide up to what main actually does Three statements in this file were written against a main where the interface existed and nothing used it. #7484 changed that, and #7654 adds the cost field, so: - "no op is routed on main today" becomes the actual list of five, with the pointer to tests/plugin_contracts.json as the description that cannot drift; - "nothing checks your run against the contract yet" becomes the arity check that now exists — and keeps the warning that matters more, that arity is not meaning: v4 and v41 both take 15 arguments with a different second one; - a section on `latency_us`: what it means, why an offline validation ratio is not it, and why omitting beats extrapolating. Documentation that describes a main it is not merging into is worse than none, which is why this waits for #7654 rather than landing in two passes. 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A provider hands back a kernel and, optionally, one number: how long that
kernel takes for this call. AITER records it and hands it back. Nothing
else.
Not reporting stays the default: every provider written before this field
existed, and every provider with no number for the shape in front of it, gets
None.This is groundwork, and that is the argument for doing it now
There are one or two providers today — too few to choose between. But the
shape of this field is public contract, and once a second and third provider
have each implemented their own reading of it, it cannot be changed. The cost
of getting it right now is one optional field. The cost of getting it wrong is
a migration across every provider that exists by then.
What was nearly shipped instead, and why it is not here: a free-form
dict. One provider reports{"latency_us": 12.4}, another reports{"tflops": 820, "efficiency": "87%"}. Both are performance data, both arevalid, and they cannot be compared — which was the entire point. Either the
interface names one comparable quantity or it collects curiosities.
What the number means
Not a tuning result for some other shape. AITER labels what it records with
the conditions of the call the candidate was offered for, so a number measured
elsewhere arrives wearing conditions it was never measured under — worse than
no number, because it looks sourced. A provider with nothing for the shape in
front of it omits the field rather than extrapolating.
Conditions are AITER's to supply, not the provider's.
select()alreadyreceives the real arguments, so shape and dtype are readable from them and the
arch is this machine's. Asking a provider to restate them would be redundant,
and would invent a question with no good answer: when the declared shape and
the actual call disagree, which is true?
One practical note for whoever writes the next provider: match on
gcnArchName, not ontorch.cuda.get_device_name(). On MI355X underrocm/atom-devwith torch 2.10.0+rocm7.2.4, the device name readsAMD Radeon Graphicswhile the arch readsgfx950:sramecc+:xnack-. That mismatch is whythe AKLR pilot initially loaded zero schemas.
Deliberately left out
easy and removing one is not, and every optional field on a public contract
is a future "somebody fills this and nobody reads it".
can serve, by design, so normal traffic only ever sees one quote. Collecting
every quote needs a walk that asks everyone, and that cannot live on the hot
path — it would hand back the 1.9µs [JIT] Route five ops through the provider interface, and let a compiled op report its signature #7484 just removed, doubled. When there
are enough providers to make the comparison worth building,
explain()already produces a quote without running anything, so that walk is a variant
of it rather than a second contract change. That is the reason the field
lives on
KernelCandidaterather than in a newestimate()method on theprovider: the number is already there when the walk arrives.
that names an owner for that decision. A number a provider picks for itself
must not outrank it. A test holds this: a provider reporting 99999µs wins
over one reporting 1µs, because it is earlier in the enable list.
The field is appended, after
run, and a test holds it thereCaught reviewing my own diff: the first version inserted
latency_usbetweenqualificationandrun.KernelCandidateis what every provider constructs, out of tree, where nogrep of this repository can see the call sites. A provider building one
positionally —
— would have had
my_kernelbound tolatency_us, and would have received aValueErrorabout a field it never passed. Appending is the onlybackward-compatible place to add a field to this class, and the test is what
tells whoever adds the next one. Mutation-checked: moving the field back ahead
of
runturns it red.The semantics live in
KernelCandidate's docstring rather than in a commentbeside the field, for the same reason — a provider author reads
help(KernelCandidate)or the RFC, not this file.Values that look like data and carry none
0, a negative,infandnanare refused at construction. Each would berecorded, handed back, and eventually compared against a real number. There is
one way to say "I do not know" and it is omission.
A gate that does not move, and should be said out loud
tests/plugin_contracts.jsondoes not change, and I expected it to. Itfingerprints the five routed ops — signature, source, version — by walking
aiter/**/*.pyfor@_route(op=…). It does not cover the provider-facingdataclasses.
That is correct for a backward-compatible addition. It is worth stating because
the same blindness covers a change that would not be:
KernelCandidateandKernelProviderare what every provider is written against, and nothing in CIwatches their shape. Extending the gate needs its own fingerprint and bump
rules, so it is raised in #7240 rather than bolted onto this.
Known limitation
Native never reports. Only providers can, so "is the plugin worth enabling
at all" is not a question this protocol answers — that needs a tune flow on
both sides. Comparing provider against provider is unaffected.
Stacking
This sits on #7484, which sits on #7466, which sits on #7465.
aiter/plugin/does not exist on
mainyet, so this cannot merge before them, and the mergeorder is 7465 → 7466 → 7484 → this one.
Its own change is 143 lines across two files. Everything else in the diff
belongs to the three below it and shrinks away as they merge, so reviewing it
against #7484 rather than against
mainis the shorter read.Testing
pytest -q tests/— 107 passed in the CPU-only plugin suite, 1 skipped, 467 subtests. Six new tests:omission stays
None; a reported number reacheslast_decision(),on_decision()andexplain()unchanged; a native route reportsNone; thefour refused values, one case each; the enable list beating a better
reported number; and a positional construction still binding
runtorun.Hot path unchanged — nothing-enabled 0.153µs against the kill switch's
0.144µs, both machine-independent gates in
tests/test_plugin_overhead.pygreen. The field is one dataclass member and one attribute copy; it does not
touch the default-deny short-circuit.
PR Self-Review
Reviewed revision
00b161a30eBehavior and intent
No existing behaviour changes.
KernelCandidategains one optional field andDecisioncarries it through; a provider that does not set it is indistinguishablefrom before this PR. Routing, selection order, overhead and every existing
reader are untouched — the only new path is a rejection at construction for a
latency_usthat cannot mean anything.The one judgement worth reviewing is the semantics, because it is the part that
cannot be changed later: the number describes the call the candidate was
offered for, not a historical measurement. Everything else here — the single
metric, the absence of a comparison path, the refusal of
0/inf/nan— isdownstream of that choice.
Validation and unverified scope
pytest -q tests/on a built checkout (8x gfx942) — 107 passed in the CPU-only plugin suite, 1 skipped,467 subtests.
black --checkandruff checkclean. Overhead gates green at0.153µs nothing-enabled.
Unverified: no provider reports a number yet, so the field is exercised by
tests rather than by a real provider. Whether 12.4 is accurate is outside
this interface by construction — AITER records what it is told and does not
check it, which is stated rather than hidden. No GPU path is involved; this is
CPU-only by nature.
PR-specific question
Is one microsecond figure the right quantity to standardise on, or should the
first comparable quantity be throughput-shaped (so it stays meaningful as shapes
scale)? Latency was chosen because it needs no shape normalisation to be
compared between two providers answering the same call — but this is the
decision that is hardest to revisit later, so it is the one worth arguing with.
Changed op tests
None. This PR touches
aiter/plugin/__init__.pyandtests/test_plugin.pyonly. No file under
op_tests/is changed, and no routed op's signature moves.🤖 Generated with Claude Code