Repository navigation
[CI] [MoE] moev2 phases 0–2: scaffolding, legacy-parity harness, and the per-tensor fp8 path (not graduated) - #8255
Conversation
4bdced2 to
c32cff4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved validation flaws can let shared failures, legacy-only execution, and incorrect outputs pass while hiding metadata-default changes and failing on supported whole-graph cases.
5 open issues
What changed in this PR
This PR introduces aiter/moev2 alongside legacy MoE dispatch, using composable kernel segments and execution plans. The first path, per-tensor FP8 a8w8_pt, is opt-in; no path is enabled by default.
Changes:
- Adds path selection, capability checks, tuned dispatch, and execution for the initial FP8 path.
- Moves shared legacy helpers into reusable modules while preserving existing exports.
- Adds dispatch snapshots, CPU/GPU differential checks, and performance baselines to support incremental migration.
| File | Description |
|---|---|
tests/test_moev2_switch.py |
Tests path selection, routing, and API compatibility. |
tests/test_moev2_ranking.py |
Tests ranking rules and consistency checks. |
tests/test_moev2_imports.py |
Enforces import isolation from legacy modules. |
tests/test_moev2_hooks.py |
Tests hook restoration and cache clearing. |
tests/test_moev2_differential.py |
Runs CPU and GPU parity harnesses. |
tests/test_moe_dispatch_snapshot.py |
Checks legacy dispatch against golden snapshots. |
tests/moe_dispatch/snapshot.py |
Generates and compares frozen dispatch records. |
tests/moe_dispatch/record.py |
Normalizes dispatch results for comparison. |
tests/moe_dispatch/ranking_checks.py |
Checks ranking across simulated architectures. |
tests/moe_dispatch/perf_baseline.py |
Records and compares end-to-end latency. |
tests/moe_dispatch/key_checks.py |
Checks key round-trips and tuned lookup parity. |
tests/moe_dispatch/inventory.py |
Inventories legacy imports and monkeypatches. |
tests/moe_dispatch/gpu_suites.py |
Maps migration paths to GPU suites. |
tests/moe_dispatch/gpu_differential.py |
Generates and runs GPU parity cases. |
tests/moe_dispatch/golden/perf_gfx950.json |
Stores gfx950 latency baselines. |
tests/moe_dispatch/differential.py |
Compares dispatch, logs, launches, and outputs. |
tests/moe_dispatch/arch_sim.py |
Simulates GPU architectures for CPU checks. |
tests/moe_dispatch/__init__.py |
Defines the dispatch harness package. |
aiter/moev2/tuning/__init__.py |
Reserves the future tuning package. |
aiter/moev2/shapes.py |
Houses shared shape and token-bucketing helpers. |
aiter/moev2/segments/whole_graph.py |
Adapts registered whole-graph implementations. |
aiter/moev2/segments/sort.py |
Implements sorting backend selection and execution. |
aiter/moev2/segments/quant.py |
Adapts activation and intermediate quantization. |
aiter/moev2/segments/defaults.py |
Houses legacy default kernel heuristics. |
aiter/moev2/segments/ck.py |
Defines CK adapters and FP8 shuffle validation. |
aiter/moev2/segments/base.py |
Defines segment capabilities and parameters. |
aiter/moev2/segments/asm.py |
Defines the assembly stage-one adapter. |
aiter/moev2/segments/__init__.py |
Defines the kernel adapter package. |
aiter/moev2/routing/topk.py |
Relocates shared top-k routing. |
aiter/moev2/routing/__init__.py |
Defines the routing package. |
aiter/moev2/reference/__init__.py |
Defines the reference implementation package. |
aiter/moev2/README.md |
Documents migration flow and file lifetimes. |
aiter/moev2/policy.py |
Houses shared activation quantization policy. |
aiter/moev2/paths.py |
Registers, selects, and routes migration paths. |
aiter/moev2/migration/a8w8_pt.py |
Implements initial FP8 eligibility and fallback. |
aiter/moev2/migration/__init__.py |
Defines the migration package. |
aiter/moev2/hooks.py |
Provides scoped test and benchmark overrides. |
aiter/moev2/execute/output.py |
Validates and returns caller-provided output buffers. |
aiter/moev2/execute/metadata.py |
Relocates execution metadata and assembly modes. |
aiter/moev2/execute/executor.py |
Executes plans with legacy-compatible buffer handling. |
aiter/moev2/execute/__init__.py |
Defines the execution package. |
aiter/moev2/envs.py |
Parses and caches the migration switch. |
aiter/moev2/dispatch/tuned.py |
Reads tuned tables and reproduces lookup fallbacks. |
aiter/moev2/dispatch/resolver.py |
Resolves plans while preserving legacy dispatch behavior. |
aiter/moev2/dispatch/profile.py |
Reserves measured alternative-plan lookup. |
aiter/moev2/dispatch/plan.py |
Defines plans and segment choices. |
aiter/moev2/dispatch/overrides.py |
Reads dispatch override settings. |
aiter/moev2/dispatch/ops.py |
Defines the ordered MoE operation chain. |
aiter/moev2/dispatch/kernel_names.py |
Parses and reconstructs tuned kernel names. |
aiter/moev2/dispatch/buf.py |
Describes buffers between segments. |
aiter/moev2/dispatch/__init__.py |
Defines the dispatch package. |
aiter/moev2/api.py |
Provides the v2 API and legacy argument conversion. |
aiter/moev2/__init__.py |
Documents coexistence and import boundaries. |
Review effort: Balanced
c32cff4 to
6880d5c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The default gfx950 differential fails on an unsupported CK stage-2 workload, with additional unresolved defects in binding comparisons, golden snapshots, baseline completeness, and architecture restoration.
5 open issues
Restrict unsupported whole-graph case to gfx942/cu80 · New Restore FHMoE runtime checks after cache clearing · New Compare resolved bindings by implementation and configuration, not identity · New Reject measurements missing requested token counts · New Include implementation and configuration in whole-graph snapshots · New
5 resolved since last review
Review effort: Balanced
The test set GPU_ARCHS to a two-target list, cleared the two chip-info caches it could reach, and asserted that get_gfx() then named the last target. On the MI35X runner it returned the live gfx950 instead: `get_gfx_custom_op` caches a layer below `get_gfx` and `get_gfx_custom_op_core`, so what the helper returns after a clear depends on the environment. That precondition is chip_info's own contract, not what this test is about. Build the disagreement directly instead: get_gfx() names an arch the path declines, get_gfx_runtime() names one it claims, and claims() has to follow the runtime one. Both namespaces are patched, so a path that imports get_gfx for itself is caught too -- adding `get_gfx() not in ARCHS` to claims() fails the test again. The `live_chip_info` teardown now skips a helper a test has replaced, which otherwise errors after that patching. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Bugs fixed: 1. aiter/moev2/paths.py: concurrent first calls could leave the enabled paths off. `_load_builtin` marked loading done before importing the built-in modules, so a second thread making its first MoE call skipped the import and selected from an empty (or partial) registry. If it stored that selection in `_active` after the importing thread stored its own, the paths stayed off until the next reload(). With several built-in modules, its loop over `_REGISTRY` could also raise "dictionary changed size during iteration" in default mode. Fix: no lock is held across imports (an RLock held there deadlocks when one thread imports a path module directly while another loads: each waits for the other's lock). A thread arriving during the load waits in `import_module`; loading counts as done only once every built-in module's PATH is registered, so a call made while a module imported directly is between its loader call and its registration waits too. A short RLock guards the registry and the cache; reload() bumps a generation, and active() caches its selection only if no reload happened meanwhile; _select reads a snapshot. 2. aiter/moev2/dispatch/tuned.py: clear_cache() left the default-parameter helpers `use_nt`, `get_ksplit` and `get_block_size_M` cached, so after changing AITER_USE_NT / AITER_KSPLIT or the CU count, the same untuned key kept the old values. They are cleared by name now (they stay plain lru_caches: moved verbatim from legacy, which shares them). 3. tests/moe_dispatch/gpu_differential.py: `--synth-table` imported aiter in the parent before any sys.path setup (only the child set it), so with a non-editable wheel installed it built the table from the wheel. perf_baseline.py likewise imported aiter (to name the GPU) with no checkout on the path. Both now set the path at the top of main(). 4. tests/moe_dispatch/*: the scripts added the checkout to sys.path only if it was absent, so a checkout already on the path behind another aiter (a .pth entry after PYTHONPATH) lost. All six scripts now put `tests` and the repository root first and drop later copies. 5. tests/moe_dispatch/gpu_suites.py: `--run` without `--path` ran only each path's own suites; the SHARED ones (sorting, EP, local expert IDs, shared expert) were only printed, so they could not fail an all-path run. A run now takes suites_for(path) for every path. 6. tests/moe_dispatch/gpu_suites.py: `--run` ignored Suite.archs and Suite.gpus, so an all-path run on gfx942 also ran the gfx950-only, gfx1250 and 8-GPU suites and reported them failed. It now reads the live arch and the visible GPU count, skips and lists the suites that do not fit, and fails a run where no suite applies. 7. tests/moe_dispatch/perf_baseline.py: `--check --case X` kept only the requested cases present in the baseline, so an unrecorded X compared nothing and passed, even when its measurement failed; a missing baseline file raised a traceback. `--check` now fails, before measuring, on a missing file or on any case it would measure (every case of the arch without --case) that has no recorded timings, and names the `--record --case ...` to run. 8. tests/moe_dispatch/perf_baseline.py: on an arch no case lists (gfx1250 today), `--record` wrote an empty baseline and every later `--check` passed; `--record --case` of another arch's case measured nothing and rewrote the file unchanged. Both modes now refuse there and say how to add the arch. Co-authored-by: Cursor <[email protected]>
Bugs fixed: 1. tests/moe_dispatch/arch_sim.py: a module first imported inside simulated_arch (the FlyDSL kernel modules load at launch, e.g. aiter.ops.flydsl.fused_moe_gfx942 for the gfx942 whole-graph rows) bound that context's fake get_gfx_runtime / get_cu_num. Nothing restored it, and later contexts skipped it (they patch only modules holding the real helper), so in one process the gfx942_cu80 and gfx950 contexts saw gfx942's 304 CUs there. No recorded decision changed (those helpers run at launch, which the checks stub). On exit, simulated_arch now points every module still bound to its fakes back at the real helpers. 2. tests/moe_dispatch/gpu_suites.py: `--run` started each suite with the caller's environment and directory. `python3 op_tests/x.py` puts op_tests/, not the checkout, first on sys.path, so `aiter` was whatever is installed: with a wheel the suites tested it and could pass without the proposed code; the relative suite paths also needed the caller in the repository root. Each child now runs with the checkout first on PYTHONPATH and in the checkout. Co-authored-by: Cursor <[email protected]>
One copy of the sort: - legacy moe_sorting, _moe_sorting_impl and their helpers and flags move verbatim into aiter/moev2/segments/sort.py, replacing v2's partial copy; aiter/fused_moe.py imports them back and calls the sort helpers through the module, so a patch there reaches every caller. op_tests that patched the moved globals patch aiter.moev2.segments.sort. CI (comment 1): - split_tests.sh / update_split_test_times.py add tests/test_moev2_*.py and tests/test_moe_dispatch_snapshot.py to the aiter shards. The GPU output differential is opt-in (AITER_MOEV2_GPU_DIFFERENTIAL=1). - gpu_suites.py --compare runs a path's GPU suites with AITER_MOEV2=off and with the path, fails where v2 fails and legacy passes, and prints the checkAllclose outcomes of both runs and the checks that differ (--run and --compare set AITER_MOEV2 themselves). Suite output follows its command line. GPU differential (comments 2 and 3): - cases for num_local_tokens, static a1/a2 scales, fp8 input, output=, non-contiguous input, pinned block_size_M, g1u0, swiglu_limit 0/inf (Silu, Gelu, Mixtral's shape). Where legacy raises, v2 must raise the same error. output= is NaN-filled before each run. - compare_launches stays exact on stages, kernels, arguments, sort buffers and integer tensors; floating-point launch tensors pass within 1 ulp or twice legacy's own run-to-run spread. Non-finite values must carry the bits of one legacy run. Bug fixed (comment 4, found by a vLLM end-to-end run): - a8w8_pt refused every vLLM call: vLLM passes swiglu_limit=0.0, which legacy reads as no clamp. a8w8_pt now treats None, 0 and inf as no clamp, like fused_moe_. Diagnosis and snapshots (comment 5): - Path.why_not; with AITER_MOE_EXPLAIN=1, a call no active path claims logs each path's reason once. The AITER_MOEV2 selection is logged once at INFO, naming AITER_MOEV2=off as the rollback; the differential harness leaves that line out of the dispatch lines it compares. - snapshot.py --check / --update print every changed, new and missing key; --update replaces an unreadable file. .gitattributes marks the golden files diff=gzip. - The snapshot files carry no file name or mtime in their gzip header, so their bytes depend on their content only; all six rewritten once. - Golden refresh from main (MXMOE under expert parallelism for SiTUv2): six gfx950 EP keys (E=896, topk=16, a4w4 and a8w4, M 1024-8192) now resolve like their non-EP calls (=base) instead of the CK and FlyDSL defaults. Ownership notes (comment 6): - every aiter/moev2 module, the README, the hook sites and the legacy functions v2 copies in aiter/fused_moe.py, the test harness, and the op_tests and CI scripts that touch moev2. Co-authored-by: Cursor <[email protected]>
Reply to comment 1 (tests not run by CI)Thanks, confirmed: Fixed in c1969ef (the branch is now rebased onto main f3da4e7):
Run locally on c1969ef: MI350X (gfx950, 256 CUs), torch 2.13.0+rocm, a clean worktree with every
Not covered: gfx942. The cu80 FlyDSL whole-graph and ASM differential cases need a gfx942 cu80, Reply to comment 2 (coverage gaps in the GPU differential)Thanks, added in c1969ef. Two findings:
On MI350X (gfx950): 43 cases, 0 problems (91 with Reply to comment 3 (flakiness of the GPU differential)Agreed, changed in c1969ef. New CPU tests cover the rules (1 ulp passes; 1.5x fails unless legacy's own spread covers it; Reply to comment 4 (hardware and end-to-end coverage)Not before this round. Since then, on gfx950 (MI350X): Mixtral-8x7B-Instruct with vLLM's online This run found a bug: vLLM passes With the fix, every MoE call in the Not covered: gfx942 cu304 (no MI300X/MI325X available to us) or any gfx942 GPU, and SGLang. Reply to comment 5 (gradual rollout plan)Graduation criteria. A path graduates per arch, and per CU count where the tuned tables differ
After that, the path stays opt-in for at least one aiter release before its default flips on that Staged enablement. During the opt-in release, Rollback and diagnosis. Snapshots. Uncompressed they're 7-9 MB per arch (about 33 MB), more than GitHub shows as a Whole-graph hook: added to the PR description. Reply to comment 6 (ownership notes)Done in c1969ef. Every module under In The test harness ( |
There was a problem hiding this comment.
🔵 Needs a closer look
The broad MoE dispatch/execution migration affects shared legacy helpers and needs maintainer review plus exact-head gfx942/gfx950 parity and performance evidence that was unavailable for independent verification.
Review effort: Balanced
|
@zufayu this is the run book on gfx942 PR 8255 (moev2
|
| cu304 (MI300X/MI325X) | cu80 (MI308X) | |
|---|---|---|
| default | gfx942 cu304 torch ...: 43 cases, then 0 problems, exit 0 |
gfx942 cu80 torch ...: 44 cases, then 0 problems, exit 0 |
--synth-table |
synthesized 127 per-tensor rows for gfx942 cu304, 91 cases, 0 problems |
synthesized 127 per-tensor rows for gfx942 cu80, 92 cases, 0 problems |
- The cu80-only case is
(1, 4096, 192, 192, 8, "Silu", ...), the FlyDSL whole-graph row. It checks the new("whole_graph", call)kernel-bench record end to end. - Comment 3's target: on cu80, the DeepSeek-V3 shape (7168/256, 256 experts, top 8) at 64, 1024 and 4096 tokens takes ASM stage 1, which isn't repeatable. It must pass now, because floating-point launch tensors get 1 ulp or twice legacy's own spread.
- If a case prints
FAIL: rerun it 3 times. AFAILon one run only, naming ana2or activation tensor, is the remaining race that hits v2's run but neither legacy run (a known residual). Report it with the printed message. A repeatableFAILis a real difference.
Comment 4: end to end (vLLM)
The model is Mixtral-8x7B-Instruct with vLLM's online FP8 (per-tensor), which a8w8_pt claims. Run each command once with AITER_MOEV2=a8w8_pt and twice with AITER_MOEV2=off; legacy's two runs give the noise band. Do this for 4 configs:
- TP1 eager: add
enforce_eager=Trueto lm_eval'smodel_args, or--enforce-eagerfor bench; - TP1 graph: vLLM's default, torch.compile plus CUDA graphs;
- TP2+EP eager: lm_eval
tensor_parallel_size=2,enable_expert_parallel=True, bench--tensor-parallel-size 2 --enable-expert-parallel, withHIP_VISIBLE_DEVICES=0,1; - TP2+EP graph.
export VLLM_ROCM_USE_AITER=1 AITER_MOE_EXPLAIN=1
M=/path/to/Mixtral-8x7B-Instruct-v0.1
MODE=a8w8_pt # then off, twice (name the logs off1/off2)
# Accuracy: GSM8K, 5-shot
AITER_MOEV2=$MODE lm_eval --model vllm \
--model_args pretrained=$M,quantization=fp8,tensor_parallel_size=1,max_model_len=4096 \
--tasks gsm8k --num_fewshot 5 --batch_size auto 2>&1 | tee acc_${MODE}_tp1_graph.log
# Throughput
AITER_MOEV2=$MODE vllm bench throughput --model $M --quantization fp8 --tensor-parallel-size 1 \
--dataset-name random --random-input-len 1024 --random-output-len 256 --num-prompts 1000 \
--max-model-len 4096 --seed 0 2>&1 | tee tput_${MODE}_tp1_graph.log
# Decode-heavy throughput: --random-input-len 128 --random-output-len 1024 --num-prompts 64
# Did v2 take the calls?
grep -h "AITER_MOEV2=" acc_a8w8_pt_*.log tput_a8w8_pt_*.log | sort -u
grep -c "does not claim" acc_a8w8_pt_*.log tput_a8w8_pt_*.logExpected:
- Selection line:
AITER_MOEV2='a8w8_pt': a8w8_pt on aiter.moev2, every other call on the legacy code (AITER_MOEV2=off runs every call on the legacy code). The off runs sayAITER_MOEV2='off': every call on the legacy code. does not claimcount: 0 in everya8w8_ptlog. Any line names the reason a call stayed on legacy; report it.- GSM8K (strict-match and flexible-extract): the
a8w8_ptscore is inside, or within about ±0.01 of, the band of the two off runs. Eager scores should be close to gfx950's: about 0.62–0.63 strict. With CUDA graphs, vLLM scored lower and noisier on gfx950 (0.43–0.48) with or without aiter, so compare graph runs only with graph runs. - Throughput:
a8w8_pt/ off total tokens/s between about 0.98 and 1.05. gfx950 gave 0.99–1.006 on the 1024/256 workload and 1.00–1.05 on 128/1024. Alternate the runs (off, v2, v2, off) to cancel drift.
Comment 5: rollout gates on gfx942
The graduation criteria for each target are the comment 1–4 runs above, plus the perf gate. gfx942 has no baseline yet, so record one with legacy, then check v2 against it:
AITER_MOEV2=off python3 tests/moe_dispatch/perf_baseline.py --record # writes tests/moe_dispatch/golden/perf_gfx942.json
AITER_MOEV2=a8w8_pt python3 tests/moe_dispatch/perf_baseline.py --checkExpected:
--record: printswrote .../golden/perf_gfx942.json, with 5 gfx942 cases:dsv3_tp8_pt, thea8w8_ptcase;dsv3_tp8_blockscale,qwen3_235b_tp8_ptoken,qwen3_235b_tp4_blockscaleandqwen3_235b_tp8_bf16, which run legacy in both modes and serve as a noise check.
--check: exit 0, with noSLOWER <case> M=<m>: a -> b usorMISSINGlines (tolerance 10%).- Shorter run: add
--case dsv3_tp8_ptto both commands. - Per-machine baseline: the file is keyed by arch only, not CU count, so record and check on the same machine. Commit only the baseline you mean to keep, cu304 most likely.
Rollback and diagnosis check:
AITER_MOEV2=off AITER_MOE_EXPLAIN=1 python3 op_tests/test_moe_per_tensor_a2_init.py 2>&1 | grep "AITER_MOEV2="
AITER_MOEV2=a8w8_pt AITER_MOE_EXPLAIN=1 python3 op_tests/test_moe_2stage.py -q 1 --no-flydsl-csv 2>&1 | grep -m5 "does not claim"Expected:
- First command: prints
AITER_MOEV2='off': every call on the legacy code. - Second command: prints a reason for each kind of call
a8w8_ptrefuses, once per reason. For example,path a8w8_pt does not claim a call (swiglu_limit=7.0 clamps); the legacy code runs it. - Snapshot tooling: CPU-only and arch-independent, already covered by the comment 1 CPU tests.
Comment 6: ownership notes
These are comments and docstrings only, so there's nothing to run on gfx942.
Report back
For each target (cu304, cu80):
- the
gpu_differentialcase and problem counts, both modes; - the
gpu_suites --comparesummary and anyoff X, v2 Ylines; perf_baseline --checkoutput, plus the recordedperf_gfx942.jsonif it should be committed;- the GSM8K and throughput table for off, off2 and
a8w8_ptper config, and thedoes not claimcount.
A failed import of a built-in path module marked loading as done before re-raising. Python drops the failed module from sys.modules, but later calls skipped the import, so a caller that caught the first error and called again got a selection from an empty registry: AITER_MOEV2=on (or a path name) silently ran legacy. - aiter/moev2/paths.py: a failed import leaves _builtin_loaded false and re-raises, so the next call imports again; loading still counts as done only after every built-in PATH is registered. - A module that keeps failing now raises on every call. _select ran the import before checking for off, so the rollback would have raised too; AITER_MOEV2=off now selects nothing before loading any path module. Tests (tests/test_moev2_switch.py): - test_a_failed_builtin_import_is_retried_by_the_next_call: the first call raises, the retry selects the path; fails on the old code. - test_off_selects_nothing_without_importing_the_path_modules: off with an unimportable module selects nothing, on raises; fails with the old order. CPU: tests/test_moev2_*.py and tests/test_moe_dispatch_snapshot.py 123 passed, 1 skipped; black and ruff clean. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because unfrozen tuning inputs can destabilize dispatch snapshots, while shared baselines for distinct gfx942 targets can produce misleading performance comparisons.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
@qli88 ran the gfx942 cu80 (MI308X) half of the run book. Everything below is on that machine. Environment
Comment 1 — CI coverage
Per-suite Two differing checks showed up, both in Both are calls Neither difference reproduces in six runs, and the single Comments 2 and 3 — GPU differential
44 ok / 0 FAIL / 0 KNOWN / 0 LEGACY / 0 SKIP. The expected cu80 counts (44 and 92) both match. The two cu80-only items you could not reach on gfx950:
Comment 5 — perf gate and diagnosis
One caveat worth knowing: a first record/check pair reported Legacy re-measured 6-9% above its own recorded baseline, so the first baseline simply landed on a
Diagnosis output works. Two small run book fixes
Comment 4 — end to end (vLLM), TP1 eagerMixtral-8x7B-Instruct-v0.1 with vLLM's online per-tensor FP8 ( Every MoE call reached v2: and the GSM8K, 1319 questions, 5-shot, enforce_eager, one run with the path and two with
Not merely inside legacy's band — identical to it, on both metrics. Throughput (1024/256, 1000 prompts, alternating off / v2 / v2 / off): running, will follow. Not covered on this machine: gfx942 cu304 (no MI300X/MI325X here), and the TP2+EP and |
|
Throughput for the gfx942 cu80 run above, finishing comment 4. Same machine, same build 1024 in / 256 out, 1000 prompts
v2/legacy = 1.005 on the means, 1.0005 against the adjacent 128 in / 1024 out, 64 prompts (decode-heavy)
v2/legacy = 1.000 on the means. This workload is noisy at 64 prompts: legacy's two runs
So for gfx942 cu80 (MI308X), every item in the run book that this target can answer is green: Still open for gfx942: cu304 (no MI300X/MI325X available here), and on cu80 the TP2+EP and |
zufayu
left a comment
There was a problem hiding this comment.
Approving on the evidence below. Note I pushed the last two commits on this branch (both tests-only), so this is not an independent review of those.
What I verified on ad446d86eb:
- Legacy default path is untouched:
AITER_MOEV2unset still runs the legacy code, the dispatch snapshot is byte-identical on all four arch grids, and the call-site hook builds nothing when no path is active. - CPU differential passes over the claimed keys on all four simulated archs. This only started exercising the checkout rather than an installed
amd-aiterwheel aftere9ee06b1; before that the subprocess scripts resolvedaiterfrom site-packages. - GPU differential on gfx942 cu80: 16 of 16 cases, 0 problems, including the ASM stage-1 plus CK stage-2 rows and the FlyDSL whole-graph row that the description had listed as verified only on CPU.
python3 -m pytest -q testspasses locally.- Downstream Atom, vLLM and Windows jobs are green on
f76850c9e9;git diff f76850c9e9 ad446d86eb -- ':!tests'is empty, so the runtime those jobs exercised is byte-identical to this head. The SGLang DeepSeek-R1-MXFP4 job fails the same way onmain(a NumPy C-API / ml_dtypes ABI break in the SGLang image) and DeepSeek-V3.2 passes.
Open, and not introduced by this PR:
- The gfx942 ASM stage 1 kernel leaves roughly 12 of 512 a2 slots unwritten on some runs, and which ones varies, so two legacy runs of the same call disagree there by arbitrary amounts (one run peaked at 2.5, another at 2.1e27 in the same slot). Dynamic per-tensor a2 quant reads the whole buffer, so this reaches the scale, and it makes the GPU gate flake on gfx942 regardless of v2. Legacy and v2 allocate a2 identically, so this is pre-existing; it matters for graduating the path, not for merging it disabled.
- The four Copilot findings are fixed in the code, and the threads are resolved, but the self-review bot only counts a reply from the PR author, so it still reports them.
This approval assumes the required checks finish green on this head; at the time of writing build_aiter_wheels (3.12) is still running and nothing has failed.
|
Finishing comment 4 on gfx942 cu80 (MI308X): the remaining three vLLM configurations. Accuracy, GSM8K 1319 questions, 5-shot (one run with the path, two with
(strict-match; flexible-extract tracks it.) On TP2+EP eager the two TP1 graph scores far below eager (0.3268 vs 0.6482), but off and v2 are identical across all Throughput, 1000 prompts, alternating off / v2 / v2 / off:
TP2+EP eager first gave 0.9845 on 2+2 runs, so I added one run per mode. The full six: Legacy's third run dropped 9.6% by itself, so this workload swings much harder under EP than at TP1
gfx942 cu80 is now complete against the run book, with nothing attributable to moev2. Still |


Title:
[CI] [MoE] moev2 phases 0–2: scaffolding, legacy-parity harness, and the per-tensor fp8 path (not graduated)Summary
This PR adds
aiter/moev2, a rebuild offused_moedispatch and execution from small parts:MoeProblem);It lives next to the legacy code and takes over one group of calls (a path) at a time.
Nothing changes by default. Paths run only when explicitly enabled with
AITER_MOEV2. No path is graduated, so with the variable unset oroff, every call runs exactly the legacy code.The branch is rebased on
mainf3da4e779(71 files, +11,071/−1,588). Its 12 commits:1b5a5dfa9): scaffolding, a harness that locks in legacy behavior, and helpers moved verbatim out offused_moe.py. No behavior change.78c43ff08): the problem/plan/segment framework, plus the first path,a8w8_pt(per-tensor fp8, 2-stage). It runs only withAITER_MOEV2=a8w8_pt(oron).011c59ea1tocd99b3a68, 7 commits): claims use the runtime GPU instead of the build-time arch list, the test scripts test the checkout instead of an installedaiter, and the parity checks have more coverage.bde11a82e,d0953c56a,c1969efc8): see "Changes from the review" below.aiter/moev2/README.mdlists every new file with its purpose. It also says whether the file is permanent or removed once the migration finishes and the legacy code is retired.Motivation
Legacy dispatch and execution are one monolith:
get_2stage_cfgs,_fused_moe_implandfused_moe_2stagesserve every quant type, and kernel choice, execution details and fallbacks are intertwined. That makes it hard to change one kernel family without touching all the others. moev2 splits this into parts that can be migrated one workload family at a time. Each path claims only the calls it reproduces exactly and hands every other call back to the unchanged legacy code.How to enable and roll back
When
AITER_MOEV2is set, aiter logs the selection once at INFO, namingAITER_MOEV2=offas the rollback.Changes
Phase 0/1: scaffolding and harness (no behavior change)
aiter/moev2scaffolding:AITER_MOEV2switch (envs.py);paths.py, empty in this commit);fused_moesignature (api.py);hooks.py);dispatch/tuned.py).fused_moe.py:resolve_activation_dtype,quant_remap,get_inter_dim,fused_topk, and the torch reference MoE. Each definition is AST-identical to the one it replaces, and each is imported back intofused_moe.py, so every existingfrom aiter.fused_moe import ...still works (44 names checked).aiter/moev2never imports the legacy MoE modules. The legacy modules may import from it, andtests/test_moev2_imports.pyenforces this.fused_moe()hook: it does nothing while no path is enabled.tests/moe_dispatch, to lock in legacy behavior:get_2stage_cfgspicks for every tuned row plus a grid of untuned keys, read from frozen tuned tables;perf_gfx950.json).Phase 2: the framework and the
a8w8_ptpath (not graduated)MoeProblemround-trips the legacyget_2stage_cfgskey, so v2 and legacy can be compared key by key.dispatch/holds the kernel-name parser, the tuned lookup (with legacy's fallbacks), the resolver (legacy order, legacy log lines, legacy raises), and a default ranking table with static checks.execute/mirrors_fused_moe_implandfused_moe_2stagesstatement for statement.a8w8_ptcovers:deterministic=True, or a registered presort;swiglu_limitthat clamps (None, 0 and inf mean no clamp, as in legacy),betaorlinear_beta;AITER_ONLINE_TUNE;MOEMetadata/AsmMoeMode,get_padded_M,ck_moe_stage1,asm_stage1, the default kernel parameters, and the tuned-table reader. Each is AST-identical and imported back.RuntimeError, at the same two points, after the same log lines.hidden_statescopies.a2before dynamic per-tensor quant.op_tests/test_moe_per_tensor_a2_init.pyis added to the path's GPU suites.flat=3) tuned rows are declined.get_2stage_cfgsfeature (num_local_tokens, activation scales, fp8 input, unshuffled weights, bias, padding,doweight_stage1, Gelu, ...). A changed decision then names the exact feature responsible.Changes from the review
moe_sorting,_moe_sorting_impland their 11 other helpers and flags move verbatim intoaiter/moev2/segments/sort.py, replacing v2's partial copy.fused_moe.pyimports them back and calls the sort helpers through the module, so patchingaiter.moev2.segments.sortreaches every caller.split_tests.shandupdate_split_test_times.pyaddtests/test_moev2_*.pyandtests/test_moe_dispatch_snapshot.pyto the aiter shards. These tests simulate archs, so any GPU runner works. The GPU output differential is opt-in (AITER_MOEV2_GPU_DIFFERENTIAL=1) because some legacy kernels aren't repeatable.gpu_suites.py --compareruns a path's GPU suites withAITER_MOEV2=offand then with the path. It fails where v2 fails and legacy passes, and prints both runs'checkAllcloseoutcomes and the checks whose outcome differs.num_local_tokens, statica1/a2scales, fp8 input,output=, non-contiguous input, a pinnedblock_size_M, g1u0,swiglu_limit0 and inf (Silu, Gelu, and Mixtral's shape). Where legacy raises, v2 must raise the same error.output=is NaN-filled before each run.compare_launchesstays exact on stages, kernels, arguments, sort buffers and integer tensors. Floating-point launch tensors pass within 1 ulp or twice legacy's own run-to-run spread, so a non-repeatable legacy kernel (ASM stage 1 on gfx942 cu80) doesn't fail the gate. Non-finite values must carry the bits of one legacy run.a8w8_ptrefused every vLLM call. vLLM passesswiglu_limit=0.0, which legacy reads as no clamp.a8w8_ptnow treats None, 0 and inf as no clamp, likefused_moe_.Path.why_not(call). WithAITER_MOE_EXPLAIN=1, a call no active path claims logs each path's reason once, e.g.path a8w8_pt does not claim a call (swiglu_limit=7.0 clamps); the legacy code runs it.snapshot.py --checkand--updateprint every changed, new and missing key, and.gitattributesmarks the golden filesdiff=gzip.main: six gfx950 expert-parallel keys (E=896, top-16, SiTUv2, a4w4 and a8w4, M 1024–8192) now resolve like their non-EP calls, because of main's MXMOE-under-EP change.clear_cache()left three default-parameter caches stale;aiterinstead of the checkout;gpu_suites.py --runignored arch and GPU-count limits and skipped the shared suites;perf_baseline.py --checkpassed with no baseline;arch_simleaked its fake chip info into later contexts.aiter/moev2module, the README, the hook sites and copied legacy functions inaiter/fused_moe.py, the test harness, and the op_tests and CI scripts that touch moev2 say the code is under development, owned by @qli88, and point toaiter/moev2/README.md.kernel_bench_callablenow also receives the FlyDSL whole-graph launch, as("whole_graph", call), in addition tostage1andstage2. The parity harness compares that launch with v2's. Existing consumers look upstage1andstage2by name, so they are unaffected; whole-graph calls just stop reporting "no kernels captured".Legacy code copied, not moved
v2 never imports legacy. Reusable legacy code is moved into
aiter/moev2and imported back byfused_moe.py. This coversmoe_sorting,MOEMetadata, the stage wrappers,fused_topk, the reference MoE and the tuned-table reader, so there is one copy of each.Three parts are copied for now:
executor.run_two_stage/prologue,resolver.resolveand the ranking table. They reproduce the slices of_fused_moe_impl,fused_moe_2stagesandget_2stage_cfgsthat the porteda8w8_ptpath reaches. Those legacy functions serve every path, so they can't move until every path is ported. Their bodies are deleted at that point (phase 6.1).Until then, a drift between the copies fails a test even though it shows no merge conflict:
test_dispatch_plans_match_legacy(CPU, in CI) compares v2's plan with legacy's for every golden key;test_outputs_match_legacy(GPU) compares kernel launches and outputs;Rollout
gpu_suites.py --path <p> --compare;perf_baseline.py --check, no case more than 10% slower) against a baseline recorded on that arch. Only gfx950 has one today;Path.graduatedtakes a set of archs, so gfx950 can go before gfx942. During that release,AITER_MOEV2=<path>runs as a canary in aiter's downstream jobs, and each default flip is its own PR.Performance
Mixtral-8x7B-Instruct, vLLM online FP8 (
quantization="fp8"), vLLM 0.32.1rc1,vllm bench throughputwith random prompts, total tokens/s. Each value is the mean of two runs, alternated off/v2/v2/off on one GPU group. Before isAITER_MOEV2=off; after isAITER_MOEV2=a8w8_pt.Kernel level:
AITER_MOEV2=a8w8_pt python3 tests/moe_dispatch/perf_baseline.py --checkagainstgolden/perf_gfx950.json(recorded with legacy) exits 0: no case is more than 10% slower.Testing
MI250X: not a target (no per-tensor fp8 MoE). MI300X: not run on GPU at this head; gfx942 is covered by CPU simulation only (see "Validation and unverified scope"). GPU testing was on MI350X (gfx950).
c1969efc8)tests/test_moev2_*.py,tests/test_moe_dispatch_snapshot.py)gpu_differential.py --path a8w8_pt;--synth-table)gpu_suites.py --path a8w8_pt --compare:test_moe_2stage -q 1,test_moe_per_tensor_a2_init,test_moe_sorting,test_moe_ep,test_moe_local_expert_ids,test_moe_dp_share_expert)a8w8_pt;checkAllcloseoutcomes identical except twotest_plain_fp8_swiglu_limitlimit=7.0checks, legacy-run calls whose outcome flips between legacy runs tooa8w8_ptruns ran on v2, with the same kernel sequences as legacy; GSM8K (1319, 5-shot, strict) inside the spread of two legacy runs in 3 configs and above both in the fourth (TP2+EP graphs: 0.477 vs 0.467 / 0.448; graph mode is noisy, see Known limits)Mutation checks confirm the new tests catch real breakage:
swiglu_limittest, all sixswiglu_limit0/inf and Mixtral GPU cases fail.a2scaled by 1.3, the GPU differential fails.Documentation
The feature is opt-in and not graduated, so the user guide is unchanged.
aiter/moev2/README.mddocuments the switch, the rollback, every file and the check commands. The rollback goes into the release notes and user docs when the first path graduates.Dependencies
Breaking Changes
None for callers: with
AITER_MOEV2unset, every call runs the legacy code, and every name importable fromaiter.fused_moestill is.One change for code that patches the sort:
moe_sorting's implementation and backend flags (_moe_sorting_impl,_USE_CK_MOE_SORTING,_USE_FLYDSL_MOE_SORTING, ...) now live inaiter.moev2.segments.sort. Assigning them onaiter.fused_moeno longer reaches the sort; assign them onaiter.moev2.segments.sort. The two op_tests that did this are updated.Known limits
a8w8_ptdeclines a clampingswiglu_limit(finite and nonzero), so those calls stay on legacy.fused_moe_prepare_stage2/fused_moe_run_stage2) calls_fused_moe_impldirectly, so it runs legacy even withAITER_MOEV2set.checkAllcloselines (28 swiglu-limit checks intest_moe_2stage -q 1, 2 intest_moe_ep, 13 intest_moe_dp_share_expert). All exit 0, and they fail the same way withAITER_MOEV2off and on.PR Self-Review
Reviewed revision
c1969ef
Behavior and intent
Default behavior does not change: with
AITER_MOEV2unset oroff, every call still uses the legacyfused_moepath. The PR introduces an explicitly enableda8w8_ptpath for per-tensor FP8 two-stage MoE, and decomposes the monolithic dispatch and execution flow into a problem, feasible kernel segments, and a plan. The existing implementation is insufficient for a controlled multi-phase migration because dispatch choices, execution details and fallback boundaries are intertwined. The new framework can claim one narrowly defined workload family at a time and decline every call it cannot reproduce back to legacy. Two legacy-visible changes are mechanical: the sort's implementation moved toaiter.moev2.segments.sort(imported back), andkernel_bench_callablealso receives the whole-graph launch.Validation and unverified scope
On
c1969efc8, gfx950 (MI350X), with JIT modules rebuilt from this head and CK at the submodule commit:AITER_MOEV2_GPU_DIFFERENTIAL=1 python3 -m pytest -q tests/test_moev2_differential.py -k outputs_match: 1 passed;python3 tests/moe_dispatch/gpu_differential.py --path a8w8_pt(43 cases) and the same with--synth-table(91 cases): 0 problems;python3 tests/moe_dispatch/gpu_suites.py --path a8w8_pt --compare: exit 0, all six suites pass in both modes;AITER_MOEV2=a8w8_pt python3 tests/moe_dispatch/perf_baseline.py --check: exit 0.The vLLM runs (Mixtral-8x7B online FP8, vLLM 0.32.1rc1) ran on the review fixes before the rebase onto
mainand were not rerun after it. They found theswiglu_limit=0.0bug fixed here.Main's
tests/test_plugin_routed_ops.py::test_a_readback_under_capture_is_refused_and_takes_the_context_with_itfails the same way on cleanmain.Unverified:
AITER_MOEV2=a8w8_pt.PR-specific question
The new configuration is consumed only by workload keys that the
a8w8_ptpath claims: per-tensor FP8 weights on gfx942 or gfx950, two-stage execution, Silu or Gelu, separated gate/up, using the CK default heuristic, matching tuned CK or ASM+CK rows, or matching gfx942 FlyDSL whole-graph rows. Keys with herd routing, deterministic mode, a registered presort, a clampingswiglu_limit, beta/linear-beta, bias, padding, scatter, caller-selected activation dtypes, online tuning, unsupported tuned kernel families, or an unreproducible second lookup are declined to legacy.Unrelated shapes keep their prior selection, for these reasons:
mainitself changed;Changed op tests
op_tests/test_moe_sorting.py:set_moe_sorting_backendnow sets_USE_CK_MOE_SORTINGand_USE_FLYDSL_MOE_SORTINGonaiter.moev2.segments.sort, wheremoe_sortingnow lives. Assigned onaiter.fused_moe, the flags would no longer select the backend, and the test would silently cover only the default one. The coverage is unchanged: the same 312 sort comparisons pass before and after the move, across all three backends.op_tests/test_moe_2stage.py:test_output_buffer_contractswaps_moe_sorting_implonaiter.moev2.segments.sortfor the same reason, and a docstring names the moved_adaptive_moe_sort.op_tests/test_moe_per_tensor_a2_init.pyis unchanged; it is listed in thea8w8_ptGPU suites so its zero-fill coverage runs in both modes.