Skip to content

[CK] [FlyDSL] [fused_moe] [Test] Keep CK-capable clamped SiLU on CK, ship its gfx942 instances, and de-flake split-K graph replay - #8531

Merged
zufayu merged 3 commits into
mainfrom
ck-moe-dual-arch-instances
Nov 24, 2026
Merged

zufayu merged 3 commits into
mainfrom
ck-moe-dual-arch-instances

Conversation

@zufayu

@zufayu zufayu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hotfix for main CI. Three fixes for the three independent failures a run currently hits: MI300X shard 5 (red since #7361 landed) needs two of them, and MI35X shard 6 flakes on a fourth, unrelated assertion.

Motivation

test_plain_fp8_swiglu_limit_dispatch reads md.stage1.keywords. On main, a clamped per-token FP8 SiLU on gfx942 takes the FlyDSL whole-graph default from #7820 / #8178, whose metadata has stage1=None, so the test fails with AttributeError: 'NoneType' object has no attribute 'keywords' (run 45246107786; the other seven shards pass).

Routing those calls back to CK exposes a second bug. At 304 CUs a limit-7 call selects the tuned gfx942 256x16…MulABScale row from #7361, but get_gfx() returns only the last GPU_ARCHS entry, so the gfx942;gfx950 wheel never built that instance: Unknown or incompatible CK MoE kernel.

Both halves were measured separately on MI300X before being combined here:

branch shard 5 result
main AttributeError: 'NoneType' object has no attribute 'keywords'
codegen fix only same AttributeError — it does not touch dispatch
routing fix only Unknown or incompatible CK MoE kernel: moe_ck2stages_gemm1_256x16x64x256_1x4_MulABScale_…
both (this PR) expected green

Neither half turns shard 5 green on its own, which is why they ship together. Every other MI300X and MI35X shard passed on both.

The third failure: MI35X shard 6

test_flydsl_hgemm.py::test_hgemm_memory fails intermittently on the m=19, n=120, k=1088, policy="ft", split_k=9 row with graph replay mismatch: 0.00043859 — 1 wrong element in 2280, one BF16 ULP. Root cause in #8374: with BF16 output and split_k > 1 the gfx950 A16W16 kernel accumulates each K partition with BufferAtomicPkAdd, so every add rounds to BF16 and the result depends on atomic order once a running sum needs more than 8 significant bits. The exact-fraction inputs make every product a multiple of 1/64, so a running sum of magnitude 4 or more is order-sensitive. Measured 90/500 and 196/500 on MI355X, always element (14, 100). The bit-exact assertion holds for FP32 output, not BF16.

This carries the fix from #8351: for BF16 output with split_k > 1, accept the reference value or either adjacent BF16 value, and keep the test honest with a finiteness check and an assertion that the replay did not reuse the captured input. Every other dtype and split_k == 1 keep the bit-exact comparison, and the three eager launches above it still catch missing or repeated K tiles exactly.

Changes

  • aiter/fused_moe.py: keep the gfx942 FlyDSL whole-graph default only where CK rejects the shape (inter_dim not a multiple of 128, including V4.1-Flash at 576). The new predicate is the one the NotImplementedError gate below already uses, so the two cannot drift. A tuned impl__flydsl_gfx942__ row still wins. This does not revert [CK] [JIT] [aiter] Clamp FP8 per_Token / per_Tensor SiLU on #7019's runtime swiglu_limit #7361.
  • op_tests/test_flydsl_hgemm.py: allow one BF16 ULP in the split-K graph-replay check ([FlyDSL] [Test] Allow one BF16 ULP in atomic split-K graph replay #8351 verbatim).
  • csrc/ck_gemm_moe_2stages_codegen/: emit every built arch's CK MoE instance list into the lookup, not only get_gfx()'s. gfx942-only tiles are instantiated for the host and the gfx942 device pass and left out of the gfx950 one, guarded whenever both targets are built. Heuristic dispatch still follows get_gfx(); this only widens the lookup.

Considered and rejected: the smaller fix

Deleting the 16 tuned rows in a8w8_plain_tuned_swiglu_limit_fmoe_gfx942.csv would turn main green with no code change, because the heuristic then names a kernel get_gfx() already built. Rejected deliberately (#8334, 2026-11-21): it discards #7361's tuning, and retuning onto a gfx950 TypeCast name or dropping exact lookup are both larger changes than fixing the generator.

Performance (if applicable)

Not applicable: dispatch and build-time codegen. No kernel changes; the calls this moves back onto CK run the tuned rows #7361 measured.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • No documentation change is needed, with the reason stated below

Dispatch fix and build-time codegen; the swiglu_limit contract is unchanged.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None.

PR Self-Review

Reviewed revision

747f357

Behavior and intent

A clamped per-token FP8 SiLU that CK can clamp stays on the CK runtime-limit stage-1 instead of the gfx942 FlyDSL whole-graph default, and a dual-arch CK MoE prebuild contains every built arch's instance list so the tuned MulABScale rows those calls select exist in a GPU_ARCHS=gfx942;gfx950 wheel.

Validation and unverified scope

On CI MI300X, each half was run alone and failed exactly as predicted (table above), with all other shards green on both. The dual-arch build_aiter_wheels succeeded for both py3.10 and py3.12. This revision is the first with both halves; its shard 5 is the result to read.

On a local gfx942 box (MI308X, 80 CU), driving get_2stage_cfgs at the dispatch test's shape (2048, 768, 128, 8): on main 6 of 6 per-token cases at limits 7.0/5.0 return stage1=None; with the routing fix, 0 of 6. stage1.func is ck_moe_stage1, run_1stage false, ksplit 0. inter_dim=192 still takes FlyDSL for per_Token and still raises NotImplementedError for per_Tensor. swiglu_limit None / 0.0 / inf leave run_1stage unchanged. The crash is CU-independent, so it is not specific to the 304-CU runner.

test_plain_fp8_swiglu_limit now runs there too, after initialising 3rdparty/composable_kernel: 30/30 pass on gfx942 (per_Token and per_Tensor x tokens 1/64/1024 x swiglu_limit None/0/inf/1/7). At the tightest clamp, swiglu_limit=1, fused_moe err is 0 in all six rows, while the unclamped reference for the same rows sits at 77-87 and the swapped-limit reference at ~0.35 — so the clamp is demonstrably applied, not merely indistinguishable. swiglu_limit=7 lands at 0 to 0.004 against a 0.01 gate.

Generated CK MoE sources are byte-identical before and after the codegen simplification for GPU_ARCHS gfx942;gfx950, gfx950;gfx942, gfx942 and gfx950.

Unverified: at 80 CU no row in the tuned CSV (all keyed cu_num=304) is selected, so the local sweep exercises the heuristic kernel on the same CK runtime-limit stage-1 rather than the 256x16…MulABScale tile CI selects. The gfx950-only test_flydsl_hgemm path cannot run there at all — the FlyDSL A16W16 kernel supports gfx950 and gfx1250 only — so that third fix is first exercised by this PR's MI35X shards. A GPU_ARCHS list naming a third target alongside both MoE arches is guarded but not built here.

One MI35X shard-6 failure appeared on an earlier revision: test_flydsl_hgemm.py::test_hgemm_memory, 1 of 2280 elements off by one bf16 ULP under an atol=0 rtol=0 graph-replay assert. It came from a run created before the ci:mi300x label, i.e. a GPU_ARCHS=gfx950 build, where this PR's generated sources are byte-identical to base — so its diff cannot have caused it.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

Routing: gfx942 only, per_Token FP8 weights and activations, use_g1u1, shuffled weights, separated gate, BF16 input, an active finite swiglu_limit, and no tuned FlyDSL row in use. Within that, inter_dim % 128 == 0 now stays on the CK runtime-limit stage-1 and everything else keeps the FlyDSL whole-graph default. The invariant is that the predicate is the same one the NotImplementedError gate below it uses — the gate that defines what that stage-1 accepts — so a shape CK cannot clamp cannot be routed to it; it raises instead.

Codegen: no call selects a different kernel. Only gfx942 and gfx950 have distinct CK MoE instance lists (arch == "gfx950" picks the a8w8_gfx950 / a16w16_gfx950 tables), and MOE_INSTANCE_ARCHES names exactly those two, so any other GPU_ARCHS entry contributes nothing. Heuristic dispatch still formats from get_gfx()'s list, so every dtype and shape resolves as before. Two invariants keep a gfx950 run out of a gfx942-only tile: tuned lookup is an exact name match and the CSVs are keyed by gfx and cu_num, so a gfx950 runtime never reads a gfx942 row; and those tiles carry #if !defined(__HIP_DEVICE_COMPILE__) || defined(__gfx942__) || defined(__gfx9_4_generic__), so the gfx950 device pass has no code object for them at all. The host pass still instantiates them, which is what lets a tuned gfx942 row take their address.

**What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

op_tests/test_moe_2stage.py::test_plain_fp8_swiglu_limit_dispatch fails on base by crashing: it dereferences md.stage1.keywords for a route whose metadata has stage1=None. That is the red shard on main.

op_tests/test_flydsl_moe_gfx942.py::test_num_local_tokens_dispatch fails on base because it asserted the Qwen bypass (inter_dim 512) takes the FlyDSL whole-graph default, which is the routing this PR corrects. Verified both ways on a local gfx942: it passes with the fix and fails against main's aiter/fused_moe.py.

No canonical test covers this. test_plain_fp8_swiglu_limit is the numerical check for the same shapes and asserts output values, not which backend ran, so it stays green whichever backend takes the call — which is how the misroute survived from #7820 until #7361's dispatch test was added.

Changed op tests

op_tests/test_moe_2stage.py covers the gfx942 per-token inter_dim 192 case taking FlyDSL while per-tensor still raises. That split is what the routing change does, and no existing test asserted it.

op_tests/test_flydsl_moe_gfx942.py covers the bypass split: Qwen inter_dim 512 stays on CK, V4.1-Flash inter_dim 576 stays on FlyDSL. The previous assertion required FlyDSL for the Qwen bypass, which is the bug.

op_tests/test_flydsl_hgemm.py is the #8351 change described above. It is not redundant with the exact checks it sits next to: those three eager launches keep rtol=0, atol=0 and are what catch a missing or repeated K tile; this one covers the single accumulation path where bit-exactness was never a property of the kernel.

The first two are edits to existing dispatch tests, not new files. The codegen half adds no test: one driving gen_instances.py and asserting on generated text would be a build-script test in op_tests/, pinned to hard-coded tile names and a tuned CSV, and the miss it guards surfaces as the runtime Unknown or incompatible CK MoE kernel above.

Known and out of scope

csrc/ck_tile_gemm_moe_2stages/moe_cktile2stages_common.py has the same arch = get_gfx() split at lines 543 and 592, so the ck_tile MoE generator carries the identical blind spot. It is not reachable today — no tuned CSV names a ck_tile MoE kernel, so those calls take the heuristic, which follows get_gfx() and stays self-consistent. Left out of this hotfix; worth its own issue.

Fixes #8334

@zufayu
zufayu requested a review from a team November 24, 2026 02:35
@github-actions github-actions Bot added the CK label Nov 24, 2026
@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 747f3572e05b · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

A clamped per-token FP8 SiLU that CK can clamp stays on the CK runtime-limit stage-1 instead of the gfx942 FlyDSL whole-graph default, and a dual-arch CK MoE prebuild contains every built arch's instance list so the tuned `MulABScale` rows those calls select exist in a `GPU_ARCHS=gfx942;gfx950` wheel.

Validation and unverified scope

**On CI MI300X**, each half was run alone and failed exactly as predicted (table above), with all other shards green on both. The dual-arch `build_aiter_wheels` succeeded for both py3.10 and py3.12. This revision is the first with both halves; its shard 5 is the result to read.

**On a local gfx942 box** (MI308X, 80 CU), driving `get_2stage_cfgs` at the dispatch test's shape `(2048, 768, 128, 8)`: on main 6 of 6 per-token cases at limits 7.0/5.0 return `stage1=None`; with the routing fix, 0 of 6. `stage1.func is ck_moe_stage1`, `run_1stage` false, `ksplit` 0. `inter_dim=192` still takes FlyDSL for per_Token and still raises `NotImplementedError` for per_Tensor. `swiglu_limit` None / 0.0 / inf leave `run_1stage` unchanged. The crash is CU-independent, so it is not specific to the 304-CU runner.

`test_plain_fp8_swiglu_limit` now runs there too, after initialising `3rdparty/composable_kernel`: 30/30 pass on gfx942 (per_Token and per_Tensor x tokens 1/64/1024 x `swiglu_limit` None/0/inf/1/7). At the tightest clamp, `swiglu_limit=1`, `fused_moe err` is 0 in all six rows, while the unclamped reference for the same rows sits at 77-87 and the swapped-limit reference at ~0.35 — so the clamp is demonstrably applied, not merely indistinguishable. `swiglu_limit=7` lands at 0 to 0.004 against a 0.01 gate.

Generated CK MoE sources are byte-identical before and after the codegen simplification for `GPU_ARCHS` `gfx942;gfx950`, `gfx950;gfx942`, `gfx942` and `gfx950`.

**Unverified:** at 80 CU no row in the tuned CSV (all keyed `cu_num=304`) is selected, so the local sweep exercises the heuristic kernel on the same CK runtime-limit stage-1 rather than the `256x16…MulABScale` tile CI selects. The gfx950-only `test_flydsl_hgemm` path cannot run there at all — the FlyDSL A16W16 kernel supports gfx950 and gfx1250 only — so that third fix is first exercised by this PR's MI35X shards. A `GPU_ARCHS` list naming a third target alongside both MoE arches is guarded but not built here.

One MI35X shard-6 failure appeared on an earlier revision: `test_flydsl_hgemm.py::test_hgemm_memory`, 1 of 2280 elements off by one bf16 ULP under an `atol=0 rtol=0` graph-replay assert. It came from a run created before the `ci:mi300x` label, i.e. a `GPU_ARCHS=gfx950` build, where this PR's generated sources are byte-identical to base — so its diff cannot have caused it.

PR-specific question

**Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?**

Routing: gfx942 only, per_Token FP8 weights and activations, `use_g1u1`, shuffled weights, separated gate, BF16 input, an active finite `swiglu_limit`, and no tuned FlyDSL row in use. Within that, `inter_dim % 128 == 0` now stays on the CK runtime-limit stage-1 and everything else keeps the FlyDSL whole-graph default. The invariant is that the predicate is the same one the `NotImplementedError` gate below it uses — the gate that defines what that stage-1 accepts — so a shape CK cannot clamp cannot be routed to it; it raises instead.

Codegen: no call selects a different kernel. Only gfx942 and gfx950 have distinct CK MoE instance lists (`arch == "gfx950"` picks the `a8w8_gfx950` / `a16w16_gfx950` tables), and `MOE_INSTANCE_ARCHES` names exactly those two, so any other `GPU_ARCHS` entry contributes nothing. Heuristic dispatch still formats from `get_gfx()`'s list, so every dtype and shape resolves as before. Two invariants keep a gfx950 run out of a gfx942-only tile: tuned lookup is an exact name match and the CSVs are keyed by `gfx` and `cu_num`, so a gfx950 runtime never reads a gfx942 row; and those tiles carry `#if !defined(__HIP_DEVICE_COMPILE__) || defined(__gfx942__) || defined(__gfx9_4_generic__)`, so the gfx950 device pass has no code object for them at all. The host pass still instantiates them, which is what lets a tuned gfx942 row take their address.

**What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

`op_tests/test_moe_2stage.py::test_plain_fp8_swiglu_limit_dispatch` fails on base by crashing: it dereferences `md.stage1.keywords` for a route whose metadata has `stage1=None`. That is the red shard on main.

`op_tests/test_flydsl_moe_gfx942.py::test_num_local_tokens_dispatch` fails on base because it asserted the Qwen bypass (`inter_dim` 512) takes the FlyDSL whole-graph default, which is the routing this PR corrects. Verified both ways on a local gfx942: it passes with the fix and fails against main's `aiter/fused_moe.py`.

No canonical test covers this. `test_plain_fp8_swiglu_limit` is the numerical check for the same shapes and asserts output values, not which backend ran, so it stays green whichever backend takes the call — which is how the misroute survived from #7820 until #7361's dispatch test was added.

Changed op tests

`op_tests/test_moe_2stage.py` covers the gfx942 per-token `inter_dim` 192 case taking FlyDSL while per-tensor still raises. That split is what the routing change does, and no existing test asserted it.

`op_tests/test_flydsl_moe_gfx942.py` covers the bypass split: Qwen `inter_dim` 512 stays on CK, V4.1-Flash `inter_dim` 576 stays on FlyDSL. The previous assertion required FlyDSL for the Qwen bypass, which is the bug.

`op_tests/test_flydsl_hgemm.py` is the #8351 change described above. It is not redundant with the exact checks it sits next to: those three eager launches keep `rtol=0, atol=0` and are what catch a missing or repeated K tile; this one covers the single accumulation path where bit-exactness was never a property of the kernel.

The first two are edits to existing dispatch tests, not new files. The codegen half adds no test: one driving `gen_instances.py` and asserting on generated text would be a build-script test in `op_tests/`, pinned to hard-coded tile names and a tuned CSV, and the miss it guards surfaces as the runtime `Unknown or incompatible CK MoE kernel` above.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

get_gfx() returns the last GPU_ARCHS entry, so a GPU_ARCHS=gfx942;gfx950
wheel builds only the gfx950 CK MoE instance list. Tuned rows that name a
gfx942 kernel then resolve to nothing at runtime: "Unknown or incompatible
CK MoE kernel". A gfx942-only build is unaffected, which is why this does
not show up outside the dual-arch prebuild CI uses on main.

_instance_arches() is get_gfx() plus any other MoE target in GPU_ARCHS, so
the lookup carries every built arch's instances. _kernels_for_arch() holds
the per-arch call pair and the generator body keeps the shape it had.
gfx942-only tiles are instantiated for the host and the gfx942 device pass
and left out of the gfx950 one, guarded whenever both targets are built --
the host instantiation is what lets a tuned gfx942 row take their address.
Heuristic dispatch still follows get_gfx(); this only widens the lookup.

Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu force-pushed the ck-moe-dual-arch-instances branch from 8750468 to 48efa54 Compare November 24, 2026 03:34
@zufayu
zufayu requested a review from amd-ruitang3 November 24, 2026 03:40
@zufayu zufayu added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 24, 2026
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a
multiple of 128) is routed to the FlyDSL whole-graph default from #7820 /
#8178. That backend's metadata has stage1=None, so
test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords,
crashes with AttributeError: 'NoneType' object has no attribute 'keywords'
-- MI300X shard 5 on main, most recently run 45246107786.

The route is also the wrong one for these calls: the whole-graph backend
clamps the BF16 activations it reads, a different quantization point from
the per-token path the call and the tuned rows from #7361 ask for. (The
accuracy claim in #8334 about that backend is retracted; it is accurate
against its own reference, see #8350.)

Keep the whole-graph default only where CK rejects the shape (inter_dim
not a multiple of 128, including V4.1-Flash at 576). The new predicate is
the same one the NotImplementedError gate below uses, which is what
defines what CK's runtime-limit stage-1 accepts. A tuned
impl__flydsl_gfx942__ row still wins. This does not revert #7361.

Fixes #8334

Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot changed the title [CK] Emit every built arch's MoE instances in a dual-arch build [CK] [FlyDSL] Emit every built arch's MoE instances in a dual-arch build Nov 24, 2026
@zufayu zufayu changed the title [CK] [FlyDSL] Emit every built arch's MoE instances in a dual-arch build [CK] [FlyDSL] [fused_moe] Keep CK-capable clamped SiLU on CK and ship its gfx942 instances Nov 24, 2026
@ROCm ROCm deleted a comment from github-actions Bot Nov 24, 2026
@zufayu zufayu changed the title [CK] [FlyDSL] [fused_moe] Keep CK-capable clamped SiLU on CK and ship its gfx942 instances [CK] [FlyDSL] [fused_moe] [Test] Keep CK-capable clamped SiLU on CK, ship its gfx942 instances, and de-flake split-K graph replay Nov 24, 2026
@zufayu
zufayu merged commit 62cb8de into main Nov 24, 2026
76 of 77 checks passed
@zufayu
zufayu deleted the ck-moe-dual-arch-instances branch November 24, 2026 13:08
aarushjain29 added a commit to aarushjain29/aiter that referenced this pull request Nov 30, 2026
…table

The heuristic dispatch of a ck2stages module ran the kernel table of
get_gfx(), the last GPU_ARCHS entry, while hipcc compiles the module for
every entry. A GPU_ARCHS="gfx942;gfx950" build, which is how multi-arch
wheels are built, therefore dispatched gfx942 devices through the gfx950
a16w16 and a8w8 tables: shapes the gfx942 table covers, such as a16w16
inter_dim=320, were rejected (ROCm#5766). ROCm#8531 added the gfx942 instances
to such a build, so tuned gfx942 names resolve, but left the dispatch on
get_gfx().

Generate the table of each arch in get_gfx_list() instead. An instance
that only some archs' tables have is compiled only for those archs, and
the heuristic dispatch, which now takes the device arch from
get_device_gfx(), runs the table of the arch it is on. This replaces
ROCm#8531's gfx942-only instance set with the per-arch guards.

A "native" GPU_ARCHS entry is resolved to the build GPU with
get_gfx_runtime(), so it gets a table that matches a device.

ck_moe_stage2 gets the device guard ck_moe_stage1 has, so
get_device_gfx() and the stream come from the tensors' device.

JIT builds regenerate a module's sources in the directory of its last
build, and an instance's arch guard depends on GPU_ARCHS. Write each
instance unless its file already holds it, instead of skipping existing
files, so stale guards are replaced and unchanged files keep their mtime
for ninja.

Fixes ROCm#5766

Signed-off-by: aarushjain29 <[email protected]>
zufayu pushed a commit that referenced this pull request Dec 3, 2026
* [MoE] moev2 step 3.1: bf16/fp16 a16w16 path (not graduated)

Unquantized bf16/fp16 fused_moe calls (QuantType.No) can run through
aiter.moev2 when enabled with AITER_MOEV2=a16w16 (or on). The path is not
graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The CPU dispatch snapshot of legacy
  fused_moe is identical on gfx942, gfx942_cu80, gfx950 and gfx1201,
  including the new QuantType.No feature variants, which are byte-identical
  to ones generated with the upstream base's aiter package.
- When a16w16 runs a call in v2, it makes the same choices as legacy:
  same kernels, parameters and inputs, same log lines and exceptions, and
  the same outputs within legacy's own run-to-run noise (see Tests).
- a8w8_pt keeps its choices. It no longer takes g1u0 weights, which now
  run on legacy (see Known differences).
- Both paths decline what they do not reproduce, and those calls run on
  legacy: herd_topk, deterministic=True, a registered presort, a
  clamping swiglu_limit (None, 0 and inf do not clamp), beta or
  linear_beta, bias, global scales, padding, scatter, caller-chosen
  activation dtypes, AITER_ONLINE_TUNE,
  g1u0 weights, and a call whose second lookup after the sort would raise
  or be declined.

What changed:
- migration/a16w16.py: path a16w16. It claims QuantType.No calls with
  g1u1 bf16/fp16 3D weights on gfx942/gfx950, Silu or Gelu, separated
  gate/up. Its segments are sort, quant, CK stage 1/2 and whole graph.
- migration/local.py: what the single-GPU paths share. That is the
  common claims checks, the per-key cached resolve, the log-only second
  lookup after the sort, run and dispatch_record. a8w8_pt now uses it.
  The check phase 2 added to a8w8_pt moves here, so every local path
  declines a call whose second lookup would raise or be declined, and
  says so under AITER_MOE_EXPLAIN=1.
- Path.takes(problem): the dispatch keys a path runs. One segment (CK)
  serves several formats, and takes keeps one path from taking another
  path's keys. Dispatch, the CPU differential and the ranking checks use
  it.
- CK stage 1/2 and the whole graph accept bf16 and fp16, one capability
  per dtype. CK stage 1 is g1u1 only, since it always reads w1 as gate and
  up (N = w1.size(1) / 2).
- Ranking:
  - an a16w16 entry: the get_2stage_cfgs CK default branch;
  - named boolean predicates in when(...). fmoe_1stage tests a copy of the
    keys of legacy fused_moe_1stage_dict, current with upstream (it has
    the gfx950 SwiGLU per_1x32 keys), and a test checks the copy;
  - regions that hand their problems back to legacy (legacy="...").
  The shipped table uses neither predicates nor legacy regions yet. When
  the resolver declines, it says why: no entry applies, a legacy region,
  or no listed structure is feasible.
- Dispatch snapshot: QuantType.No keys also get the feature variants
  (FEATURE_QUANT_TYPES), and the goldens are regenerated.
- README: rows for local.py and a16w16.py (to be removed), plus the
  updated descriptions of paths, ranking, resolver, CK and the tests.
- Tests:
  - claims, takes and their agreement on key fields;
  - g1u0 not claimed;
  - the second-lookup declines, now through the shared dispatch;
  - feature variants of QuantType.No keys are legacy calls;
  - predicates and legacy regions;
  - gpu_differential.py gains a16w16 cases and per-path synthetic rows.

Known differences and limits:
- g1u0 calls run on legacy. Legacy's CK 2-stage gives wrong output for
  g1u0 (the stage-1 kernel reads w1 as gate and up), so v2 has nothing to
  match. The QuantType.No keys of fused_moe_1stage_dict are all g1u0, so
  legacy's default 1-stage ASM fmoe branch stays on legacy too. For
  a8w8_pt this drops 544 / 751 / 544 keys on gfx942 / gfx942_cu80 /
  gfx950 that phase 2 claimed, all of them the g1u0 feature variants;
  it gains none.
- gfx942-only parts are checked only by the CPU differential: the
  impl__flydsl_gfx942 tuned rows and the gfx942-only suites. gfx1201
  bf16 rows stay on legacy.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 100
  passed.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a16w16 8000 / 11,724 / 8084 and a8w8_pt 5984 /
    8280 / 5984 keys on gfx942 / gfx942_cu80 / gfx950 (none on gfx1201);
  - key_checks.py: 181,478 keys, 27,963 tuned rows;
  - ranking_checks.py: 51,828 ranked keys, both entries reached.
- GPU differential, gfx950, 0 problems, each also with AITER_USE_NT=1
  and AITER_BYPASS_TUNE_CONFIG=1:
  - a16w16: 21 default and shipped-tuned cases, and 69 with a synthetic
    table of bf16 CK rows;
  - a8w8_pt: 15 cases, and 63 with its synthetic table.
- GPU suites, gfx950, AITER_MOEV2=off vs on (both paths):
  test_moe_2stage -q 0 and -q 1 (--no-flydsl-csv), test_moe.py,
  test_moe_per_tensor_a2_init, test_moe_sorting, test_moe_ep,
  test_moe_local_expert_ids and test_moe_dp_share_expert. Same exit codes
  and the same verdict for every check, except two swiglu_limit=7.0
  checks of test_moe_2stage -q 0 (per-token and per-tensor fp8, which run
  on legacy in both modes). Their verdicts also change between two runs
  with AITER_MOEV2=off (1 or 2 of 2048 elements past the tolerance).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255):
- local.py carries PR 8255's a8w8_pt code: why_not reasons, the clamps
  helper, w1/w2 global scales unsupported, the live arch only, and the
  preview prologue that declines before copying anything. Both paths
  set why_not and supported_archs and have the ownership NOTE.
- gpu_differential.py keeps PR 8255's variant, raise and gfx942 cu80
  cases; the a8w8_pt g1u0 variant is dropped (no longer claimed).
- The golden delta equals the original step's exactly. The key counts
  and GPU results above are from the original base. On this base: CPU
  tests 133 passed; differential a16w16 8712 / 12,773 / 8803 and
  a8w8_pt 6528 / 9031 / 6528 keys on gfx942 / gfx942_cu80 / gfx950;
  key_checks, ranking_checks and snapshot --check, 0 problems. The GPU
  differential is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.2: fp8 per-token and 1x128 blockscale paths (not graduated)

fp8 per-token (QuantType.per_Token) and fp8 1x128 blockscale
(QuantType.per_1x128, and per_128x128, which legacy remaps to it)
fused_moe calls can run through aiter.moev2 when enabled with
AITER_MOEV2=a8w8_ptok / a8w8_blockscale (or on). Neither path is
graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The CPU dispatch snapshot of legacy
  fused_moe is identical on gfx942, gfx942_cu80, gfx950 and gfx1201,
  including the new per_Token and per_1x128 feature variants, which are
  byte-identical to ones generated with the upstream base's aiter package.
- When either path runs a call in v2, it makes the same choices as
  legacy: same kernels, parameters and inputs, same log lines and
  exceptions, and the same outputs within legacy's own run-to-run noise.
  The exceptions are two legacy ASM stage 1 kernel families that are not
  repeatable even legacy against legacy (see Known differences).
- Calls legacy runs on 1-stage ASM are handed back to legacy: the default
  1-stage regions of both formats, and 1-stage tuned rows. So is what the
  shared local checks decline (herd_topk, deterministic=True, a
  registered presort, a clamping swiglu_limit, beta, linear_beta, bias,
  global scales, padding, scatter, caller-chosen activation dtypes,
  AITER_ONLINE_TUNE, g1u0, and a call whose second lookup after the
  sort would raise or be declined).
- a8w8_pt and a16w16 keep their keys and choices.

What changed:
- migration/a8w8_ptok.py: path a8w8_ptok. It claims per-token calls with
  g1u1 fp8 3D weights (the arch's fp8) on gfx942/gfx950, Silu or Gelu,
  separated gate/up. These resolve to CK 2-stage, ASM stage 1 + CK
  stage 2, or the FlyDSL gfx942 whole graph. int8 and int4 weights stay
  on legacy.
- migration/a8w8_blockscale.py: path a8w8_blockscale, the same checks for
  per_1x128 / per_128x128. These resolve to CK 2-stage (with the 1x128
  block_m and split-K defaults) or asm.stage1_1x128 + CK stage 2.
- segments/asm.py: asm.stage1_1x128, the ASM stage 1 that writes the
  quantized intermediate and its fp32 scales into one buffer. It covers
  GEMM1 and the intermediate quant, and asks for the a1 scale transposed.
  The per-tensor ASM stage 1 also takes per-token fp8.
- execute/executor.py: a stage 1 that covers the intermediate quant gets
  its own buffer and splits its output into the GEMM2 inputs, as legacy
  does. segments/quant.py: the a1 quant can write the scale transposed.
- CK stage 1/2 accept per-token and 1x128 fp8; the whole graph accepts
  per-token fp8.
- segments/defaults.py: default_block_m / default_ksplit, the legacy
  default branch's 2-stage block_m and split-K per quant type.
- Ranking:
  - entries fp8_per_token and fp8_blockscale. Their legacy regions are
    the 1-stage branches of get_2stage_cfgs, with the thresholds as
    written; everything else ranks CK 2-stage;
  - predicates inter_dim_128 and blockscale_1stage_kernel (the kernel
    library's fmoe_fp8_blockscale_g1u1_has_kernel, which legacy calls);
  - when() tests its conditions in the order written, so the kernel
    library is asked only where legacy asks it;
  - FMOE_1STAGE_KEYS reads fp8 as the arch's dtypes.fp8 when looked up,
    as legacy does.
- The resolver finds stage segments by the op they cover rather than by
  name (MoePlan.starting). local.why_not takes a set of quant types.
  overrides.xbf16 reads AITER_XBFLOAT16 where legacy reads it.
- Dispatch snapshot: per_Token and per_1x128 keys also get the feature
  variants (FEATURE_QUANT_TYPES), and the goldens are regenerated.
- README: rows for a8w8_ptok.py and a8w8_blockscale.py (to be removed),
  plus the updated descriptions of plan, ranking, resolver, overrides,
  quant, CK, ASM, defaults, executor, the differential and the tests.
- Tests:
  - claims and takes of both paths;
  - the per-token 1-stage hand-back, the 1x128 block_m and split-K
    defaults, a tuned ASM 1x128 row running the packed stage 1, and the
    packed buffer splitting like legacy;
  - when() evaluation order;
  - feature variants of per_Token and per_1x128 keys are legacy calls;
  - the CPU differential counts 1-stage hand-backs separately;
  - gpu_differential.py gains cases for both paths (shapes with shipped
    gfx950 rows among them) and, for a8w8_blockscale, synthetic rows that
    swap the arch's ASM 1x128 stage 1 into its CK rows.

Known differences and limits:
- Two legacy ASM stage 1 families give different outputs for identical
  inputs on gfx950, legacy against legacy, on main and on the older base
  this work started from. The GPU differential reports them (they are
  not excused):
  - per-token fmoe_stage1_bf16_pertokenFp8_g1u1_64x128_2tg_pf3 and
    _32x128_3tg_pf2 at the shipped 5120/1536 E40 top8 and E41 top10
    rows: output garbage up to 1e34 in some runs;
  - the 1x128 fmoe_stage1_bf16_pertokenFp8_blockscale_g1u1_* family,
    which only the synthetic table runs on gfx950 (shipped ASM 1x128 rows
    are gfx942 only): stage 1 output differs on every run.
- Upstream's tuned lookup now falls back to rows tuned for another
  activation, except CK 2-stage and MXFP4 rows. The shipped gfx950
  4096/384 E128 top8 1x128 Silu rows are 1-stage at 4 to 128 tokens, so a
  Gelu call there runs 1-stage on legacy (and is handed back). The GPU
  differential's Gelu case for that shape therefore moves from 32 tokens
  to 2, which still runs the CK split-K default.
- gfx942-only parts are checked only by the CPU differential: the ASM
  1x128 rows and the impl__flydsl_gfx942 rows.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 112
  tests, 111 passed. test_outputs_match_legacy[a8w8_ptok] fails on the
  per-token legacy race above.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a8w8_ptok 3657 / 6724 / 3061 and a8w8_blockscale
    5523 / 7583 / 6154 keys on gfx942 / gfx942_cu80 / gfx950, with 2375 /
    3357 / 4111 and 1529 / 605 / 4256 keys handed back as 1-stage;
    a16w16 and a8w8_pt unchanged (none on gfx1201);
  - key_checks.py: 323,445 keys, 51,639 tuned rows;
  - ranking_checks.py: 104,820 ranked keys, every entry and region
    reached.
- GPU differential, gfx950, shipped tables, AITER_USE_NT=1 and
  --synth-table:
  - a8w8_ptok: 22 cases (70 with the synthetic table); the only
    problems are 2 of the per-token race cases in each mode;
  - a8w8_blockscale: 20 cases, 0 problems; with the synthetic table, 64
    of 136 pass and all 72 failures run the ASM 1x128 family;
  - with AITER_BYPASS_TUNE_CONFIG=1, legacy runs 6 per-token and 4
    blockscale cases on 1-stage ASM, and v2 hands them back; the rest
    pass;
  - a16w16 and a8w8_pt: 0 problems in every mode.
- GPU suites, gfx950, AITER_MOEV2=off vs on (all four paths):
  test_moe_2stage -q 2, -q 3 and -q 5 (--no-flydsl-csv), test_moe_tkw1,
  test_moe_blockscale, test_moe_sorting, test_moe_ep,
  test_moe_local_expert_ids and test_moe_dp_share_expert. Same exit codes
  and the same verdict for every check, except three that run on legacy
  in both modes and also change between two AITER_MOEV2=off runs: the
  per-tensor swiglu_limit=7.0 check of test_moe_2stage -q 3 and -q 5, and
  the first check of test_moe_tkw1 (its 1-stage tkw1 ASM kernel, which
  fails or warns on every run).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
step 3.1):
- Both new paths set why_not and supported_archs and carry the
  ownership NOTE; like a8w8_pt they claim swiglu_limit None, 0 and inf
  (legacy reads them as no clamp for every format).
- differential.py keeps PR 8255's compare_launches (the 1-ulp and
  legacy-spread tolerance, whole-graph launches, a second legacy run)
  and adds this step's 2-stage guard, 1-stage hand-backs and output
  check. gpu_differential.py keeps PR 8255's rule that a case where
  legacy and v2 both raise fails unless listed in _RAISES; this step's
  "both raise" pass is not taken. New GPU cases: output=, a
  non-contiguous input and swiglu_limit 0 / inf for both new paths.
- The fused_moe.py note on get_2stage_cfgs points at the README's path
  list instead of naming per-tensor fp8.
- Goldens regenerated. gfx950 and gfx1201 get exactly this step's
  delta; on gfx942 and gfx942_cu80, 125 / 223 of the new swiglu_limit=7
  per-token variant lines differ from the original step's: upstream
  #8531 keeps clamped SiLU on CK where the old base chose the FlyDSL
  whole graph, and PR 8255 records whole-graph plans structurally.
- The counts and GPU results above are from the original base. On this
  base: CPU tests 143 passed (the GPU-only ones skip); differential
  a8w8_ptok 3979 / 7355 / 3329 and a8w8_blockscale 6012 / 8265 / 6682
  keys on gfx942 / gfx942_cu80 / gfx950, with 2601 / 3624 / 4486 and
  1673 / 664 / 4644 handed back as 1-stage; key_checks, ranking_checks
  and snapshot --check, 0 problems. The GPU differential is rerun at the
  end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.3: int8 and int4-weight formats (not graduated)

No new paths. The int8 and int4-weight formats join the paths that
already own their scale layout:
- a8w8_pt takes int8 per-tensor weights;
- a8w8_ptok takes int8 per-token weights, and int4 weights packed eight to
  a uint32 with fp8 activations.
No path is graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The dispatch snapshot grid gains the fp8 x
  uint32 per-token combination (272 keys per arch, 2992 with their feature
  variants; additions only). The snapshot is identical on gfx942,
  gfx942_cu80, gfx950 and gfx1201 to one generated with the upstream
  base's aiter package.
- When either path runs an int8 or int4 call in v2, it makes the same
  choices as legacy: same kernels, parameters and inputs, same log lines
  and exceptions, and the same outputs within legacy's own run-to-run
  noise. One int8 case is the exception (see Known differences).
- int8 calls with doweight_stage1 stay on legacy. No ASM int8 stage 1
  kernel applies the routing weights, so legacy raises in the kernel
  lookup, and still does.
- A format added to a path later stays behind AITER_MOEV2 once the path
  graduates, until it passes its own gate (Path.graduated_claims).

What changed:
- CK segments accept the int8 and fp8 x int4 instances gen_instances.py
  builds. asm.stage1 accepts int8 without doweight_stage1 (the get_cfg
  kernel tables have no int8 kernel with it).
- Ranking: entries int8_per_token, int8_per_tensor and int4_per_token,
  following the legacy default branch:
  - int8 runs ASM stage 1 + CK stage 2 (int8 is not in the CK branch's
    weight list), with block_m rounded up to a CK stage 2 size;
  - int8 per-token keeps legacy's 1-stage branch above 32 tokens as a
    legacy region;
  - int4 runs CK 2-stage.
- migration/local.py: claims require w2 to have w1's dtype, and leave int8
  with doweight_stage1 to legacy (in claims and in the key-level check,
  so claims and takes agree).
- paths.py: Path.graduated_claims(call). When the path runs by default, it
  claims only the calls this also accepts; None accepts all.
- Dispatch snapshot: the fp8 x uint32 per-token grid combination, and the
  goldens are regenerated.
- README: the paths, CK, ASM and path rows describe the new formats.
- Tests:
  - int8 and int4 claims, including mixed w1/w2 dtypes and int8 with
    doweight_stage1;
  - a8w8_pt runs only when enabled;
  - int8 defaults run ASM stage 1 and int4 runs CK;
  - the ASM int8 stage 1 has no doweight_stage1 kernel;
  - gpu_differential.py builds int8 and int4 weights and adds their
    cases.

Known differences and limits:
- Left on legacy: per-token torch.int4 weights (the a16wi4 path, a later
  step) and per-tensor uint32.
- The int8 per-tensor Gelu GPU case (32 tokens, 4096/384, E128 top8) runs
  the default ASM stage 1 fmoe_stage1_bf16_pertokenInt8_g1u1_32x128_3tg_pf3,
  whose output differs between two legacy runs (in 2 of 3 pairs; final
  outputs within 0.016). On the older base this work started from,
  legacy raised in CK stage 2 for this call, so the case passed there.
  The GPU differential reports it in every mode.
- The other ASM stage 1 kernels that are not repeatable legacy against
  legacy (step 3.2) still show up: the per-token fp8 race cases, and,
  with the synthetic table, two int8 per-tensor cases that legacy has
  already been seen to get wrong in some runs.
- gfx942-only parts are checked only by the CPU differential.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 119
  tests, 117 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok]
  fail on the legacy ASM stage 1 cases above.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a8w8_pt 7480 / 9787 / 7480 and a8w8_ptok 5817 /
    8884 / 6189 keys on gfx942 / gfx942_cu80 / gfx950, with 3343 / 4325 /
    4111 per-token keys handed back as 1-stage; a16w16 and
    a8w8_blockscale unchanged (none on gfx1201);
  - key_checks.py: 335,413 keys, 51,639 tuned rows;
  - ranking_checks.py: 118,703 ranked keys, 7 entries, every region
    reached.
- GPU differential, gfx950, shipped tables, AITER_USE_NT=1,
  AITER_BYPASS_TUNE_CONFIG=1 and --synth-table:
  - a8w8_pt: 23 cases (9 int8), 72 with the synthetic table. The only
    problem is the int8 Gelu case above in each mode; with the synthetic
    table, also the int8 (64, 7168, 256, E256, top8) case, whose two legacy
    runs differed by 4e36;
  - a8w8_ptok: 40 cases (18 int8 or int4), 88 with the synthetic table.
    The only problems are 2 per-token fp8 race cases in each mode, and in
    bypass mode the 6 fp8 cases legacy runs on 1-stage ASM, which v2 hands
    back;
  - a16w16 and a8w8_blockscale: as in step 3.2.
- GPU suites, gfx950, AITER_MOEV2=off vs on (all paths):
  test_moe_2stage -q 1, -q 2 and -q 3 (--no-flydsl-csv),
  test_moe_per_tensor_a2_init, test_moe_tkw1, test_moe_sorting,
  test_moe_ep, test_moe_local_expert_ids and test_moe_dp_share_expert.
  Same exit codes and the same verdict for every check, except checks
  that run on legacy in both modes and also change between two
  AITER_MOEV2=off runs: the per-token and per-tensor swiglu_limit=7.0
  checks of test_moe_2stage -q 2 and -q 3, and the first check of
  test_moe_tkw1 (its 1-stage tkw1 ASM kernel).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.2):
- local.why_not gives reasons for the new declines (int8 weights with
  doweight_stage1, w2 dtype differing from w1); both paths keep why_not
  and supported_archs.
- route_to_v2 applies graduated_claims and still logs refusals under
  AITER_MOE_EXPLAIN, now also "a format not graduated yet" when only
  the graduation gate turns a call away (tested in
  test_moev2_switch.py).
- gpu_differential.py case tuples: field 10 is the weight format, field
  11 a dict of options; PR 8255's input variants move to
  {"variant": name} (case_variant), and a test rejects the old form.
- The golden delta equals the original step's exactly. The counts and
  GPU results above are from the original base, where a case that
  raised the same error on legacy and v2 passed; PR 8255 fails such a
  case unless listed in _RAISES. On this base: CPU tests 150 passed (the
  GPU-only ones skip); differential a8w8_pt 8160 / 10,675 / 8160 and
  a8w8_ptok 6323 / 9699 / 6729 keys on gfx942 / gfx942_cu80 / gfx950;
  key_checks, ranking_checks and snapshot --check, 0 problems. The GPU
  differential is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.4a: feasible_plans checks segment boundaries (not graduated)

A plan is now feasible only if every buffer a segment reads matches the
one produced before it, not only if the segments cover adjacent ops. This
prepares formats whose segments share an op but not a buffer layout. No
behavior change for the registered paths.

Behavior claim:
- Legacy dispatch is unchanged: the dispatch snapshot is identical on all
  4 archs, and to one generated with the upstream base's aiter package.
- v2 dispatch is unchanged: the CPU differential claims the same keys per
  path on every arch as before, and the ranking checks rank the same keys.

What changed:
- Segment.reads(p) lists the buffers a segment reads. Each is matched
  against the last buffer of its kind produced upstream, the call's
  hidden_states first. A segment without the declaration raises, so it
  cannot join a plan by accident.
- feasible_plans reports a segment that fits the op chain but no plan
  because of its boundaries, with the first mismatch.
- Buf.mismatch gives the reason. quant.inter reads any unquantized
  intermediate, because asm.stage1 writes bf16 for fp16 outputs too.
- README: the buf, base, resolver and test rows.
- Tests: the boundary check and the rejection reasons.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 120
  tests, 118 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok]
  fail on the legacy ASM stage 1 cases that are not repeatable, as in
  step 3.3.
- CPU gates, on all 4 archs, 0 problems, with the same counts as step
  3.3: differential.py 26,820 / 37,978 / 27,907 keys claimed on gfx942 /
  gfx942_cu80 / gfx950; key_checks.py 335,413 keys; ranking_checks.py
  118,703 ranked keys.
- No GPU run: the change is in plan resolution only, and the CPU
  differential shows the same plans for every claimed key.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.3): the code hunks apply unchanged (Sort.reads lands in
segments/sort.py, where PR 8255 moved the sort); buf.py keeps PR 8255's
ownership NOTE. The test counts above are from the original base. On
this base: CPU tests 152 passed (the GPU-only ones skip); the CPU
differential claims the same keys per path as step 3.3 on every arch;
key_checks, ranking_checks and snapshot --check, 0 problems.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.4: mxfp4 a4w4 path (not graduated)

MXFP4 a4w4 fused_moe calls on gfx950 (per_1x32 fp4x2 activations and
weights, Silu or Gelu, separated gate/up, g1u1) can run through
aiter.moev2 with AITER_MOEV2=a4w4. The path is not graduated, so the
default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The snapshot grid adds the per_1x32
  feature variants and a4w4 Silu with doweight_stage1 on preshuffled
  weights (the combination that reaches the CK-Tile split-K default).
  Every existing record is kept as is; the goldens grow to 114,542 /
  135,489 / 159,565 / 110,824 keys on gfx942 / gfx942_cu80 / gfx950 /
  gfx1201.
- CPU differential, all 4 archs: 0 problems. gfx950 claims 9,363 a4w4
  keys, hands 552 back as legacy 1-stage and 284 to a legacy 2-stage
  branch (CK-Tile split-K). The other paths claim the same keys as in
  step 3.4a.
- On a gfx950 GPU, gpu_differential.py --path a4w4 runs 27 cases with
  the shipped table, the synthetic table, AITER_USE_NT=1 and
  AITER_BYPASS_TUNE_CONFIG=1. Both sides launch the same kernels on the
  same inputs with the same outputs, except (16, 6144, 512, 257, 9) and
  (16, 4096, 512, 512, 10). On those two cases, two legacy runs also
  differ in the sorted ids (legacy issue). The other paths give the same
  results as in step 3.3.

What changed:
- The FlyDSL, MXMOE and route-reduce helpers move from fused_moe.py into
  segments/flydsl.py, segments/mxmoe.py and segments/sort.py (adaptive
  aux sort, fused decode sort+quant). Their text is identical to this
  base's fused_moe.py. Legacy imports them back, so both sides run the
  same objects. _stage2_scratch now lives in segments/flydsl.py;
  aot/flydsl/moe.py and op_tests/test_moe_scatter_reduce.py patch it
  there.
- segments/mxfp4.py: FlyDSL stage 1 (plain, fused fp4 quant, layout-v2
  output), FlyDSL stage 2, layout-v2 stage 2 (plain and scatter over the
  aux sort), MXMOE stage 1 and 2, sort.aux; CK with the fp4 instances
  (and doweight_stage1, which legacy runs on CK). Boundaries aux_sorted,
  v2_sorted and mxmoe_sorted; Buf.layout=None reads any layout.
- Resolver hooks:
  - Segment.check_row: legacy's tuned-row discard chain, with the same
    warnings.
  - Segment.declines_row: a tuned CK row on preshuffled weights, which
    legacy overrides with the FlyDSL heuristic.
  - Segment.default_kernels: default kernel names, with legacy's tile
    tiers and warning.
  - Segment.stage2_kernel: the fp8 GEMM2 rename, from q_dtype_a2 or
    AITER_SITUV2_A4W4_FP8_INTER.
  - Segment.metadata_fields.
- This base's legacy MXFP4 changes, mirrored:
  - The MXMOE discard chain rejects a row excluded for the call, inline
    GEMM1 with non-BF16 input, and a sort block_m or GEMM2 tile that
    differs from GEMM1's BM. It no longer rejects stage-1 bias. MXMOE
    stage 1 gets native_scale_layout.
  - LocalDispatch makes legacy's runtime fallbacks before the first
    dispatch logs anything: the MXMOE fallback when block_size_M differs
    from the configured BM (resolve again with _exclude_mxmoe; raise as
    legacy does if the fallback still needs another block_m), and the
    inline-sort fallback (resolve again with _disable_inline_sort). It
    checks the fallback keys without logging and declines the call if
    one of them declines. The inline-sort check probes a JIT module, so
    it runs only after the first lookup has logged, as in legacy; a call
    whose _disable_inline_sort key declines is therefore declined even
    where the inline-sort row could run. The post-sort relookup drops
    both flags, as legacy does.
  - executor.run_mxfp4 follows the per_1x32 branches of _fused_moe_impl
    and fused_moe_2stages, including:
    - a contiguous hidden_states copy outside inline sort;
    - num_local_tokens passed to the fused decode sort+quant;
    - pre-quantization only for fp4 GEMM1 activations;
    - the configured SiTU betas for MXMOE;
    - topk_ids for skip_dropped_routes;
    - the valid-token count for MXMOE stage 2;
    - topk_weights for FlyDSL v2 stage 2 with the fp4 intermediate.
  - The resolver discards a post-reduction row for a weight layout other
    than separated gate/up on fully shuffled weights, with legacy's
    warning, and runs the default heuristics. With a dedicated table it
    declines instead.
- hooks.legacy_globals bridges legacy's _fused_decode_sort_quant_disabled
  (set by test_moe_sorting_mxfp4.py) to v2, next to kernel_bench_callable.
  When legacy's flag is unset it leaves the v2 hook as the caller set it.
- Ranking entry a4w4: the FlyDSL heuristic where legacy picks it, the
  CK-Tile split-K default as a legacy= region, CK 2-stage otherwise.
  local.key_args_supported requires Silu or Gelu.
- Differential: keys handed back to a legacy 2-stage branch are counted
  separately and checked against the legacy record. The GPU differential
  compares m_indices as ids, and compares sorted MX scales only at the
  bytes the quant kernels write.
- README: rows for the new segment and path modules and the updated
  dispatch, execute and test modules.
- Tests: the MXMOE discard chain, the block_size_M and inline-sort
  fallbacks (declines decided before logging, and the order of lookups
  and warnings in run), the post-reduction discard, and legacy_globals
  with legacy's flag unset.

Known differences and limits:
- Left on legacy:
  - 1-stage tuned rows (and FLAT, 1-stage only) until 3.6;
  - CK-Tile split-K (3.5, with the a8w4 CK-Tile port);
  - num_local_tokens, a1_scale and activation scales (no segment
    declares them, so these calls find no plan);
  - Swiglu/Situv2/Relu2, interleaved gate/up, bias, padding and scatter
    (3.5).
- Legacy issue, unchanged: the MXFP4 sorts used for few tokens
  (mxfp4_moe_sort and mxfp4_moe_sort_quant_fwd) do not give the same
  token order on every run. The two GPU cases above fail on it with
  legacy alone.

Tests:
- CPU and GPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py,
  133 tests, 131 passed. test_outputs_match_legacy[a8w8_pt] and
  [a8w8_ptok] fail on the legacy cases that are not repeatable, as in
  step 3.3. [a4w4] fails in some runs on the two sort cases above.
- CPU gates, 0 problems on all 4 archs: key_checks.py 524,332 keys;
  ranking_checks.py 129,333 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0, -q 4,
  --no-legacy), the MXFP4 sort, aux, dispatch and codegen tests, the
  FlyDSL MoE tests, and test_moe.py, test_moe_sorting.py, test_moe_ep.py,
  test_moe_local_expert_ids.py and test_moe_dp_share_expert.py.
  - Results: the same exit codes and check verdicts in both modes, except
    the per-token swiglu_limit=7.0 check. That check also flips between
    two runs with v2 off.
  - --no-legacy exits 1 in both modes: the FlyDSL AOT cache is missing on
    this machine. Rerun with --csv-filter afp4_wfp4 mxmoe_g1_a4w4 to skip
    the cache check: 745 checks with the same verdicts apart from the
    swiglu_limit check, exit 0 in both modes. After the review fixes,
    --csv-filter mxmoe_g1_a4w4 again: 203 checks, all the same.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.4a):
- fused_moe.py is this base's file minus the moved definitions. PR 8255
  had already moved moe_sorting and the adaptive aux sort helpers
  (with _empty_bf16, which stays there) into segments/sort.py, so this
  step adds there only the fused decode sort+quant, Sort's extras and
  accumulate, and SortAux. All 40 moved definitions equal this base's
  text, including three changed upstream since the original step:
  _flydsl_v2_stage2_wrapper and _mxfp4_a4w4_stage2_fw (the
  scatter_intermediate combine, #7771; expert_mask and topk_ids, #7542)
  and _mxfp4_inline_sort_unsupported (inline sort under EP, #7542).
- This base's legacy MXFP4 expert-parallel rules (#7542), mirrored:
  - a tuned inline-sort row is no longer discarded under EP;
  - under EP the MXMOE discard chain rejects BM16, activations other
    than SiTUv2, a GEMM2 that is not flydsl_moe2_layout_ and the scatter
    epilog, and checks the generated aux shapes only without EP;
  - run_mxfp4 raises under EP only for a GEMM2 that is not a layout-v2
    kernel, and forwards expert_mask and topk_ids to the MXMOE stage 2
    too.
- PR 8255's review changes applied to this step's code:
  - a4w4 has why_not and supported_archs; the new modules carry the NOTE
    banner (flydsl.py and mxmoe.py with the shared-with-legacy wording);
  - LocalDispatch decides the MXFP4 fallbacks on the preview prologue,
    so a call it declines reaches legacy before the prologue copies
    anything; the fallback warnings read the prepared call;
  - key_args_supported keeps clamps (None, 0 and inf do not clamp);
  - compare_launches keeps PR 8255's tolerance (1 ulp, or twice legacy's
    own spread) for floating-point tensors and its whole-graph handling;
    MX scales (at the bytes the quant kernels write) and fp4 values must
    be bitwise equal, and sorted fp4 buffers are masked on their raw
    bytes (fp4 tensors cannot be indexed).
- Tests: the live-arch claims test runs each path on its first arch
  (a4w4 is gfx950 only); under EP the BM16 inline-sort row is now
  discarded by the MXMOE chain, and a BM128 MXMOE row by the SiTUv2 rule,
  with legacy's warnings; the run test checks that the fallbacks are
  decided on the preview and the warnings get the prepared call; CPU
  tests for the sorted fp4 and MX-scale comparisons. gpu_differential
  adds the generic variants for a4w4 (and noncontiguous on an inline-sort
  MXMOE shape).
- The golden delta equals the original step's exactly. The counts and GPU
  results above are from the original base. On this base: CPU tests
  166 passed (the GPU-only ones skip); differential 0 problems on all
  4 archs, gfx950 claims 10,413 a4w4 keys, hands 623 back as legacy
  1-stage and 299 to CK-Tile split-K, and the other paths claim the same
  keys as in step 3.4a; key_checks 524,332 keys, ranking_checks 140,392
  ranked keys and snapshot --check, 0 problems. The GPU differential
  (with the new variant cases and this base's EP behavior) is rerun at
  the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.5: a16w4, a16wi4, a8w4, mxfp8 paths and a4w4 leftovers (not graduated)

Every per_1x32 2-stage format can run through aiter.moev2 with
AITER_MOEV2=<path>. New paths: a16w4 (bf16 x MXFP4, gfx942/gfx950),
a16wi4 (bf16 x int4 in 1x32 groups, gfx942/gfx950), a8w4 (MXFP8 x
MXFP4, gfx950) and mxfp8 (MXFP8 x MXFP8, gfx950). a4w4 gains Swiglu,
SiTUv2, bias, activation parameters, padding and the CK-Tile branches.
No path is graduated, so the default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The snapshot grid gains bias,
  interleave, pad and standard-layout variants of the per_1x32
  combinations, an MXFP4-only shape and a bf16 x fp4 SiTUv2
  doweight_stage1 combination. Every existing record resolves as
  before; the goldens grow to 126,095 / 147,042 / 171,118 / 122,377
  keys on gfx942 / gfx942_cu80 / gfx950 / gfx1201, identical to the
  records this base's own code writes.
- CPU differential, all 4 archs: 0 problems. gfx950 claims a4w4=20,175,
  a16w4=7,064, a16wi4=5,052, a8w4=13,211, mxfp8=5,142 keys (other paths
  as in step 3.4); gfx942 a16w4=5,108, a16wi4=4,572; gfx942_cu80
  a16w4=4,801, a16wi4=3,996. 0 problems on gfx950 under
  AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1 and AITER_OPUS_STAGE2_FP8=0; under
  AITER_BYPASS_TUNE_CONFIG=1 only the known declines of 1-stage rows
  legacy runs 2-stage.
- On a gfx950 GPU, gpu_differential.py with the shipped table, the
  synthetic table, AITER_USE_NT=1 and AITER_BYPASS_TUNE_CONFIG=1: a4w4
  49 cases, a16w4 22, a16wi4 11, a8w4 37, mxfp8 20. Both sides launch
  the same kernels on the same inputs with the same outputs, and raise
  the same errors, except on legacy issues that two legacy runs also
  show (see Known differences) and two a4w4 SiTUv2 declines under
  AITER_BYPASS_TUNE_CONFIG=1. Runs sharing a JIT directory in parallel
  logged or raised differently around the mxfp8 CK build that fails;
  run alone, mxfp8 matches. gfx942 not run on a GPU.

What changed:
- The CK-Tile stage functions move verbatim from fused_moe.py to
  segments/ck_tile.py, the MXFP4 reroute and bias predicates to
  segments/flydsl.py and _opus_stage2_fp8_enabled to segments/opus.py.
  Legacy imports them back.
- executor.run_mxfp4 follows every per_1x32 branch of _fused_moe_impl
  and fused_moe_2stages: bf16/fp8/int4 activation quant, bias, local
  topk ids, Opus and CK-Tile arguments, route-bucket checks. Calls
  legacy rejects with the a16w4 NotImplementedError are declined before
  dispatch, so legacy raises.
- Segments: cktile.gemm1/gemm2 (legacy's four CK-Tile branches in
  order, the swiglu_mxfp4_bf16_cktile alias row), opus.gemm1,
  opus.gemm1_layout, opus.gemm2 (tuned only), asm.stage1_cktile; FlyDSL,
  MXMOE and CK caps for the new formats; the untuned a16wi4 fallback and
  MXMOE SiTUv2 heuristic as default kernels. The FlyDSL bias rule
  follows legacy's enable_bias, which differs between heuristic and
  tuned plans (Segment.row_params).
- local.claims takes per-path allowances (activations, gate modes,
  bias, activation parameters, padding, quant_dtype_a, g1u0) and splits
  calls by activation format; key_args_supported checks the same at
  key level.
- Ranking: RANKING moves to dispatch/ranking_table.py, which states the
  table rules (no overlapping entries or regions, a default for every
  problem, prefer xor legacy, feasible last structure, no dead
  regions). Regions can be untuned_only. New predicates for the legacy
  CK-Tile and FlyDSL branches and padding.
- This base's legacy changes the original step did not cover, mirrored:
  - The resolver discards, with legacy's warnings, a 1-stage SiTUv2 ASM
    row on preshuffled MXFP4 weights (#6995), a 1-stage row for an
    activation the ASM kernels lack, and a 1-stage SwiGLU OAI row the
    call cannot run (no kernel name, not flat=1, bias, a swiglu_limit
    other than 7.0, gate/up not separated GGUU). The last two apply to
    plain ASM rows only, as legacy checks rows naming other kernel
    families first; such 1-stage rows are declined (none ships). It
    declines where legacy raises (SiTUv2 on mixed shuffles, other
    gate/up layouts or runtime betas) and for a dedicated table (the
    FHMoE path).
  - MXMOE stage 1 sets has_bias from the call's bias1 alone.
  - The prologue normalizes a SiLU swiglu_limit as _fused_moe_impl does;
    run_mxfp4 hands an active SiLU limit to a CK or ASM stage 1 and
    raises for CK-Tile, as fused_moe_2stages does.
  - The MXMOE segments take a8w4 problems too, and the a8w4 path lists
    them, for the tuned flydsl_mxmoe_g1_a8w4_* rows (kimik3, dsv4,
    gptoss a8w4 tables).
  - a8w4 declines interleaved calls while AITER_USE_GROUPED_GEMM is on:
    legacy may hand them to grouped_gemm_gfx1250_a8w4 before dispatch.
- Differential: --env NAME=VALUE compares live legacy records under a
  dispatch override; every legacy= region maps to its stage 1. The GPU
  differential covers the new weight formats, SiLU swiglu_limit on
  a4w4, a 1-stage SwiGLU OAI row discarded for bias, and compares a
  failed JIT build by its module; --synth-table works for paths with no
  gfx942 CK rows to rewrite.
- README: rows for the new segment, path and table modules and the
  updated ones.
- Tests: the SiTUv2 and SwiGLU OAI 1-stage discards and declines, the
  SiTUv2 post-reduction case, the prologue's SiLU limit, MXMOE a8w4 rows
  (inline or prequantized fp8, discarded with expert_mask), and a8w4
  leaving interleaved calls to the grouped path.

Known differences and limits:
- Left on legacy: 1-stage tuned rows (3.6), FHMoE rows (3.7), padded
  keys on kernels that take no padding (CK, MXMOE, layout-v2 GEMM2),
  CK 2-stage a16w4, CK-Tile alias rows outside the CK-Tile branches,
  and, under AITER_BYPASS_TUNE_CONFIG=1, a4w4 SiTUv2 keys with a tuned
  row (the branch legacy takes then is not ported). Under that variable
  legacy also attaches an Opus row's route-bucket fields to the default
  (a possible warning); v2 does not, and no shipped table has them.
- op_tests/test_moe_2stage.py::test_presorted_moe_hook counts sorts by
  patching fused_moe.moe_sorting, which v2 does not call through. With
  AITER_MOEV2=on its own-sort call runs on v2 and fails that assertion,
  ending a --no-legacy run. Calls with a registered presort stay on
  legacy.
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the MXFP4 sorts for few tokens do not give the same token
  order every run (a4w4 (16, 6144, 512, 257, 9), (16, 4096, 512, 512,
  10) and (16, 3584, 384, 896, 16, SiTUv2); a8w4 MXMOE (16, 7168, 384,
  385, 7)); the FlyDSL a8w4 stage 1 ..._w3_gui_fp8 races on (64, 7168,
  3072, E24, top6). Also: a8w4 on untagged separated weights raises in
  the untuned branches; a tuned cktile_* kernelName1 with an Opus stage
  2 runs ASM stage 1; the mxfp8 CK instances fail to compile; tuned
  mxfp8 Swiglu drops its bias.

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 154 tests,
  150 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok] fail
  on the legacy cases that are not repeatable, as in step 3.3; [a4w4]
  and [a8w4] on the legacy issues above (each failing case rerun and
  matched to them).
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,700 keys;
  ranking_checks.py 202,831 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 4, 6, 7, 8,
  9 --no-flydsl-csv, --no-legacy), the MXFP4 sort, aux, dispatch,
  codegen and glm5 EP dispatch tests, the FlyDSL MoE, a16wfp4, inter_dim
  and mxfp8 passthrough tests, test_moe_sorting.py, test_moe_ep.py,
  test_moe_local_expert_ids.py and test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    per-token swiglu_limit=7.0 check, which also flips between two runs
    with v2 off, and --no-legacy's test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from the swiglu_limit check; both modes
    exit 1 where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.4):
- fused_moe.py is this base's file minus the seven moved definitions,
  which equal this base's text. PR 8255's legacy moe_sorting already
  returns local topk ids, so segments/sort.py takes from this step only
  Sort's and SortAux's return_local_topk_ids, bias features and pads.
- PR 8255's review changes applied to this step's code:
  - local.why_not takes the per-path allowances and names each refusal
    (the activation format of the call too); the new paths and a4w4
    have why_not and supported_archs; arch checks use get_gfx_runtime
    alone; ranking_table.py, ck_tile.py and opus.py carry the NOTE
    banner (ck_tile.py and opus.py with the shared-with-legacy wording);
  - a clamping swiglu_limit (None, 0 and inf do not clamp) and the
    global scales stay refused without act_params; key_args_supported
    keeps clamps;
  - the a16w4 NotImplementedError decline is decided on the preview
    prologue, before anything is copied;
  - compare_launches keeps PR 8255's tolerance and dataclass expansion,
    with this step's own-buffer and split-K stage 1 exemptions; the GPU
    cases keep the unified encoding (options dict with "variant") and
    add the generic variants for a16w4, a16wi4, a8w4 and mxfp8.
- This base's legacy MXFP4 expert-parallel rules (#7542, ported in step
  3.4) cover the MXMOE a8w4 rows too: under EP a BM16 row is discarded
  as BM16 and a BM64 Silu row by the SiTUv2 rule, with legacy's
  warnings. The output_aux EP raise legacy also applies to MXMOE + Opus
  metadata has no v2 counterpart to mirror: no MXMOE stage 1 feeds an
  Opus stage 2 in v2, so such rows are declined.
- README: status lists the nine registered paths.
- The golden delta equals the original step's exactly. The counts and GPU
  results above are from the original base. On this base: CPU tests
  184 passed (the GPU-only ones skip); differential 0 problems on all 4
  archs, claiming the same keys as the original step on every arch
  (and on gfx950 under AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1 and AITER_OPUS_STAGE2_FP8=0, 0
  problems); key_checks 571,700 keys, ranking_checks 212,754 ranked
  keys and snapshot --check, 0 problems. The GPU differential (with the
  variant cases, this base's EP behavior, and the cases where legacy and
  v2 both raise, which this base's harness accepts only when listed) is
  rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.6: 1-stage ASM fmoe (default, tuned, FLAT, g1u0) (not graduated)

The 1-stage ASM fmoe kernels run through aiter.moev2 with
AITER_MOEV2=<path>, wherever legacy runs them: the default 1-stage
regions, tuned 1-stage rows (xbf16 and FLAT too) and the g1u0 bf16 and
int8 keys. No path is graduated, so the default is unchanged. The local
grouped gfx1250 branch is not ported (step 4.6a); a8w4 leaves those
calls to legacy.

Behavior claim:
- Legacy dispatch is unchanged. fused_moe_1stage, _ASM_ACT_TAG and
  _retarget_asm_activation move verbatim to segments/asm.py and
  _moe_prepare_unsorted_input to segments/sort.py; legacy imports them
  back. The goldens (126,095 / 147,042 / 171,118 / 122,377 keys on
  gfx942 / gfx942_cu80 / gfx950 / gfx1201) are identical to the records
  this base's own code writes.
- CPU differential, all 4 archs: 0 problems. Keys claimed: gfx950
  87,674 (78,551 in step 3.5), gfx942 43,123 (36,500), gfx942_cu80
  53,578 (46,775). Keys legacy runs 1-stage that v2 still declines:
  gfx950 9,330 -> 338, gfx942 4,872 -> 89, gfx942_cu80 4,930 -> 15 (see
  Known differences). 0 problems on gfx950 and gfx942 under
  AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1, AITER_OPUS_STAGE2_FP8=0 and
  AITER_XBFLOAT16=1; under AITER_BYPASS_TUNE_CONFIG=1 only declines of
  calls whose tuned 1-stage row v2 cannot run while legacy, bypassing
  the table, runs them 2-stage (338 on gfx950, 89 on gfx942; 2,409 on
  gfx950 in step 3.5).
- On a gfx950 GPU, gpu_differential.py with the shipped table, the
  synthetic table, AITER_USE_NT=1 and AITER_BYPASS_TUNE_CONFIG=1:
  a16w16 21 cases (69 synthetic), a16w4 25, a8w8_blockscale 31 (147
  synthetic), a8w4 37, a4w4 52, a8w8_ptok 49 (97 synthetic). Both sides
  launch the same kernels on the same inputs with the same outputs and
  logs, except on legacy issues that two legacy runs also show (see
  Known differences), the two a4w4 SiTUv2 declines under
  AITER_BYPASS_TUNE_CONFIG=1 of step 3.5, and, in runs sharing a JIT
  directory in parallel, the log of a CK build that fails landing in a
  different case (as in step 3.5). gfx942 not run on a GPU.

What changed:
- Segments: asm.fmoe_1stage covers quant through reduce and builds
  legacy's fused_moe_1stage call (kernel name, activation, quant type,
  xbf16, FLAT mode, expert_mask). sort.flat is legacy's pass-through for
  the FLAT modes (flat 1 and 2: unsorted topk, over-allocated moe_buf,
  num_local_tokens in the num_valid_ids slot). ASM stage 1 is g1u1 only.
- Buf: a layout in `reads` may be a set. ASM stage 1 reads the default
  or unsorted sort; the Opus and FlyDSL layout segments read default or
  aux_sorted, so only the 1-stage fmoe follows sort.flat.
- Resolver: 1-stage plans from the default regions and tuned rows, with
  legacy's log line. match_row takes plain ASM 1-stage rows (named
  kernel, no stage 2), matching FLAT rows to sort.flat. It declines
  post-reduction rows (flat=3), other 1-stage rows, rows whose flat or
  xbf16 cell legacy cannot parse (legacy raises) and a 1-stage plan with
  a finite SiLU limit (legacy raises).
- executor.run_one_stage follows legacy's 1-stage branch: contiguous
  hidden_states, the host sort or the FLAT pass-through (given the
  row's mode), expert_mask and the FLAT output copy.
- local: 1-stage plans have no lookup after the sort, as in legacy.
- Ranking: an ASM 1-stage structure in the fp8 per-token, 1x128, int8
  and g1u0 regions; g1u0 tables for a16w16 and int8 per-token.
  check_problems ignores 1-stage plans an entry does not list (only
  tuned rows reach them).
- Paths: a16w16 and a8w8_ptok (int8) claim g1u0; a4w4, a16w4 and
  a8w8_blockscale gain the FLAT and 1-stage segments; a8w4 declines
  calls legacy sends to the grouped gfx1250 kernel (the narrower check
  of the original step replaces step 3.5's).
- This base's legacy changes the original step did not cover, mirrored:
  the post-reduction mode and expert_mask of fused_moe_1stage (the moved
  code is the new one), num_local_tokens in the FLAT prep, moe_sorting
  passing through only the modes without a host sort, the retarget of a
  1-stage row tuned for the twin activation (with legacy's INFO line),
  the SiLU-limit raise and the skipped second lookup.
- Differential: 1-stage and FLAT launch positions; the g1u0 legacy
  branches. The GPU differential gains default, tuned, xbf16 and FLAT
  1-stage cases.
- README: rows for the changed modules.
- Tests: 1-stage defaults and tuned rows (FLAT, xbf16, retarget), the
  declines, the SiLU-limit decline, the skipped second lookup, the FLAT
  sort pass-through, a strided input and the FLAT mode reaching the
  sort, the ranking of 1-stage plans only tuned rows reach, and a8w4
  leaving grouped gfx1250 calls to legacy.

Known differences and limits:
- Left on legacy: post-reduction rows (8 shipped a4w4 rows), 1-stage
  rows outside the plain form (empty kernelName1, a stage 2), g1u0
  calls outside the 1-stage regions (legacy's CK 2-stage is wrong for
  g1u0), the grouped gfx1250 branch (step 4.6a), FHMoE rows (3.7),
  calls with bias, padding or other features fmoe lacks whose key has a
  tuned 1-stage row (legacy runs the row and drops the bias or padding),
  and tuned 1-stage rows for keys outside legacy's default 1-stage table,
  where v2 has no 1-stage plan: the Gelu calls the act-type-disabled
  fallback gives a SiLU row (the gfx942 1x128 keys, which legacy
  retargets to the Gelu twin; a8w8_ptok tkw1 Gelu on gfx950).
- op_tests/test_moe_2stage.py::test_presorted_moe_hook still ends a
  --no-legacy run with AITER_MOEV2=on (step 3.5).
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the ASM 1x128 blockscale stage 1 is not repeatable on
  gfx950 (the same 72 synthetic cases fail since step 3.2); the MXFP4
  sorts for few tokens (a4w4 (16, 4096, 512, 512, 10), (16, 6144, 512,
  257, 9), (16, 3584, 384, 896, 16, SiTUv2); a8w4 MXMOE (16, 7168, 384,
  385, 7)); the ASM per-token fp8 stage 1 (a8w8_ptok (8|64|256, 5120,
  1536, 40|41, 8|10)); the FlyDSL a8w4 stage 1 w3 kernels ((64, 7168,
  3072, E24, top6), (2048, 7168, 384, E384, top6)). The FLAT sort drops
  expert_mask; v2 does the same.

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 169 tests,
  165 passed. test_outputs_match_legacy [a4w4], [a8w4], [a8w8_pt] and
  [a8w8_ptok] fail on the legacy issues above, as in step 3.5.
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,700 keys;
  ranking_checks.py 210,064 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0, 2, 3, 4,
  5, 6, 7 --no-flydsl-csv, --no-legacy), test_moe.py, test_moe_tkw1.py,
  test_moe_blockscale.py, the MXFP4 sort, aux, dispatch, codegen and
  glm5 EP dispatch tests, the FlyDSL MoE, a16wfp4 and inter_dim tests,
  test_moe_sorting.py, test_moe_ep.py, test_moe_local_expert_ids.py and
  test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    swiglu_limit=7.0 checks of test_moe_2stage.py, which also flip
    between two runs with v2 off; the first test_moe_tkw1.py check, a
    2-stage case on the ASM per-token fp8 stage 1 that legacy does not
    repeat (failed off, warning on; the same flip in step 3.3); and
    --no-legacy's test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from a swiglu_limit check; both modes exit 1
    where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.5):
- fused_moe.py is this base's file minus fused_moe_1stage, _ASM_ACT_TAG
  and _retarget_asm_activation, which equal this base's text and are
  re-exported from segments/asm.py. PR 8255 already moved legacy
  moe_sorting, its FLAT branch and _moe_prepare_unsorted_input to
  segments/sort.py, so this step adds only Sort.flat and SortFlat there.
- PR 8255's review changes applied to this step's code: a16w16 and
  a8w8_ptok pass the g1u0 allowance to local.why_not; asm.py carries the
  NOTE banner with the shared-with-legacy wording; compare_launches
  keeps PR 8255's tolerance and whole-graph guard and gains this step's
  1-stage and FLAT launch layouts; the GPU cases keep the unified
  encoding.
- a8w4 mirrors legacy's grouped gfx1250 checks exactly: a gfx1250-strict
  build counts as gfx1250 (the original step checked gfx1250 alone), and
  an expert_mask call with doweight_stage1, which legacy hands to the
  generic MoE, is claimed. It reads get_gfx itself, as legacy's check
  does, and why_not names the refusal.
- This base's legacy 1-stage branch and the 1-stage regions of
  get_2stage_cfgs equal the original base's.
- The goldens are unchanged, as in the original step. The counts and GPU
  results above are from the original base. On this base: CPU tests 199
  passed, 9 skipped (the GPU-only ones); differential 0 problems on all
  4 archs, with the same a16w4, a16wi4, a4w4, a8w4 and mxfp8 claims and
  the same 1-stage and 2-stage hand-backs as the original step on
  gfx950; a16w16, a8w8_pt, a8w8_ptok and a8w8_blockscale see about 9%
  more keys, from this base's tuned tables (a8w8_pt included, which this
  step does not change); key_checks 571,700 keys, ranking_checks 220,531
  ranked keys and snapshot --check, 0 problems. The GPU differential is
  rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.7: FHMoE path (fhmoe_, shared expert as the last row) (not graduated)

FHMoE calls (fused_moe with shared-expert tensors, which legacy sends
to fhmoe_) run through aiter.moev2 with AITER_MOEV2=fhmoe. No path is
graduated, so the default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The FHMoE contract, metadata and table
  helpers and the two FlyDSL FHMoE stage wrappers move verbatim to
  aiter/moev2/segments/flydsl_fhmoe.py; aiter/fhmoe.py imports them
  back. _fhmoe_impl gets the same v2 hook as fused_moe_; the fhmoe_ op
  schema is unchanged. The goldens (126,095 / 147,042 / 171,120 /
  122,377 keys on gfx942 / gfx942_cu80 / gfx950 / gfx1201) are
  identical to the records this base's own code writes; gfx950 gains
  two keys, the dedicated-table misses (both raise).
- CPU differential, all 4 archs: 0 problems. gfx950: fhmoe claims
  1,804 keys; it declines 15,180 where legacy raises (non-FlyDSL plans,
  dedicated-table misses) and 1,520 where legacy runs (see Known
  differences). The other paths' counts are unchanged from step 3.6.
  0 problems on gfx950 and gfx942 under AITER_FLYDSL_FORCE=0,
  AITER_MXMOE_FALLBACK=0, AITER_SITUV2_A4W4_FP8_INTER=1,
  AITER_OPUS_STAGE2_FP8=0 and AITER_XBFLOAT16=1; under
  AITER_BYPASS_TUNE_CONFIG=1 only step 3.6's 1-stage declines (the same
  338 gfx950 and 89 gfx942 keys).
- On a gfx950 GPU, gpu_differential.py --path fhmoe: 14 cases (MXFP4
  interleaved and separated, DSV4 I384 tuned and beyond its table, HY4
  MXFP8 with the shared expert clamped and unclamped, another MXFP8
  geometry, the block size and clamp_shared errors) launch the same
  kernels on the same inputs with the same outputs and logs, or raise
  the same errors, with the shipped table, AITER_USE_NT=1 and
  AITER_BYPASS_TUNE_CONFIG=1. All other paths rerun as in step 3.6 (the
  shared code changed): a16w16 21 (69 synthetic), a16w4 25, a16wi4 11,
  a4w4 52, a8w4 37, a8w8_blockscale 31 (147 synthetic), a8w8_pt 23 (72
  synthetic), a8w8_ptok 49 (97 synthetic), mxfp8 20; the same results
  as before, apart from the legacy issues under Known differences.
- op_tests/test_fhmoe.py: 119 passed with AITER_MOEV2=off and =on;
  under AITER_MOEV2=fhmoe v2 runs 46 calls, raises the 2 errors the
  tests expect and declines none.

What changed:
- Segments flydsl_fhmoe.gemm1, gemm1_q and gemm2: the FlyDSL MXFP4 and
  MXFP8 stages run through the FHMoE wrappers (Silu, the shared expert,
  dedicated tables). Segment.call_args(c) gives a stage the call
  arguments its launch adds (the shared weights, shared_expert_id,
  swiglu_limit, clamp_shared); run_mxfp4 starts the stage arguments from
  them, as legacy starts from _stage1_extra_args/_stage2_extra_args.
  Sort and the quant segments accept the shared expert and a dedicated
  table.
- Path fhmoe (entry "fhmoe", gfx950): run follows _fhmoe_impl (the
  contract, the activation format from the gate layout, the
  clamp_shared check, the DSV4 I384 or MXFP8 dedicated table), then the
  local dispatch with the table in the key and the selected block size
  enforced. The problem has SharedExpertSpec("fused_row"). The
  capability checks supports_dsv4_i384_fhmoe and
  supports_mxfp8_fhmoe_config resolve through the path. claims declines
  under AITER_ONLINE_TUNE, while a presort is registered (legacy
  consumes it) and for the interleaved MXFP4 calls legacy's grouped
  gfx1250 branch takes (the check moves from a8w4 to local).
- local: the FHMoE key; a lookup with no call (the capability probes)
  skips the second-lookup decline, as legacy's probe calls only
  get_2stage_cfgs.
- Ranking: an fhmoe entry (FlyDSL 2-stage where use_mxfp4_flydsl
  holds; elsewhere legacy raises). Entries without `shared` match only
  problems without a shared expert. The resolver declines a dedicated
  table without an exact row, where legacy raises.
- api.fused_moe sends shared-expert calls to the fhmoe path after
  legacy's argument checks (api.fhmoe_call), including this base's
  herd_topk and deterministic errors, in legacy's order.
- This base's changes the original step did not cover, mirrored: the
  hook sits in _fhmoe_impl (upstream wraps it in drop_presort_on_error
  under the fhmoe_ op), the presort decline, the herd/deterministic
  errors, and the second-lookup decline's token argument.
- Harness: the differential compares FHMoE keys separately and reports
  outcomes (claimed, declined where legacy raises or runs); FHMoE keys
  in the ranking checks; FHMoE GPU cases built as op_tests/test_fhmoe.py
  builds them; the snapshot keys add a dedicated-table miss per
  geometry.
- README: rows for the new and changed modules.
- Tests: the FHMoE helpers moved verbatim, the stages, the capability
  checks against legacy, the API errors (herd_topk and deterministic
  too), the grouped gfx1250 and presort declines.

Known differences and limits:
- Declined where legacy runs (gfx950 CPU differential, all on the
  snapshot's feature variants; no base key): MXMOE rows path fhmoe has
  no segment for (exclude_mxmoe 325, fp8_input_no_scales 190) and calls
  no FHMoE plan serves (fp8_input 353; num_local_tokens, activation
  scales and input activation scales 163 each, the a4w4 gap; scatter
  163, which fhmoe_ rejects before its dispatch). Legacy runs them
  unchanged.
- Legacy's grouped gfx1250 branch is not ported (step 4.6a):
  interleaved MXFP4 FHMoE calls it would take stay on legacy.
- The six private FHMoE hooks on _fused_moe_impl stay for legacy.
- gpu_differential.py --synth-table has no fhmoe rows.
- op_tests/test_moe_2stage.py::test_presorted_moe_hook still ends a
  --no-legacy run with AITER_MOEV2=on (step 3.5).
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the ASM 1x128 blockscale stage 1 (the same 72 synthetic
  cases since step 3.2); the MXFP4 sorts for few tokens (a4w4 (16, 4096,
  512, 512, 10), (16, 6144, 512, 257, 9), (16, 3584, 384, 896, 16,
  SiTUv2); a8w4 (16, 7168, 384, 385, 7)); the ASM per-token fp8 stage 1
  (a8w8_ptok (8|64|256, 5120, 1536, 40|41, 8|10)); the CK int8
  per-tensor Gelu stage 1 (a8w8_pt (32, 4096, 384, 128, 8), as since
  step 3.3); the FlyDSL a8w4 stage 1 w3 kernel ((64, 7168, 3072, E24,
  top6)). In runs sharing a JIT directory in parallel, a CK module
  another process is building fails to load (mxfp8 and a8w4 std_shuffle
  cases; mxfp8 rerun alone: 20 of 20 ok).

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 177 tests,
  173 passed. test_outputs_match_legacy [a4w4], [a8w4], [a8w8_pt] and
  [a8w8_ptok] fail on the legacy issues above, as in step 3.6.
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,702 keys;
  ranking_checks.py 220,216 ranked keys (10,152 FHMoE).
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0 to 9
  --no-flydsl-csv, --no-legacy), test_moe.py, test_moe_tkw1.py,
  test_moe_blockscale.py, test_moe_per_tensor_a2_init.py, the MXFP4
  sort, aux, dispatch, codegen and glm5 EP dispatch tests, the FlyDSL
  MoE, a16wfp4, inter_dim and mxfp8 passthrough tests, test_fhmoe.py,
  test_moe_sorting.py, test_moe_ep.py, test_moe_local_expert_ids.py and
  test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    swiglu_limit=7.0 checks of test_moe_2stage.py, which also flip
    between two runs with v2 off; the first test_moe_tkw1.py check (the
    ASM per-token fp8 stage 1, as in step 3.3); and --no-legacy's
    test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from a swiglu_limit check; both modes exit 1
    where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.6):
- aiter/fhmoe.py's moved definitions equal this base's text (the file has
  no upstream drift); it carries PR 8255's NOTE above the moev2 imports
  and at the _fhmoe_impl hook, and flydsl_fhmoe.py the shared-with-legacy
  NOTE.
- PR 8255's review changes applied to this step's code: path fhmoe has
  why_not (claims = why_not is None) and supported_archs, and checks the
  runtime arch; legacy_grouped_gfx1250 moves from a8w4 to local with
  step 3.6's port fixes (gfx1250-strict, and the EP + doweight_stage1
  early return); LocalDispatch.run passes the forced q_dtype_a and
  config_file to both dispatch_key calls.
- Fixed while porting (the original step had them too):
  - Every claimed FHMoE call raised KeyError 'w1_global_scale': the
    fhmoe_ op has no NVFP4 global scales, so run's defaults now add them
    as None, and api.fhmoe_call rejects shared-expert calls that set
    them.
  - herd_topk with NVFP4 global scales now raises legacy's error before
    the call is built.
  - why_not declines up front the arguments no FHMoE stage takes
    (a1_scale, a2_scale, num_local_tokens, doweight_stage1), so a
    declined call no longer logs the table checks twice.
- The goldens gain the same two gfx950 keys as in the original step. The
  counts and GPU results above are from the original base. On this base:
  CPU tests 207 passed, 10 skipped (the GPU-only ones); differential 0
  problems on all 4 archs, with fhmoe claiming 1,804 gfx950 keys and
  declining 15,180 where legacy raises and 1,520 where it runs, as in
  the original step; the other paths' counts equal step 3.6 on this
  base. key_checks 571,702 keys, ranking_checks 230,683 ranked keys
  (10,152 FHMoE) and snapshot --check, 0 problems. The GPU differential
  is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.8: coverage report in CI (not graduated)

Step 3.8 of the moev2 revamp: a coverage report over the snapshot key
grid that fails CI on capability gaps and unranked segments and lists
the tuned rows that do not run. No path is graduated, so the default is
unchanged.

Behavior claim:
- No dispatch changes: the paths decline the same calls as before and
  legacy runs them. The CPU differential on every arch has 0 problems.
  The bf16 g1u0 keys without a 1-stage fmoe kernel now go to the named
  legacy branch, and the differential checks that legacy runs CK stage 1
  for them.
- Coverage, ranking and key checks: 0 problems on every arch.

What changed:
- aiter/moev2/dispatch/coverage.py:
  - classify: how the resolver serves a problem a path takes. The kinds
    are a plan, a gap (no plan from the path's segments), a ranking
    region naming a legacy branch, a decline caused by the tuned row, or
    a resolver raise (unshuffled gfx950 fp8 CK weights, as in legacy).
  - row_status: whether the exact tuned row runs, and if not, why.
  - segment_errors: fails a segmen…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:mi300x Run MI300X standard and OPUS CI on PRs CK FlyDSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gfx942 clamped SiLU: dispatch crash and a mis-matched test reference (RETRACTED accuracy claim)

3 participants