Skip to content

[Plugin] Route topk_gating and top_k_per_row_decode as custom ops - #7874

Merged
zufayu merged 1 commit into
mainfrom
codex/route-topk-decode
Nov 13, 2026
Merged

zufayu merged 1 commit into
mainfrom
codex/route-topk-decode

Conversation

@zufayu

@zufayu zufayu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First use of route(..., fake=...) from #7850 on ops downstream actually calls.

Which two, and why these

op ATOM call sites (non-comment) where
top_k_per_row_decode 26 dcp_ops, rtpllm, sglang, vllm, deepseek_v41/indexer — five backends
topk_gating import + call the MoE routing path for DeepSeek-V4 and MiniMax-M3 (atom/model_ops/moe.py)

Both are names a framework writes itself, not aiter internals reached through some other entry point. That is the line this batch is drawn on: an op ATOM never names is not a contract candidate, whatever its call count inside aiter.

What changes

Each gains a fake and @route(op=..., version=1, fake=...) on the public name, following fused_qk_norm_rope_cache_quant_shuffle from #7850. No private forwarding layer: both ops return None and write through their arguments, so the fake is return, and nothing in the signature needs restating in a wrapper.

With no provider enabled, each makes exactly the call it made before. What changes is that a provider can be asked, and that asking it can no longer split a caller's compiled graph.

Validation

Everything below ran on gfx942, torch 2.9.1, against this tree (PYTHONPATH pointed at the worktree — the system-installed aiter on this box cannot import, see Limits).

check result
op_tests/test_moe_topk_gating.py passes, exit 0 — 3 score funcs x 3 dtypes x the shape sweep
op_tests/test_topk_per_row.py passes, exit 0
numeric equivalence vs. this branch's base bit-identical, reproducibly
both ops registered torch.ops.aiter_routed.*, OpOverloadPacket for each
tests/test_plugin_contracts.py, tests/test_plugin_selector_arity.py 20 passed
baseline regenerated with routed_contracts(), 17 -> 19; none lost, none carrying backend or kernelName
black, ruff check clean

One result worth writing down

The first equivalence run disagreed, and it was not the patch. top_k_per_row_decode(stable=False) is not deterministic: the unmodified base gives a different answer on two consecutive runs with identical input. Under stable=True the two trees agree bit for bit, repeatedly.

So the hash comparison only carries information once the hash is known to be stable without the change. That is now checked rather than assumed, and anyone re-running this A/B should pass stable=True.

Limits

No multi-GPU or gfx950 path is exercised here; test_topk_per_row.py skips its sampled_per_device case for want of two gfx950 devices. ci:all is set so the downstream suites run.

🤖 Generated with Claude Code

PR Self-Review

Reviewed revision

b76f21e5321328fca2cd2cd3b95570c34dd2e168

Behavior and intent

Two ops a framework names directly cannot be served by any provider. top_k_per_row_decode has 26 non-comment call sites across five ATOM backends; topk_gating sits on the DeepSeek-V4 / MiniMax-M3 MoE routing path. Both return None and write through their arguments, so each takes a trivial fake and route(..., fake=...) on the public name — the pattern #7850 established on fused_qk_norm_rope_cache_quant_shuffle.

The existing behaviour is insufficient only in that no provider can be asked. With none enabled, each op makes the call it made before; registration is what keeps the plugin's dispatch out of a caller's compiled graph once one is.

Validation and unverified scope

Verified on gfx942, torch 2.9.1, against this tree:

  • op_tests/test_moe_topk_gating.py passes, exit 0 — three score functions x three dtypes x the shape sweep;
  • op_tests/test_topk_per_row.py passes, exit 0;
  • numeric equivalence against this branch's base is bit-identical and reproducible, under stable=True;
  • both ops register — OpOverloadPacket under torch.ops.aiter_routed;
  • tests/test_plugin_contracts.py and tests/test_plugin_selector_arity.py: 20 passed;
  • baseline regenerated with routed_contracts() rather than edited, 17 -> 19, none lost, none carrying backend or kernelName;
  • black and ruff check clean.

Unverified: no gfx950 or multi-GPU path — test_topk_per_row.py skips sampled_per_device for want of two gfx950 devices, and the sampled shapes are not served on gfx942. No compiled-region test is added here; #7850 covers the mechanism with synthetic ops. ci:all is set so the downstream suites run.

The boundary this introduces, and what covers it

Registration makes each op opaque to Dynamo, which is the point — but it also means the fake, not the body, is what a trace sees. Both fakes are correct by construction here because both ops return nothing: there is no value for a fake to get wrong. That is why these two were taken first.

The evidence that the opaque form still computes what the traced form did is the bit-identical equivalence run plus the two op_tests passing against the patched tree — the ops are exercised through the registered path, since the decorator is on the public name every caller uses.

One result worth recording: the first equivalence run disagreed and the patch was not the cause. top_k_per_row_decode(stable=False) is non-deterministic — the unmodified base gives different answers on two consecutive runs with identical input. The comparison carries information only under stable=True, which is how it was then run. A hash A/B says nothing until the hash is known to be stable without the change.

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, and no selection logic is touched. Both ops keep their bodies byte for byte: top_k_per_row_decode's FlyDSL gates (_FLYDSL_TOPK_DECODE_GATES, the arch/width/rows table) and topk_gating's herd gate decide exactly what they decided before, because the decorator sits outside the body and nothing inside it reads the plugin. With no provider enabled, each call reaches the same kernel through the same branch.

The evidence that unrelated shapes keep their selection is the two op_tests sweeps rather than an argument: test_moe_topk_gating.py covers three score functions x three dtypes x its shape ladder, and test_topk_per_row.py covers its own, including the 90000-width rows that exercise the long-row gates. Both pass against this tree, exit 0. The bit-identical equivalence run adds that a given shape produces the same bytes, not merely a passing tolerance.

Changed op tests

None. Two existing op_tests/ files were run against this tree; neither is modified.

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: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu requested a review from a team November 12, 2026 10:49
@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 7874 --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.

@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision b76f21e53213 · 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

Two ops a framework names directly cannot be served by any provider. `top_k_per_row_decode` has 26 non-comment call sites across five ATOM backends; `topk_gating` sits on the DeepSeek-V4 / MiniMax-M3 MoE routing path. Both return `None` and write through their arguments, so each takes a trivial fake and `route(..., fake=...)` on the public name — the pattern #7850 established on `fused_qk_norm_rope_cache_quant_shuffle`.

The existing behaviour is insufficient only in that no provider can be asked. With none enabled, each op makes the call it made before; registration is what keeps the plugin's dispatch out of a caller's compiled graph once one is.

Validation and unverified scope

Verified on gfx942, torch 2.9.1, against this tree:

- `op_tests/test_moe_topk_gating.py` passes, exit 0 — three score functions x three dtypes x the shape sweep;
- `op_tests/test_topk_per_row.py` passes, exit 0;
- numeric equivalence against this branch's base is bit-identical and reproducible, under `stable=True`;
- both ops register — `OpOverloadPacket` under `torch.ops.aiter_routed`;
- `tests/test_plugin_contracts.py` and `tests/test_plugin_selector_arity.py`: 20 passed;
- baseline regenerated with `routed_contracts()` rather than edited, 17 -> 19, none lost, none carrying `backend` or `kernelName`;
- `black` and `ruff check` clean.

**Unverified:** no gfx950 or multi-GPU path — `test_topk_per_row.py` skips `sampled_per_device` for want of two gfx950 devices, and the `sampled` shapes are not served on gfx942. No compiled-region test is added here; #7850 covers the mechanism with synthetic ops. `ci:all` is set so the downstream suites run.

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, and no selection logic is touched. Both ops keep their bodies byte for byte: `top_k_per_row_decode`'s FlyDSL gates (`_FLYDSL_TOPK_DECODE_GATES`, the arch/width/rows table) and `topk_gating`'s herd gate decide exactly what they decided before, because the decorator sits outside the body and nothing inside it reads the plugin. With no provider enabled, each call reaches the same kernel through the same branch.

The evidence that unrelated shapes keep their selection is the two `op_tests` sweeps rather than an argument: `test_moe_topk_gating.py` covers three score functions x three dtypes x its shape ladder, and `test_topk_per_row.py` covers its own, including the 90000-width rows that exercise the long-row gates. Both pass against this tree, exit 0. The bit-identical equivalence run adds that a given shape produces the same bytes, not merely a passing tolerance.

Changed op tests

None. Two existing `op_tests/` files were run against this tree; neither is modified.

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 merged commit ff1b726 into main Nov 13, 2026
@zufayu
zufayu deleted the codex/route-topk-decode branch November 13, 2026 05:12
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]>
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