Skip to content

[FlyDSL] [CI] Moev2 pr2 - #8912

Merged
zufayu merged 23 commits into
ROCm:mainfrom
qli88:moev2_pr2
Dec 3, 2026
Merged

zufayu merged 23 commits into
ROCm:mainfrom
qli88:moev2_pr2

Conversation

@qli88

@qli88 qli88 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Title: [MoE] moev2 step 3: the remaining single-GPU paths, coverage gates and a per-call decision cache (not graduated)

Summary

This PR continues the moev2 migration that #8255 started. #8255 added the framework and one path, a8w8_pt. This PR ports every other single-GPU fused_moe format to v2:

  • New paths:
    • a16w16: bf16/fp16, unquantized;
    • a8w8_ptok: fp8 per-token;
    • a8w8_blockscale: fp8, 1x128 activations and 128x128 weight blocks;
    • a4w4: MXFP4 x MXFP4;
    • a16w4: bf16 x MXFP4;
    • a16wi4: bf16 x int4 in 1x32 groups;
    • a8w4: MXFP8 x MXFP4;
    • mxfp8: MXFP8 x MXFP8;
    • fhmoe: fhmoe_, with the shared expert as the last row.
  • New formats in existing paths: int8 and int4 weights join a8w8_pt and a8w8_ptok.
  • 1-stage ASM fmoe: default regions, tuned rows, FLAT and g1u0, wherever legacy runs them.
  • CI gates:
    • a coverage report over the snapshot key grid;
    • a count of every v2 decline of a call legacy runs, each checked against a list of known declines;
    • a GPU-suite compare between v2 and legacy.
  • A per-call decision cache, so v2's host time per call stays at or below legacy's.

Nothing changes by default. Paths run only when enabled with AITER_MOEV2. No path is graduated, so with the variable unset or off, every call runs the legacy code.

There is one exception: a race fix in the FlyDSL mixed stage 1 kernel (mixed_moe_gemm_2stage_common.py). Legacy and v2 share that kernel, so legacy gets the fix too. See "Breaking Changes".

The branch is on main 333b78da1 (64 files, +15,721/−3,454). About 2,400 of those lines are legacy code moving out of fused_moe.py and fhmoe.py into aiter/moev2; legacy imports it back. The 20 commits:

  1. Steps 3.1 to 3.9 (52ee10db8 to 7ca86aba9, 10 commits): one commit per format or capability, then the coverage report and the graduation gates.
  2. Step 3 follow-ups (84111cc6d, 28c792f1e, 7e004dcdb, e337faa06, 35c4db468):
    • Segment.reach replaces tuned_only;
    • review fixes for CK-Tile alias rows, FHMoE and the MXFP4 fallbacks;
    • the Segment reference docstring.
  3. PR 2 review fixes (528dd4548, b4ea67694):
    • int8 rows with an empty kernelName1;
    • the FlyDSL async-copy races;
    • the differential harness;
    • the cached MXFP4 fallbacks.
  4. Call cache (57e38f682).
  5. Main's legacy MoE changes, ported (be0783898, and its review fixes in f8f6b76b7): [ASM] [HIP] [MoE] Run the FLAT and EMSORT MXFP4 fmoe tiles on padded intermediate widths #7611, [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211, [CK] [FlyDSL] [JIT] [MoE] Add a stage2 FP8 row table for AITER_FLYDSL_STAGE2_FP8=1 #8669 and [MoE] Skip unused intermediate allocation for fused stage-1 quantization #7172 changed legacy code that v2 mirrors. See "Port of main's legacy MoE changes".

aiter/moev2/README.md lists every file, its purpose, and whether it stays or goes when legacy is retired.

Motivation

#8255 describes the motivation. Legacy dispatch and execution form one monolith that serves every quant type, and v2 splits it into parts that can be migrated one workload family at a time.

With this PR, every single-GPU format has a v2 path. Each path claims only the calls it reproduces exactly and hands every other call back to the unchanged legacy code. The gates added here are what a path must pass before it graduates (see "Rollout").

How to enable and roll back

AITER_MOEV2=a4w4            python ...   # one path
AITER_MOEV2=a4w4,a8w4       python ...   # several paths
AITER_MOEV2=on              python ...   # every registered path
AITER_MOEV2=off             python ...   # rollback: every call on the legacy code (same as unset today)
AITER_MOE_EXPLAIN=1                      # log the plan v2 picks, and why a path refuses a call
AITER_MOEV2_CALL_CACHE=0                 # decide every call afresh (default: cached per call signature)
AITER_MOEV2_CALL_CACHE=check             # also decide every cache hit afresh; raise CallCacheMismatch on a difference

The paths are a8w8_pt, a16w16, a8w8_ptok, a8w8_blockscale, a4w4, a16w4, a16wi4, a8w4, mxfp8 and fhmoe. The first nine hook fused_moe_; fhmoe hooks fhmoe_.

Changes

Paths and formats (steps 3.1 to 3.7)

  • 3.1 a16w16:
    • migration/local.py holds what the single-GPU paths share: 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.
    • Path.takes(problem) names the dispatch keys a path runs. One segment, CK, serves several formats, so this keeps one path from taking another's keys.
    • The ranking table gains named predicates and regions that hand their problems back to legacy (legacy="...").
  • 3.2 a8w8_ptok, a8w8_blockscale:
    • asm.stage1_1x128, the ASM stage 1 that writes the quantized intermediate and its scales into one buffer. The executor splits that buffer into the stage 2 inputs, as legacy does.
    • Legacy's default block_m and split-K per quant type, in segments/defaults.py.
  • 3.3 int8 and int4 weights:
    • a8w8_pt takes int8 per-tensor weights.
    • a8w8_ptok takes int8 per-token weights, and int4 weights packed in uint32 with fp8 activations.
    • Path.graduated_claims keeps a format added to a graduated path behind AITER_MOEV2 until that format passes its own gate.
  • 3.4a: a plan is feasible only if every buffer a segment reads matches the one produced before it (Segment.reads, Buf.mismatch).
  • 3.4 a4w4:
    • FlyDSL stage 1 (plain, fused fp4 quant, layout-v2) and stage 2 (plain, layout-v2, scatter over the aux sort);
    • MXMOE stages 1 and 2;
    • CK with the fp4 instances.
    • Resolver hooks for legacy's tuned-row discard chain, default kernel names and the fp8 GEMM2 rename.
  • 3.5 a16w4, a16wi4, a8w4, mxfp8, and the rest of a4w4 (Swiglu, SiTUv2, bias, activation parameters, padding, CK-Tile):
    • executor.run_mxfp4 follows every per_1x32 branch of _fused_moe_impl and fused_moe_2stages.
    • CK-Tile and Opus segments.
  • 3.6 1-stage ASM fmoe:
    • asm.fmoe_1stage builds legacy's fused_moe_1stage call: kernel name, activation, xbf16, FLAT mode and expert_mask.
    • sort.flat is legacy's pass-through for the FLAT modes.
    • On gfx950, the keys legacy runs 1-stage that v2 still declines drop from 9,330 to 338.
  • 3.7 fhmoe:
    • The FlyDSL MXFP4 and MXFP8 stages run through the FHMoE wrappers: Silu, the shared expert, dedicated tables.
    • _fhmoe_impl gets the same v2 hook as fused_moe_. The fhmoe_ op schema is unchanged.

Coverage and graduation gates (steps 3.8, 3.9 and the follow-ups)

  • dispatch/coverage.py and coverage_checks.py, in CI on every simulated arch:
    • It classifies how each key a path takes is served: a plan, a gap, a legacy branch, a decline caused by the tuned row, or a raise.
    • It fails on a gap or raise where legacy runs the key, unless known_declines.py lists it.
    • It reports the tuned rows that don't run.
  • Segment.reach:
    • Every segment declares how dispatch reaches it:
      • ranked: in a ranking entry;
      • tuned: only through tuned rows, and some shipped row must run it;
      • hibernating: added before anything runs it, and must name its GPU test.
    • The coverage report fails a segment whose reach is wrong.
  • The CPU differential:
    • It counts every v2 decline of a key legacy runs, and each must match an entry in tests/moe_dispatch/known_declines.py.
    • Each entry gives the paths, the reason as an anchored regular expression, why, and its todo.
    • Known entries that match nothing are listed.
  • gpu_suites.py --compare fails where v2 fails and legacy passes, for a path that isn't implemented, and when no suite runs on the arch.

Legacy code moved, not copied

v2 never imports legacy. Legacy code that v2 reuses moves into aiter/moev2, verbatim (AST-identical), and fused_moe.py / fhmoe.py import it back, so both sides run the same objects. This PR moves:

  • the FlyDSL, MXMOE and route-reduce helpers (adaptive aux sort, fused decode sort+quant) to segments/flydsl.py, segments/mxmoe.py and segments/sort.py;
  • the CK-Tile stage functions to segments/ck_tile.py;
  • the MXFP4 reroute and bias predicates to segments/flydsl.py;
  • _opus_stage2_fp8_enabled to segments/opus.py;
  • fused_moe_1stage, _ASM_ACT_TAG and _retarget_asm_activation to segments/asm.py;
  • _moe_prepare_unsorted_input to segments/sort.py;
  • the FHMoE contract, metadata and table helpers and the two FlyDSL FHMoE stage wrappers to segments/flydsl_fhmoe.py.

Every name importable from aiter.fused_moe and aiter.fhmoe before this PR still is. executor.run_mxfp4, executor.run_one_stage, the resolver and the ranking table are copies, as in #8255. The CPU differential and the GPU differential fail on any drift.

Review fixes

  • The FlyDSL mixed stage 1 kernel (compile_mixed_moe_gemm1_common, async A copy), shared with legacy:
    • Barrier race. Nothing kept the compiler from moving interleaved_half's scale and B loads above its async copies. The wait before the K-loop barrier was a raw s_waitcnt with a count lower than the number of loads issued after the copy, so waves could read stale LDS. It showed as about 3 in 10 wrong a8w4 runs of (64, 7168, 3072, E24, top6).
      • A sched_barrier now follows the copy.
      • The barrier waits vmcnt(async_loads_after_copy), counted from the loads the half issues.
    • K-wave copy guard. With k_wave > 1, the guard compared the group-relative K offset with k_dim instead of klen. With an odd number of K tiles per wave group (55 shipped rows), the last half copied one tile past the group, into a buffer the k-wave reduction overwrites.
    • At k_wave 1 the ISA is byte-identical, and stage 1 times are unchanged within noise.
  • int8 rows with an empty kernelName1 are declined: legacy runs ASM stage 1 there, and v2 ran CK. No shipped table has such a row.
  • CK-Tile alias rows follow legacy's branch order and keep the stage 2 bias. FHMoE applies legacy's _use_fhmoe_wrappers consistency check to the same lookups legacy checks. An a4w4 inline-sort fallback no longer runs the MXMOE block-size check.
  • The differential harness:
    • Output compares are NaN-aware.
    • Legacy's run-to-run noise is capped at 16 ulps of the peak.
    • Sorted rows compare by (token, slot), because the a4w4/a8w4 sorts order rows inside an expert with atomics. The sort layout itself must still match.
    • After a legacy stage 1 that doesn't repeat, the integer tensors quantized from its output get legacy's own spread.
    • Where legacy raises, v2 must raise the same error.
    • Only failures that may be legacy noise are rerun.
    • Out of memory fails the run.

Per-call decision cache (aiter/moev2/dispatch/call_cache.py)

v2 used to decide every call afresh: route_to_v2 ran every active path's why_not, and LocalDispatch.run built the dispatch key twice. Now:

  • signature(call, entry) is a standalone function. It keys each parameter of fused_moe / fused_moe_ / fhmoe_ by its declared class:

    • by value;
    • by whether it is None;
    • by weight dtype, shape and tags;
    • by rows, with the token count bucketed by get_padded_M;
    • or not at all, for execution-only parameters.

    It adds what the decision also reads: the activation dtype, arch, CU count, AITER_ONLINE_TUNE, AITER_MOE_EXPLAIN, a registered presort, and legacy's grouped gfx1250 branch.

  • What is cached: route_to_v2 caches the chosen path per signature. LocalDispatch.run splits into _decide, which is pure and cached, and _execute, the per-call steps (prologue, warnings, block-size checks, launch). A hit and a miss share _execute.

  • AITER_MOEV2_CALL_CACHE, read on every call:

    • on by default;
    • 0 turns it off;
    • check decides every hit afresh and raises on a difference. The tests and both GPU harnesses run with check.
  • Unclassified parameters: a new entry parameter missing from the class table turns the cache off at that entry, with a warning.

  • Host trims:

    • An entry hook builds the call only when a path is active at that entry.
    • resolve_activation_dtype is memoized on its inputs and the variables it reads.
  • Not paid by default: with AITER_MOEV2 unset, no entry hook builds a call.

Port of main's legacy MoE changes

Rebasing onto main 333b78da1 brought in five legacy MoE changes; v2 follows four of them:

test_main_legacy_rows_against_legacy compares legacy's get_2stage_cfgs with v2's dispatch_record, records and logs, on a shipped padded FLAT row, the shipped stage 2 FP8 rows at 8,192 to 131,072 tokens and a gfx942 MXFP8 row with bias. The CPU differential is at 0 problems on all four archs, with and without AITER_FLYDSL_STAGE2_FP8=1.

Rollout

The graduation criteria and the opt-in period are as in #8255. A path graduates per arch, and per CU count where the tuned tables differ, once these pass on that hardware:

  • the CPU differential and coverage report at 0 problems, with every decline on the known list;
  • the GPU differential;
  • gpu_suites.py --compare;
  • the perf gate;
  • an end-to-end vLLM run.

This PR graduates nothing.

Performance

vLLM 0.32.1rc1, vllm bench throughput with random prompts, total tokens/s, MI350X (gfx950).

  • Before is AITER_MOEV2=off.
  • After is AITER_MOEV2=on for the big models (every path), and the one path for Mixtral (a16w16, a8w8_ptok, a8w8_blockscale).
  • Prefill: 1000 prompts, 1024 in / 256 out. Decode: 64 prompts, 128 in / 1024 out.
  • Method:
    • One vLLM job on the node at a time, with off and v2 alternated (off, v2, v2, off) on one GPU group. Each value is the mean of 2 runs per mode. A cell whose gap was over 1.5% got 8 more runs per mode (marked 10+10).
    • Every run first serves the same workload untimed (256 prompts for prefill, 64 for decode), so first-use JIT and FlyDSL specializations don't land in the timed run.
    • Graph-mode decode runs with vLLM's engine core in-process (VLLM_ENABLE_V1_MULTIPROCESSING=0). With the engine core in its own process, it starts stepping before all 64 prompts are added, so the timed prefill splits differently from run to run. That moves decode throughput by up to 10% in both modes. In-process, the timed prefill is one batch every run.
    • Prefill and eager decode run in vLLM's default layout.
  • Measured on be0783898; the graph decode cells and one prefill cell were rerun on f8f6b76b7. The review fixes in f8f6b76b7 change no dispatch of the shipped tables (the snapshot, differential and coverage outputs are identical).
  • Dummy-weight models (DeepSeek-V4-Pro, MiniMax-M3-MXFP8, gpt-oss-120b) are timed only.

Big models, torch.compile + CUDA graphs:

Model (v2 paths) Config Prefill before after Change Decode before after Change
DeepSeek-V4-Pro (fhmoe + a8w4) TP8 16,127 16,279 +0.9% 2,660 2,659 0.0%
DeepSeek-V4-Pro (a8w4) TP8 + EP 14,131 14,540 +2.9% (10+10) 2,691 2,689 −0.1%
DeepSeek-V4.1-Flash (a8w4) TP4 33,030 33,010 −0.1% 4,428 4,416 −0.3%
DeepSeek-V4.1-Flash (a8w4) TP4 + EP 33,044 32,967 −0.2% 4,780 4,754 −0.5%
DeepSeek-V4.1-Flash (a4w4) TP4 33,821 33,828 0.0% 4,789 4,762 −0.6% (10+10)
DeepSeek-V4.1-Flash (a4w4) TP4 + EP 33,550 33,364 −0.6% 4,673 4,703 +0.6%
MiniMax-M3-MXFP8 (mxfp8) TP4 18,228 18,089 −0.8% 3,351 3,352 0.0%
MiniMax-M3-MXFP8 (mxfp8) TP4 + EP 17,194 17,056 −0.8% 3,232 3,230 −0.1%
MiniMax-M3-MXFP4 (a16w4 + a4w4) TP2 14,106 14,090 −0.1% 2,901 2,904 +0.1%
MiniMax-M3-MXFP4 (a16w4 + a4w4) TP2 + EP 13,879 13,885 0.0% 2,765 2,776 +0.4%
gpt-oss-120b (a16w4 + a8w4) TP1 74,705 74,728 0.0% 5,621 5,614 −0.1%
gpt-oss-120b (a16w4 + a8w4) TP2 + EP 57,104 57,129 0.0% 8,211 8,213 0.0%

Mixtral-8x7B-Instruct (bf16, vLLM online FP8 per-channel and per-block):

Path Config Prefill before after Change Decode before after Change
a16w16 TP1 eager 19,011 19,050 +0.2% 2,191 2,211 +0.9% †
a16w16 TP1 graphs 19,373 19,351 −0.1% 3,210 3,193 −0.5%
a16w16 TP2 + EP eager 29,522 29,551 +0.1% 2,271 2,395 +5.5% † (10+10)
a16w16 TP2 + EP graphs 29,677 29,699 +0.1% 4,512 4,515 +0.1%
a8w8_ptok TP1 eager 20,542 20,494 −0.2% 2,437 2,473 +1.5% †
a8w8_ptok TP1 graphs 22,206 22,166 −0.2% 5,275 5,280 +0.1%
a8w8_ptok TP2 + EP eager 30,100 30,104 0.0% 2,362 2,320 −1.8% † (10+10)
a8w8_ptok TP2 + EP graphs 30,491 30,482 0.0% 7,842 7,844 0.0%
a8w8_blockscale TP1 eager 17,229 17,272 +0.3% 2,106 2,168 +3.0% † (10+10)
a8w8_blockscale TP1 graphs 17,700 17,702 0.0% 5,047 5,050 0.0%
a8w8_blockscale TP2 + EP eager 24,933 24,965 +0.1% 2,261 2,187 −3.3% † (10+10)
a8w8_blockscale TP2 + EP graphs 25,132 25,109 −0.1% 7,763 7,738 −0.3% (10+10)

† Eager decode is host-bound and swings with CPython's frame-stack allocation, not only with v2's cost (below).

Prefill and graph-mode decode are at parity.

  • Graph-mode decode: every cell is within ±0.6%. The MoE call is replayed from the CUDA graph, so v2's Python never runs during decode, and the captured GPU work is identical to legacy's.
  • Prefill: every cell is within ±0.9%, except DeepSeek-V4-Pro TP8 + EP at +2.9% (every v2 run above every off run).
  • MiniMax-M3-MXFP8 prefill, −0.8% in both configs: its prefill pieces run eagerly, and there routing alone (the hook active, every call signed and routed, legacy running it) costs about −0.7%. That is the per-call signature, about 30 µs per call in vLLM (see "Known limits").

Eager decode. The kernels and device time are the same as legacy's; the step is host-bound, so these cells measure host time.

  • a16w16 is faster on v2: with EP, legacy's sort costs 137 µs per call against v2's 89 µs.

  • The a8w8 cells swing with CPython 3.12's frame-stack chunks. Python frames live in 16 KiB chunks. A call whose frame doesn't fit maps a new chunk, and its return unmaps it. If a call on the hot path sits on a chunk boundary, every call pays an mmap / munmap pair (about 2.5 µs). Where the boundaries fall depends on the whole stack under the MoE call: vLLM's process layout and the MoE frames of each mode. Counted in each process that runs the model (16 KiB pairs per run):

    Cell Layout off v2 Gap
    a8w8_blockscale TP1 engine core in its own process (default) 661k 136k v2 +7.7%
    a8w8_blockscale TP1 engine core in-process 431k 1,153k v2 −4.9%
    a8w8_blockscale TP2 + EP default 265k 732k v2 −6.6%
    a8w8_ptok TP2 + EP default 232k 210k v2 −2.4%

    (One run per mode, so the gap column is noisier than the tables above.)

    So the sign of the a8w8 eager cells follows the stack layout rather than the code: TP1 blockscale is +3.0% in the default layout and −3.5% in-process. The a8w8_ptok TP2 + EP gap (−1.8%) is not explained by this: v2 has fewer pairs, and its fused_moe call is not slower (256 µs against legacy's 263 µs). The rest of the step is unaccounted for.

Host time per call. The first throughput run showed v2 behind where the host is the bottleneck, by −2.5% to −5.4%. Two fixes in this PR:

  • The MXFP4 fallbacks were resolved on every MXFP4/MXFP8 call (about 110 µs per call). They are now cached per dispatch key.
  • The call cache (above). In vLLM (DSv4.1 a8w4 TP4), host time inside fused_moe per run is:
    • legacy 72.2 s;
    • v2 without the cache 82.9 s;
    • v2 with it 71.3 s.

Kernel level: AITER_MOEV2=on python3 tests/moe_dispatch/perf_baseline.py --check against golden/perf_gfx950.json (recorded with legacy) exits 0 on be0783898: no case is more than 10% slower.

Testing

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

MI250X is not a target for these formats. MI300X (gfx942) is covered by CPU simulation only; see "Validation and unverified scope". GPU testing was on MI350X (gfx950).

Check (head f8f6b76b7; GPU rows on be0783898, the head before the review fixes, which change no shipped-table dispatch) Result
CPU tests in CI (tests/test_moev2_*.py, tests/test_moe_dispatch_snapshot.py; call cache in check mode) dispatch 133, differential 34 passed / 10 skipped (the opt-in GPU cases; each v2 call runs twice, the second from the cache), call cache 17, switch 41, ranking 15, coverage 8, snapshot 3, imports 4, hooks 4
Dispatch snapshot, 4 archs gfx942 126,095 / gfx942_cu80 147,042 / gfx950 171,120 / gfx1201 122,377 keys, identical
CPU differential, 4 archs 0 problems on every arch. Keys claimed: gfx942 46,120, gfx942_cu80 57,578, gfx950 92,708 (a4w4 20,890, a8w4 13,211, a8w8_blockscale 11,326, a8w8_ptok 11,210, a16w16 8,803, a8w8_pt 8,160, a16w4 7,110, mxfp8 5,142, a16wi4 5,052, fhmoe 1,804). gfx1201 has no path. Every decline of a key legacy runs is on the known list. Also 0 problems with AITER_FLYDSL_STAGE2_FP8=1 on gfx942 and gfx950
Coverage, key and ranking checks, 4 archs 0 problems. Coverage: on gfx950, 2,263 tuned rows run and 18 do not (8 a4w4 post-reduction rows; 6 a16w4 1-stage SiTUv2 rows that legacy discards too; 4 a8w4 MXMOE + Opus rows). Key checks: 127,056 / 148,858 / 172,450 / 123,338 keys. Ranking checks: 55,850 / 68,789 / 115,309 ranked keys
Call cache (tests/test_moev2_call_cache.py) every entry parameter has a class and is keyed as declared; one signature gives one decision over perturbed calls; every variable the decision reads per call is read by the signature; the activation-dtype memo keys each variable resolve_activation_dtype reads; check mode raises on a missing input; the kill switch is read per call; an unclassified new parameter turns the cache off at its entry
GPU differential, gfx950, call cache in check mode (gpu_differential.py --path P, --synth-table for the CK paths; each v2 case runs twice) no CallCacheMismatch on any path. 0 problems on a16w16 (+synth), a8w8_blockscale (+synth), a4w4, a16w4, a8w4, mxfp8 and fhmoe. Cases that raise on both compare the errors; the only build failures are the known MX per_1x32 CK modules. 0 problems also on the synth tables of a8w8_pt and a8w8_ptok. The remaining problems are cases where two legacy runs differ, so v2 can't be validated there: a8w8_pt, the int8 per-tensor Gelu case (legacy's ASM int8 stage 1, known since step 3.3; in 10 reruns it fails 7 times on this head and 9 times on the head before the rebase, mostly as "legacy output not repeatable"); a8w8_ptok, 2 cases (legacy's ASM per-token fp8 stage 1 intermittently writes 1e31 to 1e38); a16wi4, the fp16 case
GPU suites, gfx950 (gpu_suites.py --path P --compare, every path, call cache in check mode) all exit 0, no CallCacheMismatch. op_tests/test_moe_sorting.py fails in both modes: an Opus sort mismatch at one token with expert_mask and padding_extra, not v2. Off and v2 pass and fail the same suites with the same checkAllclose counts, except swiglu_limit=7.0 checks of the per-token / per-tensor fp8 runs, which flip between pass and warning in both directions (they flip between legacy runs too)
vLLM end to end, accuracy (GSM8K 1319, 5-shot), on the head before the rebase (4b5f3526a, rebased as 57e38f682). Mixtral bf16 / fp8 per-tensor / per-channel / per-block, DSv4.1-Flash a8w4 and a4w4, MiniMax-M3 MXFP4, plus dummy-weight DSv4-Pro, MiniMax-M3-MXFP8 and gpt-oss-120b; TP and TP + EP, eager and graphs every MoE call in the v2 runs ran on v2, except 108 gpt-oss TP1 a8w4 calls on MXMOE / layout-v2 rows (declined by design). Same kernel sequences as legacy; scores inside the spread of legacy runs. Rerun with the call cache in check mode: DSv4.1 TP4 eager 0.9022 strict (legacy 0.9022 / 0.9030), Mixtral fp8 per-channel TP1 eager 0.6346 (legacy 0.6315 / 0.6171); no mismatch, and the same ops and arguments as legacy at every token count
FlyDSL kernel fix (gfx950, on the head before the rebase) 100 relaunches of each of 10 recorded stage 1 kernels bitwise equal (one had 33 distinct outputs before). An ISA check finds no barrier with a buffer-to-LDS load in flight (2 kernels before). 5 shipped dsv41 a8w4 k_wave 4 cases bitwise equal over 200 replays, before and after, at the same stage 1 time. (64, 7168, 3072, E24, top6) a8w4: 30 of 30 ok (about 3 in 10 failed before)
black, ruff clean

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The feature is opt-in and not graduated, so the user guide is unchanged. aiter/moev2/README.md documents:

  • every new file;
  • the switches, including AITER_MOEV2_CALL_CACHE;
  • the check commands;
  • what must be added to the call cache's class table when an entry gains a parameter, or a decision reads something new.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None for callers: with AITER_MOEV2 unset, every call runs the legacy code, and every name importable from aiter.fused_moe and aiter.fhmoe still is.

For code that patches moved names: assigning a moved name on aiter.fused_moe or aiter.fhmoe no longer reaches the code that uses it. Assign it where it now lives (see "Legacy code moved"). For example, _STAGE2_SCRATCH now lives in aiter.moev2.segments.flydsl; aiter/aot/flydsl/moe.py and op_tests/test_moe_scatter_reduce.py are updated.

The FlyDSL mixed stage 1 race fix changes the kernel's code for legacy too:

  • The async-copy kernels get a sched_barrier and an exact barrier wait.
  • k_wave > 1 kernels with an odd tile count per group drop one stray copy.

FlyDSL's cache key hashes the source, so cached binaries rebuild.

Known differences from legacy

Multi-arch GPU_ARCHS: v2 chooses kernels by the device (deliberate)

chip_info asks runtime dispatch to use get_gfx_runtime() (the device). get_gfx() follows GPU_ARCHS and, when that lists several archs, returns the last one. So on a GPU that is not the last entry, the two differ: for example, a GPU_ARCHS="gfx942;gfx950" source build run on an MI300X with GPU_ARCHS still set. Installed wheels without GPU_ARCHS set, and CI test runs (the test script sets it to the detected arch), don't hit this.

Legacy MoE reads get_gfx() at runtime sites. Where v2 stands:

Site Legacy v2
Kernel choice (claims, tuned rows, ranking, 1-stage kernels) fused_moe_1stage_dict.get(get_gfx()) Device arch: fixed, a deliberate difference (as c6fb48e9d, "use the runtime GPU for path claims", made the claims)
Grouped gfx1250 branch, a16w4 FlyDSL CDNA refusal get_gfx() get_gfx() on purpose: local.legacy_grouped_gfx1250 and executor.a16w4_unsupported predict legacy's choice; v2 declines and legacy runs the call
FLAT ASM arch assertion, ASM top-k condition get_gfx() get_gfx(), copied (executor.run_one_stage; routing/topk.py is shared): not fixed, same as legacy
herd_topk gfx1250 checks get_gfx() v2 declines every herd_topk call

No check covers this: the CPU differential simulates one arch at a time, and the GPU runs use single-arch builds.

Fix plan, a later behavior change on both sides (step 7.1, or a standalone PR with the legacy MoE owners):

  1. Switch every runtime get_gfx() read of legacy MoE (the sites above and the shared routing/topk.py) to get_gfx_runtime().
  2. In the same commit, switch the v2 copies and predictions with them.
  3. Add a test that no runtime MoE code calls get_gfx(), and CPU tests that patch get_gfx() to another arch and check that legacy and v2 dispatch as they do without it.
  4. Validate:
    • the dispatch snapshots are unchanged;
    • on a GPU, the GPU differential and gpu_suites.py --compare give the same results under a multi-arch GPU_ARCHS whose last entry is not the device as with GPU_ARCHS unset.

Calls v2 declines (legacy runs them unchanged)

Every decline of a call legacy runs is counted and must match an entry in tests/moe_dispatch/known_declines.py. Each entry gives the reason, why, and its todo. Counts on the snapshot grid (mostly its feature-variant keys): gfx942 10,291, gfx942_cu80 10,573, gfx950 26,903, all on the list; gfx1201 0. The main groups:

  • g1u0 outside the 1-stage fmoe keys. Legacy's CK 2-stage reads w1 as gate and up, so its output is wrong and v2 has nothing to match.
  • Not ported yet:
  • Kernels without a capability:
    • padded keys on kernels that take no padding;
    • per_1x32 calls with caller activation scales or num_local_tokens;
    • a16wi4 with doweight_stage1;
    • FHMoE on rows of kernel families it has no segment for.
  • Tuned rows legacy runs without honoring the call:
    • 1-stage rows for bias, padding, exclude_mxmoe or Gelu calls;
    • a16w4 interleaved gate/up on FlyDSL rows;
    • CK-Tile alias rows outside the CK-Tile branches;
    • MXMOE a8w4 stage 1 paired with an Opus stage 2.
  • Under AITER_BYPASS_TUNE_CONFIG=1: the a4w4 SiTUv2 CK-Tile/CK branch and the MXMOE fallback that a bypassed row turns off.

Other differences

  • Separate dispatch caches. v2 and legacy keep separate caches, so a key that v2 serves on one call and legacy on another logs its dispatch line once per side. This happens with a presort registered on some calls only.
  • Route-bucket fields. Under AITER_BYPASS_TUNE_CONFIG=1 with an Opus kernelName2 row, legacy adds the row's route-bucket fields to the 1-stage, CK and ASM metadata; v2 does not. Only custom tables have those columns.
  • Blank kernel names. Crafted rows with a blank kernel name are declined; legacy runs them. No shipped row has one.
  • test_presorted_moe_hook. op_tests/test_moe_2stage.py::test_presorted_moe_hook counts sorts by patching fused_moe.moe_sorting, which v2 doesn't call through. Under AITER_MOEV2=on, its own-sort call runs on v2 and fails that assertion. Calls with a registered presort stay on legacy.

Known limits

  • Legacy kernels that don't repeat, legacy against legacy. The GPU differential reports these cases; they are not excused:
    • the ASM per-token fp8 stage 1 at 5120/1536 E40/E41, with output garbage up to 1e38 in some runs;
    • the ASM 1x128 blockscale stage 1 on gfx950, which only the synthetic table runs;
    • the ASM int8 per-tensor Gelu stage 1;
    • the a16wi4 fp16 case.
  • Other legacy issues seen while testing, unchanged:
    • the mxfp8 CK instances fail to compile;
    • tuned mxfp8 Swiglu drops its bias;
    • a8w4 on untagged separated weights raises in the untuned branches;
    • op_tests/test_moe_sorting.py fails at one token with expert_mask and padding_extra, on clean legacy too.
  • The routing cost. In vLLM, the per-call signature and routing still cost about 30 µs per call wherever a path is active. A per-layer handle that signs once at load is planned before graduation.
  • The public two-stage API (fused_moe_prepare_stage2 / fused_moe_run_stage2) calls _fused_moe_impl directly, so it runs legacy even with AITER_MOEV2 set.
  • gfx1201 has no v2 path; gfx1250 is out of scope (step 4.6a).

PR Self-Review

Reviewed revision

f8f6b76

Behavior and intent

Default behavior doesn't change: with AITER_MOEV2 unset or off, every call still uses the legacy fused_moe / fhmoe_ path, and no entry hook builds a call.

The PR adds explicitly enabled v2 paths for every remaining single-GPU MoE format. It also adds the CI gates a path must pass before it graduates, and a per-call decision cache that keeps v2's host time per call at or below legacy's. Each path claims only the calls it reproduces exactly, and hands every other call to legacy.

Three changes are visible to legacy:

  • Legacy helpers moved into aiter/moev2 and imported back. They are AST-identical, and every public name still resolves.
  • _fhmoe_impl gets the same opt-in hook as fused_moe_.
  • The FlyDSL mixed stage 1 kernel gets a race fix that legacy shares.

Validation and unverified scope

Validated on f8f6b76b7, CPU:

  • lint is clean;
  • the CPU tests in CI pass;
  • the snapshot, differential, coverage, key and ranking checks show 0 problems on all four simulated archs, with output identical to the head before the rebase; the differential also with AITER_FLYDSL_STAGE2_FP8=1.

Validated on be0783898 (the review fixes in f8f6b76b7 change no shipped-table dispatch), gfx950 (MI350X), with JIT modules rebuilt and CK at the submodule commit:

  • the GPU differential and gpu_suites.py --compare give the results above, for every path, with the call cache in check mode;
  • AITER_MOEV2=on python3 tests/moe_dispatch/perf_baseline.py --check: exit 0;
  • vLLM throughput as above (graph decode rerun on f8f6b76b7).

Unverified:

  • vLLM accuracy after the rebase. The GSM8K runs above are on the head before it (4b5f3526a). The rebase changed the MoE code only by main's legacy changes and their port, which the CPU differential and the GPU differential cover.

  • gfx942 on a GPU, both cu304 (MI300X/MI325X) and cu80 (MI308X). The gfx942-only parts have run in CPU simulation only: the ASM 1x128 rows, the FlyDSL whole-graph rows, and the gfx942 suites. There is no gfx942 perf baseline yet.

  • SGLang and ATOM end-to-end runs.

  • Multi-arch GPU_ARCHS builds (see "Known differences").

PR-specific question

The new configuration, the paths and the call cache, is consumed only when AITER_MOEV2 names a path, and then only by the calls that path claims. A path claims a call only if:

  • its quant type, weight dtypes, arch and gate/activation form match the path;
  • Path.takes accepts the dispatch key;
  • the resolver finds a plan v2 reproduces.

Every other call is declined to legacy before anything is logged or copied.

Unrelated shapes keep their prior selection, for these reasons:

  • the feature is opt-in;
  • the legacy snapshot is identical on all four arch grids;
  • the feature-variant keys exercise each exclusion independently;
  • the CPU differential requires every claimed key to match legacy's plan, and every decline of a key legacy runs to be on the known list;
  • the call cache is checked in check mode across the tests, both GPU harnesses and the vLLM accuracy runs.

Changed op tests

  • op_tests/test_moe_scatter_reduce.py: test_stage2_scratch_never_shares_live_memory patches _STAGE2_SCRATCH on aiter.moev2.segments.flydsl, where the scratch now lives. Patched on aiter.fused_moe, it would no longer reach the scratch, and the test would check nothing. The coverage is unchanged.

@qli88
qli88 requested review from a team and a balanced review from Copilot November 30, 2026 06:47
@github-actions github-actions Bot changed the title Moev2 pr2 [FlyDSL] [CI] Moev2 pr2 Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8912 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical race between route lookup and reload can repopulate _ROUTES with an obsolete path, causing later calls to keep returning an inactive route.

1 open issue
What changed in this PR

Extends the opt-in MoE v2 migration from #8255 to the remaining single-GPU formats, with cached routing and broader validation. No paths are enabled by default; the shared FlyDSL synchronization fix also affects legacy execution.

Changes:

  • Adds format-specific paths, kernel segments, and buffer compatibility checks.
  • Caches routing decisions and expands coverage, ranking, and cache-consistency checks.
  • Shares additional legacy helpers and fixes FlyDSL asynchronous-copy ordering and bounds.
File Description
tests/​test_moev2_switch.py Tests entry gating, registrations, graduation, and legacy hooks.
tests/​test_moev2_ranking.py Expands ranking checks across formats and legacy fallbacks.
tests/​test_moev2_coverage.py Tests coverage classification and segment reachability.
tests/​moe_dispatch/​ranking_checks.py Checks path-specific ranking, including shared experts.
tests/​moe_dispatch/​known_declines.py Records accepted legacy fallbacks and their reasons.
tests/​moe_dispatch/​keys.py Expands the dispatch grid with formats and feature variants.
tests/​moe_dispatch/​hibernating.py Defines test references for otherwise-unused segments.
tests/​moe_dispatch/​gpu_suites.py Defaults GPU suites to cache-check mode.
tests/​moe_dispatch/​coverage_checks.py Adds coverage reports and segment reachability checks.
tests/​conftest.py Defaults tests to cache-consistency checking.
op_tests/​test_moe_scatter_reduce.py Updates the scratch-cache patch target after relocation.
aiter/​ops/​flydsl/​kernels/​mixed_moe_gemm_2stage_common.py Fixes asynchronous-copy waits, ordering, and K-wave bounds.
aiter/​moev2/​segments/​whole_graph.py Expands whole-graph capabilities and declares input requirements.
aiter/​moev2/​segments/​sort.py Adds auxiliary, FLAT, and fused sort/quant support.
aiter/​moev2/​segments/​quant.py Adds MXFP4/MXFP8 quantization and buffer contracts.
aiter/​moev2/​segments/​opus.py Adds Opus stage segments and tuned-row validation.
aiter/​moev2/​segments/​defaults.py Adds quantization-specific block-size and split-K defaults.
aiter/​moev2/​segments/​ck.py Expands CK formats and tuned-row restrictions.
aiter/​moev2/​segments/​base.py Defines segment reachability, boundaries, and launch contracts.
aiter/​moev2/​paths.py Adds cached routing and entry-specific activation gates.
aiter/​moev2/​migration/​mxfp8.py Registers the MXFP8 activation/weight path.
aiter/​moev2/​migration/​a8w8_ptok.py Registers per-token FP8, int8, and packed-int4 support.
aiter/​moev2/​migration/​a8w8_pt.py Adds int8 support and adopts shared dispatch logic.
aiter/​moev2/​migration/​a8w8_blockscale.py Registers block-scaled FP8 support.
aiter/​moev2/​migration/​a8w4.py Registers MXFP8 activations with MXFP4 weights.
aiter/​moev2/​migration/​a4w4.py Registers MXFP4 activation/weight support.
aiter/​moev2/​migration/​a16wi4.py Registers BF16 activations with grouped int4 weights.
aiter/​moev2/​migration/​a16w4.py Registers BF16 activations with MXFP4 weights.
aiter/​moev2/​migration/​a16w16.py Registers unquantized BF16/FP16 support.
aiter/​moev2/​hooks.py Propagates legacy benchmark and fused-sort controls.
aiter/​moev2/​dispatch/​tuned.py Shares the stage-2 FP8 table and exposes lookup tiers.
aiter/​moev2/​dispatch/​plan.py Adds segment lookup by starting operation.
aiter/​moev2/​dispatch/​overrides.py Adds dispatch switches for newly supported paths.
aiter/​moev2/​dispatch/​kernel_names.py Exposes the CK-Tile alias constant.
aiter/​moev2/​dispatch/​coverage.py Classifies resolutions and checks segment reachability.
aiter/​moev2/​dispatch/​buf.py Adds buffer-format and layout compatibility checks.
aiter/​moev2/​api.py Adds shared-expert call conversion and dispatch metadata.
aiter/​aot/​flydsl/​moe.py Updates the relocated scratch-helper patch target.
.github/​split-test-times/​aiter.tsv Adds timing estimates for MoE dispatch test sharding.

Review effort: Balanced

Comment thread aiter/moev2/paths.py Resolved
@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 0d147cffb635 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The shared FlyDSL synchronization change affects legacy execution, and its async-copy ordering and k-wave bounds need maintainer review and exact-head GPU validation beyond the earlier-revision evidence and CPU-simulated gfx942 coverage supplied.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 30, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The shared legacy/FHMoE async-copy synchronization change needs kernel-owner review because wait-count ordering and head-matched gfx942 GPU correctness and performance remain unverified.

No open issues 🎉

Review effort: Balanced

@zufayu
zufayu self-requested a review December 1, 2026 05:01
@zufayu zufayu assigned Bernard-Liu and unassigned yadaish Dec 1, 2026
@zufayu

zufayu commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

CI: all red shards are infra failures — no test failed

I went through all 7 failed shards of the Aiter Test run (46478108406):

  • Shards 0/2/3: Download Aiter wheel artifact timed out after 30 min, and the retry timed out after another 30 min. The tests never ran.
  • Shards 4/6/7: The self-hosted runner lost communication with the server — the runner died mid-job.

Nothing in this PR failed a test; the gate just propagated the infra failures. No fix needed on your side for the CI itself — the fresh run from your next push supersedes it.

What's needed before merge

1. Rebase onto current main. main is 58 commits ahead of your base 333b78da (as of today). Only one textual conflict — aiter/moev2/migration/a8w8_pt.py; take your side (the block moved into migration/local.py). The real work is the semantic ports:

2. Port #6987 (FlyDSL MoE RMSNorm, bafa492a) — it landed on main after your last push and overlaps this PR in three places:

  • aiter/fused_moe.py: the ~90-line post_gemm2_rms_weight pipeline vs. your −2203;
  • aiter/moev2/api.py: the 3 new RMSNorm parameters on op_call/fused_moe need to go into your rewrite;
  • aiter/moev2/migration/local.py: _UNSUPPORTED_ARGS is missing post_gemm2_rms_weight. Without it, v2 would claim a call that passes it and silently drop the RMSNorm. It also needs a class in the call-cache PARAMS table (otherwise the cache turns off at that entry with a warning).

3. Reconcile #8550 (31bd852b, stage 1: wait for the A LDS-DMA before the half-step barrier) with this PR's own race fix in mixed_moe_gemm_2stage_common.py — same kernel, same region, two fixes to merge.

4. Re-run the CPU gates (snapshot / differential / coverage / key+ranking, all 4 archs) after the port, then push — the fresh CI run replaces the current red.

On the diff itself I have no blocking findings: the moved functions are byte-identical to legacy, the re-export seam is complete, and the k_dim→klen boundary fix checks out.

qli88 and others added 3 commits December 2, 2026 08:41
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]>
…raduated)

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
  ROCm#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]>
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]>
qli88 and others added 8 commits December 2, 2026 08:42
…bute and method (not graduated)

Behavior claim:
- Documentation only. No code path, dispatch result, log line or default
  value changes. No path graduates.

What changed:
- segments/base.py: the Segment docstring is the reference for segment
  authors. Attributes are grouped by who reads them: identity and
  dispatch (name, prefixes, covers, capabilities, reach), plan
  parameters (structure_params, rank_local_params), and runtime and
  collective behavior (stateful, zero_tokens_ok, hints, output_lifetime,
  lossy_values, default_lossy). Each says what it means and who reads
  it; each attribute line gets a one-line comment. The methods are
  listed by purpose, with the ones every segment implements.
- segments/flydsl.py, segments/mxmoe.py: the module docstrings point at
  mxfp4.py and flydsl_fhmoe.py, where the segments that run these
  kernels live.

Known differences and limits:
- The plan parameters and the runtime and collective attributes are
  declared, but nothing reads them yet (the tuner and MoeEngine will);
  the docstring says so. Today block_m is a plan field, not read from
  structure_params.
- default_params is not called by the resolver yet.

Tests:
- black and ruff clean.
- pytest CPU (test_moev2_coverage, test_moev2_switch,
  test_moev2_dispatch): 155 passed.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.9 with the earlier follow-ups):
- segments/base.py applies unchanged.
- segments/flydsl.py and segments/mxmoe.py: the new sentence goes
  before PR 8255's NOTE banner in each module docstring; the segments
  it names are where it says on this base; flydsl.py also names
  mxmoe.gemm2, which runs flydsl_moe2_layout_* kernels.
- Corrected for this base (review): sort and quant segments implement
  run, not build; the ranking table, hibernating.py and the executor
  read `name` (the known-decline list does not); only reject_reason is
  called by the resolver, and a segment overriding it or accepts cannot
  end a ranking region (ranking._shape_free); default_params is not
  called yet; block_m is MoePlan.params, copied to MOEMetadata; the
  hooks read off specific segments (flat, default_xbf16,
  transpose_a1_scale, out_buffer, split_out) are listed. The attribute
  lines keep PR 8255's form without comments (the docstring is the
  reference), and MoeEngine is "planned" rather than "phase 4". The
  README segments/base.py row mentions the docstring.
- On this base: goldens unchanged; CPU tests 217 passed, 10 skipped (the
  GPU-only ones); differential, coverage report, key_checks,
  ranking_checks and snapshot --check identical to the previous commit
  (0 problems, by default and under AITER_BYPASS_TUNE_CONFIG=1 and
  AITER_XBFLOAT16=1).

Co-authored-by: Cursor <[email protected]>
…Tile alias bias, FHMoE logs, differential) (not graduated)

Behavior claim:
- A v2 path no longer raises or drops a bias where legacy runs, and no
  longer logs before a decline, in the cases below. Every other dispatch
  result, log line and default is unchanged. No path graduates; every
  path still runs only with AITER_MOEV2=<path>.

What changed:
- local.py: the MXMOE fallback's block size check ("No fallback backend
  supports block_size_M=...") ran after the inline-sort fallback too. It
  tested whether `_exclude_mxmoe` was in the kwargs, which
  api.dispatch_key always sets (False); it now tests the value. Before,
  an a4w4 call on a shipped BM16 inline-sort row that the call cannot run
  (weights not marked is_shuffled, or a non-contiguous tensor) logged the
  warning and the fallback lookup, then raised TypeError (block_size_M
  unset) or NotImplementedError (pinned and different); legacy runs it.
- local.py: the lookup after the sort is log-only again. Legacy passes
  `_metadata_transform=lambda _: metadata` into fused_moe_2stages, so
  `_use_fhmoe_wrappers` never sees that lookup; the FHMoE consistency
  check (`_check_fhmoe`) now runs on the first lookup and each MXFP4
  fallback only.
- ck_tile.py: after an alias kernelName1 (swiglu_mxfp4_bf16_cktile),
  cktile.gemm2 takes the key's stage 2 bias whichever CK-Tile stage 2
  the row names, as legacy's CK-Tile branches do. A row with a real `cktile_*`
  kernelName2 dropped bias2 before. Only custom tables have such rows.
- fhmoe.py: a call with a1_scale, a2_scale or num_local_tokens (key
  features the FHMoE segments do not declare) is declined before the
  dedicated-table capability probes, which log; before, v2 logged the
  probe lines, declined, and legacy logged them again.
- differential.py: a key declined only by the lookup after the sort was
  skipped without comparison (compare_fhmoe crashed on it). It is now a
  decline with that lookup's reason, checked against known_declines.py.
  Under AITER_BYPASS_TUNE_CONFIG=1 this adds 11 gfx950 a4w4
  exclude_mxmoe keys (3584/384 E896 top16 SiTUv2), all under the known
  "a bypassed tuned row turns the MXMOE fallback off" entry.
- known_declines.py: the SiTUv2 CK-Tile/CK entry's explanation names
  every way past the MXMOE fallback (AITER_BYPASS_TUNE_CONFIG,
  AITER_MXMOE_FALLBACK=0, a shape it rejects).
- migration/a8w4.py docstring: `cktile_*` kernelName1 rows decline.
- Tests: the inline-sort fallback runs without a block size check (with
  block_size_M unset and pinned); the fallback test uses dispatch_key's
  real kwargs; the alias row keeps the stage 2 bias; FHMoE declines
  these calls before the contract and the probes. README rows updated.

Known differences and limits:
- v2 and legacy keep separate dispatch caches, so a key v2 serves on one
  call and legacy on another (a presort registered on some calls only)
  logs its dispatch line once per side.
- gpu_suites.py --compare does not check that v2 ran any call.
- The known entries for per_1x32 activation scales and 1-stage Gelu
  rows are broader than their cause (declines only).
- Whole-graph gfx942 rows import aiter.fused_moe at run time.
- coverage.classify still counts a key declined only by the lookup after
  the sort as "plan".

Tests:
- black and ruff clean. Dispatch goldens regenerated: identical to the
  pristine base on every arch.
- CPU differential, ranking and key checks: unchanged, 0 problems on
  every arch. Under AITER_BYPASS_TUNE_CONFIG=1 and AITER_XBFLOAT16=1:
  0 problems; gfx950 bypass known total 37057 -> 37068 (the 11 keys
  above), the rest unchanged.
- pytest CPU: 186 passed; the 4 failures are known
  test_outputs_match_legacy cases (a4w4, a8w4, a8w8_pt, a8w8_ptok).
  After the last differential.py change: test_moev2_dispatch.py 122
  passed, the harness tests 9 passed.
- New tests fail without their fix (TypeError on the inline-sort
  fallback; stage2_has_bias False on the alias row).
- GPU differential (default, synth, nt, bypass) of a16w4, a16wi4,
  a4w4, a8w4, mxfp8, fhmoe: a16w4, a16wi4 and fhmoe 0 problems (fhmoe
  synth stops on the missing fhmoe synth rows, as before); a4w4, a8w4
  and mxfp8 only the known MXFP4 sort races (todo 5.14), the a8w4 w3
  race (5.22) and the JIT build races of modules that never build
  (5.20; 0 problems run alone).

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.9 with the earlier follow-ups). Parts this base already
has, kept as they are:
- The lookup after the sort is already log-only: the follow-up 3 port
  fixed it (be371c8), with the same docstring and README wording.
- FHMoE: fhmoe.why_not already refuses a1_scale, a2_scale and
  num_local_tokens when the call is claimed (step 3.7 port), before
  run, the contract and the probes, and a test covers it; the run
  check and its test are not added. The README fhmoe.py row says the
  call is not claimed.
- differential.py is unchanged: the step 3.9 port's v2_decline already
  gives a decline of the lookup after the sort its reason and checks
  it against known_declines.py (op and fhmoe entries), with the same 11
  gfx950 a4w4 keys under AITER_BYPASS_TUNE_CONFIG=1.
Taken from this commit: the _exclude_mxmoe value check, the CK-Tile
alias stage 2 bias, the known_declines.py wording, the README rows for
ck_tile.py and differential.py, and the tests (the fallback test keeps
this base's preview/prepared-call checks). Both new tests fail without
their fix (TypeError on the inline-sort fallback; stage2_has_bias
False on the alias row).
Corrected in the port:
- migration/a8w4.py: the follow-up 1 port's docstring said a cktile_*
  kernelName1 row declines only when its stage 2 is not CK-Tile. Every
  such row declines (cktile.gemm1 owns only the alias). The 15
  cktile_a8w4_bm32 rows of gptoss_fp8fp4_tuned_fmoe.csv lose the lookup
  to other rows of their keys, so no shipped key changes.
- README: the ck_tile.py row says "whichever CK-Tile stage 2" (an alias
  row with another stage 2 declines); the fhmoe.py row also names
  doweight_stage1 and says the probes are v2's.
- The inline-sort part of the fallback test also checks the log lines.
On this base: goldens unchanged; CPU tests 218 passed, 10 skipped (the
GPU-only ones); differential the same as the follow-up 4 port (claims
and known counts, by default, under AITER_BYPASS_TUNE_CONFIG=1 and
under AITER_XBFLOAT16=1), 0 problems; coverage report, 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]>
…docstrings (not graduated)

Review round over the 15 ported step 3 commits.

- ck.py: a tuned row with an empty kernelName1 on weights outside legacy's CK
  list (bf16, fp16, uint32, fp4x2, fp8; or 1x128 with doweight_stage1), i.e.
  int8, is declined: legacy runs ASM stage 1 for it with block_m rounded to a
  CK stage 2 size, v2 ran CK stage 1. Not under AITER_BYPASS_TUNE_CONFIG,
  where the row is ignored. No shipped tuned table has such a row.
- differential.py: NaN-aware output compare, bit-exact compare for
  bitwise=True, legacy run-to-run noise capped at 16 ulps of the peak, the
  second legacy run used as a noise reference only when its sort buffers
  match, kernel_bench_callable restored, known entries matching no decline
  listed on all-arch runs.
- gpu_differential.py: where legacy raises, v2 must raise the same error,
  running or declining the call (as on moev2_official); `_RAISES` variants
  still need v2 to run and raise. These cases print as RAIS and are counted,
  with a warning for each after a failed JIT build. Caches cleared before the
  warm-up; unexpected comparison errors fail the case.
- fused_moe.py: re-exports of names moved out of it restored.
- coverage.classify resolves with emit_on_raise=False.
- Docstrings of the a16w4, a8w4, mxfp8, a16wi4, fhmoe paths, local._dispatch
  and quant._keeps_bf16 match the code; README lists the coverage, ranking
  and key checks.
- .github/split-test-times/aiter.tsv: measured times of the moev2 test files.

Co-authored-by: Cursor <[email protected]>
…sort order, MXFP4 fallback cache (not graduated)

Behavior claim:
- No path graduates; every path still runs only with AITER_MOEV2=<path>.
  The v2 dispatch results, log lines and defaults are unchanged. The FlyDSL
  mixed stage 1 kernel (legacy and v2 share it) no longer races on its
  async LDS copy.

What changed:
- mixed_moe_gemm_2stage_common.py (compile_mixed_moe_gemm1_common), async
  A copy:
  - Nothing kept the compiler from moving interleaved_half's scale and B
    loads above or between its async copies. The wait before the K-loop
    barrier was a raw s_waitcnt that SIInsertWaitcnts does not see, and
    its count was not the number of loads issued after the copy, so waves
    could read stale LDS. Seen as about 3 in 10 wrong a8w4 runs of
    (64, 7168, 3072, E24, top6). A sched_barrier now follows the copy,
    and the barrier waits vmcnt(async_loads_after_copy), counted from
    the same loads the half issues. Heterogeneous B keeps vmcnt(0); the
    non-async path is unchanged.
  - With k_wave > 1, the copy guard compared the group-relative K offset
    with k_dim instead of klen. With an odd number of K tiles per wave
    group (55 shipped rows), the last half copied one tile past the group
    into a buffer that the k-wave reduction overwrites. The guard now
    compares with klen. At k_wave 1 the ISA is byte-identical.
  - Stage 1 times unchanged within noise. 100 relaunches of each of 10
    recorded kernels are bitwise equal.
- local.py: run resolves the MXFP4 fallbacks through the mxfp4_fallbacks
  cache (keyed like dispatch, plus block_size_M) instead of on every call
  (todo 5.130).
- differential.py:
  - Sorted rows compare by (token, slot), so the order inside an expert
    may differ (a4w4 and a8w4 sorts claim positions with atomics). The
    sort layout itself must still match: num_valid_ids, padding positions
    and each (token, slot)'s expert.
  - The reverse sort buffer and the caller's weight scales compare whole.
  - Native a4w4 stage 2 scales compare in sorted order; the ASM 1x128
    stage 1 buffer compares rows and scales in their own dtypes.
  - After a stage 1 legacy does not repeat (_unrepeatable_stage1), the
    integer tensors quantized from its output get legacy's own spread.
    Stage 1's inputs and num_valid_ids stay bitwise.
- gpu_differential.py:
  - Only a failure that may be legacy noise is rerun; a v2 race must not
    pass on a lucky run.
  - Only legacy modules known never to build may fail to build.
  - Running out of GPU memory is reported and fails the run.
- tests: unit tests for each harness rule above, and one for resolving
  the a4w4 fallbacks once per key.

Co-authored-by: Cursor <[email protected]>
…ignature (not graduated)

Behavior claim:
- No path graduates; every path still runs only with AITER_MOEV2=<path>.
  The cache returns exactly the decisions computed afresh. Every dispatch
  result, log line and default is unchanged; legacy calls pay nothing.
  With AITER_MOEV2 unset, no entry hook builds a call.

Why: v2 decided every call afresh. route_to_v2 ran every active path's
why_not, and LocalDispatch.run built the dispatch key twice. That cost
1.3% to 2% of vLLM prefill throughput on the MXFP4/MXFP8 paths, and up to
8% of Mixtral eager decode (todo 5.130).

What changed:
- dispatch/call_cache.py (new): signature(call, entry), a standalone
  function. It projects each entry parameter by its class in PARAMS:
  - VALUE: by value;
  - PRESENT: whether it is None;
  - WEIGHT: dtype, shape and tags;
  - ROWS: shape, with the token count bucketed by get_padded_M;
  - EXEC: not at all.
  It adds what the decision also reads: the activation dtype, arch, CU
  count, AITER_ONLINE_TUNE, AITER_MOE_EXPLAIN, the presort registration
  and legacy's grouped gfx1250 branch. A parameter missing from PARAMS
  turns the cache off for that entry, with a warning.
- AITER_MOEV2_CALL_CACHE, read on every call: unset or 1 caches, 0
  decides every call afresh, check decides every hit afresh as well and
  raises CallCacheMismatch where the two differ. The tests (conftest) and
  both GPU harnesses run with check.
- paths.py: route_to_v2 caches the chosen path, or none, per signature,
  and hands the signature to the path in the call. paths.reload() and so
  tuned.clear_cache() clear the cache.
- local.py: run splits into _decide (pure, cached per signature and
  forced arguments) and _execute, the per-call steps that a cached and a
  fresh decision share: prologue, fallback warnings, block-size checks
  and the launch. The first execution of a decision logs its lookup, as
  legacy logs it once per key.
- Host trims, results unchanged:
  - The entry hooks build the call only where a path is active at that
    entry (any_active(entry)).
  - resolve_activation_dtype is memoized on its inputs and the variables
    it reads (ACTIVATION_ENV).
  - legacy_globals returns a shared no-op context when there is nothing
    to set.
  - The grouped_moe_gfx1250 import is cached.
- Tests: tests/test_moev2_call_cache.py (17) covers:
  - every entry parameter has a class, and each class is keyed as
    declared;
  - one signature gives one decision under perturbations;
  - every variable the decision reads per call is in the signature;
  - check mode, the kill switch and declines.
  run_differential runs each v2 call twice, the second from the cache.
  The switch tests pin the entry hooks.
- README: where to add what a decision newly reads.

Measured (gfx950):
- route_to_v2 hit about 8.4 us in a micro benchmark.
- vLLM prefill, cache vs off, all within +-0.9%: dsv41 a8w4 and a4w4,
  minimax_mxfp8, each at tp4 and tp4ep. Without the cache these were
  -1.3% to -2.0%.
- DSv4-Pro tp8ep +2.6%.
- CPU suites pass. gpu_suites --compare on all 10 paths in check mode
  raised no CallCacheMismatch. GSM8K equals off.

Co-authored-by: Cursor <[email protected]>
…Cm#8669, ROCm#7172) (not graduated)

Main changed the legacy MoE path that v2 mirrors; v2 follows:

- ROCm#7611 intermediate_pad: the 1-stage ASM segment passes the layout's
  intermediate_pad to fused_moe_1stage, and a padded MXFP4 Silu/Gelu call
  without a row uses the FLAT/EMSORT 1-stage row tuned at the logical width,
  logging the legacy line.
- ROCm#8211 gfx942 MXFP8 x MXFP4 SiTUv2 1-stage ASM: the SiTUv2 discard on
  preshuffled weights spares that kernel's rows, a row of it the call cannot run
  (activation, per-expert bias, stage2_scatter) is discarded with the legacy
  warning, and calls whose w1 / w1_scale are tagged a8w4_gfx942_layout stay on
  legacy (the tag is in the call-cache signature).
- ROCm#8669 AITER_FLYDSL_STAGE2_FP8=1: the stage2 FP8 table's row replaces the main
  row unless it is of a smaller token tier (tuned.stage2_fp8_table,
  tuned.lookup_with_tier).
- ROCm#7172 run_mxfp4 does not allocate the stage 1 output for a fused-quant stage 1.

Tests cover each branch against legacy; the README and docstrings are updated.

Co-authored-by: Cursor <[email protected]>
…not graduated)

Fixes from an independent review of the port:

- The gfx942 MXFP8 x MXFP4 1-stage discard applies to plain ASM rows only, like
  the 1-stage activation and SwiGLU OAI discards: for a row that also names a
  stage 2, legacy checks its CK-Tile / Opus discards first, so v2 declines it.
- The AITER_FLYDSL_STAGE2_FP8=1 table is read through legacy's
  cfg_2stages_stage2_fp8 (tuned.share_stage2_fp8_table), as the default table
  is through cfg_2stages.
- coverage.classify / row_status use resolver.select_row (was _select_row), so
  they see the stage2 FP8 and logical-width rows.
- test_main_legacy_rows_against_legacy compares v2 with legacy get_2stage_cfgs
  (records and log lines): a shipped padded FLAT row (v2 declines: no segment
  takes padding), the shipped stage2 FP8 rows at 8192..131072 tokens and against
  a main row of a larger tier, and a gfx942 MXFP8 row with bias. The MXFP8 and
  padded tests check more cases.
- README and docstrings: padded calls are declined; the FP8 table is shared.

Co-authored-by: Cursor <[email protected]>
…(not graduated)

A route miss that overlapped reload() put its result into _ROUTES after
reload() had cleared it: a thread paused in path A's claims while another
replaced A with B at the same entry left A cached, so later calls with that
signature kept running A with only B active. route_to_v2 now reads
_generation before _route and puts the entry only if it is unchanged, under
_lock, as active() publishes the selection. The dispatch decisions live in
the route entry, so an unpublished entry's decisions serve only its call.

Co-authored-by: Cursor <[email protected]>
…ROCm#6987, ROCm#6529, ROCm#8939, ROCm#8550, ROCm#8966) (not graduated)

Ports what landed on main since this PR's base into its copies of the legacy
dispatch.

ROCm#6987 (FlyDSL MoE post-GEMM2 RMSNorm): v2 declines a call passing
post_gemm2_rms_weight (_UNSUPPORTED_ARGS, and fhmoe_call's unsupported list),
so the legacy pipeline applies the norm. op_call raises legacy's ValueError
when the weight and the stage2_scatter combine disagree. The call cache
classifies the weight (PRESENT) and eps/zero_centered (EXEC); FHMoE's
_OP_DEFAULTS gains the three defaults.

ROCm#6529 (a16w4 row guards): mxfp4_row_rejection discards a flydsl_moe1_abf16_
row for bias or interleaved gate/up, and a flydsl_moe1_abf16_wfp4_ row for
activations other than Swiglu/SiTUv2 or a caller block_size_M other than the
row's block_m, in legacy's order and with its warnings. dispatch_key passes
block_size_M as _fused_moe_impl now does; the relookup takes the first
lookup's block size unless the caller pinned one, as fused_moe_2stages does.
block_size_M is a launch extra every capability accepts. The dispatch keys
gain a block_size_M=64 feature variant; goldens updated (the bias and
interleave variants of 255 tuned a16w4 rows per main, plus the new variant).

ROCm#8939 (untuned FlyDSL report once per shape): the heuristic FlyDSL, MXMOE and
a16wi4 fallback lines are UntunedFallback, emitted as legacy's
_warn_untuned_flydsl. The differential compares each key from a fresh report
state on both sides.

ROCm#8966 (block_size_M=0 on direct calls): the prologue reads 0 as unset, as
_fused_moe_impl now does.

ROCm#6247 (gfx942 a8w4 stage 1): v2 declines weights tagged a8w4_gfx942_layout,
which the `_g942` stage 1 requires, so its fused_moe_2stages handling stays
legacy's; the decline's docstring names both kernels. (The wrapper's
in_dtype/x_layout pass-through went into step 3.4, which moves the wrapper.)

ROCm#8550 (stage 1 A LDS-DMA wait): its count now serves only the path without
the async copy, whose wait is this PR's async_loads_after_copy; comment
updated. On gfx950, stage 1 relaunched 100 times with filled allocations is
bitwise stable on main's DSv4.1 t32x128x256 gui fp8 keys and this PR's a8w4
repro (pre-ROCm#8550 main: 37 of 99 differ), within 1% of ROCm#8550 alone.

CPU gates on gfx942, gfx942_cu80, gfx950 and gfx1201: snapshot identical,
differential 0 problems (also AITER_BYPASS_TUNE_CONFIG=1, AITER_FLYDSL_FORCE=0),
key, ranking and coverage checks pass; tests/test_moev2_*.py 260 passed.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The cross-backend migration and shared synchronization changes need specialist review because head-matched GPU validation is missing and gfx942 execution has only been CPU-simulated.

No open issues 🎉

Review effort: Balanced

zufayu
zufayu previously approved these changes Dec 2, 2026

@zufayu zufayu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Verified before approving:

  • #6987 port (post-GEMM2 RMSNorm): checked all places — local.py _UNSUPPORTED_ARGS now declines post_gemm2_rms_weight, api.py passes the three params through and raises legacy's ValueError on a weight/combine disagreement, fhmoe_call's unsupported list, call-cache classifies the weight PRESENT and eps/zero_centered EXEC, fhmoe _OP_DEFAULTS gains the three defaults.
  • #8550 reconciliation: the stage-1 wait now serves only the path without the async copy, with the bitwise validation rerun on the merged kernel (100 relaunches, stable; pre-#8550 main 37/99 differ).
  • CPU gates on gfx942/gfx942_cu80/gfx950/gfx1201: snapshot identical, differential 0, key/ranking/coverage pass.
  • CI green: all 8 MI35X shards pass. The one red shard was a topk segfault in code this PR never touches (passed on rerun; the a8w8 asm checkAllclose lines are pre-existing log noise, identical on main).

Nice work porting the full backlog (#6529/#8939/#8966/#6247 included).

…rential runs

Legacy and v2 report an untuned FlyDSL fallback once per shape (ROCm#8939).
gpu_differential runs a legacy warm-up before the compared legacy and v2
runs, so the warm-up consumed legacy's report and the compared logs
differed by that line. _clear_dispatch_caches() now also forgets both
sides' reports, as the CPU differential does per key.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a critical async barrier edge case can omit the copy wait, risking stale LDS reads.

No open issues 🎉

Review effort: Balanced

@zufayu
zufayu merged commit 5b0e22a into ROCm:main Dec 3, 2026
63 checks passed
whx-sjtu added a commit to whx-sjtu/aiter that referenced this pull request Dec 3, 2026
Conflicts:
- aiter/moev2 (ROCm#8912 moved the per-path second lookup into
  migration/local.LocalDispatch): main's a8w8_pt taken as is; this
  branch's 3584 tier moved into local.py the way it lived in a8w8_pt (the
  second lookup keys on api.tuned_token, and a tier token without a row
  for the shape resolves at its bucket). api.problem_from_key keeps main's
  fhmoe argument and this branch's tier fallback.
- aiter/fused_moe.py: main imports _FUSED_DECODE_SORT_QUANT_* from moev2;
  this branch's row-strided quant switch and helper kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Dec 3, 2026
Conflicts with #8912 (moev2 PR2) and #7139 (relu2):

- aiter/fused_moe.py: keep main's _warn_untuned_flydsl, its updated moev2
  note and the stage2 FP8 table shared with moev2
  (_stage2_fp8_cfg_2stages, share_stage2_fp8_table). Keep this branch's
  undecorated _get_2stage_cfgs behind the per-CU-count cache
  (_get_2stage_cfgs_per_cu), so _get_2stage_cfgs_cache_clear stays
  _get_2stage_cfgs_per_cu.cache_clear. The stage2 FP8 lookup goes through
  _lookup_cfg, so it gets the full-chip CU fallback too.
- aiter/moev2/segments/defaults.py: keep main's default_block_m and
  default_ksplit; get_ksplit stays the uncached wrapper of the
  CU-count-keyed _ksplit.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Dec 3, 2026
Conflict in aiter/moev2/dispatch/tuned.py: main (#8912) made lookup()
a wrapper of the new lookup_with_tier(), which also returns the token
tier the row was found at (the resolver uses it to decide whether the
AITER_FLYDSL_STAGE2_FP8=1 row replaces the default row). The token x
get_tuned_cu_nums() CU fallback loop of this branch now lives in
lookup_with_tier(), so lookup(), the stage2 FP8 lookup and the tier
comparison all see the full-chip rows on a partition. On a miss it
returns the last tier tried, as on main. The partition test also
checks the returned tier.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants