Skip to content

[JIT] Route five ops through the provider interface, and let a compiled op report its signature - #7484

Merged
zufayu merged 12 commits into
ROCm:mainfrom
zufayu:codex/aklr-route-two-ops
Nov 10, 2026
Merged

zufayu merged 12 commits into
ROCm:mainfrom
zufayu:codex/aklr-route-two-ops

Conversation

@zufayu

@zufayu zufayu commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The first actual use of the interface. #7465 builds the mechanism and #7466
makes its tests block CI, but until this PR nothing in AITER is routed — the
machinery is complete, tested, and unused.

This routes five ops, fixes the one thing in AITER that made routing
impossible, and demonstrates an external provider serving through it on real
hardware.

Builds on #7466. Review the last nine commits only. This is also the PR
that changes aiter/jit/utils/torch_guard.py, so it wants a JIT reviewer
alongside an op owner.

A compiled op could not report its own signature

torch_compile_guard returns a (*args, **kwargs) closure and does not use
functools.wraps, so inspect.signature() of any guarded op — which is
every @compile_ops function, and several that use the guard directly —
reported the closure's parameters rather than the op's.

before:  (*args, **kwargs)
after:   (out: torch.Tensor, input: torch.Tensor, weight: torch.Tensor,
          epsilon: float, gemma_norm: bool = False) -> None

This is a prerequisite, not a side change. route() captures the public
signature as the op contract, and against (*args, **kwargs) there is no
contract: no per-op binder can be generated, so every call pays
Signature.bind — sixty times the cost measured in #7465 — and
apply_defaults() has no defaults to apply, so a provider's select() would
see a different number of arguments depending on how the caller spelled the
call.

The guard already knows the original as calling_func_; it now exposes it on
every path it returns, which covers both its own users and compile_ops'.

Blast radius: this changes what introspection reports for every compiled op
in the tree, which is why it is called out rather than buried. Both wrappers
are plain Python functions, not OpOverloadPacket, so the assignment cannot
raise; it happens after torch.library registration; and nothing else in the
tree reads __wrapped__ on these. Both tests in tests/test_jit_signature.py
fail without it — verified by reverting it.

Where the routes sit, and why it moved

Five ops are routed: rmsnorm, rmsnorm_with_add, pertoken_quant,
gemm_a8w8_blockscale and gemm_a8w8_blockscale_bpreshuffle. All
stay native by default; routing only changes what happens once a provider is
explicitly enabled.

rmsnorm was first routed at the low-level HIP binding behind
module_rmsnorm_quant — a public name only because the module is
star-imported, but in substance one backend's entry point. That was wrong and
this PR corrects it.
A provider declaring op rmsnorm saw neither public
spelling: rms_norm and rmsnorm2d_fwd both call _rms_norm_fwd_dispatch
directly, and that function chooses between the HIP binding and opus. The opus
path could not reach a provider at all, and the op name was backend-neutral
while what it resolved to was not — the same defect #7150 exists to remove, one
level further down.

The route now sits on _rms_norm_fwd_dispatch: below both public spellings,
above the backend choice. Downstream is unaffected — vLLM calls rms_norm,
ATOM calls rmsnorm2d_fwd, and neither changes.

That move changed the contract's shape, from write-out to functional, so the
version went to 2 — and deliberately not as a supersedes of version 1. A
provider written against v1 handed a v2 call would treat the input tensor as its
output buffer. supersedes= means "still acceptable", which this is not. The
contract gate caught the change and required the bump, which is what it is for.

What these mount points cover, stated because a provider author will look
here for it:

  • rmsnorm and rmsnorm_with_add now cover both public spellings and both
    backend branches.
  • rmsnorm_with_add is rmsnorm2d_fwd_with_add, the per-layer residual-add
    path vLLM, SGLang and ATOM call. It dispatches to a different kernel and has a
    second output, so it is a separate contract rather than a shape of the first.
  • pertoken_quant is the torch reference implementation rather than a
    production kernel, and it is reused by per_block_quant_wrapper, so serving
    it also serves the per-block quant torch path.
  • The two GEMM entries are routed exactly as they already exist. AITER exposes
    the shuffled-b weight layout as its own public function; that is a layout
    rather than a backend, so the name is allowed, but the two are not
    independent -- gemm_a8w8_blockscale with isBpreshuffled delegates to the
    other one's E8M0 route. Whether they should converge is RFC: decouple backend names from public op definitions (start with MoE) #7150's question, and
    routing them unchanged keeps this PR out of a public API change.

A kernel is checked against the contract before it is accepted

A declared op version is a provider's claim that it implements a contract.
Nothing checked the claim, and the failure when it is wrong is silent: a kernel
written for a write-out contract, handed a functional one, has argument counts
that line up by accident and writes its result into the caller's input. Four
positional arguments into a five-parameter function with one default raises
nothing — verified.

A candidate's kernel is now bound against the contract's shape before it is
accepted, and one that cannot take the call is refused with reason
contract-mismatch. A *args, **kwargs forwarder passes, which is right: it
does accept the call. Checked once per kernel and remembered, so the hot path is
one dictionary lookup — 0.14µs.

It catches shape, not meaning. A contract whose parameters are unchanged and
whose semantics moved is what the version number is for, and nothing automatic
can see it. The two are complements.

With the check in place, the version can stop being ceremony.
route(op=...) defaults to version 1, so an op whose contract has never moved
says nothing about versions. A provider may list op names instead of mapping
them to versions — op_versions = {"rmsnorm"} means whichever is current — and
one spanning a contract change still declares explicitly. That default is only
safe because of the check: a provider meaning "current" while built against an
older shape is refused rather than run.

An external provider serving, end to end

The milestone's remaining condition. A reference provider arrives the way a real
one does — a package and a .dist-info on sys.path, found through
importlib.metadata, nothing monkeypatched into discovery — and serves
rmsnorm2d_fwd end to end, checked against the op's own arithmetic so the test
proves it computed the op rather than merely claimed the route. The same
provider declines pertoken_quant, and declines per call for a shape it does
not cover.

The provider source is written out in full in the test rather than hidden in a
fixture, because it doubles as the answer to "what does a provider ship": a
name, the API versions it supports, the op versions it serves, a select() that
may decline, and an evidence reference AITER records without interpreting.

Beyond the tests, this was also run against AKLR
(https://github.com/AMD-AGI/AKLR) on MI355X, for both the normalization and the
GEMM pilots, with no AITER code special-cased for it.

rmsnorm_with_add: AKLR served the residual-add contract with output matching
the reference to 3.9e-3 and the residual output exact, serving some token counts
and declining others for its own reasons.

gemm_a8w8_blockscale_bpreshuffle, m x 4096 x K in fp8 with per-128-block
scales:

m n k route result
1 4096 4096 provider (aklr) max abs diff 0.5 vs native, rel 6.3e-04 (bf16 noise)
4 4096 4096 provider (aklr) exact
8 4096 8192 provider (aklr) selected, then raised inside run()
1 5120 4096 native declined before anything ran
4 4096 3072 native declined before anything ran
8 4096 6144 native declined before anything ran

The run predates #7465's consolidation of the enablement controls, so the
script enabled AKLR through AITER_PLUGIN_ENABLE; the same run today sets
configure(enable=("aklr",), source=...) and routes identically.

The third row is the failure boundary doing its job: the kernel failed inside
run() on this host's flydsl build, and the error propagated rather than
falling back, which is what the RFC requires once execution has begun. The
native baselines were taken by disabling the op and re-calling, with an
assertion that the baseline really routed native — an earlier version of that
script compared AKLR against itself and reported a meaningless "max diff 0".

Three caveats, recorded rather than smoothed over.

The adapter is not yet upstream in AKLR.

The device name has to be overridden before anything loads at all. In the image
this ran in — rocm/atom-dev, torch 2.10.0+rocm7.2.4 — ROCm reports the card as
"AMD Radeon Graphics" rather than as MI355X, on every run rather than
occasionally, and AKLR accepts a schema only when every field it declares
matches. Without the override every schema is skipped, every call routes native,
and the interface looks broken while behaving exactly as specified. It is the
first thing anyone reproducing this will hit, so it belongs in the steps and not
in a footnote. The information is not missing — gcnArchName reads
gfx950:sramecc+:xnack- on the same card — it is the name that is unreliable.
What to match on is the provider's decision; relaxing it has been raised in
AMD-AGI/AKLR#95.

And the interface told us only provider-declined, while AKLR internally knew
whether the call was out of contract, unmeasured, or on a machine with no
schemas loaded. Letting a provider's own reason through explain() is raised
in #7240 rather than added here.

Nobody pays for a route they did not turn on

Routing five ops means five ops now reach dispatch on every call — including on
every machine where no provider is enabled, which on the day this merges is all
of them. That path used to walk eligibility and build a frozen Decision for a
call no provider could possibly serve: 1.902µs, against the kill switch's
0.137µs. At roughly 120 rmsnorm calls per token it is about 0.23ms of CPU per
decode step in eager mode (a captured graph pays it once, at capture). It is a
pure loss — nobody paying it gets anything back.

An empty enable list and AITER_PLUGINS=0 assert the same thing, so dispatch
treats them as one branch and goes straight to native: 1.902µs → 0.149µs.

The profile is why the branch is placed where it is rather than trimmed:

_config()       0.036µs
_eligible()     0.109µs   (cache hit)
_run_native()   1.613µs   of which Decision(...) alone is 0.863µs

A frozen dataclass costs more to build than the rest of the path put together,
so there was no trimming that would have closed the gap.

The cost is that these calls record no Decision: last_decision() and
decision_counts() stay empty while nothing is enabled, the same trade the kill
switch already makes. explain() and status() still answer in full, on
demand, and three tests say so. Turning routing off also stops producing a
route-change log line, which is likewise what the kill switch does.

Two things this uncovered were defects rather than consequences:

  • last_decision() would have returned the stale provider route after
    configure(enable=()) turned routing off. Its docstring already argued why
    that is worse than returning nothing — for the kill switch only. The read now
    applies one rule to both states.
  • the route-change log lost its most useful line. An op with no entry yet was
    treated as having no comparable past, so the first provider route after a
    framework enables one was recorded as a silent baseline. What it was doing
    before is not unknown — it was running native — so
    ('native', None, None) -> ('provider', …) is now an audit line.

tests/test_plugin_overhead.py gains a second machine-independent gate:
nothing-enabled must cost within 3x of the kill switch. The 1.9µs path fails it.
The three tests that had used default-deny as a convenient "no provider" fixture
now enable a provider declaring another contract version instead, so the
recording path keeps its coverage rather than losing it to the shortcut.

Also here

  • last_decision() no longer answers with a record the kill switch
    invalidated.
    With AITER_PLUGINS=0 dispatch records nothing, which is what
    makes that path cost 0.141µs — and the consequence was that the reading went
    on returning whatever was recorded before, with nothing saying it was stale.
    The check is on the read, not the dispatch path: 0.011µs where it is asked,
    rather than 0.056µs on every call that is not. It now covers an empty enable
    list on the same grounds — see above.
  • _reset_for_testing() no longer clears ops routed by importing aiter, so
    status() and explain() keep reporting production routes after the first
    test.
  • End-to-end tests live in tests/test_plugin_routed_ops.py, not
    tests/test_plugin.py, because they import torch and call the real ops. The
    interface's own tests stay buildless so they can gate every PR without a GPU
    runner ([CI] Run the provider interface tests as a CPU-only gate on every PR #7466). That exposed an interaction worth naming:
    pytest.importorskip("aiter") does not skip when tests/conftest.py has put
    a stub under that name, so tests needing a real build ran against the stub and
    failed instead of skipping.

Testing

A built checkout with devices (8x gfx942): pytest -q tests/ — 320 passed, 1
skipped. The two graph-capture tests run here rather than being skipped, and
were mutation-checked: breaking either assertion's premise turns them red.

The plugin tests alone are 109, and black --check and ruff check are clean.

On MI355X the same suite was 329 passed, 5 failed at an earlier revision; all
five failures were test_flydsl_aot_replay.py and
test_mega_moe_gfx1250_recipe.py patching JitFunction._compile_or_execute,
which that container's flydsl 0.2.4 does not have. Neither file is touched by
these commits, and neither introspects signatures, which is the one way
torch_guard.py could have reached them.

Hot-path cost: 2.56µs serving (mean of six runs, 2.51-2.63), 0.149µs with
nothing enabled
, 0.14µs with AITER_PLUGINS=0, against 4.6µs for one
Signature.bind. Serving is above #7466's 2.42µs (six runs, 2.36-2.51) — the
ranges do not overlap, so it is a real cost added by this PR's commits rather
than run-to-run drift. The 1µs budget stays missed, and stays stated.

The nothing-enabled number is the one that applies to everybody on day one, and
it was 1.902µs until the last commit; see Nobody pays for a route they did not
turn on
above.

🤖 Generated with Claude Code

PR Self-Review

Reviewed revision

9af468069a

Behavior and intent

Until this PR nothing in AITER is routed: #7465 builds the mechanism and #7466
makes its tests block CI, but the machinery is complete, tested and unused.
This routes five ops, fixes the one thing in AITER that made routing
impossible, and demonstrates an external provider serving through it on real
hardware.

All five stay native by default. Routing changes what happens only once a
framework calls configure(enable=[...]), which nothing in the tree does.

The change with reach beyond the plugin is in aiter/jit/utils/torch_guard.py:
guarded ops now report their own signature through __wrapped__ instead of the
closure's (*args, **kwargs). That is a prerequisite — route() captures the
public signature as the op contract, and against (*args, **kwargs) there is
no contract — and it changes what introspection reports for every compiled op
in the tree, which is why it is called out rather than buried.

rmsnorm's mount point also moves, from one backend's HIP binding up to
_rms_norm_fwd_dispatch where both public spellings converge. That changed the
contract from write-out to functional, so the op version goes to 2, and
deliberately not as a supersedes of version 1: a provider written against v1
handed a v2 call would treat the input tensor as its output buffer.

Validation and unverified scope

A built checkout with devices (8x gfx942): pytest -q tests/ — 320 passed, 1
skipped; the plugin tests alone are 109. black --check and ruff check
clean. Hot-path cost 2.56µs serving (six runs, 2.51–2.63), 0.149µs with nothing
enabled, 0.14µs with AITER_PLUGINS=0, against 4.6µs for one Signature.bind.

The two graph-capture tests run on a device here rather than skipping, and
both were mutation-checked. On MI355X the suite was 329 passed, 5 failed at an
earlier revision, all five being that container's flydsl 0.2.4 against tests
that patch an attribute it does not have — neither file is touched here, and
neither introspects signatures, the one way torch_guard.py could reach
them.

On real hardware, with AKLR (https://github.com/AMD-AGI/AKLR) installed through
packaging metadata and enabled through configure(): it served
gemm_a8w8_blockscale_bpreshuffle at two shapes with output matching native,
declined three shapes before anything ran, and at one shape its kernel failed
inside run() — where the error propagated rather than falling back, which
is the designed failure boundary.

Unverified: no performance claim is made for any routed op; this is a
correctness and routing pilot. On the MI355X host only one layout variant and
one fp8 dtype could be exercised, because that is all AKLR could load there.
The torch_guard.py blast radius is argued from inspection of both wrappers
and a tree-wide search for __wrapped__ readers, not from running every
compiled op.

PR-specific question

What permissions and untrusted-input boundary does this CI change have, and
can fork PR code or text reach a privileged execution path?

This PR changes no workflow file and adds no CI permissions; the question is
selected because .github/ appears in the diff range of the series rather than
in this PR's own changes. The boundary it does move is at runtime, not in CI: a
kernel provider is third-party code loaded through an entry point into the
AITER process. That is why discovery is isolated (a broken wheel is recorded
and skipped, never raised into a kernel call), why select() runs inside a
try/except that takes the next provider, and above all why installation grants
nothing — a provider serves only after a framework names it in configure(),
so a wheel arriving as a transitive dependency cannot change which kernels run.
Provider-reported fields are recorded verbatim as provenance and never
interpreted, so nothing a provider says can steer selection.

Changed op tests

None. No file under op_tests/ is changed. The end-to-end tests that call real
ops live in tests/test_plugin_routed_ops.py, alongside the rest of the plugin
tests, so the CPU-only gate in #7466 keeps covering them.

@github-actions

github-actions Bot commented Nov 5, 2026

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 7484 --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.

@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 9af468069a83 · 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

Until this PR nothing in AITER is routed: #7465 builds the mechanism and #7466
makes its tests block CI, but the machinery is complete, tested and unused.
This routes five ops, fixes the one thing in AITER that made routing
impossible, and demonstrates an external provider serving through it on real
hardware.

All five stay native by default. Routing changes what happens only once a
framework calls `configure(enable=[...])`, which nothing in the tree does.

The change with reach beyond the plugin is in `aiter/jit/utils/torch_guard.py`:
guarded ops now report their own signature through `__wrapped__` instead of the
closure's `(*args, **kwargs)`. That is a prerequisite — `route()` captures the
public signature as the op contract, and against `(*args, **kwargs)` there is
no contract — and it changes what introspection reports for every compiled op
in the tree, which is why it is called out rather than buried.

`rmsnorm`'s mount point also moves, from one backend's HIP binding up to
`_rms_norm_fwd_dispatch` where both public spellings converge. That changed the
contract from write-out to functional, so the op version goes to 2, and
deliberately not as a `supersedes` of version 1: a provider written against v1
handed a v2 call would treat the input tensor as its output buffer.

Validation and unverified scope

A built checkout with devices (8x gfx942): `pytest -q tests/` — 320 passed, 1
skipped; the plugin tests alone are 109. `black --check` and `ruff check`
clean. Hot-path cost 2.56µs serving (six runs, 2.51–2.63), 0.149µs with nothing
enabled, 0.14µs with `AITER_PLUGINS=0`, against 4.6µs for one `Signature.bind`.

The two graph-capture tests run on a device here rather than skipping, and
both were mutation-checked. On MI355X the suite was 329 passed, 5 failed at an
earlier revision, all five being that container's flydsl 0.2.4 against tests
that patch an attribute it does not have — neither file is touched here, and
neither introspects signatures, the one way `torch_guard.py` could reach
them.

On real hardware, with AKLR (https://github.com/AMD-AGI/AKLR) installed through
packaging metadata and enabled through `configure()`: it served
`gemm_a8w8_blockscale_bpreshuffle` at two shapes with output matching native,
declined three shapes before anything ran, and at one shape its kernel failed
*inside* `run()` — where the error propagated rather than falling back, which
is the designed failure boundary.

Unverified: no performance claim is made for any routed op; this is a
correctness and routing pilot. On the MI355X host only one layout variant and
one fp8 dtype could be exercised, because that is all AKLR could load there.
The `torch_guard.py` blast radius is argued from inspection of both wrappers
and a tree-wide search for `__wrapped__` readers, not from running every
compiled op.

PR-specific question

*What permissions and untrusted-input boundary does this CI change have, and
can fork PR code or text reach a privileged execution path?*

This PR changes no workflow file and adds no CI permissions; the question is
selected because `.github/` appears in the diff range of the series rather than
in this PR's own changes. The boundary it does move is at runtime, not in CI: a
kernel provider is third-party code loaded through an entry point into the
AITER process. That is why discovery is isolated (a broken wheel is recorded
and skipped, never raised into a kernel call), why `select()` runs inside a
try/except that takes the next provider, and above all why installation grants
nothing — a provider serves only after a framework names it in `configure()`,
so a wheel arriving as a transitive dependency cannot change which kernels run.
Provider-reported fields are recorded verbatim as provenance and never
interpreted, so nothing a provider says can steer selection.

Changed op tests

None. No file under `op_tests/` is changed. The end-to-end tests that call real
ops live in `tests/test_plugin_routed_ops.py`, alongside the rest of the plugin
tests, so the CPU-only gate in #7466 keeps covering them.

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 changed the title [Prototype] Route rmsnorm and pertoken_quant, and record their contracts [JIT] Route rmsnorm and pertoken_quant, and let a compiled op report its signature Nov 5, 2026
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch from 1472e3c to ee9687a Compare November 5, 2026 04:27
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch from 9212c0b to cea956b Compare November 5, 2026 08:11
@zufayu zufayu changed the title [JIT] Route rmsnorm and pertoken_quant, and let a compiled op report its signature [JIT] Route three ops through the provider interface, and let a compiled op report its signature Nov 6, 2026
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch from e83613f to f75ce65 Compare November 7, 2026 06:58
@zufayu zufayu changed the title [JIT] Route three ops through the provider interface, and let a compiled op report its signature [JIT] Route five ops through the provider interface, and let a compiled op report its signature Nov 7, 2026
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch 6 times, most recently from b67aabd to d1ab2e6 Compare November 8, 2026 00:51
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch from eadb134 to 031bc35 Compare November 8, 2026 08:04
zufayu and others added 5 commits November 10, 2026 01:44
Its select() read args[0] for both contracts to find the hidden size. That
works today by coincidence: the functional contract takes the input first and
the write-out one takes the output, and both happen to carry the hidden size in
the same axis. It would break silently the first time a contract's parameter
order moved, and the failure would be a wrong coverage decision rather than an
error.

The provider source in this file is written out in full because it doubles as
the answer to "what does a provider ship". Something written to be copied
should demonstrate the careful version, so it now names which argument carries
the shape for each contract, and the comment says why reading one position for
both is the wrong habit.

Co-Authored-By: Claude Code <[email protected]>
The GEMM pilot routes gemm_a8w8_blockscale and
gemm_a8w8_blockscale_bpreshuffle as they already exist. AITER exposes the
shuffled-b weight layout as its own public function; that is a layout rather
than a backend, and whether the two should converge is ROCm#7150's question.
Routing them unchanged keeps this pilot out of a public API change.

The two are not independent: gemm_a8w8_blockscale with isBpreshuffled
delegates to the other one's E8M0 route, so both are recorded in the contract
baseline rather than only the entry a caller is likeliest to name.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
rmsnorm is at version 2 and accepts only version 2; the gate now reads that
from the file rather than from a default. A later edit adding version 1 back
has to change this line, which is the point: it moves no signature and no
fingerprint, so nothing else would show it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
"capture" appeared nowhere in this tree -- not in the module, not in a test --
while the RFC names graph capture as part of the contract. It is the quietest
failure mode in the design: replay runs no Python, so whatever dispatch
decided on the capturing call is what the graph does for its whole life, and
because replay records no Decision, nothing afterwards says which call decided
it. A first call that landed inside capture could freeze an op on the wrong
route with no observable trace.

Measured on an MI355X before writing the tests: select() is called once during
capture and zero times across three replays, and last_decision() after replay
still describes the capturing call.

Two tests hold it:

- a provider selected at capture stays selected; replays add no Decision at
  all, and the reading still describes the capturing call, which is precisely
  why an operator cannot tell replays apart from it;
- AITER_PLUGINS=0 does not reach an already-captured graph. The switch stops
  future dispatch; it cannot un-bake a kernel, because there is no dispatch
  left inside the graph to stop. Anyone reaching for it during an incident
  needs to know the graphs have to be rebuilt.

Both run on a real device (8x gfx942 here) rather than being skipped, and both
were mutation-checked: breaking each assertion's premise turns them red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
On the day this merges, every caller is in the state where no provider is
enabled -- and that state walked eligibility and built a frozen Decision for a
call that no provider could possibly serve. Measured here: 1.902us per routed
call against the kill switch's 0.137us. Five routed ops, rmsnorm twice per
layer, is roughly 0.23ms of CPU per decode step in eager mode. It is a pure
loss: nobody paying it gets anything back.

An empty enable list and the kill switch say the same thing -- no provider can
serve this call -- so dispatch now treats them as one branch and goes straight
to native. 1.902us -> 0.149us, which is what the kill switch costs.

Profiling first, because the expensive half was not the one I expected:

  _config()        0.036us
  _eligible()      0.109us   (cache hit)
  _run_native()    1.613us   of which Decision(...) alone is 0.863us

A frozen dataclass costs more to build than everything else on the path put
together. Skipping the branch skips both.

The cost is that these calls record no Decision, so last_decision() and
decision_counts() stay empty while nothing is enabled. Same trade the kill
switch already makes. explain() and status() still answer in full, on demand,
and three tests now say so rather than leaving it to the commit message.

Two things fell out of the change that were defects, not consequences:

- last_decision() would have returned the *stale* provider route after
  configure(enable=()) turned routing off. Its docstring already argued why
  that is worse than returning nothing -- for the kill switch. The read now
  applies the same rule to both states.
- the route-change log lost its most useful line. An op with no entry was
  treated as having no comparable past, so the first provider route after a
  framework enables one was recorded as a silent baseline. What it was doing
  before is not unknown -- it was running native -- so that transition is now
  an audit line, which is the one an operator most wants.

Tests: the three that used default-deny as a convenient "no provider" fixture
now use an enabled provider that declares another contract version, so the
recording path keeps its coverage instead of losing it to the shortcut. The
overhead file gains a second machine-independent gate: nothing-enabled must
cost within 3x of the kill switch, which the 1.9us path would fail.

pytest -q tests/ -- 318 passed, 1 skipped, 463 subtests, on 8x gfx942.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu force-pushed the codex/aklr-route-two-ops branch from 391ddac to 9af4680 Compare November 10, 2026 01:49
@github-actions github-actions Bot changed the title [CI] [JIT] Route five ops through the provider interface, and let a compiled op report its signature [JIT] Route five ops through the provider interface, and let a compiled op report its signature Nov 10, 2026
@github-actions github-actions Bot removed the CI label Nov 10, 2026
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
demonsan added a commit that referenced this pull request Nov 10, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
@zufayu
zufayu merged commit 95c9ab3 into ROCm:main Nov 10, 2026
zufayu added a commit to zufayu/aiter that referenced this pull request Nov 10, 2026
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. ROCm#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 ROCm#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 ROCm#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 ROCm#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
ROCm#7484.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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 added a commit to zufayu/aiter that referenced this pull request Nov 11, 2026
DeepSeek V4.1's attention path calls six AITER ops and not one of them is
routed: the five ops ROCm#7484 routed are rmsnorm, pertoken_quant and the two
blockscale GEMMs, which the V4.1 path does not touch. A provider can serve
nothing on that model today.

This routes the one of the six that needs no other decision first.

**Why this one.** Five of the six run only on the decode path, which is inside
a CUDA graph, and `warmup_model()`'s dummy batch is prefill-only — so their
first call lands in a capture, the case ROCm#7240 now states obligations for and
ROCm#7713 pins. `mla_sparse_prefill_v41` is prefill. It is reached outside any
capture, so routing it exercises the DSV4.1 contract end to end without
depending on anything else landing first.

**Mounted where the op begins.** `@compile_ops` wraps only the low-level asm
entry point; the public `mla_sparse_prefill_v41` is plain Python, so the route
sits on the contract rather than on one backend's implementation — the lesson
from routing rmsnorm at `_rms_norm_fwd_dispatch`.

**Not folded in with v4.** `mla_sparse_prefill_v4` stays unrouted and will be
its own contract when it is. The two take the same fifteen arguments and mean
different things by them — v4's second is `q_rope`, v41's is `q_scale` — so a
kernel bound to the wrong one passes the arity check and reads a scale tensor
as a RoPE component. ROCm#7240 states the rule.

**`backend=` needs no special handling.** It is a contract parameter, not a
routing switch (ROCm#7240), and on this op it is degenerate anyway: `"opus"` is the
only accepted value, both spellings reach the same implementation, and ATOM's
call site passes neither.

The baseline gains one entry and the existing five are untouched, which is the
property worth checking in the diff.

`pytest -q tests/test_plugin*.py` — 98 passed. On MI355X,
`plugin.status()["routed_ops"]` lists six ops with `mla_sparse_prefill_v41`
among them. No provider serves it yet, so every call still routes native,
exactly as the first five did when they landed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu added a commit that referenced this pull request Nov 11, 2026
…raph capture (#7713)

* Pin what a provider's first call may do inside a capture

#7484 pinned what replay does to a routing decision. Neither of those tests
covers the case a real deployment hits first: an op whose first call lands
*inside* a capture, because the warmup pass did not reach it. The existing
`_capture` helper warms before recording, by design -- so the uncovered path is
the one the helper exists to avoid.

That path is not hypothetical in this tree. `capture_cudagraph()` calls
`warmup_exchange()` before recording because `warmup_model()`'s dummy batch is
prefill-only, and an all-to-all on the decode path would otherwise set up its
NCCL peer connections inside the capture, where that hangs. A decode-only
routed op is in exactly that position.

Two tests, answering the two questions a provider author has.

**Can I allocate lazily?** Yes, and the test says so because the intuition runs
the other way. Capture-time allocations are widely assumed to land in the
graph's private pool and die with it. Measured: 16 MiB allocated on a first call
inside a capture belongs to the provider, survives the graph, same address. A
provider does not need to pre-allocate to be correct -- an obligation worth not
imposing.

**Can I read a result back?** No, and the refusal is not recoverable. The
second assertion is the one that matters: after the failure the CUDA context is
unusable, and the next unrelated `torch.rand` fails naming neither capture nor
the provider. The cost of a `logger.info(f"...{probe.item()}")` in a lazy init
is not an error in that init; it is every CUDA operation in the process
afterwards, reported somewhere else.

That test runs in a subprocess, and the reason is the finding itself: proving
this ruins the process that proves it. Run inline, it fails every CUDA test
after it in this file -- including #7484's own capture tests, which is how the
behaviour was found. An earlier draft parametrised five readback forms inline;
the first passed and poisoned the other four.

Verified on MI355X (gfx950, torch 2.10.0+rocm7.2.4): 13 passed, including the
pre-existing tests that the inline version took down. Not runnable on a
checkout whose flydsl predates the pin main now requires -- `requires_built_aiter`
skips the module there rather than failing it.

The obligation these pin is stated in #7240.

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

* Record that both capture assertions were mutation-checked

Swapping the probe's `.item()` for a `torch.empty` -- legal under capture --
reports NOT_REFUSED and CONTEXT_SURVIVED, failing both assertions. Without
that, the test could have passed for a reason other than the one it names,
and the next person would have to rerun the experiment to find out.

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]>
demonsan added a commit that referenced this pull request Nov 11, 2026
… an out-of-tree provider

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
zufayu added a commit that referenced this pull request Nov 11, 2026
* Route mla_sparse_prefill_v41, the first DSV4.1 op

DeepSeek V4.1's attention path calls six AITER ops and not one of them is
routed: the five ops #7484 routed are rmsnorm, pertoken_quant and the two
blockscale GEMMs, which the V4.1 path does not touch. A provider can serve
nothing on that model today.

This routes the one of the six that needs no other decision first.

**Why this one.** Five of the six run only on the decode path, which is inside
a CUDA graph, and `warmup_model()`'s dummy batch is prefill-only — so their
first call lands in a capture, the case #7240 now states obligations for and
#7713 pins. `mla_sparse_prefill_v41` is prefill. It is reached outside any
capture, so routing it exercises the DSV4.1 contract end to end without
depending on anything else landing first.

**Mounted where the op begins.** `@compile_ops` wraps only the low-level asm
entry point; the public `mla_sparse_prefill_v41` is plain Python, so the route
sits on the contract rather than on one backend's implementation — the lesson
from routing rmsnorm at `_rms_norm_fwd_dispatch`.

**Not folded in with v4.** `mla_sparse_prefill_v4` stays unrouted and will be
its own contract when it is. The two take the same fifteen arguments and mean
different things by them — v4's second is `q_rope`, v41's is `q_scale` — so a
kernel bound to the wrong one passes the arity check and reads a scale tensor
as a RoPE component. #7240 states the rule.

**`backend=` needs no special handling.** It is a contract parameter, not a
routing switch (#7240), and on this op it is degenerate anyway: `"opus"` is the
only accepted value, both spellings reach the same implementation, and ATOM's
call site passes neither.

The baseline gains one entry and the existing five are untouched, which is the
property worth checking in the diff.

`pytest -q tests/test_plugin*.py` — 98 passed. On MI355X,
`plugin.status()["routed_ops"]` lists six ops with `mla_sparse_prefill_v41`
among them. No provider serves it yet, so every call still routes native,
exactly as the first five did when they landed.

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

* Route the two decode-path V4.1 ops whose contracts need nothing new

outside a graph capture. These are the next two, chosen because their contracts
raise no question this interface has not already answered: nine arguments each,
no workspace, no backend parameter, no backend word in the name — the same
shape as the five ops already routed.

Both mount on the public entry point. `@compile_ops` wraps
`_inverse_rope_group_quant_kernel`, not the function callers use, so the route
sits on the contract rather than on one backend's implementation.

**These are decode-path ops, and that has a consequence worth stating here
rather than discovering later.** A framework's warmup runs a prefill-only dummy
batch, so a decode-only op is not called during warmup and its first call lands
inside `capture_cudagraph()`. Allocation there is safe; reading a result back is
not, and the failure poisons the CUDA context rather than raising something a
provider author can act on. The obligation this places on providers is in
ROCm/ATOM#3157.

Routing them now is still correct: with no provider enabled, dispatch
short-circuits before eligibility and every call goes native, so nothing
changes for anyone today. What it buys is the contract being in place, so a
provider can be written against it while the framework-side warmup is sorted
out. The ordering risk is real but it is a deployment-time risk, not a
merge-time one, and it is documented in both places a provider author would
look.

`fused_qk_norm_rope_cache_quant_shuffle` is deliberately not here: nineteen
arguments fusing norm, rope, cache, quant and shuffle is a contract-granularity
question for #7240, and routing it first would freeze that granularity into
public contract. `mla_decode_fwd_v4_nm_ps` is also held back — it carries a
workspace, and no provider has ever served a contract with one, so it deserves
a PR that can say something about that rather than riding along in this one.

The baseline gains two entries and the existing five are untouched. Generated
with the gate's own `routed_contracts()` scanner.

`pytest -q tests/test_plugin*.py` — 98 passed. On MI355X,
`plugin.status()["routed_ops"]` lists seven ops with both of these among them.

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

* Route the first contract that carries a workspace, and check what that means

handle. Until now that was an assertion nobody had executed: no routed op had
one, so nothing in the tree demonstrated it, and nothing would have noticed if
it stopped being true.

`mla_decode_fwd_v4_nm_ps` takes `MlaV4NmPsWorkspace`, a NamedTuple of five
tensors the caller allocates through `get_mla_v4_nm_ps_workspace`. Routing it
makes the claim testable, and the test is the point of this PR rather than the
decorator.

The question the claim hides is concrete. Dispatch canonicalizes arguments
through generated code before handing them to a Provider, and a NamedTuple
could plausibly arrive rebuilt, flattened into its fields, or copied. Any of
those breaks the ownership the pattern exists for: the Provider would be
writing into scratch the caller cannot read back, and nothing would say so.

It arrives as the same object. The test asserts `is`, not `==`, on the way into
`select()` and again on the way into `run()`, checks the field names survive,
and checks that defaults past the workspace are still canonicalized into
positional arguments. Mutation-checked by making dispatch rebuild NamedTuples
after canonicalization, which turns it red on the first assertion.

Worth stating what this does not establish: no Provider has served this
contract against real V4.1 tensors, and the workspace's *lifetime* rules --
who may write to it, when it may be reused -- are semantics the contract
carries, not something argument passing can check.

Decode-path op, so the first-call-under-capture consideration from #7716
applies here too: provider obligations in #7240, pinned by #7713, framework
gap filed as ROCm/ATOM#3157. With no Provider enabled, every call routes
native and nothing changes on merge.

Baseline gains one entry, existing six untouched, generated with the gate's own
scanner. `pytest -q tests/test_plugin*.py` -- 99 passed. On MI355X,
`plugin.status()["routed_ops"]` lists it.

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

* Route both batched mxscale GEMMs, and pin why they stay two

The last V4.1 op this series routes is `batched_gemm_a8w8_mxscale_bpreshuffle`.
Routing it alone would have been wrong: its non-shuffled sibling
`batched_gemm_a8w8_mxscale` takes the same five arguments and is reached from
the same path, so leaving one unrouted would let a Provider serve half the
pair and look complete. Both are routed here.

They get the same fingerprint, and that is correct rather than a bug in the
gate. The gate reads signatures, and these signatures are identical:
`x, wo_a, x_scale, w_scale, dtype`. What separates them is the *content* of
`wo_a` -- row-major in one, baked into the (16, 16) MFMA-fragment layout in the
other -- with the same shape, dtype and strides either way.

AITER already says what that costs, in the entry point's own docstring:

    That is why it is a separate entry rather than a flag: the shuffled weight
    has the same shape, dtype and strides as the row-major one, so a mismatched
    kernel reads the right bytes in the wrong order and returns a plausible
    wrong answer instead of failing.

This is the sharpest case of what #7240 states about contract granularity.
`v4`/`v41` at least differ in parameter names; here nothing differs. Neither
the contract gate nor the candidate arity check can tell a kernel bound to the
wrong one apart, and there is no downstream mechanism that recovers.

So the test added here does not assert correctness -- nothing available can.
It asserts that the pair stays a pair. The two look like an obvious duplicate,
so the plausible way to break this is a later cleanup routing one and calling
the other redundant; the assertion makes that delete an explanation rather
than a line. First draft of it skipped when an op was missing, which let
exactly that mistake pass -- mutation-checked after the fix: removing either
route turns it red.

Decode-path ops, so the first-call-under-capture consideration from #7716 and
#7717 applies: obligations in #7240, pinned by #7713, framework gap filed as
ROCm/ATOM#3157. With no Provider enabled every call routes native.

Baseline gains two entries, existing seven untouched. `pytest -q
tests/test_plugin*.py` -- 99 passed. On MI355X both appear in
`plugin.status()["routed_ops"]`.

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

* Route the fused qk-norm/rope/cache/quant op, completing V4.1's API surface

This is the last op ATOM's DeepSeek V4.1 path imports from AITER that was not
routed. With it, every AITER entry point that path calls can be served by a
Provider: sparse prefill (#7715), the two paged decodes (#7716, #7717), the
inverse-rope quant (#7716) and both batched mxscale GEMMs (#7719).

I argued earlier for holding this one back, on two grounds that did not
survive checking.

The first was arity: nineteen parameters fusing five stages looked like a
contract too coarse to serve. Counted properly it is twelve tensors and seven
shape/strategy scalars, which for an op reading q, k, v, two weight sets, the
rope cache, two KV caches and two scale sets is not unusual.

The second was that routing one member would drag in a family -- there are six
nearby entry points differing in quant granularity, rope dimensionality and a
2way variant. ATOM imports exactly one of them, in two files. The others serve
paths outside this surface and can stay unrouted without leaving a hole.

Mounted on the public entry point; `@compile_ops` wraps
`_fused_qk_norm_rope_cache_quant_shuffle_hip`, not the function callers import.

**This contract returns None.** It is the first routed op that delivers
entirely through mutation -- q, k, and the KV caches are written in place. That
is a real constraint on dispatch, not just on providers: code that reads a
falsy return as "the provider declined" would fall through to native after the
provider had already written, running the work twice with the second pass over
the first's output. Nothing in dispatch inspects return values today, and the
test added here is what says so. Mutation-checked by making dispatch treat a
falsy result as a decline, which turns it red on the native-fallback assertion.

Decode-path op, so the first-call-under-capture consideration applies as in
ROCm/ATOM#3157. No Provider enabled means every call routes native.

Baseline gains one entry, existing eight untouched. `pytest -q
tests/test_plugin*.py` -- 99 passed. Verified on MI355X.

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 pushed a commit that referenced this pull request Nov 12, 2026
… an out-of-tree provider (#6689)

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
… an out-of-tree provider (#6689)

AITER keeps the op contract and the aiter.plugin routing surface; the gemm_fusion
framework, kernels, configs, runtime and evidence move to the plugin_poc provider.
The plugin interface is staged byte-identically from PR #7484 so this branch is
testable before #7484 lands.

- aiter/plugin/: staged #7484 interface.
- aiter/ops/gemm_fusion/sp_qkv: route-only neutral op (route(op=..., version=1))
  on the existing flat 15-arg signature; native body raises NoKernelProviderError;
  CONTRACT.md rewritten for the contract/provider model.
- aiter/__init__.py: lazy sp_qkv_fused export; sp_qkv_covers removed.
- op_tests/test_gemm_fusion_sp_qkv_op.py: CPU-only registration/no-provider/fake-
  provider/kill-switch/contract-mismatch/decline tests.
- Removed from aiter (now in plugin_poc feat/sp-qkv-aiter-provider): aiter/gemm_fusion,
  aiter/ops/gemm_fusion/sp_qkv implementation, csrc/gemm_fusion, configs and the
  implementation docs/tools/tests.

CPU gate: pytest op_tests/test_gemm_fusion_sp_qkv_op.py -q -> 7 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants