Skip to content

[Triton/Gluon] [Feature] Fused MoE top-k combine + reduce-scatter for gfx950 - #7771

Merged
azaidy merged 38 commits into
mainfrom
vinayak/moe-combine-reduce-scatter
Nov 25, 2026
Merged

azaidy merged 38 commits into
mainfrom
vinayak/moe-combine-reduce-scatter

Conversation

@vgokhale

@vgokhale vgokhale commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds moe_combine_reduce_scatter for gfx950. One fused kernel does the MoE top-k combine and reduce-scatter over 2, 4 or 8 ranks (push mode), so the combined [M, hidden] tensor is not written to memory. A new stage-2 keyword, scatter_intermediate, gives the stage-2 rows to the op. The intent is to fuse the topk combine and reduce scatter phases of prefill's all reduce in TP mode.

Stacked on #7792. This PR uses the shared gfx950 comms code of #7792 (_gluon_kernels/common/comms_gfx950.py and comms/ipc_buffers.py), merged in ee4a7bd. Review #7792 first. On top of #7792 this PR changes 6 files: the kernel, the wrapper, the config, the test, the benchmark and aiter/fused_moe.py. The PR targets main, because the CI runs only for PRs to main.

API

  • comm = MoeCombineReduceScatter(cpu_group, max_tokens, hidden, topk, config=None) makes the IPC inboxes (collective). It is a subclass of IpcCommBuffers ([Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792). It uses min(BLOCKS, CU count) CTAs, rounded down to a multiple of PARTS. config replaces keys of the tuned config (BLOCKS, PARTS, LAG, num_warps); the constructor rejects values that the kernel cannot build.
  • fused_moe_2stages(..., _stage2_extra_args={"scatter_intermediate": d}) puts the stage-2 rows in d and does not combine them. The default None changes nothing.
  • out = fused_moe_combine_reduce_scatter(d["inter"], d["reverse_sorted"], d["sorted_weights"], d["M"], comm) returns the [ceil(M / world), hidden] rows of this rank.

Results

MI355X, hidden 6144, top-4. Time in us for each layer, maximum of the ranks, median of 3 runs. Before: mxfp4_moe_scatter_reduce + pad copy + reduce-scatter (AITER custom up to 64 MiB, else RCCL). After: this op. A device-side sync before each timed launch removes the skew between ranks.

M TP2 TP4 TP8
2343 303.7 -> 279.3 (-8.0%) 189.6 -> 170.3 (-10.2%) 150.0 -> 116.2 (-22.5%)
4096 494.6 -> 469.3 (-5.1%) 296.2 -> 266.6 (-10.0%) 209.5 -> 182.2 (-13.0%)
5857 816.5 -> 663.8 (-18.7%) 469.8 -> 366.0 (-22.1%) 302.0 -> 230.9 (-23.5%)
8192 1123.2 -> 918.9 (-18.2%) 618.9 -> 496.8 (-19.7%) 361.0 -> 304.8 (-15.6%)
14394 1943.1 -> 1600.8 (-17.6%) 1145.1 -> 853.0 (-25.5%) 692.9 -> 484.5 (-30.1%)
16383 2240.6 -> 1817.8 (-18.9%) 1308.9 -> 957.5 (-26.8%) 783.0 -> 550.0 (-29.8%)

Testing

  • On AITER v0.1.28.post1, the kernel is bitwise equal to mxfp4_moe_scatter_reduce + a rank-order fp32 sum at each M above. This includes M % 4 != 0, 2 launches back to back and a forced time-out. On this branch, the kernel has the same gfx950 instruction stream.
  • New multi-GPU test op_tests/multigpu_tests/triton_test/test_moe_combine_reduce_scatter.py (2, 4 and 8 ranks, 3 shapes, M 1 to 16383, HIP graph, stage-2 keyword) and benchmark bench_moe_combine_reduce_scatter.py (--sweep KEY=V1,V2 times other config values).
  • Tests on this branch (MI355X): the test passes at 2, 4 and 8 ranks, bitwise. A negative control fails as expected (reference sum in another order, a 1-ulp change, an inverted time-out check).

Limitations

  • gfx950, 2, 4 or 8 ranks and bf16 only. Tested (hidden, top-k): (6144, 4), (3072, 4) and (5120, 2). Top-k 8 spills registers, so DeepSeek and Kimi shapes need a shallower prefetch.
  • At 8 ranks, 2 or 3 CTAs share a row (PARTS in the JSON config), so that the prefetch of 7 peer rows stays in registers.
  • The IPC inbox of each rank is (world - 1) x ceil(max_rows / world) x hidden x 2 bytes: 151 MB at 16384 tokens and hidden 6144.
  • d["inter"] is a stage-2 scratch buffer. Use it before the next stage-2 call.

PR Self-Review

Reviewed revision

f1de979

Behavior and intent

This PR adds a new op, fused_moe_combine_reduce_scatter, and an optional stage-2 keyword, scatter_intermediate, which gives the stage-2 rows to the caller and does not combine them. Before, TP prefill ran mxfp4_moe_scatter_reduce (it writes the combined [M, hidden] tensor), a pad copy and a reduce-scatter. The op does the top-k combine and the reduce-scatter in one kernel, so the combined tensor and the copy go away. It is 5% to 30% faster at 2343 to 16383 tokens. With the default None, fused_moe does not change.

Validation and unverified scope

Relation to the two-stage API (#7135)

#7135 adds fused_moe_run_stage2(per_slot=True), which also gives stage-2 rows without the top-k sum. It does not cover this case:

  • per_slot is not available for the scatter epilogue or for _mxfp4_a4w4_stage2_fw. Large prefill M uses them.
  • per_slot rows have the routing weight applied. The combine here applies the weights itself, so its output is bitwise equal to mxfp4_moe_scatter_reduce.
  • fused_moe_prepare_stage2 does its own sorting and quantization. The TP prefill caller (vLLM) gives prequantized, sorted rows to fused_moe_2stages.

So scatter_intermediate is a stage-2 keyword at the same level as per_slot_out. The wrapper rejects a call that gives both.

PR-specific question

Only the new op reads the new config configs/gfx950/gluon/fusions/moe_combine_reduce_scatter/DEFAULT.json. It holds the CTAs for each row (PARTS) for each world size. No existing op reads it, so other ops and shapes keep their previous selection. The fused_moe.py change acts only when a caller passes scatter_intermediate and stage 2 ends in the bf16 scatter epilogue. Other calls follow the old path, and the test checks that a call with another epilogue writes the complete output.

Changed op tests

…x950)

Add fused_moe_combine_reduce_scatter: one Gluon kernel for gfx950 does
the MoE top-k combine and the reduce-scatter over 4 ranks (push mode).
Each rank combines the top-k rows of a token as mxfp4_moe_scatter_reduce
does and writes the row into the IPC inbox of the owner rank. The owner
adds the 4 ranks in rank order in fp32 and rounds once to bf16. The
combined [M, hidden] tensor is not written to memory.

Add the stage-2 keyword scatter_intermediate to _mxfp4_a4w4_stage2_fw
and _flydsl_v2_stage2_wrapper. With a dict and the bf16 scatter
epilogue, stage 2 returns the intermediate, reverse_sorted and
sorted_weights instead of the combine. With None, nothing changes.

Signed-off-by: Vinayak Gokhale <[email protected]>
@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 7771 --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.

…catter

Make the world size a constexpr (WORLD in 2, 4, 8). The peer buffers come
as a tuple and the per-peer code uses static loops. The inbox and the
flags are (WORLD - 1) x ceil(max_rows / WORLD) rows.

Add PARTS: PARTS CTAs share a row, one column part each, with a flag for
each (row, part). At 8 ranks the prefetch of 7 peer rows spills
registers with one CTA a row; PARTS 3 (hidden 6144) and 2 (hidden 3072,
5120) keep it in registers. The JSON config selects BLOCKS and PARTS by
world size and hidden size.

The 4-rank build (PARTS 1) has the same gfx950 instruction stream as
before (2779 instructions). The multi-GPU test runs at 2, 4 and 8 ranks.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale
vgokhale marked this pull request as ready for review November 10, 2026 23:40
@vgokhale
vgokhale requested a review from a team November 10, 2026 23:40
@aiter-bot

aiter-bot commented Nov 10, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision f1de979c02f5 · mode shadow

Author self-review accepted. Readiness report:

Author answers

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

Behavior and intent

This PR adds a new op, `fused_moe_combine_reduce_scatter`, and an optional stage-2 keyword, `scatter_intermediate`, which gives the stage-2 rows to the caller and does not combine them. Before, TP prefill ran `mxfp4_moe_scatter_reduce` (it writes the combined [M, hidden] tensor), a pad copy and a reduce-scatter. The op does the top-k combine and the reduce-scatter in one kernel, so the combined tensor and the copy go away. It is 5% to 30% faster at 2343 to 16383 tokens. With the default `None`, `fused_moe` does not change.

Validation and unverified scope

- `op_tests/multigpu_tests/triton_test/test_moe_combine_reduce_scatter.py` at head c98584640 (#7792 and main 76c1d8755 merged; MI355X): passed at 2, 4 and 8 ranks. f1de979c0 merges main again; at f1de979c0 the CI 8-GPU job passes it on Triton 3.9.0. The merge of main 76c1d8755 had one conflict in `aiter/fused_moe.py`: #7542 added `expert_mask` and `topk_ids` next to `scatter_intermediate` in the keywords of `_mxfp4_a4w4_stage2_fw`. The merge keeps all three, and the function passes all three to `_flydsl_v2_stage2_wrapper`. The output is bitwise equal to `mxfp4_moe_scatter_reduce` and a rank-order fp32 sum.
- The move to the shared code of #7792 does not change the outputs (84 outputs at 2 and 4 ranks, bitwise equal to 79ca9aa5f) or the AMDGCN of the kernel (13 specializations at 2, 4 and 8 ranks). Time at TP4, hidden 6144: 1.000 to 1.001 of 79ca9aa5f at 2343 to 14394 tokens.
- The test covers M not a multiple of the world size, 2 launches back to back, a HIP graph, a forced time-out, the reuse of one dict across a scatter call and a fallback call, and an empty `sorted_weights`.
- Unverified: top-k 8 shapes such as DeepSeek and Kimi (not tuned, the prefetch spills), and architectures other than gfx950.

PR-specific question

Only the new op reads the new config `configs/gfx950/gluon/fusions/moe_combine_reduce_scatter/DEFAULT.json`. It holds the CTAs for each row (`PARTS`) for each world size. No existing op reads it, so other ops and shapes keep their previous selection. The `fused_moe.py` change acts only when a caller passes `scatter_intermediate` and stage 2 ends in the bf16 scatter epilogue. Other calls follow the old path, and the test checks that a call with another epilogue writes the complete output.

Changed op tests

- `op_tests/multigpu_tests/triton_test/test_moe_combine_reduce_scatter.py`: new. It tests the new op and the stage-2 keyword at 2, 4 and 8 ranks, 3 shapes, M from 1 to 16383, bitwise against a rank-order reference. No other test covers this op.
- `op_tests/op_benchmarks/triton/bench_moe_combine_reduce_scatter.py`: new. It times the op against `mxfp4_moe_scatter_reduce` + pad copy + reduce-scatter, as the AITER Triton rules require for a new op.
- `op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py`, `op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_mxfp8.py`, `op_tests/op_benchmarks/triton/utils/argparse.py` and `op_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py`: from #7792, which this PR is stacked on. See #7792 for them.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

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

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

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

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

@vgokhale
vgokhale requested a review from Boss2002n November 11, 2026 00:24
@zufayu
zufayu requested a review from a team November 11, 2026 00:52
vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 11, 2026
…erence)

The rest of the M3.1 TP4 work of vinayak/minimaxm31-opts (c63be15),
rebased onto main. Not a PR: it needs vllm-project#63483 (the DBO
commit below), ROCm/aiter#7771 (scatter_intermediate) and vllm-project#7773 (bf16
shared expert), the DSV4.1 mono/common modules it imports, and env
registration before it can be one.

- Decode glue (VLLM_M3_DECODE_GLUE=1): one FlyDSL launch from the
  o_proj partial to the MoE inputs, 17-192 rows; Lamport transport;
  bf16 shared expert in the A16W4 MoE (VLLM_M3_GLUE_SHARED_FUSED).
- Post-MoE reduce-scatter + gather (VLLM_M3_DECODE_POSTAR=rsag16).
- SP MoE half for eager steps of VLLM_M3_SP_MIN_ROWS+ rows
  (VLLM_M3_SP_PREFILL=1), top-k combine fused into the post-MoE
  reduce-scatter (VLLM_M3_SP_SCATTER_RS=1, Gluon).

Compared with c63be15: the sparse decode attention's MXFP8 o_proj
input now comes from vllm-project#65508 (upstream), so our epilogue, its shared
buffers and VLLM_M3_ATTN_MXFP8_OUT are gone; the indexer, XCD plan,
wide-R drafter and MXFP8 linear changes are the commits below; the
glue's debug and tuning knobs are constants at the values of the
AgentX runs (widths 24-192:8, epoch reset, lamport, explicit SP MoE,
exact MoE rows, SP post-MoE on, scatter-RS gluon, 16384 rows, 60 s
waits, no counters log). The glue files keep long lines and some
ruff/mypy findings (not yet PR code).

Signed-off-by: Vinayak Gokhale <[email protected]>
@Boss2002n
Boss2002n requested a balanced review from Copilot November 11, 2026 02:33

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

Reused result dictionaries can retain stale intermediate and routing entries, while empty weight buffers can trigger out-of-bounds scalar loads.

2 open issues
What changed in this PR

Adds a fused MoE top-k combine and reduce-scatter operation for gfx950, avoiding a separate combined-tensor write during tensor-parallel prefill.

Changes:

  • Adds a Gluon kernel, IPC communication wrapper, and tuning configuration for 2, 4, or 8 ranks.
  • Exposes stage-2 intermediate rows through the optional scatter_intermediate argument.
  • Adds multi-GPU correctness, graph-replay, timeout tests, and a benchmark.
File Description
op_tests/​op_benchmarks/​triton/​bench_moe_combine_reduce_scatter.py Benchmarks fused-operation latency across ranks.
op_tests/​multigpu_tests/​triton_test/​test_moe_combine_reduce_scatter.py Tests numerical results, stage-2 integration, graphs, and timeout recovery.
aiter/​ops/​triton/​configs/​gfx950/​gluon/​fusions/​moe_combine_reduce_scatter/​DEFAULT.json Defines launch settings by rank count and hidden size.
aiter/​ops/​triton/​comms/​fused/​moe_combine_reduce_scatter.py Manages IPC buffers and exposes the public operation.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​comms/​fused/​moe_combine_reduce_scatter.py Implements fused combine, peer exchange, and rank-order reduction.
aiter/​fused_moe.py Adds optional access to stage-2 rows before combining.

Review effort: Balanced

Comment thread aiter/fused_moe.py Resolved
… TP decode on gfx950

Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8.
One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8
ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant
(e4m3 values, E8M0 scale for each 32 values).

The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of
the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER
custom all-reduce does. Each rank then norms and quantizes all rows, so all
ranks get the same bits. The sum of squares has a fixed order, and the test
checks all outputs bitwise against a CPU reference.

Each wait has a time limit. A wait that times out writes an error record into
the buffer of each rank, and reset() clears it. HIP graphs are supported.

Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark.

Signed-off-by: Vinayak Gokhale <[email protected]>
…reject empty weights

- _mxfp4_a4w4_stage2_fw and _flydsl_v2_stage2_wrapper clear the
  scatter_intermediate dict first. Before, a dict from an earlier scatter
  call kept its items when a later call wrote the complete output with
  another epilogue.
- fused_moe_combine_reduce_scatter rejects an empty sorted_weights. The
  kernel loads a weight for each (token, k), also for a skipped position.
- Test: one dict for a scatter call and then a reduce call, and the
  empty sorted_weights check.

Signed-off-by: Vinayak Gokhale <[email protected]>
vgokhale added a commit to vgokhale/vllm that referenced this pull request Nov 18, 2026
Without ROCm/aiter#7771 the SP path set up unfused but still imported the
fused op on every step and failed with ModuleNotFoundError.

Signed-off-by: Vinayak Gokhale <[email protected]>
…educe-scatter

aiter/fused_moe.py: keep main's per_slot_out (#7135) next to this PR's
scatter_intermediate on _flydsl_v2_stage2_wrapper, and reject both at once.

Signed-off-by: Vinayak Gokhale <[email protected]>
Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + MoE route kernel uses the same
module.

Two helpers get the names of the shared copies: _poll is _poll_slots,
and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE
argument. Its default ("") gives the same store as before.

The kernel name (repr), the wrapper and the AMDGCN of the kernel do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
Use the shared gfx950 comms helpers (common.py, the same file as in #7792 and
#7832) for _pack_bf16, _bf_lo, _bf_hi, _errec_asm and _errec_cons. The error
record asm and constraints are the same strings for 1 to 8 buffers.
_fail_record and _drain stay here: their arguments differ.

Signed-off-by: Vinayak Gokhale <[email protected]>

@Boss2002n Boss2002n 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.

Must fix before merge

  1. The kernel is not in the tuner (DEFAULT.json): the tuner cannot try values for BLOCKS, PARTS, LAG or num_warps 16, and the wrapper has no config= argument. Fix: add an @kernel entry in tuning/kernels.py, the SEARCH_SPACE values and config=, like gemm_afp4wfp4_preshuffle.
    2.. _fail_record is defined twice (kernel): it is a copy of the one in common.py, with one line different. Fix: import it from common.py.

Nice to fix

  • Build on #7792 instead of adding common.py again; this PR uses only 5 of its helpers (common.py). Also delete the old comment above _thread_ids (kernel).
  • Remove token counts 5857, 8192 and 14394; they test the same paths as 2343 and 4096 (test).
  • Use one input generator for both the test and the benchmark (bench).
  • Limit BLOCKS to the CU count, as #7792 does; without it the kernel is expected to time out on a device with fewer CUs (wrapper).
  • Add the ci:multi-gpu label so that CI runs the new test.

…FP8 scale

The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then
values up to 896 went into e4m3, which holds at most 448. At an amax of
exactly 1.75 x 2^k, the scale was one step lower than the scale of the
other AITER MXFP8 ops.

The kernel now gets the scale from mx_e8m0_scale(amax, 8) in
_gluon_kernels/common/utils.py. It divides by the scale with ldexp,
because 2^-127 (scale byte 254) is not a normal fp32 value.

The test reference does not copy the kernel code: it rounds the amax
with frexp and computes in fp64. A new case has groups at the edges of
the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks
the reference against hand-computed scale bytes.

Signed-off-by: Vinayak Gokhale <[email protected]>
…luon_kernels/common

Move _gluon_kernels/gfx950/comms/common.py to
_gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon
helpers. The module docstring says that the helpers are for gfx950 only.

The helpers that kernels import get names without a leading underscore,
for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx:
the kernels use k4 as a variable name. The asm builders stay private.

The README table of shared helpers and the Copilot reuse rule list the
module. The AMDGCN of the kernel does not change.

Signed-off-by: Vinayak Gokhale <[email protected]>
MoeCombineReduceScatter is now a subclass of IpcCommBuffers (#7792).
The base class does the gfx950, group size and time limit checks, makes
the IPC buffers and the colours, and has error, reset and close.

Small differences:
- The constructor zeroes [0, inbox) of the buffer (the error record,
  the row flags and the done words) and then does a barrier.
- reset zeroes the error record one more time.
- The error sites are in the class docstring.

Signed-off-by: Vinayak Gokhale <[email protected]>
All CTAs of a launch must run at the same time, because they wait for
each other. The comm now uses min(BLOCKS, CU count) CTAs, rounded down
to a multiple of PARTS, as in #7792. The comm keeps the value in
comm.blocks. The done words, the colours, the grid and the BLOCKS
constexpr of the kernel all use it.

On a 256-CU gfx950 the value is the same as before (256, or 255 with
PARTS 3), so the kernel and the buffers do not change there.

Signed-off-by: Vinayak Gokhale <[email protected]>
…k sweep

MoeCombineReduceScatter takes an optional config, as in #7792: values
that replace the values of the tuned DEFAULT.json config (BLOCKS, PARTS,
LAG, num_warps). An unknown key is an error. The config is an argument
of the comm, not of a call: the buffer layout and the colours depend on
BLOCKS and PARTS. The constructor checks the limits of the kernel (PARTS
divides hidden / 2, LAG >= 2, num_warps a power of 2 that is large
enough for the done words), so that a sweep skips a bad config.

The benchmark takes --sweep KEY=V1,V2 (the shared helpers of #7792) and
times each combination as one line. A config that the constructor
rejects is skipped with a warning.

The AITER tuner cannot time this kernel: each tuner worker times
candidates alone on one GPU, and all ranks must launch a collective
together.

Signed-off-by: Vinayak Gokhale <[email protected]>
Remove the token counts 5857, 8192 and 14394 from the test. They test
the same paths as 2343 and 4096 (padding rows, more than LAG rows for
each CTA). Only the number of loop steps is larger. 16383 stays as the
largest count, so the buffer layout of the test does not change. The
benchmark still times 5857 and 14394.

Signed-off-by: Vinayak Gokhale <[email protected]>
@vgokhale vgokhale added the ci:multi-gpu Trigger multi-GPU op tests on PR label Nov 19, 2026
@vgokhale
vgokhale changed the base branch from main to vinayak/fused-ar-rmsnorm-mxfp8 November 19, 2026 22:35
@vgokhale
vgokhale changed the base branch from vinayak/fused-ar-rmsnorm-mxfp8 to main November 19, 2026 22:36
@vgokhale

Copy link
Copy Markdown
Contributor Author

Thank you for the review. This PR is now stacked on #7792 (merge ee4a7bd). The changes are in ee4a7bd to 399a2d1.

Must fix

  1. Tuner: the AITER tuner cannot time this kernel. Each tuner worker owns one GPU and times the candidates alone (tuning/AGENTS.md, rule 8). This kernel is a collective: all ranks must launch it together, and each CTA waits for the CTAs of the other ranks. On one GPU, the kernel only waits until its time limit. So I used the method of [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792 (9296b30). MoeCombineReduceScatter takes config=. Its values replace the values of the tuned config (BLOCKS, PARTS, LAG, num_warps), and an unknown key is an error. The constructor checks the limits of the kernel. The benchmark takes --sweep KEY=V1,V2, times each combination on all ranks, and skips a config that the constructor rejects. Example: --sweep BLOCKS=128,256 --sweep LAG=2,3.
  2. _fail_record: fixed in ef08dcb. The kernel imports fail_record from _gluon_kernels/common/comms_gfx950.py ([Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792), and the local copy is gone. The shared function broadcasts the buffer pointers to the lanes before the inline asm. The AMDGCN of the kernel did not change for the 13 specializations that I compared (2, 4 and 8 ranks).

Nice to fix

  • Built on [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792: gfx950/comms/common.py is gone. The kernel imports bf_lo, bf_hi, pack_bf16 and fail_record from comms_gfx950.py (ef08dcb). MoeCombineReduceScatter is a subclass of IpcCommBuffers (23c5255). The old comment above _thread_ids is gone. _drain, _thread_ids and the flag poll _poll stay in the kernel file, because they do other work than the shared helpers.
  • Token counts: done in 399a2d1. At hidden 6144 the test uses 1, 3, 1000, 2343, 4096 and 16383 tokens. The benchmark still times 5857 and 14394.
  • CU count: done in 1e57f7b. The comm uses min(BLOCKS, CU count) CTAs, rounded down to a multiple of PARTS, and keeps the value in comm.blocks. The done words, the colours, the grid and the BLOCKS constexpr use it. On a 256-CU gfx950 the value does not change.
  • The PR has the ci:multi-gpu label now.

The outputs are bitwise equal to the previous head (84 outputs at 2 and 4 ranks), and the time does not change (1.000 to 1.001 at 2343 to 14394 tokens, TP4).

Compute the e8m0 scale byte with integer operations only. The helper adds
0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it
subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254.

The old helper used log2, floor and a float-to-int conversion. On gfx950
this is v_log_f32 and approximately 15 instructions for each scale.

The new helper gives the same byte as the old helper for all 2^32 fp32
inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on
gfx950). This includes negative inputs: they give 254, or 0 when they
round to -0. A NaN amax now always gives 254. The old helper gave 254 or
0, as a function of the NaN payload.

Add a unit test with edge values for EXP_OFFSET 2 and 8.

Signed-off-by: Vinayak Gokhale <[email protected]>
…catter

Bring in the integer-only mx_e8m0_scale of #7792 (9f2d547). This op
does not use the helper. The merge keeps the stack on the #7792 head.

Signed-off-by: Vinayak Gokhale <[email protected]>
Make the integer helper give the same byte as the former log2 formula for
all 2^32 fp32 inputs, NaN included. Then no caller output changes. The
callers are the comms kernels and the gfx950 and gfx1250 Gluon quant
kernels.

The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2
formula did. For some NaNs this add sets the sign bit or wraps to an
exponent field of 0. These NaNs give 0, and the other NaNs give 254.

An exhaustive check on gfx950 finds no difference for all 2^32 inputs,
for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the
wrap and passes with the log2 formula and with the integer helper.

Signed-off-by: Vinayak Gokhale <[email protected]>
…duce-scatter

Bring in a1f8263 of #7792. This op does not use mx_e8m0_scale. The
merge keeps the stack on the #7792 head.

Signed-off-by: Vinayak Gokhale <[email protected]>
The test compared all output bytes. In the CI image (other Triton and
PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one
rounding step, and the test failed.

Now a bf16 or e4m3 value can be one rounding step from the reference,
in at most 1 of 10,000 values (at least 8). The scale bytes must be
equal. A failure gives the output name, the number of values that
differ and the largest step.

Signed-off-by: Vinayak Gokhale <[email protected]>
…reduce-scatter

Bring in c58e694 of #7792. Its multi-GPU test now allows a bf16 or
e4m3 value one rounding step from the reference. The kernels do not
change.

Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in main 008d53c. It has #8313, the fix of
tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI job.
There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in 74c83bc of #7792, which merges main 008d53c. Main has #8313, the
fix of tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI
job. There are no conflicts.

Signed-off-by: Vinayak Gokhale <[email protected]>
Boss2002n
Boss2002n previously approved these changes Nov 21, 2026

@Boss2002n Boss2002n 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.

LGTM

Boss2002n and others added 5 commits November 21, 2026 04:24
Bring in main 76c1d87. One conflict in aiter/fused_moe.py: #7542 added
expert_mask and topk_ids to the keywords of _mxfp4_a4w4_stage2_fw, next
to scatter_intermediate of this PR. Keep all three. The function body
already forwards all three to _flydsl_v2_stage2_wrapper.

Signed-off-by: Vinayak Gokhale <[email protected]>
…trim 8 ranks

In the CI 8-GPU job, the launch after reset timed out on all ranks at 8
ranks. The time-out check made a comm with another max_tokens, so it
launched a new kernel variant. The rank that skipped the first launch
loaded this variant only after reset, and the other ranks waited only
50 ms for it.

Now the sentinel and time-out checks use the comm size of the first
shape, so they launch a kernel that each rank has already compiled. The
50 ms limit applies only to the launch that the last rank skips. The
launch after reset has the default limit.

At 8 ranks the test runs only the first shape, the sentinel check and
the time-out check. Each other kernel variant compiles on all 8 ranks,
which took most of the CI time. 2 and 4 ranks run all checks.
At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s
(MI355X).

Signed-off-by: Vinayak Gokhale <[email protected]>
…duce-scatter

Bring in 68890e6 of #7792. Its multi-GPU test reuses the first shape's
kernel in the time-out check and runs less at 8 ranks. The kernels do
not change.

Signed-off-by: Vinayak Gokhale <[email protected]>

@azaidy azaidy 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.

LGTM!

@azaidy
azaidy merged commit a70b339 into main Nov 25, 2026
72 of 76 checks passed
@azaidy
azaidy deleted the vinayak/moe-combine-reduce-scatter branch November 25, 2026 13:59
zufayu pushed a commit that referenced this pull request Dec 3, 2026
* [MoE] moev2 step 3.1: bf16/fp16 a16w16 path (not graduated)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

What changed:
- aiter/moev2/dispatch/coverage.py:
  - classify: how the resolver serves a problem a path takes. The kinds
    are a plan, a gap (no plan from the path's segments), a ranking
    region naming a legacy branch, a decline caused by the tuned row, or
    a resolver raise (unshuffled gfx950 fp8 CK weights, as in legacy).
  - row_status: whether the exact tuned row runs, and if not, why.
  - segment_errors: fails a segmen…
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Dec 3, 2026
…rows

qr_reduce_scatter_route reduce-scatters an MoE layer's routed term from the
OPUS stage 2 per-slot MXFP8 rows, summing the topk slots on load. It is
bitwise equal to the OPUS route reduce followed by qr_reduce_scatter, without
writing and re-reading the [rows, hidden] bf16 tensor. gfx950 only.

opus_a8w4_stage2_wrapper honors scatter_intermediate (ROCm#7771): with an MXFP8
route output it hands over the per-slot rows instead of reducing them.

Add a multi-GPU test for the route reduce-scatter and a scatter_intermediate
test in test_moe_2stage.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR Triton/Gluon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants