Skip to content

[CI] [MoE] moev2 phases 0–2: scaffolding, legacy-parity harness, and the per-tensor fp8 path (not graduated) - #8255

Merged
zufayu merged 13 commits into
ROCm:mainfrom
qli88:moev2_official
Nov 25, 2026
Merged

zufayu merged 13 commits into
ROCm:mainfrom
qli88:moev2_official

Conversation

@qli88

@qli88 qli88 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 of fused_moe dispatch and execution from small parts:

  • a problem description (MoeProblem);
  • segments, one per kernel family (sort, quant, CK, ASM, whole graph);
  • a plan that chains them.

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 or off, every call runs exactly the legacy code.

The branch is rebased on main f3da4e779 (71 files, +11,071/−1,588). Its 12 commits:

  1. Phase 0/1 (1b5a5dfa9): scaffolding, a harness that locks in legacy behavior, and helpers moved verbatim out of fused_moe.py. No behavior change.
  2. Phase 2 (78c43ff08): the problem/plan/segment framework, plus the first path, a8w8_pt (per-tensor fp8, 2-stage). It runs only with AITER_MOEV2=a8w8_pt (or on).
  3. Hardening from the automated review (011c59ea1 to cd99b3a68, 7 commits): claims use the runtime GPU instead of the build-time arch list, the test scripts test the checkout instead of an installed aiter, and the parity checks have more coverage.
  4. Fixes from the human review (bde11a82e, d0953c56a, c1969efc8): see "Changes from the review" below.

aiter/moev2/README.md lists 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_impl and fused_moe_2stages serve 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

AITER_MOEV2=a8w8_pt python ...   # per-tensor fp8 calls go through moev2
AITER_MOEV2=on      python ...   # every registered path (only a8w8_pt today)
AITER_MOEV2=off     python ...   # rollback: every call on the legacy code (same as unset today)
AITER_MOE_EXPLAIN=1              # log the plan v2 picks, and why a path refuses a call

When AITER_MOEV2 is set, aiter logs the selection once at INFO, naming AITER_MOEV2=off as the rollback.

Changes

Phase 0/1: scaffolding and harness (no behavior change)

  • aiter/moev2 scaffolding:
    • the AITER_MOEV2 switch (envs.py);
    • the path registry (paths.py, empty in this commit);
    • the v2 entry point with the legacy fused_moe signature (api.py);
    • test hooks (hooks.py);
    • a cache helper (dispatch/tuned.py).
  • Helpers moved from 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 into fused_moe.py, so every existing from aiter.fused_moe import ... still works (44 names checked).
  • Import rule: aiter/moev2 never imports the legacy MoE modules. The legacy modules may import from it, and tests/test_moev2_imports.py enforces this.
  • fused_moe() hook: it does nothing while no path is enabled.
  • tests/moe_dispatch, to lock in legacy behavior:
    • a public-name inventory;
    • CPU arch simulation (gfx942, gfx942_cu80, gfx950, gfx1201);
    • a golden dispatch snapshot: what legacy get_2stage_cfgs picks for every tuned row plus a grid of untuned keys, read from frozen tuned tables;
    • a GPU suite list per planned path;
    • a perf baseline (perf_gfx950.json).

Phase 2: the framework and the a8w8_pt path (not graduated)

  • Framework:
    • MoeProblem round-trips the legacy get_2stage_cfgs key, so v2 and legacy can be compared key by key.
    • Segments declare what they can run. A problem with anything no segment declares is rejected.
    • 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_impl and fused_moe_2stages statement for statement.
  • Path a8w8_pt covers:
    • per-tensor fp8 weights on gfx942 and gfx950, Silu or Gelu, separated gate/up;
    • the CK default heuristic;
    • tuned CK and ASM+CK rows;
    • FlyDSL gfx942 whole-graph rows.
  • It declines (legacy runs the call):
    • herd routing, deterministic=True, or a registered presort;
    • a swiglu_limit that clamps (None, 0 and inf mean no clamp, as in legacy), beta or linear_beta;
    • bias, padding or scatter;
    • caller-chosen activation dtypes, or AITER_ONLINE_TUNE;
    • tuned rows for kernel families it doesn't own (1-stage, post-reduction);
    • a call whose post-sort second lookup would raise, or that v2 can't reproduce.
  • More helpers moved verbatim: output-buffer validation, 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.
  • Upstream changes mirrored. These upstream changes touch code that v2 copies rather than calls, so git showed no conflict. Each is mirrored in v2 and has tests:
  • Harness additions:
    • CPU differential: v2's plan and log lines equal legacy's for every key the path claims;
    • key round-trip checks;
    • ranking checks;
    • GPU differential: same kernels, inputs and outputs as legacy;
    • feature-variant keys in the snapshot. For per-tensor keys, the same call is added with one extra get_2stage_cfgs feature (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

  • One copy of the sort. Legacy moe_sorting, _moe_sorting_impl and their 11 other helpers and flags move verbatim into aiter/moev2/segments/sort.py, replacing v2's partial copy. fused_moe.py imports them back and calls the sort helpers through the module, so patching aiter.moev2.segments.sort reaches every caller.
  • CI:
    • split_tests.sh and update_split_test_times.py add tests/test_moev2_*.py and tests/test_moe_dispatch_snapshot.py to 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 --compare runs a path's GPU suites with AITER_MOEV2=off and then with the path. It fails where v2 fails and legacy passes, and prints both runs' checkAllclose outcomes and the checks whose outcome differs.
  • GPU differential:
    • new cases for num_local_tokens, static a1/a2 scales, fp8 input, output=, non-contiguous input, a pinned block_size_M, g1u0, swiglu_limit 0 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_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, 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.
  • Bug fixed, 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: Path.why_not(call). With AITER_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.
  • Snapshots:
    • snapshot.py --check and --update print every changed, new and missing key, and .gitattributes marks the golden files diff=gzip.
    • The gzip header carries no file name or mtime, so the bytes depend on the content only.
    • Refreshed from 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.
  • Fixes from the review:
    • concurrent first calls could leave the enabled paths off;
    • clear_cache() left three default-parameter caches stale;
    • the scripts could test an installed aiter instead of the checkout;
    • gpu_suites.py --run ignored arch and GPU-count limits and skipped the shared suites;
    • perf_baseline.py --check passed with no baseline;
    • arch_sim leaked its fake chip info into later contexts.
  • Ownership notes: every aiter/moev2 module, the README, the hook sites and copied legacy functions in aiter/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 to aiter/moev2/README.md.
  • Kernel-bench hook: kernel_bench_callable now also receives the FlyDSL whole-graph launch, as ("whole_graph", call), in addition to stage1 and stage2. The parity harness compares that launch with v2's. Existing consumers look up stage1 and stage2 by 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/moev2 and imported back by fused_moe.py. This covers moe_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.resolve and the ranking table. They reproduce the slices of _fused_moe_impl, fused_moe_2stages and get_2stage_cfgs that the ported a8w8_pt path 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;
  • the dispatch snapshot goldens pin legacy's behavior.

Rollout

  • Graduation criteria. A path graduates per arch, and per CU count where the tuned tables differ (gfx942 cu304 and cu80 are separate targets), once all of these pass on that hardware:
    • the CPU differential at 0 problems (in CI);
    • the GPU differential at 0 problems;
    • gpu_suites.py --path <p> --compare;
    • the perf gate (perf_baseline.py --check, no case more than 10% slower) against a baseline recorded on that arch. Only gfx950 has one today;
    • an end-to-end vLLM run with a model that hits the path: every call on v2, GSM8K within legacy's own run-to-run spread, throughput within noise.
  • Opt-in period. After that, the path stays opt-in for at least one aiter release before its default flips on that arch. Path.graduated takes 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.
  • Retiring legacy. The legacy code stays until every path has graduated and one release has shipped with it as the default.

Performance

Mixtral-8x7B-Instruct, vLLM online FP8 (quantization="fp8"), vLLM 0.32.1rc1, vllm bench throughput with random prompts, total tokens/s. Each value is the mean of two runs, alternated off/v2/v2/off on one GPU group. Before is AITER_MOEV2=off; after is AITER_MOEV2=a8w8_pt.

Hardware Workload/configuration Before After Change
MI350X (gfx950) 1000 prompts, 1024 in / 256 out, TP1 eager 34,728 34,366 −1.0%
MI350X (gfx950) same, TP1, torch.compile + CUDA graphs 34,850 35,044 +0.6%
MI350X (gfx950) same, TP2 + EP, eager 35,060 35,004 −0.2%
MI350X (gfx950) same, TP2 + EP, graphs 35,789 35,792 0.0%
MI350X (gfx950) 64 prompts, 128 in / 1024 out, TP1 eager 2,045 2,146 +5.0%
MI350X (gfx950) same, TP1, graphs 4,981 4,982 0.0%
MI350X (gfx950) same, TP2 + EP, eager 2,075 2,116 +2.0%
MI350X (gfx950) same, TP2 + EP, graphs 6,208 6,218 +0.2%

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

Testing

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

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).

Check (head c1969efc8) Result
CPU tests in CI (tests/test_moev2_*.py, tests/test_moe_dispatch_snapshot.py) 121 passed, 1 skipped (the opt-in GPU case)
Dispatch snapshot, 4 archs 117,166 keys identical
CPU differential, 4 archs 23,926 claimed keys (gfx942 7,072, gfx942_cu80 9,782, gfx950 7,072), 0 problems
Key checks / ranking checks 107,572 keys / 29,424 keys, 0 problems
GPU differential, gfx950 (gpu_differential.py --path a8w8_pt; --synth-table) 43 cases / 91 cases, 0 problems; opt-in pytest 1 passed
GPU suites, gfx950 (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) all 6 pass with off and with a8w8_pt; checkAllclose outcomes identical except two test_plain_fp8_swiglu_limit limit=7.0 checks, legacy-run calls whose outcome flips between legacy runs too
vLLM end to end, gfx950 (Mixtral-8x7B online FP8, TP1 and TP2+EP, eager and graphs) every MoE call in the a8w8_pt runs 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)
black, ruff clean

Mutation checks confirm the new tests catch real breakage:

  • Without the a2 zero-fill, all 4 a2_init cases fail under v2.
  • Without the gfx950 raise, the differential reports 1,088 problems, all in the feature-variant keys.
  • With the old swiglu_limit test, all six swiglu_limit 0/inf and Mixtral GPU cases fail.
  • With v2's a2 scaled by 1.3, the GPU differential fails.

Documentation

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

The feature is opt-in and not graduated, so the user guide is unchanged. aiter/moev2/README.md documents 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

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

Breaking Changes

None for callers: with AITER_MOEV2 unset, every call runs the legacy code, and every name importable from aiter.fused_moe still 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 in aiter.moev2.segments.sort. Assigning them on aiter.fused_moe no longer reaches the sort; assign them on aiter.moev2.segments.sort. The two op_tests that did this are updated.

Known limits

  • a8w8_pt declines a clamping swiglu_limit (finite and nonzero), so those calls stay on legacy.
  • The public two-stage API (fused_moe_prepare_stage2 / fused_moe_run_stage2) calls _fused_moe_impl directly, so it runs legacy even with AITER_MOEV2 set.
  • Pre-existing failures, unchanged by this PR: on gfx950, the GPU suites log 43 failed checkAllclose lines (28 swiglu-limit checks in test_moe_2stage -q 1, 2 in test_moe_ep, 13 in test_moe_dp_share_expert). All exit 0, and they fail the same way with AITER_MOEV2 off and on.
  • Legacy nondeterminism: CK stage 2 accumulates with atomics, and some ASM stage 1 kernels aren't repeatable. The GPU differential tolerates only the spread measured between two legacy runs.
  • With CUDA graphs, Mixtral GSM8K scores lower and varies run to run on this vLLM build, with aiter's MoE on or off and with aiter off. This is a vLLM issue, not this PR.

PR Self-Review

Reviewed revision

c1969ef

Behavior and intent

Default behavior does not change: with AITER_MOEV2 unset or off, every call still uses the legacy fused_moe path. The PR introduces an explicitly enabled a8w8_pt path 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 to aiter.moev2.segments.sort (imported back), and kernel_bench_callable also 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:

  • lint is clean;
  • the CPU tests that now run in CI pass, and the snapshot, differential, key and ranking checks show 0 problems;
  • 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 main and were not rerun after it. They found the swiglu_limit=0.0 bug fixed here.

Main's tests/test_plugin_routed_ops.py::test_a_readback_under_capture_is_refused_and_takes_the_context_with_it fails the same way on clean main.

Unverified:

  • gfx942 on GPU at this head, both cu304 (MI300X/MI325X) and cu80 (MI308X). The cu80-only cases, the FlyDSL whole-graph row and the ASM stage-1 DeepSeek-V3 shapes, have run in CPU simulation only.
  • There is no gfx942 perf baseline yet.
  • SGLang and ATOM end-to-end runs with AITER_MOEV2=a8w8_pt.

PR-specific question

The new configuration is consumed only by workload keys that the a8w8_pt path 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 clamping swiglu_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:

  • the feature is opt-in;
  • the legacy snapshot is unchanged on all four architecture grids, apart from the six gfx950 keys main itself changed;
  • the feature-variant keys exercise each exclusion independently;
  • the differential requires every claimed key to match the legacy plan, while every declined key continues through the unchanged legacy path.

Changed op tests

  • op_tests/test_moe_sorting.py: set_moe_sorting_backend now sets _USE_CK_MOE_SORTING and _USE_FLYDSL_MOE_SORTING on aiter.moev2.segments.sort, where moe_sorting now lives. Assigned on aiter.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_contract swaps _moe_sorting_impl on aiter.moev2.segments.sort for the same reason, and a docstring names the moved _adaptive_moe_sort.

op_tests/test_moe_per_tensor_a2_init.py is unchanged; it is listed in the a8w8_pt GPU suites so its zero-fill coverage runs in both modes.

@qli88
qli88 marked this pull request as ready for review November 19, 2026 04:55
@qli88
qli88 requested review from a team and a balanced review from Copilot November 19, 2026 04:55
@zufayu
zufayu requested a review from valarLip November 19, 2026 04:59
@zufayu zufayu self-assigned this Nov 19, 2026

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

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

Comment thread tests/moe_dispatch/differential.py Resolved
Comment thread tests/moe_dispatch/differential.py Resolved
Comment thread tests/moe_dispatch/gpu_differential.py Resolved
Comment thread tests/moe_dispatch/gpu_suites.py Resolved
Comment thread tests/moe_dispatch/record.py Resolved
zufayu

This comment was marked as abuse.

@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
zufayu
zufayu previously approved these changes Nov 19, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
@ROCm ROCm deleted a comment from aiter-bot Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:32
zufayu
zufayu previously approved these changes Nov 19, 2026
@zufayu zufayu added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 19, 2026

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.

Comment thread tests/moe_dispatch/gpu_differential.py Resolved
Comment thread tests/moe_dispatch/arch_sim.py Resolved
Comment thread tests/moe_dispatch/gpu_differential.py Resolved
Comment thread tests/moe_dispatch/perf_baseline.py Resolved
Comment thread tests/moe_dispatch/record.py Resolved
Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:53
zufayu
zufayu previously approved these changes Nov 19, 2026
zufayu and others added 4 commits November 25, 2026 01:15
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]>
@qli88

qli88 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@Bernard-Liu

Reply to comment 1 (tests not run by CI)

Thanks, confirmed: split_tests.sh --test-type aiter listed op_tests/ only and the shard list
reaches aiter_test.sh through AITER_TEST, so tests/ was never scanned; the CPU pre-check has
no built aiter, which these tests import.

Fixed in c1969ef (the branch is now rebased onto main f3da4e7):

  • split_tests.sh adds tests/test_moev2_*.py and tests/test_moe_dispatch_snapshot.py to the
    aiter shards. They run in the standard job's built container through aiter_test.sh's existing
    tests/test_*.py pytest branch (unit tests, snapshot check, CPU differential). They simulate
    arches, so they need no particular GPU.
  • test_outputs_match_legacy (the GPU differential) skips unless AITER_MOEV2_GPU_DIFFERENTIAL=1,
    so it stays out of CI.
  • gpu_suites.py gains --compare: one command 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 (a failed check does not always fail its script).

Run locally on c1969ef: MI350X (gfx950, 256 CUs), torch 2.13.0+rocm, a clean worktree with every
JIT module rebuilt from this head and CK at the PR's submodule commit.

Command Result
python3 -m pytest -q <file> for each CI file, as aiter_test.sh runs them all exit 0; the 7 moev2 files: 121 passed, 1 skipped (the gated GPU case)
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, 0 problems
same with --synth-table 91 cases, 0 problems
python3 tests/moe_dispatch/gpu_suites.py --path a8w8_pt --compare all 6 suites pass with off and with a8w8_pt; checkAllclose outcomes identical except two checks in test_plain_fp8_swiglu_limit at limit=7.0, which legacy runs in both modes (per-token is not this path; a8w8_pt declines a finite clamp) and which flip between legacy runs too
AITER_MOEV2=a8w8_pt python3 tests/moe_dispatch/perf_baseline.py --check exit 0: no case more than 10% slower than golden/perf_gfx950.json

Not covered: gfx942. The cu80 FlyDSL whole-graph and ASM differential cases need a gfx942 cu80,
which I don't have. If someone with one can run the GPU differential and
gpu_suites.py --path a8w8_pt --compare, I'll add the results here.

Reply to comment 2 (coverage gaps in the GPU differential)

Thanks, added in c1969ef. gpu_differential.py cases can now name a variant, each run at 16 and
512 tokens: static a1_scale, static a1_scale + a2_scale, fp8 input (hidden_states
pre-quantized with a1_scale and dtype=), output=, non-contiguous hidden_states,
block_size_M pinned to 32 and to 128, g1u0 weights, and num_local_tokens (bf16 and fp8 input,
with expert parallelism at 512 tokens). With output=, the harness fills the shared buffer with
NaN before each run and requires it back as the result, so neither side can pass on the other's
writes.

Two findings:

  • num_local_tokens with per-tensor fp8 raises in legacy's 2-stage path for any input dtype:
    per_tensor_quant_hip, used before GEMM2 (and before GEMM1 from bf16), takes no row count
    ("num_rows is not supported for per_tensor_quant_hip"). v2 claims these calls and raises the
    same error; those cases check that v2 runs the call and raises legacy's exact error.
  • g1u0 matches legacy (same CK kernels), but legacy's CK output for g1u0 is itself wrong. That is
    a legacy bug, tracked as a behavior change to fix on both sides together.

On MI350X (gfx950): 43 cases, 0 problems (91 with --synth-table). Not run on gfx942.

Reply to comment 3 (flakiness of the GPU differential)

Agreed, changed in c1969ef. compare_launches stays exact on stages, kernel functions,
non-tensor arguments, dtypes and shapes, the sort buffers (sorted IDs, expert blocks, sorted
weights) and every integer tensor. Floating-point launch tensors (activations, a1/a2, scales,
fp8 included) pass within 1 ulp of their own dtype at each element's magnitude, or within twice
what the same argument differs between legacy's two runs, measured over the values finite in both.
run_differential already made that second legacy run for the output's noise floor; its launches
now feed the comparison, so a non-repeatable ASM stage 1 is measured rather than assumed. Where a
value is non-finite, v2 must carry the bits of one of legacy's runs.

New CPU tests cover the rules (1 ulp passes; 1.5x fails unless legacy's own spread covers it;
sorted IDs and block_m stay exact; inf vs NaN fails; bit-identical NaNs pass; a v2 NaN where legacy
is finite fails even when legacy's runs disagree elsewhere). On MI350X (gfx950), scaling v2's
stage-2 input by 1.3 in a mutation run fails both cases tried; all 43 cases pass otherwise. I don't
have a gfx942 cu80 to rerun the DeepSeek-V3 ASM cases. One residual: a race that hits v2's run but
neither legacy run would still be reported.

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
per-tensor FP8 (quantization="fp8"), vLLM 0.32.1rc1, AITER_MOEV2=off (twice) against
a8w8_pt, in eager mode and with torch.compile plus CUDA graph capture, at TP1 and at TP2 with
expert parallelism.

This run found a bug: vLLM passes swiglu_limit=0.0 ("no clamp") on every call, and
a8w8_pt.claims declined it, so no vLLM call reached v2. Fixed in c1969ef (None, 0 and inf all
mean no clamp, as in legacy), with GPU differential cases for swiglu_limit 0 and inf and for the
Mixtral shape; they fail without the fix.

With the fix, every MoE call in the a8w8_pt runs ran on v2 (graph capture and EP included). The
kernel launch sequences match legacy's on every call both runs recorded. GSM8K (1319, 5-shot) is
within legacy's own run-to-run spread in all four configs. Throughput (vllm bench throughput) is
between 0.99x and 1.05x of legacy.

Not covered: gfx942 cu304 (no MI300X/MI325X available to us) or any gfx942 GPU, and SGLang.
CUDA-graph mode scores lower than eager on this vLLM build whether aiter is on or off, so that is
a vLLM issue, unrelated to this PR.

Reply to comment 5 (gradual rollout plan)

Graduation criteria. A path graduates per arch, and per CU count where the tuned tables differ
(gfx942 cu304 and cu80 are separate targets), once all of these pass on that hardware:

  • the CPU differential at 0 problems (in CI);
  • the GPU differential at 0 problems;
  • gpu_suites.py --path <p> --compare: no suite that passes with off fails with the path, and
    the checkAllclose outcomes it reports are explained;
  • the perf gate (perf_baseline.py --check, no case more than 10% slower) against a baseline
    recorded on that arch. Only gfx950 has one today;
  • an end-to-end vLLM run with a model that hits the path: every call on v2, kernel launch sequences
    equal legacy's, GSM8K within legacy's own run-to-run spread, throughput within noise.

After that, the path stays opt-in for at least one aiter release before its default flips on that
arch. Path.graduated takes a set of archs, so gfx950 can go before gfx942.

Staged enablement. During the opt-in release, AITER_MOEV2=<path> runs as a canary in aiter's
downstream jobs, starting with a vLLM entry for a per-tensor FP8 model (the current entries use
other formats). We'll ask vLLM, SGLang and ATOM to run their nightlies with it too. Each default
flip is its own PR, per path and arch. The legacy code stays until every path has graduated and one
release has shipped with it as the default.

Rollback and diagnosis. AITER_MOEV2=off is the rollback. It is documented in
aiter/moev2/README.md, and it will go into the release notes and user-facing docs when the first
path graduates. aiter now logs the selection once at INFO, naming the rollback. AITER_MOE_EXPLAIN
wasn't enough: it explained only the calls a path took, and our end-to-end run found vLLM's
swiglu_limit=0.0 kept every call off v2 with nothing logged. Fixed in c1969ef: each path reports
why it refuses a call (Path.why_not), and AITER_MOE_EXPLAIN=1 logs that once per reason, e.g.
"path a8w8_pt does not claim a call (swiglu_limit=0.0 clamps)".

Snapshots. Uncompressed they're 7-9 MB per arch (about 33 MB), more than GitHub shows as a
diff, so storing them uncompressed wouldn't make them reviewable there. We've kept gzip and made the
key-level diff the review artifact: snapshot.py --check prints every changed, new and missing key
with old and new values, and --update prints the same against the files it replaces, for the PR
description. The files are written with no name or mtime in the gzip header, so their bytes depend
on their content only. .gitattributes marks them for a local gzip -dc textconv. Merge conflicts
are resolved by rerunning --update.

Whole-graph hook: added to the PR description.

Reply to comment 6 (ownership notes)

Done in c1969ef. Every module under aiter/moev2/ has the banner in its docstring. The helpers
moved from fused_moe.py (and the shared functions in dispatch/tuned.py and
segments/{asm,ck,sort}.py) instead say they are shared with the legacy path and re-exported from
aiter.fused_moe: changes must keep legacy behavior (python tests/moe_dispatch/snapshot.py --check) and should loop in the moev2 owners. aiter/moev2/README.md starts with a "Status /
ownership" section listing the owner, what to coordinate, the shared helpers, the copied legacy
code and the check commands.

In aiter/fused_moe.py, all the hook sites you listed are marked: the import block, both hooks,
get_cfg_2stages, the default-table and cache_clear block, and the whole_graph record.
_fused_moe_impl, fused_moe_2stages and get_2stage_cfgs have notes naming where v2 keeps the
copy (execute/executor.py, api.py, dispatch/resolver.py, dispatch/ranking.py), asking for
changes to be mirrored or coordinated and then checked with tests/moe_dispatch. moe_sorting
needs no copy note: it now lives only in aiter/moev2/segments/sort.py and legacy imports it.

The test harness (tests/moe_dispatch/, tests/test_moev2_*.py,
tests/test_moe_dispatch_snapshot.py) is marked, and tests/moe_dispatch/__init__.py explains how
to regenerate the golden snapshots. Beyond your list, I also marked the two op_tests that patch
moev2 module globals (test_moe_sorting.py, test_moe_2stage.py) and the CI scripts that list the
moev2 suite (split_tests.sh, update_split_test_times.py). Nothing else in the repo imports
aiter.moev2.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The 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.

1 open issue

Review effort: Balanced

@qli88

qli88 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@zufayu this is the run book on gfx942

PR 8255 (moev2 a8w8_pt) on gfx942: commands and expected results

Head: c1969efc8. So far these have run only on gfx950 (MI350X).

Run everything on both gfx942 targets. Their tuned tables differ, so they are separate graduation targets:

  • cu304: MI300X / MI325X;
  • cu80: MI308X. Only this target has the FlyDSL whole-graph case and the ASM stage-1 DeepSeek-V3 shapes, so comments 3 and 5 depend on it.

Use an idle GPU; the perf and throughput numbers are meaningless under contention.

0. Setup (once per machine)

git fetch origin moev2_official && git checkout c1969efc8
git submodule update --init 3rdparty/composable_kernel   # CK must be at the PR's commit, f93c029
rm -f aiter/jit/*.so          # stale prebuilt modules cause false failures; JIT rebuilds from this head
unset AITER_JIT_DIR           # or point it at an empty directory
export PYTHONPATH=$PWD HIP_VISIBLE_DEVICES=0 AITER_TUNED_OP_BENCH_CSV=
python3 -c "from aiter.jit.utils.chip_info import get_gfx_runtime, get_cu_num; print(get_gfx_runtime(), get_cu_num())"

Expected: gfx942 304 on MI300X/MI325X, gfx942 80 on MI308X. The first GPU command below compiles the JIT modules, which takes a while.

Comment 1: CI coverage

for f in tests/test_moev2_*.py tests/test_moe_dispatch_snapshot.py; do python3 -m pytest -q "$f" || echo "FAILED: $f"; done
AITER_MOEV2_GPU_DIFFERENTIAL=1 python3 -m pytest -q tests/test_moev2_differential.py -k outputs_match
python3 tests/moe_dispatch/gpu_suites.py --path a8w8_pt --compare --log-dir suites_gfx942_cu$CU

Set CU to 304 or 80, or just name the log directory by hand.

Expected:

  • The 7 CI files: each exits 0, with 121 passed and 1 skipped in total. The skipped case is the opt-in GPU test. These tests simulate archs on CPU, so the result doesn't depend on the GPU, and no FAILED: lines are printed.
  • Opt-in GPU pytest: 1 passed.
  • gpu_suites --compare: exit 0, and no FAILED: or SKIPPED lines (all six a8w8_pt suites run on gfx942 with one GPU). Each of the six suites prints off pass, v2 pass, then a line checkAllclose: off <counts>; v2 <counts> with the same counts in both modes.
    • off X, v2 Y lines may appear only for calls v2 doesn't claim, which are noise. On gfx950 that was two test_plain_fp8_swiglu_limit ... limit=7.0 checks.
    • Any other differing check is a finding. Rerun that suite under off alone to see whether legacy flips by itself.
    • Pre-existing failed checks that appear in both modes are not caused by this PR. On gfx950 there were 43, and the suites still exit 0.

Comments 2 and 3: GPU differential coverage, and tolerance for non-repeatable kernels

python3 tests/moe_dispatch/gpu_differential.py --path a8w8_pt
python3 tests/moe_dispatch/gpu_differential.py --path a8w8_pt --synth-table

Expected:

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. A FAIL on one run only, naming an a2 or 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 repeatable FAIL is 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=True to lm_eval's model_args, or --enforce-eager for 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, with HIP_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_*.log

Expected:

  • 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 say AITER_MOEV2='off': every call on the legacy code.
  • does not claim count: 0 in every a8w8_pt log. Any line names the reason a call stayed on legacy; report it.
  • GSM8K (strict-match and flexible-extract): the a8w8_pt score 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 --check

Expected:

  • --record: prints wrote .../golden/perf_gfx942.json, with 5 gfx942 cases:
    • dsv3_tp8_pt, the a8w8_pt case;
    • dsv3_tp8_blockscale, qwen3_235b_tp8_ptoken, qwen3_235b_tp4_blockscale and qwen3_235b_tp8_bf16, which run legacy in both modes and serve as a noise check.
  • --check: exit 0, with no SLOWER <case> M=<m>: a -> b us or MISSING lines (tolerance 10%).
  • Shorter run: add --case dsv3_tp8_pt to 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_pt refuses, 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_differential case and problem counts, both modes;
  • the gpu_suites --compare summary and any off X, v2 Y lines;
  • perf_baseline --check output, plus the recorded perf_gfx942.json if it should be committed;
  • the GSM8K and throughput table for off, off2 and a8w8_pt per config, and the does not claim count.

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because 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

@zufayu

zufayu commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@qli88 ran the gfx942 cu80 (MI308X) half of the run book. Everything below is on that machine.

Environment

  • head 729c27b (one commit past the run book's c1969efc8), CK submodule f93c029e
  • get_gfx_runtime(), get_cu_num() -> gfx942 80; torch 2.9.1+git8907517, ROCm 7.0.0
  • stale aiter/jit/*.so cleared before the first run, as the run book says

Comment 1 — CI coverage

check result
the 7 CPU files 123 passed, 1 skipped, no FAILED: lines
opt-in GPU pytest (AITER_MOEV2_GPU_DIFFERENTIAL=1 ... -k outputs_match) 1 passed
gpu_suites.py --path a8w8_pt --compare exit 0, all six suites off pass, v2 pass, no FAILED:/SKIPPED:

Per-suite checkAllclose, identical counts in both modes:

test_moe_2stage           off 18 failed, 12 passed, 20 warning;  v2 18 failed, 12 passed, 20 warning
test_moe_per_tensor_a2_init  off none; v2 none
test_moe_sorting          off 4264 passed; v2 4264 passed
test_moe_ep               off 9 passed; v2 9 passed
test_moe_local_expert_ids off none; v2 none
test_moe_dp_share_expert  off 13 failed; v2 13 failed

Two differing checks showed up, both in test_moe_2stage:

off passed, v2 warning:  fused_moe QuantType.per_Token  limit=7.0
off warning, v2 passed:  fused_moe QuantType.per_Tensor limit=7.0

Both are calls a8w8_pt does not claim, so legacy executes them in either mode, and the
why_not output below names them explicitly. I then ran the suite three times under off
and three times under a8w8_pt:

per_Tensor limit=7.0   off [w w w] [w w w] [w w w]    v2 [w w w] [w w w] [w w w]
per_Token  limit=7.0   off [P w w] [w w w] [w w w]    v2 [w w w] [w w w] [w w w]

Neither difference reproduces in six runs, and the single passed is on the legacy side,
so legacy flips by itself here. Same shape as the two limit=7.0 checks you saw on gfx950.

Comments 2 and 3 — GPU differential

run result
gpu_differential.py --path a8w8_pt gfx942 cu80 torch 2.9.1+git8907517: 44 cases -> 0 problems, exit 0
--synth-table synthesized 127 per-tensor rows for gfx942 cu80, 92 cases -> 0 problems, exit 0

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:

  • ASM stage 1, DeepSeek-V3 (7168/256, 256 experts, top 8): 64, 1024 and 4096 tokens
    all ok on the first run, no reruns needed. The new tolerance (1 ulp, or twice legacy's
    own spread) holds on the non-repeatable kernel.
  • FlyDSL whole-graph row (1, 4096, 192, 192, 8, 'Silu', ...): ok, and the log confirms it
    selected impl__flydsl_gfx942__16_16_16_False:default:0.

Comment 5 — perf gate and diagnosis

perf_baseline.py --record under off, then --check under a8w8_pt: RECORD_RC=0, CHECK_RC=0,
no SLOWER or MISSING lines. All 5 gfx942 cases present.

One caveat worth knowing: a first record/check pair reported
SLOWER dsv3_tp8_pt M=1: 72.7 -> 80.9 us. It is not a regression. Repeating the case three times
in each mode:

M=1 (us)   baseline(record) 72.67
           legacy x3        77.16  77.36  78.99
           v2     x3        74.91  75.47  76.87      <- faster than all three legacy runs

Legacy re-measured 6-9% above its own recorded baseline, so the first baseline simply landed on a
fast outlier. Comparing the two sets directly, v2/legacy by median is
M=1 0.976, 16 0.999, 64 1.001, 256 0.998, 1024 0.998, 4096 1.000, 16384 1.001 — within +-0.3%
everywhere, and 2.4% faster at M=1.

dsv3_tp8_pt looks bimodal at small M on this machine (M=256 samples cluster near 595 and near 642;
the two baselines caught one cluster each), so a gfx942 baseline probably should not be committed
from a single --record.

Diagnosis output works. why_not prints each refusal once:

path a8w8_pt does not claim a call (quant_type QuantType.No); the legacy code runs it
path a8w8_pt does not claim a call (quant_type QuantType.per_128x128); the legacy code runs it
path a8w8_pt does not claim a call (quant_type QuantType.per_Token); the legacy code runs it
path a8w8_pt does not claim a call (swiglu_limit=1.0 clamps); the legacy code runs it
path a8w8_pt does not claim a call (swiglu_limit=7.0 clamps); the legacy code runs it

Two small run book fixes

  1. The rollback line check prints nothing as written. op_tests/test_moe_per_tensor_a2_init.py
    runs pytest.main() from __main__, which captures stdout. With
    python3 -m pytest -q op_tests/test_moe_per_tensor_a2_init.py -s it appears:
    [aiter.moe] AITER_MOEV2='off': every call on the legacy code. The feature is fine; the command
    needs -s.
  2. The CPU expectation is now 123 passed, not 121 — 729c27b adds the two switch tests
    (your own commit message says 123).

Comment 4 — end to end (vLLM), TP1 eager

Mixtral-8x7B-Instruct-v0.1 with vLLM's online per-tensor FP8 (quantization=fp8),
vLLM 0.16.0rc1.dev88+ge535d90de.rocm700 — note this is a different vLLM from your
0.32.1rc1, so absolute numbers aren't directly comparable with the gfx950 run; every
comparison below is v2 against legacy on the same build.

Every MoE call reached v2:

AITER_MOEV2='a8w8_pt': a8w8_pt on aiter.moev2, every other call on the legacy code
grep -c "does not claim"  ->  0

and the off runs print AITER_MOEV2='off': every call on the legacy code.

GSM8K, 1319 questions, 5-shot, enforce_eager, one run with the path and two with off:

run flexible-extract strict-match
off (1) 0.6528 0.6482
off (2) 0.6528 0.6482
a8w8_pt 0.6528 0.6482

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
CUDA-graph configurations. One environment note unrelated to the PR: any vllm command on this
box dies in load_general_plugins() because an installed ATOM vLLM plugin imports
resolve_block_hashes, which this vLLM doesn't have; I ran with VLLM_PLUGINS="".

@zufayu

zufayu commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Throughput for the gfx942 cu80 run above, finishing comment 4. Same machine, same build
(vLLM 0.16.0rc1.dev88+ge535d90de.rocm700), TP1, --enforce-eager, alternating
off / v2 / v2 / off to cancel drift.

1024 in / 256 out, 1000 prompts

run total tokens/s
off (a) 7552.90
a8w8_pt (b) 7556.52
a8w8_pt (c) 7556.47
off (d) 7482.04

v2/legacy = 1.005 on the means, 1.0005 against the adjacent off run. The two v2 runs
land within 0.001% of each other, while legacy's own two runs differ by 0.94% — the last run
drifted down, which is what the alternation is there to expose.

128 in / 1024 out, 64 prompts (decode-heavy)

run total tokens/s
off (a) 1290.39
a8w8_pt (b) 1307.94
a8w8_pt (c) 1261.98
off (d) 1279.28

v2/legacy = 1.000 on the means. This workload is noisy at 64 prompts: legacy's two runs
differ by 0.87% and v2's by 3.6%, so the per-run extremes span 0.978-1.022. The means are
effectively identical; I'd not read anything into the spread at this sample size.

grep -c "does not claim" is 0 in all four v2 throughput runs, as it was in the accuracy run.

So for gfx942 cu80 (MI308X), every item in the run book that this target can answer is green:
the CPU suite in CI, the GPU differential (44 and 92 cases, 0 problems, including the ASM stage-1
DeepSeek-V3 shapes and the cu80-only FlyDSL whole-graph row), gpu_suites --compare, the perf gate,
and the vLLM end-to-end accuracy and throughput. I found nothing attributable to moev2.

Still open for gfx942: cu304 (no MI300X/MI325X available here), and on cu80 the TP2+EP and
CUDA-graph vLLM configurations, which I can run next if they're wanted.

@zufayu zufayu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_MOEV2 unset 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-aiter wheel after e9ee06b1; before that the subprocess scripts resolved aiter from 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 tests passes 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 on main (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.

@zufayu

zufayu commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Finishing comment 4 on gfx942 cu80 (MI308X): the remaining three vLLM configurations.
Same machine and build as my two comments above (vLLM 0.16.0rc1.dev88, Mixtral-8x7B-Instruct
with online per-tensor FP8). Congrats on the merge — posting this so the cu80 half of the run book
is on the record for the graduation criteria.

Accuracy, GSM8K 1319 questions, 5-shot (one run with the path, two with off):

configuration off (1) off (2) a8w8_pt verdict
TP1 eager 0.6482 0.6482 0.6482 identical
TP1 graph 0.3268 0.3268 0.3268 identical
TP2+EP eager 0.6406 0.6406 0.6444 see below
TP2+EP graph 0.5519 0.5481 0.5550 0.0031 past the band, well inside +-0.01

(strict-match; flexible-extract tracks it.)

On TP2+EP eager the two off runs landed on the same value, which made v2's +0.0038 look
systematic, so I ran v2 twice more: 0.6444 / 0.6406 / 0.6368. v2's median is exactly legacy's
0.6406 — the EP path is simply non-deterministic and legacy's two runs happened to coincide.

TP1 graph scores far below eager (0.3268 vs 0.6482), but off and v2 are identical across all
three runs
, so it is the vLLM CUDA-graph path, not moev2 — the same effect you noted on gfx950
(0.43-0.48, with or without aiter). Graph numbers are only compared with graph numbers.

Throughput, 1000 prompts, alternating off / v2 / v2 / off:

configuration workload v2 / legacy
TP1 eager 1024/256 1.005
TP1 eager 128/1024 1.000
TP1 graph 1024/256 1.001
TP2+EP eager 1024/256 0.9997 (medians of 3+3)
TP2+EP graph 1024/256 1.007

TP2+EP eager first gave 0.9845 on 2+2 runs, so I added one run per mode. The full six:

legacy   12533.94   12503.34   11324.91      spread 10.7%
v2       12499.40   12149.07   12559.00      spread  3.4%

Legacy's third run dropped 9.6% by itself, so this workload swings much harder under EP than at TP1
— and v2 is the steadier of the two. On medians it is 0.9997. TP2+EP graph shows the same shape:
legacy's two runs differ by 1.7%, v2's by 0.79%.

grep -c "does not claim" is 0 in every v2 run across all four configurations, accuracy and
throughput alike — so graph capture and expert parallelism both route every MoE call through
a8w8_pt.

gfx942 cu80 is now complete against the run book, with nothing attributable to moev2. Still
open for gfx942: cu304, which has had no GPU run at all; I don't have an MI300X/MI325X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants