Skip to content

[RFC #7240] Let a provider report what a kernel costs, and record it unchanged - #7654

Merged
zufayu merged 1 commit into
ROCm:mainfrom
zufayu:codex/aklr-provider-latency
Nov 11, 2026
Merged

zufayu merged 1 commit into
ROCm:mainfrom
zufayu:codex/aklr-provider-latency

Conversation

@zufayu

@zufayu zufayu commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

plugin.KernelCandidate(
    provider="aklr",
    kernel_id="[email protected]",
    artifact_digest="sha256:…",
    latency_us=12.4,        # ← the whole protocol
    run=kernel,
)
plugin.last_decision().latency_us          # 12.4
plugin.explain("rmsnorm", *args).decision.latency_us   # 12.4, without running it

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 are
valid, 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

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.

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 is true?

One practical note for whoever writes the next provider: match on
gcnArchName, not on torch.cuda.get_device_name(). On MI355X under
rocm/atom-dev with torch 2.10.0+rocm7.2.4, the device name reads AMD Radeon Graphics while the arch reads gfx950:sramecc+:xnack-. That mismatch is why
the AKLR pilot initially loaded zero schemas.

Deliberately left out

  • No second metric. No tflops, bandwidth or efficiency. 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
    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 KernelCandidate rather than in a new estimate() method on the
    provider
    : the number is already there when the walk arrives.
  • 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 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 there

Caught reviewing my own diff: the first version inserted latency_us between
qualification and run.

KernelCandidate is what every provider constructs, out of tree, where no
grep of this repository can see the call sites. A provider building one
positionally —

KernelCandidate("aklr", "k1", "sha256:…", "experimental", my_kernel)

— would have had my_kernel bound to latency_us, and would have received a
ValueError about a field it never passed. Appending is the only
backward-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 run turns it red.

The semantics live in KernelCandidate's docstring rather than in a comment
beside 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, inf and nan are refused at construction. Each 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.

A gate that does not move, and should be said out loud

tests/plugin_contracts.json does not change, and I expected it to. It
fingerprints the five routed ops — signature, source, version — by walking
aiter/**/*.py for @_route(op=…). It does not cover the provider-facing
dataclasses.

That is correct for a backward-compatible addition. It is worth stating 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 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 main yet, so this cannot merge before them, and the merge
order 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 main is 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 reaches last_decision(),
on_decision() and explain() unchanged; a native route reports None; the
four refused values, one case each; the enable list beating a better
reported number; and a positional construction still binding run to run.

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.py
green. The field is one dataclass member and one attribute copy; it does not
touch the default-deny short-circuit.

PR Self-Review

Reviewed revision

00b161a30e

Behavior and intent

No existing behaviour changes. KernelCandidate gains one optional field and
Decision carries it through; a provider that does not set it is indistinguishable
from 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_us that 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 — is
downstream 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 --check and ruff check clean. Overhead gates green at
0.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__.py and tests/test_plugin.py
only. No file under op_tests/ is changed, and no routed op's signature moves.

🤖 Generated with Claude Code

@zufayu
zufayu marked this pull request as ready for review November 9, 2026 12:43
@zufayu
zufayu requested a review from a team November 9, 2026 12:43
@github-actions github-actions Bot changed the title [Build] [RFC #7240] Let a provider report what a kernel costs, and record it unchanged [CI] [JIT] [Build] [RFC #7240] Let a provider report what a kernel costs, and record it unchanged Nov 9, 2026
@zufayu
zufayu force-pushed the codex/aklr-provider-latency branch 2 times, most recently from 15579e6 to df66202 Compare November 9, 2026 14:14
@github-actions github-actions Bot changed the title [CI] [JIT] [Build] [RFC #7240] Let a provider report what a kernel costs, and record it unchanged [CI] [JIT] [RFC #7240] Let a provider report what a kernel costs, and record it unchanged Nov 9, 2026
@github-actions github-actions Bot removed the Build label Nov 9, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 9, 2026
@ROCm ROCm deleted a comment from github-actions Bot Nov 9, 2026
@aiter-bot

aiter-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 00b161a30edc · 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

No existing behaviour changes. `KernelCandidate` gains one optional field and
`Decision` carries it through; a provider that does not set it is indistinguishable
from 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_us` that 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` — is
downstream 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 --check` and `ruff check` clean. Overhead gates green at
0.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__.py` and `tests/test_plugin.py`
only. No file under `op_tests/` is changed, and no routed op's signature moves.

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

PR state

  • PASS — pull request is marked ready for review

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 requested a review from gyohuangxin November 10, 2026 01:23
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
zufayu force-pushed the codex/aklr-provider-latency branch from df66202 to 00b161a Compare November 10, 2026 05:17
@github-actions github-actions Bot changed the title [CI] [JIT] [RFC #7240] Let a provider report what a kernel costs, and record it unchanged [RFC #7240] Let a provider report what a kernel costs, and record it unchanged Nov 10, 2026
@zufayu
zufayu requested a review from junhaha666 November 10, 2026 05:18
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]>
@zufayu
zufayu merged commit 4f42e61 into ROCm:main Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants