Skip to content

[MoE] [Bugfix] Zero the a2 buffer before dynamic per-tensor quant - #6926

Merged
azaidy merged 2 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza_per_tensor_a2_zero_init
Nov 10, 2026
Merged

azaidy merged 2 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza_per_tensor_a2_zero_init

Conversation

@AndreasKaratzas

Copy link
Copy Markdown
Contributor
  • fused_moe.py: in fused_moe_2stages, allocate a2 with torch.zeros when quant_type == QuantType.per_Tensor and a2_scale is None. All other paths keep torch.empty.
  • test_moe_per_tensor_a2_init.py: new regression test. It leaves 1e30 or inf in freed allocator blocks, then runs fp8 per-tensor fused_moe with padding rows (topk_ids == -1) and with an EP expert_mask, and compares the result to torch_moe.

Stage 1 writes only the (token, k) slots that moe_sorting keeps. It does not write slots with topk_ids == -1 or slots that expert_mask removes. For dynamic per-tensor quant, per_tensor_quant_hip then takes one amax over the full a2 buffer, so old memory in those slots sets the scale for every token. A large finite value rounds every real row to fp8 zero, and inf gives NaN. This matches an intermittent vLLM failure: test_aiter_moe_token_padding_garbage_rows[single_inf-fp8_tensor_tensor] and [single_nan-fp8_tensor_token] failed on MI300 with finite output but mean |mk_out|=0.000000 (https://buildkite.com/vllm/amd-ci/builds/15340), while the same MoE shards passed in https://buildkite.com/vllm/amd-ci/builds/15267 and https://buildkite.com/vllm/amd-ci/builds/15356.

Relation to #6568: that PR changes the same a2 = torch.empty line to torch.zeros on every path, because its gfx950 a8w4 (per_1x32) path needs it, and it also zeroes four FlyDSL and MX-quant scratch buffers. If #6568 merges first, it also fixes this bug and the fused_moe.py hunk here can be dropped; the new test still adds per-tensor and EP coverage that #6568 does not have. If this PR merges first, #6568 replaces the gated allocation with torch.zeros. On the per-tensor path both changes cost the same memset; on the other paths this PR adds no cost.

Tests on MI350X (gfx950), main 7be01d1:

new test case main this PR
padding rows, stale 1e30 FAIL: diff 1.0, mean|out| 0.000000 (ref 3.787) PASS: diff 1.08e-3, mean|out| 3.771
padding rows, stale inf FAIL: 24576 of 32768 outputs NaN PASS: diff 1.08e-3
EP expert_mask, stale 1e30 FAIL: diff 1.0, mean|out| 0.000000 (ref 2.689) PASS: diff 1.04e-3, mean|out| 2.681
EP expert_mask, stale inf FAIL: 23552 of 32768 outputs NaN PASS: diff 1.04e-3
python3 op_tests/test_moe_per_tensor_a2_init.py, 10 runs 4 failed, 10 of 10 runs 4 passed, 10 of 10 runs

Without the explicit poisoning, both cases also failed on main in 3 of 3 fresh-process runs (diff 1.0, mean|out| 0.0), but that outcome depends on what earlier allocations left behind; the poisoning makes the test deterministic. op_tests/test_moe_2stage.py -q 1 --no-flydsl-csv (per-tensor fp8, tokens 1 to 163840) gives the same logits_diff (about 1e-5) as main 26f4f1f without the fix, and the same 22 checkAllclose failed and 3 logits_diff too large lines in the same order, so those come from main.

Overhead: fused_moe latency in us, CUDA graph replay, median of 7 interleaved rounds. "all paths" is #6568's fused_moe.py hunk (zero a2 on every path) measured on the same build.

quant, shape (E, topk, dim, inter) M main this PR all paths (#6568 hunk)
fp8 per-tensor, Mixtral-8x7B TP8 (8, 2, 4096, 1792) 1 38.8 40.5 (+4.1%) 40.7 (+4.8%)
fp8 per-tensor, Qwen3-30B-A3B (128, 8, 2048, 768) 1 32.5 34.4 (+6.1%) 34.3 (+5.7%)
fp8 per-tensor, Qwen3-30B-A3B (128, 8, 2048, 768) 256 168.9 171.0 (+1.3%) 171.0 (+1.3%)
fp8 per-tensor, Mixtral-8x7B TP1 (8, 2, 4096, 14336) 8192 4211.1 4273.3 (+1.5%) 4284.3 (+1.7%)
fp8 per-token, Qwen3-30B-A3B (128, 8, 2048, 768) 1 27.0 27.0 (-0.1%) 28.9 (+6.9%)
fp8 per-token, Llama4-Scout TP8 (16, 1, 5120, 1024) 1 30.4 30.4 (-0.1%) 33.0 (+8.4%)
bf16, Mixtral-8x7B TP8 (8, 2, 4096, 1792) 256 105.3 105.1 (-0.2%) 107.7 (+2.2%)
bf16, Qwen3-30B-A3B (128, 8, 2048, 768) 2048 450.9 452.8 (+0.4%) 460.9 (+2.2%)

On the per-tensor path the memset costs about 2 us at decode sizes and 0.6% to 1.7% at M=2048 and 8192 for both changes. On per-token fp8 and bf16, this PR does not change the code path and the deltas are run-to-run noise, while the all-paths version adds 1.2 to 2.6 us at M=1 and 0.5% to 3% at larger M on bf16. A kernel-side fix, where the per-tensor amax reads only the slots in sorted_ids, would remove the remaining per-tensor cost.

AI assistance (Claude Code) was used to draft this change. Every line was reviewed by the submitter.

fused_moe_2stages allocates the stage1 output a2 with torch.empty. Stage1
writes only the (token, k) slots that moe_sorting keeps. It does not write
slots with topk_ids == -1 (padding tokens) or slots that expert_mask removes
(experts on other EP ranks). For QuantType.per_Tensor with a2_scale=None,
per_tensor_quant_hip then takes one amax over the full buffer, so stale
memory in those slots sets the scale for all tokens. A large finite value
rounds every real row to fp8 zero, and inf gives NaN output.

Allocate a2 with torch.zeros on this path only. Other paths keep
torch.empty. Add op_tests/test_moe_per_tensor_a2_init.py, which leaves
1e30 or inf in freed allocator blocks before the call, for padding rows
and for an EP expert_mask.

ROCm#6568 zeroes a2 on every path for its a8w4 case and also
covers this bug. This change touches only the path whose quant reads
the full buffer, so other quant types keep the cheaper torch.empty.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

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

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

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

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

@AndreasKaratzas
AndreasKaratzas marked this pull request as ready for review October 26, 2026 01:43
@AndreasKaratzas
AndreasKaratzas requested a review from a team October 26, 2026 01:43
@valarLip
valarLip requested a review from yadaish October 26, 2026 06:23
@rasmith

rasmith commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This also helps to fix the FusedMoe Layer tests, since it has the same problem, although you have to fix padding first in order to uncover the crash.

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

Looks good, and also helps with the FusedMoe Layer tests, but you will have to fix k-padding and CK rejects first to get to this point, but then it has the same problem, although it a bit more narrow, but this fix covers the FusedMoE Layer case as well.

@ChuanLi1101

Copy link
Copy Markdown
Contributor

LGTM. Stage1 skips unrouted slots; dynamic per-tensor quant reading the whole a2 buffer needs zeros there. The stale/inf regression test covers the failure mode well.

@ChuanLi1101 ChuanLi1101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Stage1 skips unrouted slots; dynamic per-tensor quant reading the whole a2 buffer needs zeros there. The stale/inf regression test covers the failure mode well.

@ChuanLi1101 ChuanLi1101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Stage1 skips unrouted slots; dynamic per-tensor quant reading the whole a2 buffer needs zeros there. The stale/inf regression test covers the failure mode well.

@azaidy azaidy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval to unblock merge.

@azaidy
azaidy merged commit 892e5d0 into ROCm:main Nov 10, 2026
63 checks passed
zufayu pushed a commit to qli88/aiter that referenced this pull request Nov 19, 2026
Add the problem/plan/segment framework to aiter/moev2 and move the first
fused_moe path onto it. Per-tensor fp8 2-stage fused_moe calls run through
aiter.moev2 only when enabled with AITER_MOEV2=a8w8_pt (or on). This covers
the CK default heuristic, tuned CK and ASM rows, and FlyDSL gfx942
whole-graph rows. The path is not graduated: by default every call still
runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. Every existing record of the CPU dispatch
  snapshot of legacy fused_moe is identical on gfx942, gfx942_cu80, gfx950
  and gfx1201. The snapshot gains feature-variant keys (see Tests), and
  the regenerated files are byte-identical to ones generated with the
  upstream base's aiter package.
- When a8w8_pt runs a call in v2, it launches the same kernels with the
  same parameters and inputs as legacy. It also prints the same log lines,
  raises the same exceptions (including legacy's RuntimeError for
  unshuffled fp8 CK weights on gfx950), and gives the same outputs, within
  legacy's own run-to-run noise (see Tests).
- With AITER_MOEV2 unset or off, every call runs the legacy code.
  AITER_MOEV2=a8w8_pt (or on) enables the path.
- The path declines calls it does not reproduce, and they run on the legacy
  code. These are herd_topk, deterministic=True, a presort registered with
  register_presorted_moe, swiglu_limit, beta or linear_beta, bias, padding,
  scatter, caller-chosen activation dtypes, and AITER_ONLINE_TUNE.
- The path also declines a call whose second lookup it cannot reproduce.
  After sorting, fused_moe_2stages looks the key up again, on the
  hidden_states rows and without the activation-scales, num_local_tokens
  and scatter flags. _fused_moe_impl's _metadata_transform then puts the
  first lookup's result back, so the second lookup only logs, but it can
  raise. v2 resolves it before emitting anything, and declines when it
  raises (legacy raises after the sort) or when v2 declines it (v2 could
  not emit its lines). Example: gfx950, unshuffled fp8, 2 topk_ids rows
  and 3 hidden_states rows, where the 2-token row is ASM stage 1 + CK
  stage 2 with no kernelName2 and the 4-token row is a tuned CK row: the
  second lookup raises the gfx950 shuffle error.

What changed:
- aiter/moev2 adds:
  - problem.py: MoeProblem, which round-trips the legacy get_2stage_cfgs key;
  - dispatch/{ops,buf,plan,kernel_names,tuned,resolver,overrides,ranking,
    profile};
  - segments/{base,sort,quant,ck,asm,whole_graph,defaults};
  - execute/{executor,metadata,output};
  - migration/a8w8_pt.py: claims, declines and path registration.
- aiter/moev2/README.md: describes the new files (purpose, permanent or
  removed after the migration) and how a call flows through a path.
- Moved from fused_moe.py and imported back under the same names. Each
  definition is AST-identical to the current one it replaces:
  - execute/output.py: _validate_output_buffer_metadata,
    _validate_output_buffer_no_overlap, _return_output;
  - execute/metadata.py: MOEMetadata, and AsmMoeMode (the type of its flat
    field);
  - shapes.py: nextPow2, _PADDED_M_TIERS, get_padded_M, _is_row_major_2d;
  - policy.py: _normalize_mxfp4_activation_params;
  - segments/asm.py: asm_stage1;
  - segments/ck.py: ck_moe_stage1, _require_shuffled_gfx950_fp8;
  - segments/defaults.py: BLOCK_SIZE_M, get_block_size_M, get_ksplit,
    use_nt;
  - dispatch/tuned.py: _ACT_TYPE_DISABLED_KEY, plus the tuned-table
    reader. fused_moe.py's get_cfg_2stages(tune_file, tag=None) calls it
    with the swiglu_limit tag filter unchanged.
- v2 mirrors the legacy changes made upstream after this work branched.
  They change code that v2 copies rather than calls, so they raised no
  merge conflicts:
  - ROCm#6736 (gfx950 fp8 CK needs shuffled weights): the resolver raises
    legacy's RuntimeError at the same two points as get_2stage_cfgs. A
    tuned CK 2-stage row raises before any log line. The default CK
    2-stage plan raises after the "run_1stage = ..." and "using 2stage
    default" lines, which v2 also logs first.
  - ROCm#7500 (row-strided activations): the executor copies hidden_states
    that is neither contiguous nor row-major before it checks the output
    buffer for overlap, and copies any other non-contiguous hidden_states
    before sorting, as legacy does.
  - ROCm#6926 (zero a2 before dynamic per-tensor quant): with per-tensor
    quant and no a2_scale, the stage 1 output is zeroed, so the a2 scale
    ignores slots stage 1 never writes (padding rows, non-local experts).
  - ROCm#5988 (gfx950 fused MXFP4 prefill): the resolver declines tuned rows
    with flat=POST_REDUCE. Only MXFP4 rows use it today, so no a8w8_pt
    key is affected.
- The legacy key now carries _exclude_mxmoe and
  _has_input_activation_scales.
  - _exclude_mxmoe becomes the problem extra exclude_mxmoe. No segment
    accepts that extra, so v2 declines such calls.
  - _has_input_activation_scales becomes the feature a1_scale, which the
    sort, quant and CK segments accept.
- aiter.moev2.fused_moe (v2's own entry point) clears a registered presort
  when the call returns or raises, as legacy fused_moe does with
  drop_presort_after.
- kernel_names parses the bare ASM symbols that tuned tables now carry
  (fmoe_..._ps_fp32gate_route), alongside the _ZN5aiter...E names.
- api.op_call passes splitk, herd_topk, herd_routed_scaling_factor and
  deterministic to fused_moe_, matching the legacy fused_moe.
- dispatch/ranking.py holds the default ranking table as entries and
  regions:
  - an entry matches by set membership on problem fields;
  - a region is an integer threshold on named scalars, and lists its
    structures best first.
  The checks that fail CI are:
  - overlapping entries or regions, or contradictory regions;
  - unknown or non-adjacent segments;
  - a last structure whose feasibility depends on the shape;
  - over the snapshot key grid (ranking_checks.py): a rankable key that
    does not land in exactly one entry and region with a feasible last
    structure, or a region that no key reaches.
- Paths:
  - graduated may be a set of archs;
  - the entry is "api" (top of fused_moe) or "op" (inside the fused_moe_
    custom op);
  - DECLINED hands the call back to legacy;
  - the api hook is skipped while torch.compile traces.
- Tuned tables: v2 reads the default table through legacy's cfg_2stages
  global. get_2stage_cfgs.cache_clear(), used by the CK tuner and tests,
  also clears v2's caches.
- Tests:
  - new: tests/test_moev2_dispatch.py, test_moev2_ranking.py,
    key_checks.py (problem/legacy key round trip; the tuned lookup returns
    legacy's row), ranking_checks.py, gpu_differential.py;
  - test_moev2_dispatch.py covers each mirrored change: the gfx950 raise
    (same message and log lines as legacy, for a default and a tuned CK
    row), both hidden_states copies, the a2 zero-fill, and the
    POST_REDUCE decline. It also covers the second lookup: one that raises
    or that v2 declines makes the call decline with no log line and no
    sort, and one that selects another plan still runs the first plan;
  - test_moev2_switch.py: v2's fused_moe drops a registered presort when
    it raises;
  - keys.py adds feature variants for the quant types in
    FEATURE_QUANT_TYPES (per_Tensor for now; each later path adds its
    own). Each base tuned and grid key gets 20 variants, the same call with
    one more get_2stage_cfgs feature: num_local_tokens, activation scales
    (with and without input scales), fp8 input with and without scales,
    scatter, unshuffled and half-shuffled weights, stage 1 or stage 2
    bias, gate interleave, gate_up_interleave, swiglu_limit 0.0 and 7.0,
    _exclude_mxmoe, q_dtype_a2, doweight_stage1, Gelu, no g1u1, and
    padding. A changed decision for one of these calls now shows up as
    its own key in the snapshot, differential, key and ranking checks.
    The golden files are regenerated with them (about 13,000-17,000 new
    keys per arch). A unit test binds every variant to the
    get_2stage_cfgs signature, so a typo cannot become an error record;
  - gpu_suites.py adds op_tests/test_moe_per_tensor_a2_init.py (from
    ROCm#6926) to the a8w8_pt suites;
  - the switch and differential tests are extended;
  - tests that read the aiter logger through caplog turn on its
    propagation, since pytest's caplog listens on the root logger;
  - the perf golden gains a dsv3_tp8_pt case.

Known differences and limits:
- swiglu_limit=0.0, which vLLM sends for "no limit", is declined like any
  other swiglu_limit value, so those calls stay on the legacy code.
- v2's per-shape caches are LRU and evict only beyond 2048 distinct
  shapes.
- The a8w8_pt ASM and whole-graph branches are verified only by the CPU
  differential. Their tuned rows are gfx942-only, and no gfx942 was
  available.
- Legacy nondeterminism found while building the GPU gate:
  - CK stage2 accumulates with atomics, so the gate compares outputs within
    a tolerance based on legacy-vs-legacy noise.
  - Some ASM stage1 kernels are not repeatable. This is a legacy bug, and
    the gate does not excuse it: a case that hits it fails.
- test_moe_2stage -q 1 reports 28 failed checks (the swiglu limit cases),
  test_moe_ep 2 and test_moe_dp_share_expert 13. They fail the same way
  with AITER_MOEV2 off and on, and in the upstream tree without this
  work.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 89 passed.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: 22,087 claimed keys (3,885 without the feature
    variants);
  - key_checks.py: 107,572 keys, 17,149 tuned rows;
  - ranking_checks.py: 29,424 ranked keys.
- With the second-lookup check disabled, both of its decline tests fail.
- With v2's gfx950 shuffle raise disabled, the differential reports 1,088
  problems on gfx950, all in the new grid unshuffled and half-shuffled
  keys. The keys without feature variants catch none of them, since
  gfx950 has no per-tensor tuned rows.
- GPU differential, gfx950, all with 0 problems (rerun after the
  second-lookup check, which declines none of these cases):
  - 15 default cases;
  - 63 cases against a synthetic CK tuned table;
  - the default cases with AITER_USE_NT=1 and again with
    AITER_BYPASS_TUNE_CONFIG=1.
- GPU suites, AITER_MOEV2=off vs a8w8_pt, with tabulate installed:
  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. Same
  exit codes and the same outcome for every check in both modes.
  AITER_MOE_EXPLAIN=1 shows v2 resolving the per-tensor calls of
  test_moe_2stage and test_moe_per_tensor_a2_init; the other four make no
  per-tensor fp8 fused_moe call. With v2's a2 zero-fill disabled, all 4
  cases of test_moe_per_tensor_a2_init fail in a8w8_pt mode. After the
  second-lookup check, test_moe_per_tensor_a2_init passes again in
  a8w8_pt mode, with v2 selecting a plan for all 4 cases.
- GPU legacy check: op_tests/test_moe_2stage.py small cases (-t 1 16 256,
  each of the 10 quant types), every fused_moe output captured, upstream
  base (db3b870) vs this commit, same JIT build, seeded inputs
  (identical in both):
  - 8410 calls; the 170 deterministic calls are bit-identical;
  - the other 8240 vary run to run in the upstream base too;
  - for quant types 1 and 4, three runs of each tree put the mean
    distance between trees at 0.997 and 1.003 of that between runs;
  - one quant type 4 call stood apart in three runs (1.55); six fresh
    runs of each tree put it at 1.10, with no call apart and a mean of
    1.003.
- perf_gfx950.json: dsv3_tp8_pt was recorded on one idle MI355 (gfx950
  cu256). --check of all cases passes right after. The same case with
  AITER_MOEV2=a8w8_pt is within 2.2% of legacy at every token count, with
  mixed signs (mean of two runs per mode).
- black and ruff (0.16.0) clean.

Co-authored-by: Cursor <[email protected]>
zufayu added a commit that referenced this pull request Nov 25, 2026
…the per-tensor fp8 path (not graduated) (#8255)

* [MoE] moev2 phase 0/1: scaffolding, legacy-parity harness, move leaf helpers (no behavior change)

Introduce aiter/moev2, which will coexist with aiter/fused_moe.py while
fused_moe paths move over one at a time. No path is registered yet, so
every call still runs exactly the legacy code.

Behavior claim:
- No behavior change. Every fused_moe call runs the legacy code, with or
  without AITER_MOEV2.

What changed:
- aiter/fused_moe.py: the helpers below move to aiter/moev2 and are imported
  back, so every name that code and tests import from aiter.fused_moe still
  resolves (36 names checked). fused_moe() gains a switch hook that does
  nothing while no moev2 path is registered; _fused_moe_impl passes
  gfx=get_gfx_runtime() to resolve_activation_dtype, the default it already
  used.
- Moved from fused_moe.py, each definition AST-identical to the one it
  replaces:
  - policy.py: resolve_activation_dtype, quant_remap, _bound_split,
    _SWIGLU_MXFP4_BF16_BOUND;
  - shapes.py: get_inter_dim;
  - routing/topk.py: fused_topk;
  - reference/torch_moe.py: the torch reference (torch_moe, torch_moe_act,
    torch_moe_stage1, torch_moe_stage2, swiglu, situv2,
    _clamp_swiglu_gate_up) and the per-1x32 dequant helpers. It imports the
    SiLU-limit helpers from aiter.ops.moe_limits.
- aiter/moev2/README.md: what each moev2 package file and test file is for,
  and whether it is permanent or removed after the migration.
- aiter/moev2 scaffolding: AITER_MOEV2 switch (envs.py), path registry
  (paths.py, empty), v2 entry point with the legacy signature (api.py, up to
  herd_topk, herd_routed_scaling_factor and deterministic), test hooks
  (hooks.py), dispatch cache helper (dispatch/tuned.py).
- tests/moe_dispatch (lock in legacy behavior): public-name inventory, CPU
  arch simulation, a legacy dispatch snapshot, a GPU suite list per planned
  path, and a perf baseline script. Goldens:
  - dispatch snapshot for gfx942 (13135 keys), gfx942_cu80 (16108), gfx950
    (19307) and gfx1201 (12628), read from a frozen copy of the merged
    tuned_fmoe.csv and tuned_fhmoe.csv (golden/inputs);
  - perf_gfx950.json: 9 model cases x 7 token counts, one idle MI355.
    Case shapes are the sizes vLLM passes to aiter: GPT-OSS dims are padded
    2880 -> 3072 on ROCm MXFP4, and Qwen3-235B FP8 block scale runs at TP4
    (its TP8 inter_dim 192 is not a multiple of 128). The default --check
    tolerance is 10%: unchanged code drifted up to 8% at small M on gfx950.
- Tests: moev2 must not import legacy MoE modules; switch parsing and
  routing; signature parity; hooks; a differential harness that requires v2
  to make the same choice as legacy for every key it claims; the dispatch
  snapshot. The warning test turns on propagation for the aiter logger,
  which does not propagate, since pytest's caplog listens on the root logger.

Known differences and limits:
- None in behavior. The perf golden is a measurement: --check compares
  against it with a tolerance, on an idle GPU.

Tests:
- CPU: test_moev2_imports, test_moev2_hooks, test_moev2_switch,
  test_moev2_differential, test_moe_dispatch_snapshot: 24 passed, 1 skipped.
- Dispatch snapshot recorded from the parent commit and from this commit,
  same recorder and frozen inputs: byte-identical on all 4 archs.
- GPU, gfx950: op_tests/test_moe_2stage.py small cases (-t 1 16 256, each
  of the 10 quant types, with its fixed tests), every fused_moe output
  captured, parent commit vs this commit, same JIT build, seeded inputs
  (identical in both): 8410 calls. The 170 calls that are deterministic are
  bit-identical. The other 8240 vary run to run in the parent commit too
  (1-2 bf16 ULP, accumulation order); for quant types 1 and 4, three runs
  of each commit put the mean distance between the two commits at 0.98 and
  1.00 of that between runs of the parent commit (at most 1.25 on any call).
- perf_gfx950.json recorded on one idle MI355 (gfx950 cu256); a --check
  right after passes (10% tolerance).
- black and ruff (0.16.0) clean.

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

* [MoE] moev2 phase 2: per-tensor fp8 (a8w8_pt) path (not graduated)

Add the problem/plan/segment framework to aiter/moev2 and move the first
fused_moe path onto it. Per-tensor fp8 2-stage fused_moe calls run through
aiter.moev2 only when enabled with AITER_MOEV2=a8w8_pt (or on). This covers
the CK default heuristic, tuned CK and ASM rows, and FlyDSL gfx942
whole-graph rows. The path is not graduated: by default every call still
runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. Every existing record of the CPU dispatch
  snapshot of legacy fused_moe is identical on gfx942, gfx942_cu80, gfx950
  and gfx1201. The snapshot gains feature-variant keys (see Tests), and
  the regenerated files are byte-identical to ones generated with the
  upstream base's aiter package.
- When a8w8_pt runs a call in v2, it launches the same kernels with the
  same parameters and inputs as legacy. It also prints the same log lines,
  raises the same exceptions (including legacy's RuntimeError for
  unshuffled fp8 CK weights on gfx950), and gives the same outputs, within
  legacy's own run-to-run noise (see Tests).
- With AITER_MOEV2 unset or off, every call runs the legacy code.
  AITER_MOEV2=a8w8_pt (or on) enables the path.
- The path declines calls it does not reproduce, and they run on the legacy
  code. These are herd_topk, deterministic=True, a presort registered with
  register_presorted_moe, swiglu_limit, beta or linear_beta, bias, padding,
  scatter, caller-chosen activation dtypes, and AITER_ONLINE_TUNE.
- The path also declines a call whose second lookup it cannot reproduce.
  After sorting, fused_moe_2stages looks the key up again, on the
  hidden_states rows and without the activation-scales, num_local_tokens
  and scatter flags. _fused_moe_impl's _metadata_transform then puts the
  first lookup's result back, so the second lookup only logs, but it can
  raise. v2 resolves it before emitting anything, and declines when it
  raises (legacy raises after the sort) or when v2 declines it (v2 could
  not emit its lines). Example: gfx950, unshuffled fp8, 2 topk_ids rows
  and 3 hidden_states rows, where the 2-token row is ASM stage 1 + CK
  stage 2 with no kernelName2 and the 4-token row is a tuned CK row: the
  second lookup raises the gfx950 shuffle error.

What changed:
- aiter/moev2 adds:
  - problem.py: MoeProblem, which round-trips the legacy get_2stage_cfgs key;
  - dispatch/{ops,buf,plan,kernel_names,tuned,resolver,overrides,ranking,
    profile};
  - segments/{base,sort,quant,ck,asm,whole_graph,defaults};
  - execute/{executor,metadata,output};
  - migration/a8w8_pt.py: claims, declines and path registration.
- aiter/moev2/README.md: describes the new files (purpose, permanent or
  removed after the migration) and how a call flows through a path.
- Moved from fused_moe.py and imported back under the same names. Each
  definition is AST-identical to the current one it replaces:
  - execute/output.py: _validate_output_buffer_metadata,
    _validate_output_buffer_no_overlap, _return_output;
  - execute/metadata.py: MOEMetadata, and AsmMoeMode (the type of its flat
    field);
  - shapes.py: nextPow2, _PADDED_M_TIERS, get_padded_M, _is_row_major_2d;
  - policy.py: _normalize_mxfp4_activation_params;
  - segments/asm.py: asm_stage1;
  - segments/ck.py: ck_moe_stage1, _require_shuffled_gfx950_fp8;
  - segments/defaults.py: BLOCK_SIZE_M, get_block_size_M, get_ksplit,
    use_nt;
  - dispatch/tuned.py: _ACT_TYPE_DISABLED_KEY, plus the tuned-table
    reader. fused_moe.py's get_cfg_2stages(tune_file, tag=None) calls it
    with the swiglu_limit tag filter unchanged.
- v2 mirrors the legacy changes made upstream after this work branched.
  They change code that v2 copies rather than calls, so they raised no
  merge conflicts:
  - #6736 (gfx950 fp8 CK needs shuffled weights): the resolver raises
    legacy's RuntimeError at the same two points as get_2stage_cfgs. A
    tuned CK 2-stage row raises before any log line. The default CK
    2-stage plan raises after the "run_1stage = ..." and "using 2stage
    default" lines, which v2 also logs first.
  - #7500 (row-strided activations): the executor copies hidden_states
    that is neither contiguous nor row-major before it checks the output
    buffer for overlap, and copies any other non-contiguous hidden_states
    before sorting, as legacy does.
  - #6926 (zero a2 before dynamic per-tensor quant): with per-tensor
    quant and no a2_scale, the stage 1 output is zeroed, so the a2 scale
    ignores slots stage 1 never writes (padding rows, non-local experts).
  - #5988 (gfx950 fused MXFP4 prefill): the resolver declines tuned rows
    with flat=POST_REDUCE. Only MXFP4 rows use it today, so no a8w8_pt
    key is affected.
- The legacy key now carries _exclude_mxmoe and
  _has_input_activation_scales.
  - _exclude_mxmoe becomes the problem extra exclude_mxmoe. No segment
    accepts that extra, so v2 declines such calls.
  - _has_input_activation_scales becomes the feature a1_scale, which the
    sort, quant and CK segments accept.
- aiter.moev2.fused_moe (v2's own entry point) clears a registered presort
  when the call returns or raises, as legacy fused_moe does with
  drop_presort_after.
- kernel_names parses the bare ASM symbols that tuned tables now carry
  (fmoe_..._ps_fp32gate_route), alongside the _ZN5aiter...E names.
- api.op_call passes splitk, herd_topk, herd_routed_scaling_factor and
  deterministic to fused_moe_, matching the legacy fused_moe.
- dispatch/ranking.py holds the default ranking table as entries and
  regions:
  - an entry matches by set membership on problem fields;
  - a region is an integer threshold on named scalars, and lists its
    structures best first.
  The checks that fail CI are:
  - overlapping entries or regions, or contradictory regions;
  - unknown or non-adjacent segments;
  - a last structure whose feasibility depends on the shape;
  - over the snapshot key grid (ranking_checks.py): a rankable key that
    does not land in exactly one entry and region with a feasible last
    structure, or a region that no key reaches.
- Paths:
  - graduated may be a set of archs;
  - the entry is "api" (top of fused_moe) or "op" (inside the fused_moe_
    custom op);
  - DECLINED hands the call back to legacy;
  - the api hook is skipped while torch.compile traces.
- Tuned tables: v2 reads the default table through legacy's cfg_2stages
  global. get_2stage_cfgs.cache_clear(), used by the CK tuner and tests,
  also clears v2's caches.
- Tests:
  - new: tests/test_moev2_dispatch.py, test_moev2_ranking.py,
    key_checks.py (problem/legacy key round trip; the tuned lookup returns
    legacy's row), ranking_checks.py, gpu_differential.py;
  - test_moev2_dispatch.py covers each mirrored change: the gfx950 raise
    (same message and log lines as legacy, for a default and a tuned CK
    row), both hidden_states copies, the a2 zero-fill, and the
    POST_REDUCE decline. It also covers the second lookup: one that raises
    or that v2 declines makes the call decline with no log line and no
    sort, and one that selects another plan still runs the first plan;
  - test_moev2_switch.py: v2's fused_moe drops a registered presort when
    it raises;
  - keys.py adds feature variants for the quant types in
    FEATURE_QUANT_TYPES (per_Tensor for now; each later path adds its
    own). Each base tuned and grid key gets 20 variants, the same call with
    one more get_2stage_cfgs feature: num_local_tokens, activation scales
    (with and without input scales), fp8 input with and without scales,
    scatter, unshuffled and half-shuffled weights, stage 1 or stage 2
    bias, gate interleave, gate_up_interleave, swiglu_limit 0.0 and 7.0,
    _exclude_mxmoe, q_dtype_a2, doweight_stage1, Gelu, no g1u1, and
    padding. A changed decision for one of these calls now shows up as
    its own key in the snapshot, differential, key and ranking checks.
    The golden files are regenerated with them (about 13,000-17,000 new
    keys per arch). A unit test binds every variant to the
    get_2stage_cfgs signature, so a typo cannot become an error record;
  - gpu_suites.py adds op_tests/test_moe_per_tensor_a2_init.py (from
    #6926) to the a8w8_pt suites;
  - the switch and differential tests are extended;
  - tests that read the aiter logger through caplog turn on its
    propagation, since pytest's caplog listens on the root logger;
  - the perf golden gains a dsv3_tp8_pt case.

Known differences and limits:
- swiglu_limit=0.0, which vLLM sends for "no limit", is declined like any
  other swiglu_limit value, so those calls stay on the legacy code.
- v2's per-shape caches are LRU and evict only beyond 2048 distinct
  shapes.
- The a8w8_pt ASM and whole-graph branches are verified only by the CPU
  differential. Their tuned rows are gfx942-only, and no gfx942 was
  available.
- Legacy nondeterminism found while building the GPU gate:
  - CK stage2 accumulates with atomics, so the gate compares outputs within
    a tolerance based on legacy-vs-legacy noise.
  - Some ASM stage1 kernels are not repeatable. This is a legacy bug, and
    the gate does not excuse it: a case that hits it fails.
- test_moe_2stage -q 1 reports 28 failed checks (the swiglu limit cases),
  test_moe_ep 2 and test_moe_dp_share_expert 13. They fail the same way
  with AITER_MOEV2 off and on, and in the upstream tree without this
  work.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 89 passed.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: 22,087 claimed keys (3,885 without the feature
    variants);
  - key_checks.py: 107,572 keys, 17,149 tuned rows;
  - ranking_checks.py: 29,424 ranked keys.
- With the second-lookup check disabled, both of its decline tests fail.
- With v2's gfx950 shuffle raise disabled, the differential reports 1,088
  problems on gfx950, all in the new grid unshuffled and half-shuffled
  keys. The keys without feature variants catch none of them, since
  gfx950 has no per-tensor tuned rows.
- GPU differential, gfx950, all with 0 problems (rerun after the
  second-lookup check, which declines none of these cases):
  - 15 default cases;
  - 63 cases against a synthetic CK tuned table;
  - the default cases with AITER_USE_NT=1 and again with
    AITER_BYPASS_TUNE_CONFIG=1.
- GPU suites, AITER_MOEV2=off vs a8w8_pt, with tabulate installed:
  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. Same
  exit codes and the same outcome for every check in both modes.
  AITER_MOE_EXPLAIN=1 shows v2 resolving the per-tensor calls of
  test_moe_2stage and test_moe_per_tensor_a2_init; the other four make no
  per-tensor fp8 fused_moe call. With v2's a2 zero-fill disabled, all 4
  cases of test_moe_per_tensor_a2_init fail in a8w8_pt mode. After the
  second-lookup check, test_moe_per_tensor_a2_init passes again in
  a8w8_pt mode, with v2 selecting a plan for all 4 cases.
- GPU legacy check: op_tests/test_moe_2stage.py small cases (-t 1 16 256,
  each of the 10 quant types), every fused_moe output captured, upstream
  base (db3b870) vs this commit, same JIT build, seeded inputs
  (identical in both):
  - 8410 calls; the 170 deterministic calls are bit-identical;
  - the other 8240 vary run to run in the upstream base too;
  - for quant types 1 and 4, three runs of each tree put the mean
    distance between trees at 0.997 and 1.003 of that between runs;
  - one quant type 4 call stood apart in three runs (1.55); six fresh
    runs of each tree put it at 1.10, with no call apart and a mean of
    1.003.
- perf_gfx950.json: dsv3_tp8_pt was recorded on one idle MI355 (gfx950
  cu256). --check of all cases passes right after. The same case with
  AITER_MOEV2=a8w8_pt is within 2.2% of legacy at every token count, with
  mixed signs (mean of two runs per mode).
- black and ruff (0.16.0) clean.

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

* [MoE] keep moev2 parity checks honest after rebase

* [MoE] harden moev2 validation coverage

* [MoE] avoid false work and unsupported GPU validation

* [MoE] use the runtime GPU for path claims

* [MoE] test the checkout, not an installed aiter

The moe_dispatch scripts run as `python tests/moe_dispatch/<name>.py`, so sys.path[0]
is their own directory and the working directory is not on the path. They inserted
`tests` for `moe_dispatch` but nothing for the repository root, so `import aiter`
resolved to whatever copy is installed: in an image that carries an amd-aiter wheel
(CI runs `python3 -m pytest -q tests` next to one), the parity gate validated the
installed package while the pytest parent validated the checkout. Insert the
repository root as well, as tests/test_flydsl_aot_replay.py and friends already do.

perf_baseline named its baseline file with get_gfx(), which follows GPU_ARCHS and
returns the last entry on a multi-target build; the numbers come from the live GPU,
so it reads get_gfx_runtime() now and cannot compare one GPU against another's
recorded baseline.

Add the missing guard for the import graph this PR inverts: aiter/fused_moe.py now
imports aiter.moev2 at module level, so one unimportable moev2 module breaks
`import aiter.fused_moe` for every downstream MoE consumer. `import aiter` does not
import fused_moe and the moev2 runtime check does not import the legacy module, so
no aiter-side check covered it. Breaking a moev2 module fails the new test.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MoE] let the live-arch claim test see the real chip info

tests/test_moev2_dispatch.py wraps every test in `simulated_arch("gfx950")`, which
replaces chip_info.get_gfx and get_gfx_runtime with plain functions. The test added
for the multi-target build case then called `chip_info.get_gfx.cache_clear()` on a
lambda and failed with AttributeError, so `python3 -m pytest -q tests` was red. CI
had not caught it: on the previous head the MI35X shard 0 job was cancelled before
the focused regression step ran.

Give that one test a way out of the simulation: `_gfx950` steps aside when a test
requests `live_chip_info`, and that fixture hands over the real module with its
caches cleared before and after. A test about which chip-info helper dispatch calls
cannot run inside a simulation that patches both of them.

The test keeps its point: with GPU_ARCHS='gfx942;gfx1250', making claims() consult
the build-time get_gfx() as well as get_gfx_runtime() fails it again.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MoE] stop the live-arch claim test from reading GPU_ARCHS

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

* [MoE] moev2: fixes from the phase 0-2 PR review (not graduated)

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

* [MoE] moev2: more fixes from the phase 0-2 PR review (not graduated)

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

* [MoE] moev2: address the phase 0-2 PR review comments (not graduated)

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

* [MoE] moev2: retry a failed built-in path import (not graduated)

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

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants