Skip to content

Adapt AKLR to the AITER kernel plugin interface (draft handoff) - #95

Draft
zufayu wants to merge 5 commits into
AMD-AGI:mainfrom
zufayu:aiter-provider-pilot
Draft

zufayu wants to merge 5 commits into
AMD-AGI:mainfrom
zufayu:aiter-provider-pilot

Conversation

@zufayu

@zufayu zufayu commented Nov 9, 2026 •

Copy link
Copy Markdown

What this is

AKLR as a kernel plugin for AITER. AITER's provider interface (RFC ROCm/aiter#7240) lets an out-of-tree plugin serve AITER's routed ops at call time — no private AITER copy, no monkeypatch, no waiting for an in-tree merge.

This is a draft opened as a handoff to the AKLR side, not a request to merge. The section What AKLR needs to change is the point of it.

What already works

  • pyproject.toml declares the entry point [project.entry-points."aiter.plugins"] aklr = "aklr.plugins.aiter:provider" — the one line that lets AITER discover AKLR at all.
  • Four contracts are adapted: rmsnorm, rmsnorm_with_add, gemm_a8w8_blockscale and gemm_a8w8_blockscale_bpreshuffle.
  • select() answers from AKLR's own fallback_reason() and runs nothing: no kernel for this device, no measured workload at this shape, or a measured speedup below AKLR_MIN_SPEEDUP all decline here rather than failing later.
  • Verified on MI355X: output matches the op's own arithmetic to 1.953e-3 with the residual output exact, and the selected kernel's identity is recorded before execution. Serving was per Point and mixed — some token counts served, others declined for AKLR's own reasons. That mix is the result worth having: AITER asked and recorded, and judged nothing.
  • aklr/plugins/aiter/REPRODUCING.md is written so somebody who was not involved can run it. Where a step is not yet possible from released software, it says so rather than pretending.

Installing it does not enable it. AITER is default-deny: a framework turns AKLR on with aiter.plugin.configure(enable=["aklr"], source=...), which records who asked. Nothing in the environment can enable a plugin.

What AKLR needs to change

Ordered by what will block somebody first.

1. Device-name matching — this one blocks every reproduction

AKLR's schemas declare hardware: MI355X, and the match requires every field a schema states. On some ROCm builds the card reports as "AMD Radeon Graphics", which normalizes to a model id matching nothing — so every schema is skipped on the hardware those kernels were measured on:

loaded 0 schemas, 0 points; skipped 324 schemas of other targets;
device target gfx950/RADEON GRAPHICS

The only way through today is overriding DeviceTarget._target_by_device_idx by hand before importing AKLR (the recipe documents it). This is a detection failure, not a configuration problem — relaxing the match (gfx950 is enough to decide) would keep the next person from hitting it on step one.

2. Kernel identity has no accessor

There is a TODO in _candidate(): AKLR's dispatcher knows which kernel file serves a Point — the uuid hashes the kernel — but does not expose it. AITER's provenance wants that kernel's identity; the adapter currently fills in the contract id ([email protected]) instead.

A small read-only accessor on the AKLR side would fix it. This is not an interface limitation.

3. Schema loading is all-or-nothing

If any kernel fails to import, init_once raises and every contract stays closed at NO_SCHEMA — including the ones that were fine. With a mismatched flydsl it looks like:

cannot import kernel.py::run: ModuleNotFoundError: No module named 'flydsl.extension'

Today the way out is [email protected],..., named one at a time. Isolating a load failure to its own contract would be better.

Deliberately outside the contract

Not bugs — the current edge of AKLR's contracts, and where select() declines explicitly. These are the extension points if AKLR wants to cover them:

  • E8M0 group32 scales — AITER's signature allows them; AKLR declares fp32 per 128x128 of b and 1x128 of a.
  • split_k — no counterpart in this contract.
  • gemma_norm=True — not part of AKLR's rms_norm contract.

Dependency: the AITER side is not merged yet

aiter.plugin does not exist on ROCm/aiter main, so AKLR's entry point resolves to nothing on a released AITER. The interface lives in three draft PRs:

Once they merge, step 1 of the recipe becomes pip install aiter and the rest is unchanged.


🤖 Generated with Claude Code

AITER's provider interface (RFC ROCm/aiter#7240) lets an out-of-tree plugin
serve its routed ops at call time, without a private AITER copy, a
monkeypatch, or waiting for an in-tree merge. This is AKLR's side of it: an
adapter exposing `select()` over the contracts we already have, and the
packaging line that lets AITER find us.

The entry point is the whole mechanism:

    [project.entry-points."aiter.plugins"]
    aklr = "aklr.plugins.aiter:provider"

Installing it makes AKLR available, never active. AITER is default-deny, so a
framework turns us on with `aiter.plugin.configure(enable=["aklr"], source=...)`
and that source is recorded in every routing decision. Nothing in the
environment can enable a plugin.

The adapter covers rms_norm, rmsnorm_with_add and both blockscale GEMM entries.
It declines cheaply: a pre-check rejects calls outside our contract (non-fp32
scales, a split_k we have no counterpart for) before asking the dispatcher, and
`fallback_reason()` answers the rest. Declining is ordinary operation, not a
failure, and AITER reaches its own kernel with nothing having executed.

REPRODUCING.md is the recipe, written for somebody who was not involved. It
names three rough edges that are ours, in the order they bite: a host reporting
"AMD Radeon Graphics" matches none of our schemas and silently serves nothing;
one unloadable kernel closes every contract in the process rather than its own;
and a kernel built against another flydsl can pass select() and fail inside
run(), where AITER deliberately does not fall back.

Not yet usable from released software: `aiter.plugin` lives in draft PRs, so
the entry point resolves to nothing on a released AITER. The recipe says so.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu zufayu changed the title 适配 AITER kernel plugin 接口:交接给 AKLR(draft) Adapt AKLR to the AITER kernel plugin interface (draft handoff) Nov 9, 2026
select() was one if-chain reading args by index, each branch guarded with
len(args) > N. Those guards were dead: AITER canonicalizes a call against the
contract and applies defaults before asking, so a provider always sees the
full positional list. Guarding against a short one defended against nothing
and hid what the indices meant.

Each contract now has a selector that unpacks its arguments by name, and
select() is a table lookup. A contract that grows a parameter fails there
loudly -- AITER records a select error and routes native -- instead of reading
the wrong index quietly, which is the failure that argument counts lining up
by accident produces.

Also folded out of the GEMM branches: both reach one AKLR contract through the
same checks, written twice, including the isBpreshuffled recovery that the
canonical call makes unnecessary. The two run functions stay separate because
each must accept its own contract's call, which AITER verifies.

op_versions is now derived from the table, so the declared ops cannot drift
from the ones that have a selector.

Verified on MI355X (mi355-gpu-41, rocm/atom-dev, torch 2.10.0+rocm7.2.4), AKLR
discovered through packaging metadata and enabled with configure():
  rmsnorm      64x6144  served  kernel [email protected], max abs err 3.9e-3 (bf16)
  rmsnorm        7x777  declined -> native, reason provider-declined
  gemm bpreshuffle m1 n4096 k4096   served  kernel [email protected]
  gemm bpreshuffle m8 n4096 k8192   served
  gemm bpreshuffle m16 n5120 k4096  declined -> native
That exercises two selectors of different arity (4 and 6) on both paths, and
matches the expectation table in REPRODUCING.md. black and ruff
clean; every selector's arity also matches AITER's committed contract
baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu force-pushed the aiter-provider-pilot branch from 2a885ea to 2dc5feb Compare November 9, 2026 05:40
gemm_a8w8_blockscale with isBpreshuffled=True offered the bpreshuffle entry s
run function. The layout is the same either way, so it looked right, but the
two AITER entries are different contracts: blockscale takes seven arguments,
bpreshuffle six. AITER checked the candidate before handing it the call and
refused it -- reason contract-mismatch, logged by name -- so the call went
native and nothing was corrupted. That check is the only reason this was a
declined call rather than a kernel reading the wrong arguments.

The run function now follows the contract, chosen by the selector that knows
which one it is answering for; bpreshuffled stays what it always was, a flag
deciding operand_format inside the call.

Found by running the pilot on MI355X rather than by reading: both selectors
return the same AKLR contract id, and the shapes line up until AITER counts
the parameters.
zufayu and others added 2 commits November 10, 2026 02:16
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]>
kyle-256 added a commit that referenced this pull request Nov 17, 2026
* feat(plugins): serve aiter's routed ops through its kernel plugin interface

aiter now asks the providers a framework enabled, before each call of an op
it routes, whether they serve it (aiter.plugin, RFC ROCm/aiter#7240). AKLR
becomes one: aklr/plugins/aiter/provider, declared by the aiter.plugins entry
point, answers from AKLR's dispatch table without running anything and
declines whatever AKLR has no qualified kernel for, so aiter runs its own.

- AKLR_AITER_PLUGIN=1 has the sglang and vLLM plugins enable it at start-up,
  first among the providers aiter asks, the others kept; other hosts call
  aklr.plugins.aiter.provider.enable(). An aiter without the interface keeps
  its ops.
- Selectors for the routed ops AKLR has kernels for: rmsnorm, rmsnorm_with_add,
  gemm_a8w8_blockscale, gemm_a8w8_blockscale_bpreshuffle, per_group_quant (fp8
  in groups of 128 with aiter's transposed scales, mxfp8 in groups of 32),
  mhc_pre, and topk_gating with sigmoid scores and a bias (one group of
  biased_grouped_topk). Each unpacks aiter's call by name, declines what the
  AKLR contract does not take, and binds a run that takes aiter's parameters.
- An op's api gains serving(): the kernel dispatch would run for a call, or
  its fallback reason, counted as fallback_reason counts it. The candidate
  names that kernel as AKLR_TRACE does (RunnableMetadata.kernel_ref).

Takes over #95, which opened this port.

* fix(plugins): decline aiter's topk_gating while it routes by HERD

With AITER_FLYDSL_USE_HERD=1, aiter's topk_gating answers sigmoid calls
without shared experts on gfx950 with HERD routing for its model profiles
(Kimi-K3's 896 experts among them): top-(k+1) candidates and a drop by batch
popularity. AKLR's biased_grouped_topk computes the exact top-k, so serving
those calls changed which experts a token reaches. The selector now declines
them.

* fix(plugins): address the review of the aiter provider

- DispatcherRegistry.init_once takes a lock, so concurrent first calls (the
  aiter provider's, a framework hook's) run one init and do not replace the
  tables a call was selected against.
- gemm_a8w8_blockscale_bpreshuffle declines an x_scale marked is_row_major:
  aiter reads its bytes column-major whatever the marker says.
- per_group_quant declines the mxfp8 branch on a torch without
  float8_e8m0fnu, and its served test case is skipped there.
@zhenhuang12

Copy link
Copy Markdown
Collaborator

@zufayu this PR conflicts with the latest main and could not be rebased automatically. Please rebase it onto the latest main and resolve the conflicts.

kyle-256 pushed a commit that referenced this pull request Dec 1, 2026
…, not its Markdown-escaped one (#431)

schema_short_name escaped its result for Markdown, and the terminal progress line used it,
so every underscore printed as &#95;. It now returns the plain name; the two Markdown
report callers escape it themselves.

This branch has not been deployed

No deployments
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.

2 participants