Skip to content

[RFC #7240] Let a routed op be an opaque node instead of traced Python - #7850

Merged
zufayu merged 5 commits into
mainfrom
codex/route-registers-a-custom-op
Nov 12, 2026
Merged

zufayu merged 5 commits into
mainfrom
codex/route-registers-a-custom-op

Conversation

@zufayu

@zufayu zufayu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #7848, which is necessary but not sufficient.

The part #7848 does not reach

torch.compile traces through the routing wrapper, so a routed op puts this module's dispatch inside the caller's graph. #7848 removed the one untraceable thing on the fast path — a lock and an os.getenv on the first dispatch. With a provider enabled, dispatch does not stop at the fast path: it goes on through provider selection, and the break comes back.

Measured with a counting backend, provider enabled:

graphs
traced wrapper 2
registered as a custom op 1, and the provider's kernel served

Nobody ships a provider today, so nothing is broken right now. But that is the configuration this interface exists for.

What this adds

route(..., fake=...). Given a fake (meta) implementation, route registers the op with torch and returns the registered op rather than the Python wrapper. Dynamo then sees one node and never enters this module — so nothing in here, now or later, can split a caller's graph.

Opt-in, and no op in the tree passes fake= yet. This PR changes the behaviour of nothing; it makes the behaviour available. Enabling it per op is follow-up work, done where someone can verify that op.

Failing to register is an outcome, not an error

why it cannot register what happens
no fake= stays traced
a parameter without a type annotation stays traced
an argument no schema can express (e.g. a workspace dataclass) stays traced
anything else at all stays traced

"Stays traced" is what every routed op does today, so no op is worse off at any point. The excepts are deliberately broad because this runs during import aiter: an uncaught error here stops the package importing, which is far worse than an op staying traced. Every failure mode is the same failure mode — this op does not register.

Of the fifteen routed ops, roughly half would register today if given a fake; the rest need type annotations first, and mla_decode_fwd_v4_nm_ps takes a dataclass and likely never will. None of that blocks this PR.

On mutates_args="unknown"

A per-op list has to be right for every op anyone adds later, and under-declaring is undefined behaviour rather than an error — easy to get wrong, and quiet when it is. "unknown" says every argument may be written: never wrong about any op, only conservative about all of them. The cost is optimisation, not correctness.

What was and was not measured. An op writing through an argument gives the same answer under inductor whether it declares "unknown" or declares nothing, so the permissive option was not observed to break anything here. That is a reason not to claim this choice prevents a failure that has been seen — not a reason to take the permissive option. The comment in the code says exactly this.

What was measured is the part a caller depends on: such an op compiles to one graph and returns exactly what the eager path returns, with the compiled region reading the written buffer afterwards.

Tests

tests/test_plugin_custom_op.py, each case in its own process (torch._dynamo state is global and a library registration cannot be undone in-process):

  • a registered op compiles the region into one graph, correctly;
  • an op that writes through an argument is still correct when the compiled region reads that buffer;
  • a provider still serves a registered op — registration must not cost what routing is for;
  • each way of being unregisterable leaves the op traced and correct.

121 existing plugin tests pass; overhead unchanged at 0.59 of one Signature.bind. black and ruff clean.

Honest limits

The probes use synthetic ops. The installed AITER on the box I have cannot import (flydsl 0.4.1 against a tree wanting >=0.5.0) and its module_aiter_core.so wants a newer GLIBCXX, so no real routed op was exercised end to end. The mechanism under test is Dynamo tracing, which is independent of any kernel — but schema inference and fakes for the real ops still want a run on a machine that can import the package.

Related: #7848 (the fast-path half), #7240 (the interface).

🤖 Generated with Claude Code

PR Self-Review

Reviewed revision

f271ca2a51286eac95b2fcd5c2d82078fa3d18cc

Behavior and intent

torch.compile traces through the routing wrapper, so a routed op puts this module's dispatch inside the caller's graph, and anything Dynamo cannot follow splits it. #7848 removed the one such thing on the fast path; with a provider enabled, dispatch continues past it and the break returns. route(..., fake=...) registers the op with torch instead, so Dynamo sees one node and never enters this module.

The existing behaviour is insufficient only in the configuration nobody runs yet — provider enabled — which is the configuration this interface exists for.

Validation and unverified scope

Verified on gfx942 (torch 2.9.1), with a counting backend, each case in its own process:

graphs
traced wrapper, provider enabled 2
registered, provider enabled 1, and the provider's kernel served

Also measured: an op writing through an argument compiles to one graph and returns exactly what the eager path returns, with the compiled region reading that buffer afterwards; each way of being unregisterable leaves the op traced and correct.

For the one real op this PR registers, fused_qk_norm_rope_cache_quant_shuffle, an A/B against its own op_tests file on this box gives 6 failed, 5 passed, 4 errors both with and without the registration — identical, so those failures are the box (a gfx950 path) and this change introduces none of them.

Unverified: the probes for the mechanism itself use synthetic ops, so no real routed op was put through a compiled region end to end. Schema inference was checked against all fifteen real routed ops — eight infer a schema today — but inference is not execution.

Not claimed: mutates_args="unknown" was not observed to change results versus declaring nothing, under inductor. The conservative choice is taken because a per-op list must be right for every op anyone adds later and under-declaring is undefined behaviour rather than an error — not because the permissive option was seen to break.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

No configuration or tuning keys change. Registration is opt-in per op through a new fake= argument, and exactly one op in the tree passes it. Every other routed op takes the identical path it takes on main — _as_custom_op returns None without a fake before touching anything. For the one registered op, the registered implementation is the same routed wrapper, so the kernel reached and the arguments it receives are unchanged; what changes is that Dynamo stops tracing into the dispatcher. Shapes are not read anywhere in this change.

Changed op tests

None. tests/test_plugin_custom_op.py is an interface test. op_tests/test_fused_qk_norm_rope_cache_quant.py is unchanged and was used as the A/B target above rather than modified.

torch.compile traces through the routing wrapper, so a routed op puts this
module's dispatch inside the caller's graph. Anything in there that Dynamo
cannot follow splits that graph, and a framework permitting one backend
invocation per compilation then fails. #7848 removed the one such thing on
the fast path; with a provider enabled, dispatch continues into provider
selection and the break comes back.

`route(..., fake=...)` registers the op with torch instead: one node, and
nothing inside it reachable from the caller's graph. Measured, provider
enabled, against a counting backend:

    traced wrapper   2 graphs
    registered       1 graph, provider's kernel served

Registration is opt-in per op and failure to register is an outcome rather
than an error. No fake, an unannotated parameter, an argument no schema can
express -- each leaves the op exactly as it is today. Nothing regresses for
any op at any point, and an op becomes protected the day it acquires what
registration needs. No op in the tree passes `fake=` yet, so this change
alters the behaviour of nothing; it makes the behaviour available.

`mutates_args="unknown"` rather than a per-op list: a list has to be right
for every op anyone adds later, and under-declaring is undefined behaviour
rather than an error. "unknown" is never wrong, only conservative. It was
not observed to change results either way under inductor, and the comment
says so rather than claiming it prevents a failure that has been seen.

tests/test_plugin_custom_op.py, in subprocesses, pins: one graph for a
registered op; an op writing through an argument still correct with the
compiled region reading that buffer; a provider still served; and each way
of being unregisterable leaving the op traced and correct.

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

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 7850 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@zufayu
zufayu marked this pull request as ready for review November 12, 2026 03:24
@zufayu
zufayu requested a review from a team November 12, 2026 03:24
@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 4c37b0a9d2e0 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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 and others added 3 commits November 12, 2026 03:38
`fused_qk_norm_rope_cache_quant_shuffle` returns None and writes through
its arguments, so its fake is `return None` -- correct by inspection
rather than by shape arithmetic, which makes it the right op to be first.
Its public name is the routed function with no guard above it, so it was
one of the ops whose dispatch a caller's compiled graph could reach.

A/B against op_tests/test_fused_qk_norm_rope_cache_quant.py on gfx942:
6 failed, 5 passed, 4 errors both with and without the registration --
identical, so the failures are this box (a gfx950 path) and the change
introduces none of them. A deselected test is broken on main: it takes
eleven positional arguments pytest never supplies.

The test fix matters more than it looks. tests/test_plugin_custom_op.py
asked `hasattr(op, "_schema")` to tell a registered op from a Python
wrapper. `_schema` is on an OpOverload, not on the OpOverloadPacket that
route hands back, so that answered False either way and the assertion
that an unregisterable op stays traced passed without checking anything.
Now it asks the type, and forcing registration without a fake fails it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#7848 landed the eager config snapshot in the same file this branch
rewrites. Merged cleanly; verified both halves survive rather than
assuming an absent conflict marker means an intact result -- the snapshot
is built at import, _as_custom_op is intact, and the first registered op
still comes back as an OpOverloadPacket.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#6689 added the sp_qkv_fused contract. Clean merge; verified rather than
assumed -- 16 contracts with none added or lost by this branch, both the
eager snapshot and _as_custom_op intact, and the registered op still an
OpOverloadPacket.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#7791 added mla_sparse_prefill. This branch adds no contract, so the
baseline is main's 17 unchanged; the plugin changes and the one registered
op survive the merge, checked rather than inferred from a clean auto-merge.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu merged commit ef839bb into main Nov 12, 2026
@zufayu
zufayu deleted the codex/route-registers-a-custom-op branch November 12, 2026 10:43
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
#7850)

* feat(plugin): let a routed op be an opaque node instead of traced Python

torch.compile traces through the routing wrapper, so a routed op puts this
module's dispatch inside the caller's graph. Anything in there that Dynamo
cannot follow splits that graph, and a framework permitting one backend
invocation per compilation then fails. #7848 removed the one such thing on
the fast path; with a provider enabled, dispatch continues into provider
selection and the break comes back.

`route(..., fake=...)` registers the op with torch instead: one node, and
nothing inside it reachable from the caller's graph. Measured, provider
enabled, against a counting backend:

    traced wrapper   2 graphs
    registered       1 graph, provider's kernel served

Registration is opt-in per op and failure to register is an outcome rather
than an error. No fake, an unannotated parameter, an argument no schema can
express -- each leaves the op exactly as it is today. Nothing regresses for
any op at any point, and an op becomes protected the day it acquires what
registration needs. No op in the tree passes `fake=` yet, so this change
alters the behaviour of nothing; it makes the behaviour available.

`mutates_args="unknown"` rather than a per-op list: a list has to be right
for every op anyone adds later, and under-declaring is undefined behaviour
rather than an error. "unknown" is never wrong, only conservative. It was
not observed to change results either way under inductor, and the comment
says so rather than claiming it prevents a failure that has been seen.

tests/test_plugin_custom_op.py, in subprocesses, pins: one graph for a
registered op; an op writing through an argument still correct with the
compiled region reading that buffer; a provider still served; and each way
of being unregisterable leaving the op traced and correct.

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

* Register the first routed op, and fix a test that proved nothing

`fused_qk_norm_rope_cache_quant_shuffle` returns None and writes through
its arguments, so its fake is `return None` -- correct by inspection
rather than by shape arithmetic, which makes it the right op to be first.
Its public name is the routed function with no guard above it, so it was
one of the ops whose dispatch a caller's compiled graph could reach.

A/B against op_tests/test_fused_qk_norm_rope_cache_quant.py on gfx942:
6 failed, 5 passed, 4 errors both with and without the registration --
identical, so the failures are this box (a gfx950 path) and the change
introduces none of them. A deselected test is broken on main: it takes
eleven positional arguments pytest never supplies.

The test fix matters more than it looks. tests/test_plugin_custom_op.py
asked `hasattr(op, "_schema")` to tell a registered op from a Python
wrapper. `_schema` is on an OpOverload, not on the OpOverloadPacket that
route hands back, so that answered False either way and the assertion
that an unregisterable op stays traced passed without checking anything.
Now it asks the type, and forcing registration without a fake fails it.

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 that referenced this pull request Nov 13, 2026
)

Both are names a framework writes itself: top_k_per_row_decode has 26
non-comment call sites across five ATOM backends, and topk_gating sits on
the DeepSeek-V4 / MiniMax-M3 MoE routing path. Each gains a fake and
route(..., fake=...) on the public name, following #7850's own first use.

With no provider enabled each makes the call it made before; what changes
is that asking a provider can no longer split a caller's compiled graph.

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zufayu added a commit that referenced this pull request Nov 13, 2026
route(..., fake=...) landed in #7850 but is opt-in per op, and the default
-- no fake -- is the state that splits a caller's graph the day a provider
is enabled. One op in the tree passed it.

Two more can be registered without touching any contract: rmsnorm_with_add
returns nothing, and gemm_a8w8_blockscale reuses the fake its own
torch_compile_guard already runs in production.

The rest cannot, for three measured reasons, and the new gate makes each
one cost a written sentence rather than nothing: a contract carrying an
output buffer the op returns (opcheck rejects it, and under compile the
buffer is silently left unwritten), a contract rendered without type
annotations (adding them moves the fingerprint), and a parameter no schema
can express.

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zufayu added a commit that referenced this pull request Nov 13, 2026
…guard (#7854)

* feat(plugin): route the three remaining ops that already have a guard

`per_group_quant_hip`, `mhc_pre` and `mhc_post` are called on the DSV4.1
path by vLLM, SGLang and ATOM, and no provider can serve any of them. All
three are ordinary Python implementations that already carry
`torch_compile_guard`, so routing underneath it costs nothing: the guard
is what Dynamo sees, and the plugin's dispatch never reaches a caller's
compiled graph. They need neither #7850 nor the eager snapshot to be safe.

`per_group_quant` routes on a neutrally named `_per_group_quant_routed`
rather than on `per_group_quant_hip`. That was not the first draft --
test_the_backend_suffix_gate_is_not_vacuous rejected it, correctly: a
route's contract is the decorated function's whole signature, so
decorating a backend-named function writes that name's shape into what
providers implement against. `rmsnorm` sits the same way beneath its two
public spellings.

All three lacked docstrings, which #7787's gate requires of a routed op.
Written from the implementations: `mhc_pre` returns three new tensors and
writes nothing (matching its `mutates_args=[]`), `mhc_post` writes `out`
and returns None (matching `mutates_args=["out"]`), `per_group_quant`
returns `(y, scale)` and writes nothing.

Public signatures are byte-identical to main for all three, checked by
AST. Nineteen contracts, none carrying a backend parameter, none lost.

Left out deliberately: `mla_sparse_prefill_v4`, whose `backend is None`
branch chooses between asm and opus by arch and shape with a fallback,
and whose asm path is gfx1250-only -- not verifiable on the gfx942 box
this was written on, and getting it wrong changes which kernel runs. The
four bare `@compile_ops` stubs need a wrapper each, and the wrapper would
itself be exposed unless it also carries a guard and a fake; those belong
with #7850's mechanism, one at a time.

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

* [OPUS] [Plugin] Register per_group_quant, the one routed op here that cannot be shielded

The other two ops this PR routes, `mhc_pre` and `mhc_post`, carry a
`torch_compile_guard` outside their `@route`, so a caller already reaches
an opaque op and the plugin's dispatch cannot enter its graph.
`per_group_quant` does not: the route sits on `_per_group_quant_routed`,
while the guard sits on `per_group_quant_hip`, a different function. A
decorator-order scan therefore cannot see it as shielded, and it passed no
`fake=`, which leaves it in the state that splits a caller's graph the day a
provider is enabled.

The fake reports shapes only. Both results are freshly allocated in the
native body, so neither aliases an argument and `infer_schema` renders
`-> (Tensor, Tensor)` with nothing to declare about aliasing.
`transpose_scale` shuffles the scale's contents inside the kernel without
moving its shape, so it does not appear in the fake.

Verified:
  * `infer_schema(native, mutates_args="unknown")` renders a schema.
  * Shapes checked on meta tensors against the native body's two branches:
    default -> (m, n // group_size); `scale_layout_m32k4` ->
    ((m + 31) // 32 * 32, n // 32); `transpose_scale` moves neither.
  * `tests/test_plugin_contracts.py` passes on this branch (16), and the
    contract fingerprint is unchanged -- the contract is taken from the
    native signature, which this does not touch, so no op_version bump.
  * Merged locally with #7881, whose registration gate reports
    `per_group_quant` as unregistered without this commit and passes with
    it (18).

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]>
Co-authored-by: root <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
)

Both are names a framework writes itself: top_k_per_row_decode has 26
non-comment call sites across five ATOM backends, and topk_gating sits on
the DeepSeek-V4 / MiniMax-M3 MoE routing path. Each gains a fake and
route(..., fake=...) on the public name, following #7850's own first use.

With no provider enabled each makes the call it made before; what changes
is that asking a provider can no longer split a caller's compiled graph.

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
route(..., fake=...) landed in #7850 but is opt-in per op, and the default
-- no fake -- is the state that splits a caller's graph the day a provider
is enabled. One op in the tree passed it.

Two more can be registered without touching any contract: rmsnorm_with_add
returns nothing, and gemm_a8w8_blockscale reuses the fake its own
torch_compile_guard already runs in production.

The rest cannot, for three measured reasons, and the new gate makes each
one cost a written sentence rather than nothing: a contract carrying an
output buffer the op returns (opcheck rejects it, and under compile the
buffer is silently left unwritten), a contract rendered without type
annotations (adding them moves the fingerprint), and a parameter no schema
can express.

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
…guard (#7854)

* feat(plugin): route the three remaining ops that already have a guard

`per_group_quant_hip`, `mhc_pre` and `mhc_post` are called on the DSV4.1
path by vLLM, SGLang and ATOM, and no provider can serve any of them. All
three are ordinary Python implementations that already carry
`torch_compile_guard`, so routing underneath it costs nothing: the guard
is what Dynamo sees, and the plugin's dispatch never reaches a caller's
compiled graph. They need neither #7850 nor the eager snapshot to be safe.

`per_group_quant` routes on a neutrally named `_per_group_quant_routed`
rather than on `per_group_quant_hip`. That was not the first draft --
test_the_backend_suffix_gate_is_not_vacuous rejected it, correctly: a
route's contract is the decorated function's whole signature, so
decorating a backend-named function writes that name's shape into what
providers implement against. `rmsnorm` sits the same way beneath its two
public spellings.

All three lacked docstrings, which #7787's gate requires of a routed op.
Written from the implementations: `mhc_pre` returns three new tensors and
writes nothing (matching its `mutates_args=[]`), `mhc_post` writes `out`
and returns None (matching `mutates_args=["out"]`), `per_group_quant`
returns `(y, scale)` and writes nothing.

Public signatures are byte-identical to main for all three, checked by
AST. Nineteen contracts, none carrying a backend parameter, none lost.

Left out deliberately: `mla_sparse_prefill_v4`, whose `backend is None`
branch chooses between asm and opus by arch and shape with a fallback,
and whose asm path is gfx1250-only -- not verifiable on the gfx942 box
this was written on, and getting it wrong changes which kernel runs. The
four bare `@compile_ops` stubs need a wrapper each, and the wrapper would
itself be exposed unless it also carries a guard and a fake; those belong
with #7850's mechanism, one at a time.

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

* [OPUS] [Plugin] Register per_group_quant, the one routed op here that cannot be shielded

The other two ops this PR routes, `mhc_pre` and `mhc_post`, carry a
`torch_compile_guard` outside their `@route`, so a caller already reaches
an opaque op and the plugin's dispatch cannot enter its graph.
`per_group_quant` does not: the route sits on `_per_group_quant_routed`,
while the guard sits on `per_group_quant_hip`, a different function. A
decorator-order scan therefore cannot see it as shielded, and it passed no
`fake=`, which leaves it in the state that splits a caller's graph the day a
provider is enabled.

The fake reports shapes only. Both results are freshly allocated in the
native body, so neither aliases an argument and `infer_schema` renders
`-> (Tensor, Tensor)` with nothing to declare about aliasing.
`transpose_scale` shuffles the scale's contents inside the kernel without
moving its shape, so it does not appear in the fake.

Verified:
  * `infer_schema(native, mutates_args="unknown")` renders a schema.
  * Shapes checked on meta tensors against the native body's two branches:
    default -> (m, n // group_size); `scale_layout_m32k4` ->
    ((m + 31) // 32 * 32, n // 32); `transpose_scale` moves neither.
  * `tests/test_plugin_contracts.py` passes on this branch (16), and the
    contract fingerprint is unchanged -- the contract is taken from the
    native signature, which this does not touch, so no op_version bump.
  * Merged locally with #7881, whose registration gate reports
    `per_group_quant` as unregistered without this commit and passes with
    it (18).

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]>
Co-authored-by: root <[email protected]>
Jasen2201 added a commit to ROCm/ATOM that referenced this pull request Nov 13, 2026
…asses

Packed rows (V4.1's layout: `band_offsets`, offset top-k) are now the only
FP8 prefill path. The rectangular key-window path, the aiter signature
probes and both fallbacks are gone. The probes were already broken:
aiter's routed `top_k_per_row_decode` (ROCm/aiter#7850) hides `row_starts`
from `inspect.signature`, so packed never ran on current aiter. This needs
`fp8_mqa_logits(out=, out_offsets=)` from ROCm/aiter#7517.

The key workspace has a fixed size: one request of `max_model_len` plus a
step's tokens. A step whose keys exceed it is gathered and scored in passes
of whole requests (`concat_passes`). Each pass's rows are split over every
DCP rank, so no rank waits on another's share. Under DCP a pass reads this
rank's shard into its slot, all-gathers in place and restores key order;
`_all_gather_slot` serves this and the selection gather. The old allocating
DCP key gather is removed.

The plane holds a PCP/DCP rank's share of a step's rows, each up to
`max_model_len`, within the logits budget, and is shared with decode.
FP4 (one range) and FP8 (passes) build their DCP gather indices with one
helper. The pass planner and key workspace live in `indexer/workspace.py`
with V4.1's packed helpers and import no aiter, so the CPU job tests them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip pushed a commit to ROCm/ATOM that referenced this pull request Nov 16, 2026
…es (#3043)

* fix(indexer): keep FP8 prefill index logits and gathered keys in persistent workspaces

The FP8 prefill (concat) indexer allocated, per 8K chunk and per indexer layer,
buffers sized by the step's context: each band's dense logits inside aiter's
fp8_mqa_logits (up to the 2 GiB budget, e.g. 1024 rows x 350K keys = 1.4 GiB per
rank under DCP8) and the gathered keys (DCP shard, all-gather output and the
de-interleaved copy, ~45 MiB each at 350K). Their size grows every chunk of a
long prefill, so the caching allocator never reuses last chunk's block and
reserves a new one: Kimi-K3.1-Pro 1P1D DCP8 reserved +15 GiB in a minute until
HBM was full, and a hipMalloc that then never returned left the ranks
deadlocked in their collectives. The memory profile (an 8K prefill with no
history) never reaches these sizes, so the KV budget did not leave room either.

- The concat path scores its bands into the builder's LogitsWorkspace (the
  decode plane, sized for the larger of the two needs) at the pitch aiter pads
  to, through fp8_mqa_logits(logits=...) when aiter provides it.
- Gathered keys live in a ConcatKeyWorkspace held for the server's life and
  doubled only when a step's keys outgrow it; under DCP the shard is read
  straight into this rank's slot of the all-gather buffer, gathered in place
  and de-interleaved with index_select(out=).
- Both are allocated before the memory profile, so the KV budget counts them.

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

* fix(indexer): default logits budget to 1024 MiB

* fix(indexer): group prefill requests within fixed workspace capacity

* bench(indexer): compare decode scoring under logits budgets

* bench(indexer): drop the logits-budget bench script from this PR

Keeps the PR within the 15-file limit; the script is a manual GPU bench,
not collected by pytest.

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

* test(indexer): trim the grouping tests to the CPU unit set

Drop the GPU/RCCL grouping tests (skipped in non-GPU CI) and the CPU tests
that repeat coverage kept elsewhere: the pack tests live in
test_sparse_indexer_chunk.py, per-group banding in the scoring test.

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

* fix(indexer): keep the logits budget default at 2048 MiB

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

* fix(indexer): score each FP8 prefill band against its own requests' keys

A concat band's logits row was as wide as the step's keys, every request's
together, while the plane is sized for one request of the model length. A
legal batch could therefore need a row wider than the plane. 67e1e68
answered that by gathering and scoring requests in groups, but under DCP the
query rows stayed split over the whole step, so a group's rows usually
belonged to one or two ranks: the others gathered its keys and waited, and
scoring ran rank after rank, about 4-6x the critical path on a 3.55M-key
Kimi-K3.1 C72 step (host-side cost model).

A row only reads its own request's keys. Each band now scores against a
window of the gathered keys, the requests its rows belong to
(`concat_window_bands`), so its pitch is that window's width. One request is
at most the model length, which the plane holds a row of, so no step needs
grouping for the logits. Bands pack neighbouring requests while they fit and
cut a request whose rows do not.

The request grouping is removed: keys are gathered once per step (one DCP
all-gather) and every rank scores its contiguous share of the step's rows,
as on main. The key workspace grows, with a warning, when a step's keys
outgrow it, as before 67e1e68. Bounding that is left to a follow-up.

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

* refactor(indexer): share workspace band execution with V4.1

* feat(indexer): pack FP8 prefill logits in the shared workspace

* fix(indexer): pack FP8 prefill rows only and gather keys in bounded passes

Packed rows (V4.1's layout: `band_offsets`, offset top-k) are now the only
FP8 prefill path. The rectangular key-window path, the aiter signature
probes and both fallbacks are gone. The probes were already broken:
aiter's routed `top_k_per_row_decode` (ROCm/aiter#7850) hides `row_starts`
from `inspect.signature`, so packed never ran on current aiter. This needs
`fp8_mqa_logits(out=, out_offsets=)` from ROCm/aiter#7517.

The key workspace has a fixed size: one request of `max_model_len` plus a
step's tokens. A step whose keys exceed it is gathered and scored in passes
of whole requests (`concat_passes`). Each pass's rows are split over every
DCP rank, so no rank waits on another's share. Under DCP a pass reads this
rank's shard into its slot, all-gathers in place and restores key order;
`_all_gather_slot` serves this and the selection gather. The old allocating
DCP key gather is removed.

The plane holds a PCP/DCP rank's share of a step's rows, each up to
`max_model_len`, within the logits budget, and is shared with decode.
FP4 (one range) and FP8 (passes) build their DCP gather indices with one
helper. The pass planner and key workspace live in `indexer/workspace.py`
with V4.1's packed helpers and import no aiter, so the CPU job tests them.

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

* docs(indexer): the logits budget also sizes packed FP8 prefill rows

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

* refactor(indexer): drop dead score_topk keys and split the DCP gather builders

- `score_topk(keys=)` and `_score_concat`'s gathered keys lost their only
  caller with the old DCP gather; both are removed.
- `ConcatPass.dcp`, `ConcatKeys.workspace`, `IndexRows.workspace` and
  `IndexRows.passes` carry their types. Packed concat rows keep their bands
  in each pass only.
- `_build_dcp_indexer_prefill_meta` (a whole step, FP4) and
  `_dcp_pass_gathers` (FP8 passes) each have one result; both use
  `_dcp_shard_lengths` and `_dcp_gathers`.
- `PackedRows` stays with V4.1, its only user. `cdiv` joins the indexer's
  shared helpers.

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

* refactor(indexer): name the DCP pass gather and test its index on the CPU

- `DcpGather` (`local_total`, `local_cu`, `gather_index`) replaces the
  anonymous tuple on `ConcatPass.dcp`, and `StagedIndexRows.passes` and the
  builder's `gathers` carry their types.
- The gather index is host arithmetic in `indexer/workspace.py`
  (`dcp_gather_index`); the builder only uploads it, with `upload_numpy`.
  A CPU test shards keys over 4 ranks with interleave 2 and checks that
  each pass's index returns every key once, in order.
- `cdiv` comes from `atom.mono.plan.shard`; one `cp_gather` call serves
  both gather paths.

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

* docs(indexer): the logits budget sizes one band, for decode and FP8 prefill

envs.py said the budget sizes only the decode logits workspace. It also
sizes the packed FP8 prefill plane, and the workspace takes the larger
of the two. plane_capacity and LogitsWorkspace.for_rows return one band
of up to `rows` rows, not a plane that holds every band.

Zip the passes with their DCP gathers strictly, and build ConcatPass in
one call. docs/model_ops_guide.md keeps main's row; the plane is
described in environment_variables.md.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants