Repository navigation
[Plugin] Route topk_gating and top_k_per_row_decode as custom ops - #7874
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
) 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]>
First use of
route(..., fake=...)from #7850 on ops downstream actually calls.Which two, and why these
top_k_per_row_decodedcp_ops,rtpllm,sglang,vllm,deepseek_v41/indexer— five backendstopk_gatingatom/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, followingfused_qk_norm_rope_cache_quant_shufflefrom #7850. No private forwarding layer: both ops returnNoneand write through their arguments, so the fake isreturn, 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 (
PYTHONPATHpointed at the worktree — the system-installed aiter on this box cannot import, see Limits).op_tests/test_moe_topk_gating.pyop_tests/test_topk_per_row.pytorch.ops.aiter_routed.*,OpOverloadPacketfor eachtests/test_plugin_contracts.py,tests/test_plugin_selector_arity.pyrouted_contracts(), 17 -> 19; none lost, none carryingbackendorkernelNameblack,ruff checkOne 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. Understable=Truethe 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.pyskips itssampled_per_devicecase for want of two gfx950 devices.ci:allis set so the downstream suites run.🤖 Generated with Claude Code
PR Self-Review
Reviewed revision
b76f21e5321328fca2cd2cd3b95570c34dd2e168Behavior and intent
Two ops a framework names directly cannot be served by any provider.
top_k_per_row_decodehas 26 non-comment call sites across five ATOM backends;topk_gatingsits on the DeepSeek-V4 / MiniMax-M3 MoE routing path. Both returnNoneand write through their arguments, so each takes a trivial fake androute(..., fake=...)on the public name — the pattern #7850 established onfused_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.pypasses, exit 0 — three score functions x three dtypes x the shape sweep;op_tests/test_topk_per_row.pypasses, exit 0;stable=True;OpOverloadPacketundertorch.ops.aiter_routed;tests/test_plugin_contracts.pyandtests/test_plugin_selector_arity.py: 20 passed;routed_contracts()rather than edited, 17 -> 19, none lost, none carryingbackendorkernelName;blackandruff checkclean.Unverified: no gfx950 or multi-GPU path —
test_topk_per_row.pyskipssampled_per_devicefor want of two gfx950 devices, and thesampledshapes are not served on gfx942. No compiled-region test is added here; #7850 covers the mechanism with synthetic ops.ci:allis 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_testspassing 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 understable=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) andtopk_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_testssweeps rather than an argument:test_moe_topk_gating.pycovers three score functions x three dtypes x its shape ladder, andtest_topk_per_row.pycovers 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.