Skip to content

[FlyDSL] [MoE] Support row-strided MXFP4 activations - #7500

Merged
coderfeli merged 4 commits into
ROCm:mainfrom
XiaobingSuper:feat/mxfp4-row-strided-input
Nov 12, 2026
Merged

coderfeli merged 4 commits into
ROCm:mainfrom
XiaobingSuper:feat/mxfp4-row-strided-input

Conversation

@XiaobingSuper

@XiaobingSuper XiaobingSuper commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Support row-major, row-strided BF16 activations in the inline-quant MXFP4 fused MoE path without materializing the input.

Motivation

Fusing projections can produce a slice whose feature dimension is contiguous but whose row stride is wider than hidden_size. The MXFP4 inline-quant kernel previously assumed a tightly packed activation and rejected this valid layout, forcing the caller to materialize the slice.

Changes

  • Pass the BF16 activation row stride to the FlyDSL stage-1 kernel and use it for row addressing.
  • Keep the zero-copy path for 2D row-major views (stride(1) == 1); materialize unsupported activation layouts before dispatch so they do not fail in a downstream kernel.
  • Extend the existing MXFP4 fused-MoE test with row-strided correctness, unsupported-layout fallback, and CUDA Graph replay coverage.
  • Preserve the existing contiguous path and all weight/routing tensor layout requirements.

Performance

MI355X (gfx950), Kimi-K3 MXFP4 fused MoE (E=896, H=3584, I=384, topk=16), CUDA Graph replay, six alternating rounds of 300 replays:

Tokens Contiguous Row-strided (stride(0)=4480) Delta
1 21.111 us 20.989 us -0.58%
4 34.322 us 34.156 us -0.48%
16 87.746 us 87.399 us -0.40%
32 145.572 us 146.350 us +0.53%
64 217.579 us 217.778 us +0.09%

The row-strided path is within 0.6% of the contiguous baseline and adds no copy, allocation, or kernel launch.

Testing

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

Validation on MI355X (gfx950):

python3 op_tests/test_moe_sorting_mxfp4.py

Passed for row-strided vs contiguous output, inner-strided fallback vs an explicitly materialized reference, padding/num_local_tokens, and CUDA Graph capture/replay.

Black and Ruff pass for all five changed files.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed: the public fused-MoE API is unchanged.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

81834417580286eccf3308385547b3e2d976dc8a

Behavior and intent

The inline-quant MXFP4 stage-1 kernel now addresses each activation row using its runtime byte stride. Tightly packed inputs retain the same address calculation. Row-major sliced/padded views stay zero-copy; layouts that are not row-major are materialized before kernel selection.

Validation and unverified scope

Correctness, CUDA Graph replay, formatting, lint, and focused performance were validated on gfx950. MI250X and MI300X were not tested; the changed MXFP4 inline-sort specialization is selected on gfx950.

PR-specific question

Before this PR, the changed test would fail when the Kimi-K3 activation is a row-major slice with a wider parent stride: inline sort rejects the non-contiguous tensor, and the tightly packed row-address calculation cannot consume it directly. It would also expose unsupported inner-strided inputs reaching a downstream layout assumption instead of being safely materialized. The existing check covered padding and num_local_tokens only with contiguous activations; it did not exercise a runtime row stride, a non-row-major fallback, or CUDA Graph replay of the strided path.

Changed op tests

op_tests/test_moe_sorting_mxfp4.py: extends the existing Kimi-K3 inline-sort/padding check with the model-relevant row-strided activation, unsupported inner-stride fallback, and CUDA Graph replay. This covers the new runtime-stride ABI and fallback behavior without adding a separate test suite.

@XiaobingSuper
XiaobingSuper requested review from a team and a balanced review from Copilot November 5, 2026 07:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 5, 2026

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

@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision fc793180a3cc · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

@Bernard-Liu

Copy link
Copy Markdown
Contributor

Row strides that are not a multiple of 16 bytes give silently wrong output

_is_row_major_2d accepts any stride(0) >= shape[1], but the stage-1 kernel reads hidden rows in 16-byte tiles: inline_quant_load_kt indexes hidden_tiles with v_voff // 16, so the low bits of row_token * hidden_row_stride_bytes are dropped. A bf16 activation whose row stride is not a multiple of 8 elements is therefore accepted onto the zero-copy inline-sort path, and every row whose byte offset is not 16-byte aligned is read from a shifted address. No error is raised.

This is a regression. Before this PR, such inputs failed the is_contiguous() check and took the fallback path, which produces correct results.

Repro on gfx950 with the Kimi-K3 shape from _check_fused_moe_inline_sort_pad_rows (tokens=32), compared against the same values in a contiguous tensor:

Activation Path Rel. error
randn(T, H + 64)[:, :H] (row stride 7296 B) inline-sort 0.004
randn(T, H + 4)[:, :H] (row stride 7176 B) inline-sort 1.03
randn(T, H + 1)[:, :H] (row stride 7170 B) inline-sort 1.36

On the base commit, the last two cases take the fallback path and match the contiguous fallback output bit for bit.

@Bernard-Liu

Copy link
Copy Markdown
Contributor

Low priority: single-row activations that PyTorch considers contiguous are now rejected from inline sort

PyTorch ignores the stride of size-1 dimensions, so a (1, H) tensor with stride (1, 1) (for example x.view(H, 1).t()) has is_contiguous() == True. Before this PR, such a tensor passed the inline-sort check and used the tuned row. Now _is_row_major_2d requires stride(0) >= shape[1], so _mxfp4_inline_sort_unsupported rejects it. The early .contiguous() in _fused_moe_impl doesn't apply either, because the tensor is already contiguous.

As a result, the call drops the tuned inline-sort config and falls back to the heuristic MXMOE kernels (flydsl_mxmoe_g1_a4w4_64x256x256_situv2 / flydsl_moe2_layout_afp4_wfp4_bf16_t64x256x128_reduce_sbm64). It also logs inline-sort config is unsupported (non-contiguous tensors) on every call, which is misleading because the tensor is contiguous.

Repro on gfx950 with the Kimi-K3 shape (the token=1 row exists in kimik3_a4w4_tuned_fmoe.csv):

Activation Base This PR
x0[:1].clone(), stride (3584, 1) inline-sort inline-sort
torch.as_strided(x, (1, H), (1, 1)) inline-sort fallback

The fallback output is still correct; this only costs performance and adds log noise.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 08:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderfeli
coderfeli merged commit 27faf0a into ROCm:main Nov 12, 2026
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
* feat(moe): support row-strided MXFP4 activations

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

* [FlyDSL] Fix MXFP4 row-stride alignment

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

* [FlyDSL] Cover unit-stride single-row input

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

* [FlyDSL] Compare unit-stride rows against a packed reference

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

---------

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

6 participants