Repository navigation
[HIP] [JIT] Fix/gfx1201 bf16 g1u1 small m moe - #4740
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
9348e65 to
fb49231
Compare
3f66aef to
f4ca33b
Compare
095ad26 to
5169bc4
Compare
5169bc4 to
544f6ec
Compare
|
No activity for 15 days, so this is now labelled |
|
@valar-cop review |
|
@valar-cop review |
|
Non-blocking suggestion: could we add is_contiguous() checks for all seven tensor arguments at the new fmoe_g1u1_bf16_small_m entrypoint? The kernels assume contiguous storage, but the current validation only checks shapes and dtypes. I reproduced this with the unchanged HIP source in a standalone gfx942 diagnostic: a same-shape strided topk_weights view produced incorrect results, and a strided output caused writes to backing-storage elements outside the requested view. The normal fused_moe path already makes inputs contiguous and validates the output buffer, so I would not block this PR on this issue. The checks and negative tests for strided inputs/outputs can be added in a follow-up. |
Added the raw entrypoint checks. fmoe_g1u1_bf16_small_m now rejects non-contiguous out, input, gate, down, topk_ids, topk_weights, and act_workspace before launching either kernel. I also added a parametrized raw-op test that passes same-shape strided views for each tensor and verifies the entrypoint fails fast instead of reading/writing with contiguous assumptions. The normal fused_moe path still keeps its existing .contiguous() behavior. Also, re-ran the focused gfx1201 tests: root small-M test and Windows discovery path both pass 47/47. |
- op_tests/test_moe_eager_host_path.py follows the other op_tests now: no pytest, a main() that CI's `python3 <file>` runs. The pytest file it replaces had no __main__, so CI imported it and ran none of its cases. The same checks run from main() (unittest.mock instead of monkeypatch). The per-case comparison with the original path is an @benchmark sweep (quant type x tokens x EP x rows past num_local_tokens) that also checks each path against torch_moe (largest per-row relative error, 0.1 with fp8 activations, 0.01 with bf16) and ends in a markdown table of device and host time for both paths. The CUDA graph check now looks at every scratch buffer after capture, so it also fails when the capture stream itself gets one. per_Tensor runs without num_local_tokens, which per_tensor_quant_hip does not take. - main's gfx1201 small-M direct path (#4740) is chosen in _fused_moe_impl from arguments the plan key leaves out (splitk, the sort policy, the scales, the shuffle layout), after the point where a plan hit returns. Plans are not stored on that arch, so it still decides per call. The arch is one constant, _BF16_G1U1_SMALL_M_DIRECT_GFX, read by both. - moe_sorting's _scratch and _moe_sorting_impl's scratch are keyword-only. - _moe_sort_scratch states that threads sharing a stream must not interleave inside fused_moe. MI308X (gfx942), one GPU, the image's prebuilt modules with this tree's Python: `python3 op_tests/test_moe_eager_host_path.py` passes in 29 s, 11 checks and 28 sweep cases bit for bit (eager vs op), no JIT build; eager host time 60-90 us lower per call than op, device time equal. The script fails with the get_2stage_cfgs revalidation removed, and with the capture check on the scratch removed. gfx950 not run here (CI). Co-authored-by: Cursor <[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.
…route ROCm/aiter#4740 threads the public fused_moe's splitk down to fused_moe_, between bias2 and swiglu_limit, and aiter#8075 records the routed contract with it. The selector unpacked aiter's arguments by position, so the 40-argument call no longer unpacked, and every field after bias2 would have been read one place late. splitk is a split-K request to aiter's own kernels and moves only the order of the K sums, so AKLR serves the call whatever it is, as aiter's docstring for the route allows.
) `op_tests/windows/test_moe_small_m_direct.py` landed on main at 02:29 UTC today (#4740). It re-exports `op_tests.test_moe_small_m_direct`, which imports `aiter.fused_moe`, which imports FlyDSL unconditionally -- 39 names across three `aiter.ops.flydsl` modules. FlyDSL ships Linux-only wheels, and `requirements.txt` says so: `flydsl==0.4.2; sys_platform != "win32"`. The Windows smoke runner therefore logs `Ignoring flydsl: markers 'sys_platform != "win32"' don't match your environment` and never installs it, so pytest raises `ModuleNotFoundError: No module named 'flydsl'` while COLLECTING the module. A collection error is not a skip: it fails the whole smoke job. Guarding the import inside `aiter/fused_moe.py` instead would need fallbacks for all 39 names and leave the module half-defined, so the skip belongs here, next to the platform that deliberately lacks the dependency. It costs no coverage Windows had -- `aiter.fused_moe` has never been importable there. The daily scheduled run (13:00 UTC) is green through 2026-11-16 because it last ran before #4740 merged; today's would be the first to hit this. PR #8075 found it earlier only because it carries `ci:all`, which is what lets this job run on a pull request at all. Verified: black and ruff clean; 47 tests still collect on Linux, where FlyDSL is present, so the happy path is unchanged. Co-authored-by: zufayu <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[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.
…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.
…route ROCm/aiter#4740 threads the public fused_moe's splitk down to fused_moe_, between bias2 and swiglu_limit, and aiter#8075 records the routed contract with it. The selector unpacked aiter's arguments by position, so the 40-argument call no longer unpacked, and every field after bias2 would have been read one place late. splitk is a split-K request to aiter's own kernels and moves only the order of the K sums, so AKLR serves the call whatever it is, as aiter's docstring for the route allows.
…route ROCm/aiter#4740 threads the public fused_moe's splitk down to fused_moe_, between bias2 and swiglu_limit, and aiter#8075 records the routed contract with it. The selector unpacked aiter's arguments by position, so the 40-argument call no longer unpacked, and every field after bias2 would have been read one place late. splitk is a split-K request to aiter's own kernels and moves only the order of the K sums, so AKLR serves the call whatever it is, as aiter's docstring for the route allows.
…route ROCm/aiter#4740 threads the public fused_moe's splitk down to fused_moe_, between bias2 and swiglu_limit, and aiter#8075 records the routed contract with it. The selector unpacked aiter's arguments by position, so the 40-argument call no longer unpacked, and every field after bias2 would have been read one place late. splitk is a split-K request to aiter's own kernels and moves only the order of the K sums, so AKLR serves the call whatever it is, as aiter's docstring for the route allows.
…h the aiter provider, on aiter main and FlyDSL 0.5 (#271) * feat(plugins): serve aiter's 16-bit GEMMs and its Triton blockscale GEMM Selectors for the three GEMM contracts aiter routes next, in the provider's gemm module: - gemm_a16w16 (tuned_gemm: tgemm.mm, gemm_a16w16, gemm_a16w16_out) -> gemm. A with three or more dims is viewed as rows and the result viewed back; out is viewed to (rows, n) and returned. Declines scale_a/scale_b/scale_c, a shuffled B, an out whose dtype is not otype (aiter raises), and an A that cannot be viewed as rows (aiter runs F.linear). - gemm_a16w16_activation (Triton gemm_a16w16) -> gemm, y as out. Declines an activation and skip_reduce; config, kernel_type and persistent pick aiter's schedule only. - gemm_a8w8_blockscale_out (Triton gemm_a8w8_blockscale) -> gemm_a8w8_blockwise_scaled with operand_format "none:none", y as out. Declines skip_reduce, scales other than fp32, and an x_scale that is not contiguous (aiter's kernel reads it through its strides; AKLR's row-major a_scale is contiguous). For the Triton ops the output dtype is y's when y is given, as aiter's. Each run takes aiter's parameters by name and in order. * feat(plugins): serve aiter's fused_moe and biased_grouped_topk routes aiter routes two more MoE ops (ROCm/aiter, branch kyle/aklr-routes-moe): fused_moe, on the layer beneath its public fused_moe, and biased_grouped_topk. The provider gains a selector for each. - fused_moe -> AKLR's fused_moe, through the mapping the sglang and vLLM routes of aiter's public fused_moe use, now op_kwargs in aklr/plugins/aiter/fused_moe.py. The call arrives with aiter's enums as ints and is read back with aiter's enums. Declined: block_size_M other than -1, padding, activation scales, biases, the stage-2 scatter (any ep_* field), activation quant overrides, herd_topk, deterministic=True, and SiTUv2 where aiter would not quantize to fp8. The sorting policy and the HERD routing factor alone are not taken. - A sort a caller registered for aiter's next fused MoE (register_presorted_moe) is consumed beneath aiter's route, so the run pops it before anything else: left registered, it would apply to the next call aiter computes. - biased_grouped_topk -> AKLR's biased_grouped_topk, whose eight parameters are aiter's first eight. Declined: num_valid_rows, dropped groups (topk_group != num_expert_group), a bias in another dtype than the scores, and one group while aiter routes by HERD (AITER_FLYDSL_USE_HERD=1). The run returns None, as aiter's op does. tests/plugins/aiter/test_provider_moe.py covers both on CPU, with a stand-in aiter and, where aiter.plugin is importable, aiter's own dispatch. test_provider.py's contract table does not list the two ops yet, so its test_each_selector_serves_an_aiter_contract_at_its_version fails until they are added there. * feat(plugins): serve aiter's MLA and fused mHC routes as its provider aiter now routes five more ops through its kernel plugin interface (kyle/aklr-routes-mla): mla_decode_fwd, mla_paged_decode (the decode mode of mla_gluon), fp8_paged_mqa_logits, mla_sparse_prefill_v4 and mhc_fused_post_pre. Each gets a selector that unpacks aiter's call by name, declines what the AKLR contract does not take, and binds a run with aiter's parameters. - mla_decode_fwd -> mla_decode_fwd: the declines of aklr.plugins.aiter.mla, plus kv_layout, seq_lens, page_table, kv_csr_layout and return_logits; aiter's schedule metadata is ignored. Returns (o, lse). - mla_paged_decode -> flash_mla_with_kvcache, dense pool: q_nope and q_pe go as the one q they are adjacent views of (two tensors apart decline), the pool rows as (N, 1, 1, 576), the 2-D table with cache_seqlens or the flat one with cu_seqlens_k, a 4-D q as causal queries. The output is copied into aiter's o; the lse is dropped unless asked for. - fp8_paged_mqa_logits -> fp8_paged_mqa_logits: one query a request, preshuffled whole pages, no precomputed schedule, logits as wide as the block table and as max_model_len; [B, 1] lengths as [B]. - mla_sparse_prefill_v4 -> sparse_prefill_mxfp8, whose baseline is the same aiter kernel: the eleven tensors in order (fp8 NoPE as bytes), a sink required; the result is copied into out when given. - mhc_fused_post_pre -> mhc_fused_post_pre: post_layer_mix (T, 4, 1) as (T, 4); shuffled fn or residual declines. * test(plugins): list aiter's new routed ops in AITER_CONTRACTS * fix(plugins): take mla_decode_fwd's NVFP4 keyword-only parameters ROCm/aiter#7987 added q_aux, kv_aux, nvfp4_params and nvfp4_lse to mla_decode_fwd as keyword-only parameters. The run takes them by name, and the selector declines a call that passes any of them: that is aiter's NVFP4 path. * fix(plugins): take fused_moe's splitk, which aiter now passes to the route ROCm/aiter#4740 threads the public fused_moe's splitk down to fused_moe_, between bias2 and swiglu_limit, and aiter#8075 records the routed contract with it. The selector unpacked aiter's arguments by position, so the 40-argument call no longer unpacked, and every field after bias2 would have been read one place late. splitk is a split-K request to aiter's own kernels and moves only the order of the K sums, so AKLR serves the call whatever it is, as aiter's docstring for the route allows. * fix(plugins): return lse alone for aiter's mla_paged_decode ROCm/aiter#8075 now registers mla_paged_decode as a custom op that writes o in place and returns lse alone, so no result aliases an input; a custom op cannot return None for a tensor, so the op returns an empty fp32 tensor when return_lse is off. AKLR's run still writes its output into o, and now returns that lse instead of (o, lse). * refactor(plugins): no route of the sglang or vLLM plugin wraps an aiter function aiter routes sglang's aiter_calls (fused_moe, tgemm.mm, the Triton gemm_a16w16, mla_decode_fwd) and vLLM's layer routes on the same aiter functions (layers/fused_moe, gemm, mla) wrapped calls that aiter's kernel plugin interface now offers to AKLR's provider itself, so with both on a call reached AKLR twice. They go, with the argument mappings only they used (aklr/plugins/aiter/{mla,triton_gemm,tuned_gemm}); the provider serves these ops (fused_moe, gemm_a16w16, gemm_a16w16_activation, mla_decode_fwd) with the same checks, KV layouts included. * refactor(plugins): serve vLLM's MLA prefill through aiter's flash_attn_varlen vLLM's ROCM_AITER_FA MLA prefill backend calls aiter.flash_attn_varlen_func with the lse, over a step's new tokens and over each context chunk. The vLLM route on that backend wrapped what is now aiter's routed flash_attn_varlen, so the provider takes it instead: a selector that hands a bf16, causal or unmasked pass of at least 256 query rows to mla_prefill_varlen_lse in fp8, returning aiter's (out, softmax_lse as [heads, tokens]); every other call stays on aiter. The vLLM route and its tests go. * refactor(plugins): serve the DSA indexer's paged logits through aiter's fp8_paged_mqa_logits sglang's aiter_paged_mqa_logits calls aiter's deepgemm_fp8_paged_mqa_logits, which aiter routes as fp8_paged_mqa_logits, and the provider already serves its row calls. The sglang route on that wrapper goes. What it added, scoring a target verify's rows by request under DCP, moves into the provider's selector: the route on Indexer._get_topk_paged now only notes, through note_target_verify, whether the logits asked next are such a verify's, and the selector regroups those rows by views for fp8_paged_mqa_logits_verify, writing aiter's out_logits. Rows it cannot regroup, or a verify AKLR falls back on, take the row op as before. * ci: baseline aiter at a6c759b1f, which has the kernel plugin routes AKLR's provider serves ROCm/aiter#8075 routes flash_attn_varlen, mla_prefill_ps, mla_reduce, gemm_a8w8_bpreshuffle, causal_conv1d_split_qkv and the two KDA recurrences through aiter.plugin; #8179 restores the import aiter.fused_moe needs. This aiter pins flydsl==0.5.0 (a0c4b69c pinned 0.4.2). * docs(plugins): which framework routes stay beside aiter's provider A route may not wrap an aiter function aiter routes, nor a framework function that only calls one; a route that runs nothing may note framework state for the provider; aiter functions aiter does not route keep their routes. * fix(validation): trip on FlyDSL's compile in a capture from FlyDSL 0.5 FlyDSL before 0.5 reaches _build_call_state on a specialization's first call in the process only, so the tripwire hooked it to catch a kernel compiled inside a CUDA graph capture. FlyDSL 0.5 dropped the call-state cache: every JitFunction call traces again and rebuilds its call state, so a warmed kernel launched in the capture tripped it, and its runner died as candidate_crash (mla_decode_fwd_n_heads96 on aiter a6c759b1f). From 0.5 the tripwire hooks MlirCompiler.compile, which only a compile reaches. * test(plugins): keep aiter's own MLA routes in the dispatch test With an aiter that routes the MLA ops itself, routing a stand-in native under the same op name raised 'already routed' at setup (8 errors on aiter a6c759b1f). Those ops keep aiter's route: explain() checks the call against aiter's own contract, and only the test's own routes are called. * feat(jit): put FlyDSL's per-specialization launch cache back for AKLR's kernels on FlyDSL 0.5 FlyDSL 0.5 dropped the call-state cache: every JitFunction call traces the function again, lowers it and hashes the result before it launches. On MI355X mla_prefill_varlen_lse's launcher took 24.8 ms a call and mla_decode_fwd's 320 ms, against 0.16 and 0.09 ms on FlyDSL 0.4.2; aiter since ca6bc0f85 requires FlyDSL 0.5. FlyDSLBuilder now installs aklr.core.jit.flydsl_cache before it imports a kernel: for the JitFunctions an AKLR kernel package defines, the first call of a specialization goes through flyc.compile and every later one launches its CompiledFunction. The key is FlyDSL 0.4.2's, from FlyDSL's own signatures: the invalidating environment, the target, the compile hints, a Constexpr's value, and each runtime argument's cache signature. Other FlyDSL callers keep FlyDSL's path. Validation's compile tripwire hooks the cache's miss on FlyDSL 0.5, the first call of a specialization in the process, as _build_call_state was before 0.5. * feat(gemm): gemm_a8w8 on preshuffled weights, with Kimi-K3's KDA in-projection kernels `[email protected]` takes b preshuffled (layout variant `b_shuffled`, aiter's 16 x 16 shuffle_weight, b as (n, k)), detected by `b.is_shuffled`. Its baseline is aiter's per-token fp8 GEMM on a preshuffled weight, gemm_a8w8_bpreshuffle. Two FlyDSL schemas serve Kimi-K3's KDA in-projection (n6288, k7168): m 8-240, and m 320-8192. The kernels and their Points are those of the vLLM-route change; kernel.requires now names FlyDSL (>=0.3.2, as K3's other GEMM kernels), which moves both files to new uuids. * feat(ops): [email protected], Kimi-K3's KDA prefill short convolution, in aklr/ops/kda_conv The op vLLM's Kimi-K3 KDA prefill runs through aiter's fused q/k/v causal conv1d (causal_conv1d_split_qkv_triton_tile_fn): the contract, its reference and baseline, the FlyDSL kernel for proj 1536 with x and the conv state as strided rows, and the definition schema beside it. It was a vLLM plugin op with a route on KDA's conv; it comes to aklr/ops, where the aiter provider reaches it, and the route is not carried over. The contract id and the definition schema are unchanged. The kernel's file is renamed: its sources import aiter's FlyDSL buffer_ops, so kernel.requires names aiter too, and its workloads lose the measured fields only CI writes. n_tokens is a plain var axis here, without the bucketed dispatch that is not on this branch. * feat(plugins): serve aiter's gemm_a8w8_bpreshuffle by gemm_a8w8 on a shuffled weight aiter #8075 routes its per-token fp8 GEMM on a preshuffled weight (gemm_a8w8_bpreshuffle), which vLLM's preshuffled per-token fp8 linears call (Kimi-K3's KDA in-projection). The provider offers it to gemm_a8w8's b_shuffled layout: e4m3fn operands of one K, fp32 scales per token and per output column, no bias. check, a bias (aiter raises on one), a wider zero-padded weight, per-tensor scales, int8 (aiter's own rules) and e5m2 stay on aiter. aiter's op reads WQ as shuffled whatever it carries, and vLLM re-wraps the weight as a Parameter, which drops is_shuffled; AKLR tells a shuffled b only by that mark, and an unmarked one would read as row-major. select and run hand AKLR a view of WQ that carries it; the caller's tensor is not touched. * feat(plugins): serve aiter's causal_conv1d_split_qkv by kimi_k3_kda_conv aiter #8075 routes its Triton tile prefill conv with the q/k/v split (causal_conv1d_split_qkv), which Kimi-K3's KDA prefill calls on vLLM with x as the [dim, n_tokens] transpose of the packed q|k|v projection rows and the state as a (slots, dim, state_len) view of its SD pages. The provider hands AKLR those rows as (n_tokens, 3, proj), each slot's first width - 1 state rows (vLLM keeps more for speculative decoding) and dense index vectors (vLLM can pass a column of its slot table), as the strided_rows variant, and returns (q, k, v). Offered only inside the contract: silu (or swish), no bias, k_dim == v_dim, x rows of 3 * k_dim channel-contiguous, float32 taps of width 4, a bf16 state of x's dtype in SD pages, int32 cache_indices, bool has_initial_state and int32 query_start_loc given by the caller, and a negative or no pad_slot_id. aiter's block_m, block_n, num_warps and metadata only schedule its own kernel, and preserve_input_dtype changes nothing when x and the state share a dtype. The tests check the run against aiter's documented result, q, k, v and the state, and, with aiter's plugin interface, the route it takes. * chore(kernels): 3 kernels aiter a6c759b1f outruns become kernel-less schemas On aiter a6c759b1f (FlyDSL 0.5.0) no workload of these reaches 1.05 over aiter: sparse_prefill_mxfp8 at 128 heads (two kernels, 0.42-0.50x and 0.67-0.78x, where main recorded 1.23-1.37x and 1.89-2.08x; aiter's mla_sparse_prefill_v4 now takes 260 us) and the fused MoE of 513 experts top-11 inter 512 (1.03-1.12x). As #253 did, their workloads stay as kernel-less schemas for another optimization round; the two sparse prefill kernels share their workloads, so they leave one schema. * fix(plugins): select only reads the target-verify note; the call that runs takes it aiter's explain() asks select too and runs nothing, so a select that consumed the note let the next real call miss it. * feat(plugins): register K3's attn_res and wvSplitKrc routes on vLLM 0.32.1rc1.dev276 The vLLM of the K3 AgentX image (nightly-rocm72-df6603f0). At its commit df6603f0 both callers still call their callee, with the same parameters as v0.34.0's: _apply_attn_res calls attn_res, and rocm_unquantized_gemm_impl calls ops.wvSplitKrc. * fix(plugins): flash_attn_varlen asks with aligned stand-ins and copies offsets only to run Selecting a call with offsets off AKLR's 16-byte boundary cloned them, so a declined call or aiter's explain() enqueued device copies, and an accepted one copied them again in run. * fix(plugins): a pass sglang's MLA prefill route has declined is not offered to AKLR again The route's bf16 fallback calls aiter's flash_attn_varlen_func, which asks the provider: a causal pass the route declined could be taken there in fp8. The fallback now runs inside the provider's declining(), in which the provider declines every call on that thread. * test(validation): which compiles the graph-capture tripwire hooks on each FlyDSL With stand-in compilers: from FlyDSL 0.5 it trips on the launch cache's miss and on MlirCompiler, before 0.5 on _build_call_state; armed it trips on each hook, and disarmed restores them. * test(plugins): the stand-in fused_moe contract has aiter a6c759b1f's splitk aiter's pinned contract, provider/moe.py and test_provider_moe.py list splitk after bias2; test_provider.py's snapshot had dropped it. * feat(plugins): serve SiTUv2 on MXFP4 activations, vLLM's Kimi-K3 MoE, by situv2_a4w4_moe vLLM's Kimi-K3 recipe (AITER_SITUV2_A4W4) has aiter round SiTUv2's activations to MXFP4, which the provider declined: fused_moe takes SiTUv2 on fp8 only. situv2_a4w4_moe is that call's own contract, as its baseline makes it: gate and up rows separated, an e8m0 scale per 32. * feat(plugins): serve vLLM's verify under decode context parallelism by mla_decode_fwd_cprr vLLM's aiter MLA backend verifies draft tokens under decode context parallelism through aiter's mla_decode_fwd with g_kv_indptr, cp_world_size and cp_rank, every request with max_seqlen_q causal queries; the provider declined it as not one query a request. mla_decode_fwd_cprr is that call's contract: q and o as [batch, queries, heads, width] views of aiter's rows, the lse back as a row's. * test(plugins): the MoE dispatch tests keep aiter's own routes and check their contracts The fixture skipped both dispatch tests whenever aiter routed either op itself, so on the pinned aiter they never ran. Now an op aiter routes keeps its route, asked with explain() and never run, and only the others get a stand-in; a new test holds this file's contract snapshot to the installed routes' versions and positional parameters. * fix(plugins): tell SiTUv2 on MXFP4 activations from aiter's enums by value aiter's enums are pybind11's, a new object each lookup, so the identity test declined every Kimi-K3 MoE call on aiter a6c759b1f (found on MI355X: route native, provider declined). The stand-in enums of the tests were Python's, the same object each time; a test now uses enums that compare by value only. * chore(kernels): Kimi-K3's situv2 A4W4 MoE kernels from 61 tokens on become kernel-less schemas On MI355X with aiter a6c759b1f, through aiter's provider and against the float64 reference: - 16fab927 (61-1023 tokens): 1.00-1.04x over aiter, and 17.97 dB where aiter's own fused MoE reaches 30.46 dB; - a5d411fa (1024-16384 tokens): 1.06-1.64x, but 17.97-17.98 dB where aiter reaches 27.98-30.42 dB. Both pass the contract's 13 dB bound. The three kernels below 61 tokens match aiter (30.1-31.1 dB both, 44.7-48.0 dB between them) and stay. As #253 did, the two keep their workloads as kernel-less schemas for another round. * fix(plugins): situv2_a4w4_moe holds its kernels to 25 dB, not fused_moe's 13 aiter's own SiTUv2 A4W4 reaches 27.98-31.06 dB against the float64 reference on Kimi-K3's calls (MI355X, aiter a6c759b1f), and so do the three kernels kept (30.12-31.06 dB). fused_moe's 13 dB let two kernels 12 dB short of aiter through (17.97 dB); at 25 dB validation stops them. * chore(kernels): 3 sglang Triton MoE kernels no faster than sglang become kernel-less schemas #271 touches aklr/core, so its CI benches every plugin schema again, and these three have no workload at 1.05 over sglang's own: kimi_k3_latent_moe 02471a7b (4096-8192 tokens, 0.95-0.99x; main records 0.98-1.03x) and deepseek_v2_mxfp4_moe 22fee0b1 (24 tokens, 1.01x; main 1.02x) and f8cbd122 (32 tokens, 0.97x; main 0.99x). As #253 did, their workloads stay as kernel-less schemas. * test(ops): the preshuffled gemm_a8w8 Point at k 256, which aiter a6c759b1f's bpreshuffle takes From aiter a6c759b1f gemm_a8w8_bpreshuffle's heuristic dispatch takes k > 192 and a multiple of 64, so test_backend_matches_reference failed at the Point's k = 128 (Unsupported K).
- op_tests/test_moe_eager_host_path.py follows the other op_tests now: no pytest, a main() that CI's `python3 <file>` runs. The pytest file it replaces had no __main__, so CI imported it and ran none of its cases. The same checks run from main() (unittest.mock instead of monkeypatch). The per-case comparison with the original path is an @benchmark sweep (quant type x tokens x EP x rows past num_local_tokens) that also checks each path against torch_moe (largest per-row relative error, 0.1 with fp8 activations, 0.01 with bf16) and ends in a markdown table of device and host time for both paths. The CUDA graph check now looks at every scratch buffer after capture, so it also fails when the capture stream itself gets one. per_Tensor runs without num_local_tokens, which per_tensor_quant_hip does not take. - main's gfx1201 small-M direct path (#4740) is chosen in _fused_moe_impl from arguments the plan key leaves out (splitk, the sort policy, the scales, the shuffle layout), after the point where a plan hit returns. Plans are not stored on that arch, so it still decides per call. The arch is one constant, _BF16_G1U1_SMALL_M_DIRECT_GFX, read by both. - moe_sorting's _scratch and _moe_sorting_impl's scratch are keyword-only. - _moe_sort_scratch states that threads sharing a stream must not interleave inside fused_moe. MI308X (gfx942), one GPU, the image's prebuilt modules with this tree's Python: `python3 op_tests/test_moe_eager_host_path.py` passes in 29 s, 11 checks and 28 sweep cases bit for bit (eager vs op), no JIT build; eager host time 60-90 us lower per call than op, device time equal. The script fails with the get_2stage_cfgs revalidation removed, and with the capture check on the scratch removed. gfx950 not run here (CI). Co-authored-by: Cursor <[email protected]>
Motivation
Enable Qwen3.6 35B-A3B BF16 AITER MoE serving on gfx1201/RDNA4 systems such as Navi48/R9700S.
Currently, setting
VLLM_ROCM_USE_AITER_MOE=1for Qwen3.6 35B-A3B on gfx1201 can route small decode MoE shapes into AITER paths that do not have a valid gfx1201 kernel, making AITER MoE unusable for this model family. The observed serving failure is:This PR adds the missing BF16 G1U1 small-token-count tier with a guarded direct HIP path for:
This is part of the Qwen3.6 35B-A3B gfx1201 AITER MoE enablement stack:
fmoe_g1u1finds no suitable kernel #4492Technical Details
This PR adds
fmoe_g1u1_bf16_small_m, a direct two-kernel path for the narrow unquantized BF16 G1U1 case.Source files:
aiter/fused_moe.pyaiter/ops/moe_op.pyaiter/ops/shuffle.pyaiter/jit/optCompilerConfig.jsoncsrc/kernels/fmoe_g1u1_bf16_small_m.cucsrc/py_itfs_cu/ctypes_error.cuop_tests/test_moe_small_m_direct.pyop_tests/windows/test_moe_small_m_direct.pyImplementation summary:
Silu(gate) * upinto a BF16 activation workspace.shuffle_weight(..., layout=(16,16))non-GU-interleaved W1/W2 runtime layout._fused_moe_impl, below the guardedfused_moe_()custom-op surface, instead of through an outer publicfused_moe()branch.output=by writing into the caller-provided output tensor when present and returning that same tensor.stage2_scatter is Noneis part of the gate so EP calls fall back to the existing stage2-scatter-aware path.splitkvalue is threaded through the wrapper stack and rejected for the direct path when it requests an unsupported split-K mode.shuffle_weight(..., is_guinterleave=False)no longer stamps the sharedgate_up_interleavemetadata tag; the direct guard relies onaiter_shuffle_layoutandaiter_shuffle_is_guinterleave.module_moe_g1u1_bf16_small_m, so unrelated asm fmoe users do not compile or cache-invalidate this gfx1201-only direct kernel.The guard remains limited to:
M in {1, 2, 3, 4, 8, 16}inter_dim in {128, 256}model_dim = 2048num_experts = 256topk = 8w1.shape == (256, 2 * inter_dim, 2048)andw2.shape == (256, 2048, inter_dim)stage2_scattersplitk in {0, 1})shuffle_weight(..., layout=(16,16), is_guinterleave=False)Test Plan
Correctness
Correctness coverage uses a focused gfx1201 unit test:
The test covers:
M in {1,2,3,4,8,16}for correctness coverageinter_dim in {128,256}model_dim = 2048num_experts = 256topk = 8activation = Siluquant_type = Nooutput=buffer semanticsstage2_scatter,splitk=2, unsupported shuffle layout, GU-interleaved shuffle layout, and neighboring unsupported shape keys (M=32,inter_dim=64,model_dim=1024,num_experts=128,topk=4)shuffle_weight(..., is_guinterleave=False)does not write the sharedgate_up_interleavetagThe gfx1201 Windows CI job discovers the same coverage through:
Kernel-Level Performance
Kernel-level performance compares this AITER path against the vLLM Triton MoE path using the same BF16 hidden states, weights, routing inputs, and top-k weights.
AITER path under test:
aiter.fused_moe.fused_moeasaiter_fused_moe.aiter_fused_moe(...)dispatches into the guarded PR fast pathfused_moe_g1u1_bf16_small_m_direct.fmoe_g1u1_bf16_small_m_stage1_kernelandfmoe_g1u1_bf16_small_m_stage2_kernel.Exact AITER call under test:
vLLM baseline path under test:
vllm.model_executor.layers.fused_moe.fused_moe.fused_experts.Exact vLLM call under test:
Exact latency timing used for both paths:
End-to-End Serving
End-to-end serving coverage uses the combined AITER MoE enablement stack (current PR + #4815 + #5059) with the native vLLM SLO-goodput benchmark, comparing:
VLLM_ROCM_USE_AITER=1, VLLM_ROCM_USE_AITER_MOE=0VLLM_ROCM_USE_AITER=1, VLLM_ROCM_USE_AITER_MOE=1Note: Request goodput here means completed requests per second at a point where
p99 TTFT <= 1000 ms; offered request rate is not used as the score.BF16 serving workloads:
Representative native vLLM goodput client command used by the end-to-end benchmark driver:
The actual end-to-end runs were launched through the local helper below, which creates the run, executes the adaptive request-rate search, repeats the boundary points, and records the confirmed goodput:
Test Result
Correctness Result
Correctness result on local gfx1201/R9700 at PR head
7d2e3afedaplus this review-fix worktree:These local gfx1201 reruns replace the earlier correctness note from the older review-fix revision.
Kernel-Level Performance Result
Kernel-level performance result from the Qwen3.6 35B-A3B BF16 small-token-count harness:
All valid target rows beat the vLLM Triton
fused_expertsbaseline in this kernel-level benchmark.End-to-End Serving Result
Current native vLLM SLO-goodput serving results for the combined AITER MoE enablement stack (current PR + #4815 + #5059) are:
AITER_MOE_OFFp99 TTFT / p99 E2E (ms)AITER_MOE_ONp99 TTFT / p99 E2E (ms)AITER_MOE_OFFgoodput (req/s)AITER_MOE_ONgoodput (req/s)2K -> 1KAITER_MOE_ON3K -> 1KAITER_MOE_ON4K -> 2KAITER_MOE_ON2K -> 1KAITER_MOE_ON3K -> 1KAITER_MOE_ON4K -> 2KAITER_MOE_ONPR Self-Review
Reviewed revision
Reviewed local worktree: PR head
7d2e3afedaplus this review-fix update. The final pushed commit SHA will differ from7d2e3afeda.Behavior and intent
This PR adds a narrow gfx1201/RDNA4 BF16 G1U1 small-M direct HIP MoE path for Qwen3.6 35B-A3B decode shapes. The existing behavior is insufficient because gfx1201 small-token unquantized BF16 G1U1 MoE can route into AITER MoE without a valid gfx1201 backend, producing
RuntimeError: wrong! device_gemm with the specified compilation parameters does not support this GEMM problem.The current revision also addresses integration correctness around the new fast path:
output=is honored by writing the caller-provided buffer, EP/scatter calls are excluded from the direct path and fall back to existing scatter-aware MoE, unsupported shuffled layouts are rejected before launch, the publicsplitkvalue is threaded into the direct-path guard, the direct path is restricted to the measured Qwen3.6 shape tier, and the plain HIP kernel is isolated in its own JIT module instead of being built with the asm fmoe module.Validation
Local validation environment:
registry-sc-harbor.amd.com/framework/therock-main:1246_gfx120X_7.13.0a20260414_ubuntu24.04_py3.12_pytorch_release-2.11_0446f7b2.11.0+rocm7.13.0a202604147.13.609803.6.0+rocm7.13.0a20260414flydsl==0.4.1,pybind11==3.1.0HIP_VISIBLE_DEVICES=0gfx1201 validation run for the review-fix worktree:
Results:
Tolerance measurement on the same gfx1201 matrix: raw max absolute diff was
256.0; after applyingrtol=1e-2, max requiredatolwas62.42, so the test keepsatol=64.Kernel-level benchmark validation was run on gfx1201 for Qwen3.6 35B-A3B BF16 small-M shapes with
model_dim=2048,num_experts=256,topk=8,inter_dim in {128,256}, andM in {1,2,4,8,16}. All measured target rows beat the vLLM Tritonfused_expertsbaseline; detailed latency numbers are listed in the Test Result section above.End-to-end serving validation was run with the combined AITER MoE enablement stack (this PR plus PR2/PR3 listed above) on BF16 Qwen3.6 35B-A3B serving workloads. The measured native vLLM SLO-goodput results are listed in the End-to-End Serving Result table above.
PR-specific question
The changed direct kernel path is selected only when all direct-path invariants pass:
gfx1201quant_type == QuantType.Noactivation == ActivationType.SiluM in {1, 2, 3, 4, 8, 16}model_dim == 2048inter_dim in {128, 256}num_experts == 256topk == 8w1.shape == (256, 2 * inter_dim, 2048)andw2.shape == (256, 2048, inter_dim)topk_idsint32,topk_weightfp32)expert_maskstage2_scatterdoweight_stage1w1_scale,w2_scale,a1_scale,a2_scale)num_local_tokenssplitk in {0,1})shuffle_weight(..., layout=(16,16), is_guinterleave=False)Unsupported inputs are prevented from reaching the direct HIP kernel by
_can_use_bf16_g1u1_small_m_direct(...). The review-fix revision keepsstage2_scatter is Noneto keep EP combine-arena writes on the existing scatter-aware path, threadssplitkinto the guard, rejects neighboring shape keys that were not measured for this fast path, and uses explicit shuffle metadata checks so(32,16)or GU-interleaved shuffled weights fall back instead of being read with the direct kernel's hard-coded(16,16)non-interleaved indexing. The raw ctypes entrypoint now repeats the narrow shape/output checks before launch so direct symbol misuse fails before kernels run.Changed op tests
op_tests/test_moe_small_m_direct.py: covers the gfx1201 direct path over the small-M/inter-dim/layout shape grid, compares againsttorch_moe, assertscheckAllclose(...) == 0, covers caller-providedoutput=buffer semantics, and adds negative gate tests forstage2_scatter,splitk=2, unsupported shape keys, unsupported shuffled layout, and GU-interleaved layout. It also verifies that plainshuffle_weight()no longer writes the sharedgate_up_interleavetag. This is not redundant because the new kernel is selected only for this narrow gfx1201 BF16 G1U1 path and the new review-fix behavior is not covered by existing MoE tests.op_tests/windows/test_moe_small_m_direct.py: re-exports the same focused tests underop_tests/windowsso the gfx1201 Windows CI job can discover them. This is not redundant because the default CI GPUs are gfx942/gfx950 and the gfx1201 Windows job selectsop_tests/windows, so the original root-level file alone would not exercise this kernel in CI.Submission Checklist