Skip to content

[CK] Use K=128 for gfx950 fp8 stage2 when 256 does not divide inter_dim - #6736

Merged
zufayu merged 8 commits into
ROCm:mainfrom
zjin-lcf:fix/gfx950-fp8-stage2-k128
Oct 27, 2026
Merged

zufayu merged 8 commits into
ROCm:mainfrom
zjin-lcf:fix/gfx950-fp8-stage2-k128

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

Summary

…e intermediate size.

The 16x16 fp8 matrix instruction consumes 128 K elements, so the default K=256 tile rejects intermediate size 384.

Co-authored-by: Cursor <[email protected]>
@zjin-lcf
zjin-lcf requested a review from a team October 20, 2026 20:14
@github-actions github-actions Bot added the CK label Oct 20, 2026
@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 6736 --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.

@zufayu
zufayu self-requested a review October 21, 2026 01:28
@zufayu zufayu self-assigned this Oct 21, 2026
@zufayu

zufayu commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for adding the inter_dim=384 path. Before merging, please address the following:

  1. Please provide an apples-to-apples benchmark comparing native 384 / K=128 against padding to 512 / K=256. The PR currently does not demonstrate that the new dispatch is actually faster than the existing padded path.
  2. The dispatch condition should explicitly distinguish inter_dim % 256 == 0, inter_dim % 128 == 0, and unsupported dimensions. The current fallback to K=128 can incorrectly route dimensions such as 192, 320, or 448 that are not divisible by 128.
  3. Please integrate the regression coverage into the existing MoE two-stage/default-dispatch tests instead of adding a standalone op_tests/test_moe_gfx950_fp8_inter384.py. The test should compare against a reference implementation—not only check finite/nonzero outputs—and cover 384, 512, and at least one non-128-aligned dimension.

The K=128 tile was also selected for 192, 320, and 448. Those sizes now fail the dispatch check. 384 and 512 are checked against torch_moe in the existing default-dispatch test.

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

Copy link
Copy Markdown
Contributor Author

Thank you for your comments and suggestions.

1. Benchmarking

Measured on a MI350X, AITER_BYPASS_TUNE_CONFIG=1, per-tensor fp8, unshuffled weights, 16384 tokens, hidden 4096, 8 experts, topk 8. Warmup 20, then 40 rounds of 20 iterations. Medians:

block_m native 384 padded 512 384/512
32 4.456 ms 4.678 ms 0.953
64 4.490 ms 4.711 ms 0.953
128 4.266 ms 4.415 ms 0.966

Native 384 is about 5% faster in wall time.

2. Dispatch

A8W8_gemm2_gfx950_heuristic_dispatch now splits the three cases for every block size:

  • inter_dim % 256 == 0 selects K=256 for block_m 32 and 64
  • otherwise inter_dim % 128 == 0 selects K=128 (384)
  • otherwise TORCH_CHECK reports that gfx950 fp8 stage 2 needs a multiple of 128

192, 320, and 448 take the check. block_m 128 and 256 keep their existing K=128 instances and use the same check.

3. Test

Removed op_tests/test_moe_gfx950_fp8_inter384.py. Coverage is in op_tests/test_moe_a16w16_default_dispatch.py:

  • 384 and 512, block_m 32 and 64, per-tensor and per-token, compared with torch_moe
  • 192 and 320 expect the multiple-of-128 error

Those 10 cases passed on this gfx950. The reference comparison shuffles the fp8 weights. That is the layout this kernel reads: the fp8 stage-2 build forces preshuffle, so the preshuffle_off module is the same shuffled kernel. Unshuffled weights at 384 and at 512 (which already used K=256 before this change) are uncorrelated with torch_moe. Shuffled weights match it (cosine about 0.999 on the issue shape).

@zufayu

zufayu commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for addressing the K=128/K=256 dispatch, unsupported widths, and test placement. The remaining blocker is the exact input path from #6452.

That report passes unshuffled FP8 weights to fused_moe, but the new positive regression tests call shuffle_weight() on both weights. Those tests establish correctness for the shuffled path, not for the original preshuffle_off call. Your reply also says that unshuffled results at both inter_dim=384 and 512 do not correlate with torch_moe. Changing the 384 stage-2 tile from K=256 to K=128 may remove the launch error without establishing correct output for that call.

Please run the original unshuffled reproducer on this head and compare its output with a reference using the same logical, unshuffled weights, covering the reported per-Token and per-Tensor static/dynamic scale cases at 384 and 512. If unshuffled FP8 weights are unsupported, please make that contract explicit and keep the path from silently returning incorrect output; in that case this PR should not claim to fix #6452 without a corresponding solution for the vLLM caller. Once the valid path is established, please confirm the native-384 versus padded-512 performance result on that correct path, since the reported timings used unshuffled inputs.

Those instances read the shuffle_weight layout, so the unshuffled call returns a wrong tensor once the 384 tile launches.

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

Copy link
Copy Markdown
Contributor Author

Thank you for the comments and suggestions. The unshuffled call from #6452 is not a valid input for this kernel, so this PR no longer claims to fix that issue.

1. Original reproducer
Ran the #6452 shape on this head: 16 tokens, hidden 896, 8 experts, topk 2, Silu, unshuffled fp8 weights, compared with torch_moe on the same
logical weights. AITER_BYPASS_TUNE_CONFIG=1. Cosine similarity:

case 384 unshuffled 384 shuffled 512 unshuffled 512 shuffled
per-Token, dynamic scale 0.001 0.999 0.001 0.999
per-Tensor, static a1_scale 0.004 0.999 0.002 0.999
per-Tensor, dynamic scale 0.003 0.999 0.002 0.999

Unshuffled weights are uncorrelated at both 384 and 512. The 512 case in the issue only meant the launch did not throw. Shuffled weights match the reference. Plain fp8 CK stage 2 reads the shuffle_weight() layout, including the module selected on the untuned preshuffle_off path.

2. Contract
Unshuffled per_Tensor and per_Token fp8 weights now raise before launch:
gfx950 fp8 CK MoE reads the shuffle_weight() layout; unshuffled per_Tensor and per_Token weights are unsupported
Block-scale, mxfp4, and a16w16 are unchanged. vLLM's AiterExperts path still passes these weights unshuffled to avoid #5766, so this does not make that caller correct. #6452 stays open until that caller shuffles, or a real unshuffled kernel exists.

3. Tests
Coverage remains in op_tests/test_moe_a16w16_default_dispatch.py. Shuffled 384 and 512, block_m 32 and 64, per-tensor and per-token, are compared with torch_moe. The six unshuffled cases above expect the new error. All 16 gfx950 cases passed.

4. Performance on the valid path
Repeated the benchmark with shuffled weights. gfx950, AITER_BYPASS_TUNE_CONFIG=1, per-tensor fp8, 16384 tokens, hidden 4096, 8 experts, topk 8. Warmup 20, then 40 rounds of 20. Medians:

block_m native 384 padded 512 384/512
32 4.464 ms 4.688 ms 0.952
64 4.524 ms 4.826 ms 0.937
128 4.270 ms 4.451 ms 0.960

Native 384 is about 5% faster on the layout this kernel reads. The earlier timings used unshuffled inputs.

@zufayu

zufayu commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

I re-reviewed the latest head. The 384/512 FP8 tile selection and the reported shuffled-path performance look reasonable, but there are still two correctness blockers before merge:

  1. is_shuffled is currently computed as w1.is_shuffled or w2.is_shuffled. If only one weight is shuffled, the new guard is bypassed and one CK stage may read the other weight with the wrong layout, potentially returning silently incorrect results. Please require both weights to satisfy the shuffled contract and add negative tests for both mixed combinations (w1 shuffled / w2 plain and vice versa).
  2. The runtime guard uses build-time get_gfx(). This can be affected by GPU_ARCHS, allowing an actual gfx950 process to skip the guard. Please use the existing runtime gfx value in this function, or get_gfx_runtime().

There are also two follow-ups needed for closure:

Once the two correctness issues are fixed, the minimal INT8 coverage is added, and the description is corrected, I do not see a need for another broad performance round.

zjin-lcf and others added 4 commits October 26, 2026 13:38
The stage-2 guard treated either is_shuffled tag as enough and keyed the arch off get_gfx(), so a mixed pair or a GPU_ARCHS mismatch could skip it. The shared a8w8 dispatch now has int8 coverage for K=128, K=256, and a width 128 does not divide.

Co-authored-by: Cursor <[email protected]>
fused_moe rejects width 192 in the ASM stage-1 kernel before CK stage 2 runs, so the shared dispatch check has to be called on its own.

Co-authored-by: Cursor <[email protected]>
A correct width-512 result can also come from K=128, and get_gfx() follows GPU_ARCHS, so the suite now checks the launched kernel and still rejects unshuffled weights when that variable names another chip.

Co-authored-by: Cursor <[email protected]>
A matching moe_ck2stages config skipped the default-heuristic guard, and is_shuffled being true for either weight hid a mixed pair. The shared K check now says a8w8 because int8 uses that same dispatch.

Co-authored-by: Cursor <[email protected]>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants