Repository navigation
[Plugin] Fix torch auto_functionalized_v2 assert: route() gains explicit mutates_args - #7926
Conversation
…tates_args #7881 registering fake= for gemm_a8w8_blockscale made the op an opaque custom op whose schema infers with mutates_args="unknown", so every tensor arg is declared writable. torch 2.10 inductor then wraps the op in auto_functionalized_v2 and its post-grad decompose fails to remove it (torch _inductor/fx_passes/post_grad.py:1337 assertion), failing op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py::test_public_group32_compile_dynamic_rows deterministically on main (interim greens were shard-skipped vacuous runs). - route()/_as_custom_op() take explicit mutates_args, same knob as torch_compile_guard; default "unknown" preserves current behavior. - gemm_a8w8_blockscale writes through no argument -> mutates_args=[]. - rmsnorm_with_add writes out and residual_out -> declare exactly those (same latent failure waiting for compile coverage). Verified locally: tests/test_plugin_contracts.py 18 passed. The GPU compile test needs MI hardware; CI Triton Shard 0 should flip green. Co-Authored-By: Claude Code <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
… check) Co-Authored-By: Claude Code <[email protected]>
fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU.
fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU.
fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU.
fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU.
fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU.
…ernel plugin interface (#8075) * [Triton] Load an old module path as the module at its new path The backward-compatible finder returned the spec of the new path, so the import system ran the module code a second time under the old name. A module that registers a routed op then raised "already routed" on the second import. * [Plugin] Route the 16-bit GEMMs, the Triton blockscale GEMM and MXFP8 1x32 quant Three new contracts, all at version 1, and one more path into per_group_quant. - gemm_a16w16: routed on `_gemm_a16w16`, the layer that `tgemm.mm`, `gemm_a16w16` and `gemm_a16w16_out` all reach. `gemm_a16w16_out` drops the return value, and the native assert that the result is `out` does not run when a provider serves the call, so `gemm_a16w16_out` now checks it. - gemm_a16w16_activation: the Triton `gemm_a16w16`, routed beneath its torch_compile_guard. It has its own name because `gemm_a16w16` is the tuned contract, and this one also applies an activation and can return split-K partials. - gemm_a8w8_blockscale_out: the Triton `gemm_a8w8_blockscale`. It has its own name because `gemm_a8w8_blockscale` is the CK contract, which has no output buffer. Its `dtype` annotation is now `torch.dtype | None`. - Both Triton routes sit below `backend=`: a call that sets it bypasses routing, as `pa_fwd` does, so no contract carries a backend pin. - per_1x32_mx_quant_hip: the fp8 output, e8m0 scale, unshuffled branch calls the routed per_group_quant. The buffers and the kernel call are the same. None of the three new ops passes fake=; _NOT_REGISTERED gives the reasons. Public signatures are unchanged except the annotation above. tests/plugin_contracts.json is regenerated from routed_contracts(). * [Plugin] Route fused_moe and biased_grouped_topk fused_moe routes on fused_moe_, the layer beneath the public fused_moe, with the torch_compile_guard outside the route as mhc_pre has it. The public function keeps its signature, which sglang reads with inspect.signature; its 19 unannotated parameters and the shared-expert branch to FHMoE stay above the route. fused_moe_ is fully annotated and already guarded, so the route needs no fake and the guard registers the same aiter::fused_moe_ schema. The route takes fused_moe_ as main has it, splitk included (#4740 put it between bias2 and swiglu_limit); the docstring says a provider may ignore it, since AITER reads it only to keep its gfx1201 small-M kernel off split calls. Its docstring says what the signature cannot: the result is returned, or written into `output` and that is returned; activation and quant_type arrive as enum values; the ep_* fields are the stage-2 scatter, which P2P-writes the rows to the peers and returns a placeholder; the activation dtype follows M and the environment (AITER_SITUV2_A8W4/A4W4, AITER_BF16_FP8_MOE_BOUND, GPTOSS_SWIGLU_MXFP4_BF16_BOUND); and a sort registered with register_presorted_moe is consumed below the route, so a provider serving a call must pop it or decline, or the next native call runs on a stale sort. aiter's own callers of fused_moe (asm_moe_tkw1, MegaMoE's expert GEMM) reach the same route and run as before while no provider takes them. MegaMoE's other thread-local, the grouped GEMM's dispatch context, is set only together with stage2_scatter, which a provider without the scatter declines. biased_grouped_topk routes on its public name. It gains `-> None`, which infer_schema needs, and a fake as topk_gating has. Every path (HIP, gfx1250 exact, FlyDSL HERD) writes topk_weights and topk_ids and nothing else, so mutates_args says exactly that (#7926). The docstring also records that AITER_FLYDSL_USE_HERD=1 answers one-group calls with HERD routing rather than the exact top-k, which a provider computing the exact top-k must decline. biased_grouped_topk_hip stays unrouted: its name is a backend's. tests/plugin_contracts.json is regenerated with routed_contracts(). Checked on CPU: tests/test_plugin*.py and test_jit_signature.py pass (129; 2 need a built AITER). The two routes, rebuilt from this source with the plugin and torch_guard modules loaded on their own, register (aiter::fused_moe_ under the guard; aiter_routed::biased_grouped_topk with only the two outputs mutable), run natively with no provider, hand an enabled provider 40 and 9 arguments, and compile to one opaque node under fullgraph=True. Not run here: anything that needs a built AITER or a GPU. * [RFC #7240] Route MLA decode, MQA logits, v4 sparse prefill and fused mHC Five ops that the DSA/MLA paths of vLLM and SGLang call had no route, so no provider could serve them. Each is routed where the op begins, below any pin that picks one of AITER's own implementations; every public signature is unchanged (checked by AST against main), except two annotations that said Tensor for a None default. - mla_decode_fwd: on the public entry, its one spelling with no backend pin. The docstring now says what it returns: (logits, lse), where logits is scratch (or a view of o) and the result is o, written in place. - mla_paged_decode: the decode mode of mla_gluon (has_pe=True, no attn_sink), on a new inner layer. The DSv4 sparse prefill mode that AITER itself runs through mla_gluon (pa_prefill_sparse, sparse_attention_dsv4_bwd) is not routed. The op name is neutral: mla_decode_fwd is already the ASM decode's contract with other arguments. - fp8_paged_mqa_logits: on deepgemm_fp8_paged_mqa_logits, also reached through the old aiter.ops.triton.pa_mqa_logits path SGLang imports. It writes out_logits and returns None. - mla_sparse_prefill_v4: on _mla_sparse_prefill_v4_routed, below backend=, as v41 is; the native body keeps the asm-then-opus default. #7854 left it out because a wrong guess there changes which kernel runs on gfx1250, so pa_sparse_prefill_fp8_opus enters the route only where the default picks opus anyway (not gfx1250, no sink, or H != 128); elsewhere it runs opus directly, as before. - mhc_fused_post_pre: on _mhc_fused_post_pre_routed, below backend= and force_fused=, with a fake and mutates_args=[] since the guard sits on the public function. Above the fused bound the native still calls the routed mhc_post and mhc_pre. The first four join _NOT_REGISTERED (out-buffer in the contract, or unannotated). The baseline gains five entries from routed_contracts(); the existing 23 are untouched. tests/test_plugin*.py on a CPU box without a built AITER: 129 passed, 1 skipped (test_plugin_routed_ops.py needs a build). * [Plugin] Test the ten new routes through a provider, and their pins What a provider depends on and the contract gate cannot see. For each new route, a call through the public name callers use (tgemm's gemm_a16w16, the Triton gemm_a16w16 and gemm_a8w8_blockscale, fused_moe, biased_grouped_topk, mla_decode_fwd, mla_gluon in decode mode, deepgemm_fp8_paged_mqa_logits by both module paths, mla_sparse_prefill_v4 and the opus-pinned name, mhc_fused_post_pre, and per_1x32_mx_quant_hip into per_group_quant) reaches an enabled provider, which is handed the whole contract with the caller's value in its place. Each pin -- backend= on the Triton GEMMs and v4 prefill, the opus name where the default tries asm, force_fused= and backend= on mHC, mla_gluon's prefill mode and a sink -- runs AITER's own body and asks no provider; one case per condition. gemm_a16w16_out refuses a provider answer that is not out and takes one written into it. The old Triton path is the module at the new one. The route modules are imported at collection, so the first _reset_for_testing() keeps their ops in plugin._routed_ops. Run without a GPU (HIP_VISIBLE_DEVICES=-1, aiter built from this branch, FlyDSL 0.5.0): the 26 new cases pass. The file's 5 device tests fail there for want of a GPU, as they do on main. * [Plugin] Address the review of the ten routes - mla_paged_decode is registered. The routed layer writes o in place and returns lse alone, so no result aliases an input. A custom op cannot return Optional[Tensor], so with return_lse=False the op returns an empty fp32 tensor. mla_gluon gives (o, lse) or (o, None) as before. - fp8_paged_mqa_logits stays unregistered. Its native body returns the cache key of the compiled Triton kernel, a str, and bench_deepgemm_attention.py reads it. A custom op cannot return a str. The docstring said "returns None"; it now says what the call returns. - The public fused_moe clears a registered presort when the call ends (drop_presort_after). A call that a provider serves returns before _fused_moe_impl consumes the registration, and the next native call on reused routing buffers would use it. - The Triton gemm_a16w16 and gemm_a8w8_blockscale check, as gemm_a16w16_out does, that a routed call given y returns y. The check is by identity, not data_ptr, because gemm_a8w8_blockscale also runs under torch.compile. - mla_decode_fwd: a provider may return o as the first result only with return_logits=False. New tests: mla_gluon returns the lse that the provider gives; fused_moe leaves no presort after a served call; each Triton GEMM refuses a result that is not y and takes one that is. Run without a GPU (HIP_VISIBLE_DEVICES=-1, aiter built from this branch, FlyDSL 0.5.0): tests/test_plugin*.py 168 passed. The 5 failures are device tests that also fail on main without a GPU. * [Plugin] Route Kimi-K3's MLA prefill, fp8 in_proj GEMM and KDA conv and decode Kimi-K3 on MI355X (vLLM 0.32.1 with aiter 0.1.26; SGLang 0.5.22) calls seven AITER functions that no provider could serve because they had no route. Each is routed on the name the frameworks call, with the backend choice beneath it, and the op names carry no backend: - flash_attn_varlen (flash_attn_varlen_func): the MLA prefill of vLLM's ROCM_AITER_FA backend and SGLang's prefix chunks. Its docstring now opens the function (it used to follow the block_table check, so it was not one) and says what a provider returns: out, or out with the lse and S_dmask the flags ask for, written into `out` when one is passed; the forward only, so a call needing grad is declined. - mla_prefill_ps (mla_prefill_ps_asm_fwd) and mla_reduce (mla_reduce_v1): SGLang's fp8 MLA prefill and the merge after it; mla_reduce_v1 is also where AITER's own split-KV MLA decode merges. Both were @compile_ops bindings; the bindings move to private names with fc_name keeping their symbols, and the public names become routed Python functions over them. - gemm_a8w8_bpreshuffle: vLLM's per-token/per-channel fp8 in_proj. The torch_compile_guard stays outside the route, as on fused_moe_. - causal_conv1d_split_qkv (causal_conv1d_split_qkv_triton_tile_fn): KDA's short convolution in vLLM's prefill; it also writes conv_states. - fused_recurrent_kda and fused_recurrent_kda_packed_decode: KDA decode and its speculative form on gfx950. The packed one is routed ahead of the general one, which a provider is asked about again when the packed one runs natively. All seven join _NOT_REGISTERED with their reasons; the baseline gains seven entries from routed_contracts(), the other 33 untouched. Checked on CPU: tests/test_plugin*.py, 164 passed, 1 skipped (test_plugin_routed_ops.py needs a built AITER). * [Test] test_mha_optional_flydsl: compile the parsed function without its decorators The test parses aiter/ops/mha.py, takes one top-level function and execs it in a namespace that holds only an allow-list of names. With this PR flash_attn_varlen_func gains @_route(op="flash_attn_varlen"), and exec then evaluates the decorator expression, where _route is not bound: NameError at mha.py, in both flash_attn_varlen_func parametrisations (flash_attn_func, which has no decorator, kept passing). mha.py itself imports _route at module level, so the shipped code is unaffected. _top_level_node now strips a function's decorators before returning it. What the tests check is the body's dispatch, and a decorator added later cannot break them the same way.
What
#7881addedfake=to thegemm_a8w8_blockscaleroute, which turns the op into an opaqueaiter_routedcustom op whose schema is inferred withmutates_args="unknown"— every tensor argument declared writable. torch 2.10 inductor then wraps the op in anauto_functionalized_v2node andpost_grad.decompose_auto_functionalizedcannot remove it, asserting attorch/_inductor/fx_passes/post_grad.py:1337.Deterministic main-branch failure:
op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py::test_public_group32_compile_dynamic_rows[None]and[3]. (Interim green runs on the same commit wereTriton Tests / Shardskipped runs — vacuous green, never actually executed.)Fix
route()/_as_custom_op()accept an explicitmutates_argsoverride — the same knobtorch_compile_guardalready has. Default"unknown"is preserved (conservative, never wrong, just costs optimisation).gemm_a8w8_blockscale: writes through no argument →mutates_args=[], matching its own@torch_compile_guard(mutates_args=[]).rmsnorm_with_add: genuinely writesoutandresidual_out→ declare exactly those, matching its guard. Same latent failure mode otherwise.A wrong declaration is UB, so defaults stay conservative and docstrings say who is allowed to declare what.
Verification
tests/test_plugin_contracts.py→ 18 passed;py_compileclean on all touched files.🤖 Generated with Claude Code
PR Self-Review
Reviewed revision
fe9e6a7 (fix/route-explicit-mutates-args, head of branch at the time of answering)
Behavior and intent
Behavior change:
route()gains an explicitmutates_argsparameter (default"unknown", mirrored ontorch_compile_guard's existing knob) and_as_custom_op()forwards it toinfer_schema. Two registrations drop the conservative default with true declarations:gemm_a8w8_blockscaledeclares[](it allocates and returns Y, writes nothing through arguments — matching its existing@torch_compile_guard(mutates_args=[])), andrmsnorm_with_adddeclares["out", "residual_out"](its two real write-through arguments — also matching its guard).Why existing behavior is insufficient: since
#7881addedfake=togemm_a8w8_blockscale, the op becomes an opaqueaiter_routedcustom op whose schema declares every tensor writable. torch 2.10 inductor wraps it inauto_functionalized_v2andpost_grad.decompose_auto_functionalizedcannot eliminate the wrapper, asserting attorch/_inductor/fx_passes/post_grad.py:1337. Result: deterministic failure ofop_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py::test_public_group32_compile_dynamic_rows[None]and[3]on every main run where Shard 0 actually executed on/after888b1a04a(the interim "green" runs were shard-skipped, vacuous).Validation and unverified scope
Validated, local CPU (this docker, no GPU):
python3 -m py_compile aiter/plugin/__init__.py aiter/ops/gemm_op_a8w8.py aiter/ops/rmsnorm.py→ OKpython3 -m black --check+python3 -m ruff checkon the three touched files → clean (this is what the failing Black gate checks)python3 -m pytest tests/test_plugin_contracts.py -x -q→ 18 passed (43s): contract suite exercisingroute()signatures and dispatch behavior, proving the new optional parameter is backward compatibleVerified on GPU (mi355-gpu-41, torch 2.10.0+rocm7.2.4, container
rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0, same tag as CI):fe9e6a7:pytest op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py::test_public_group32_compile_dynamic_rows→ 2 passed in 10.94sorigin/maintarball (same node/container/test): 2 failed in 17.41s with the exactauto_functionalized_v2 was not removedInductorError — reproducibility and fix efficacy both closed.This PR's CI Triton Shard 0 is the matching reproducer.
PR-specific question
Most important boundary introduced:
mutates_argslets an op trade [never wrong, only conservative] for [correct for inductor, wrong → undefined behavior]. The evidence covering it: (a) both declarations restate the same ops' pre-existing@torch_compile_guarddeclarations, which have been the operative compile contract since before routing existed — no new semantic claim is being made about the kernels; (b) unchanged ops default to"unknown"so nothing outside the two named ops changes; (c)test_plugin_contracts.py(18/18) coversroute()'s contract enforcement. What is NOT covered: a dispatch matrix proving no other routed op withfake=rides the same trap — only these two were audited; otherfake=routes keep"unknown"(safe, still theoretically assertable under torch.compile).Changed op tests
None