Skip to content

[FlyDSL] [fused_moe] Do not route MXFP4 MoE to CK-Tile when inter_dim % 256 != 0 - #5232

Merged
zufayu merged 11 commits into
ROCm:mainfrom
xiaofei-zheng:feature/xiaofei/mxfp4-cktile-inter-dim-guard
Sep 21, 2026
Merged

zufayu merged 11 commits into
ROCm:mainfrom
xiaofei-zheng:feature/xiaofei/mxfp4-cktile-inter-dim-guard

Conversation

@xiaofei-zheng

@xiaofei-zheng xiaofei-zheng commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

[fused_moe] Do not route MXFP4 MoE to CK-Tile when inter_dim % 256 != 0

Kernel-level defect report: #5233. This PR is the host-side mitigation. If the
CK-Tile stage-2 scale indexing is fixed there, the guard added here becomes dead and should be
dropped in favour of the kernel fix.

Problem

MXFP4 MoE (QuantType.per_1x32, q_dtype_w = fp4x2) returns badly wrong results whenever
inter_dim % 256 != 0 — e.g. inter_dim = 384, which is what a moe_intermediate of 3072
gives at TP8. There is no error, no warning and no NaN; only the output is wrong.

rel L2 per stage against torch_moe_stage1 / torch_moe_stage2, token=32, model_dim=6144,
E=256, topk=8, block_m=32, split_k=2, with stage 2 fed the reference stage-1 output so the two
stages are isolated:

 inter     path    stage1    stage2
   256   cktile  0.003933  0.004314
   384   cktile  0.003986 10.280723   <-- broken
   384   flydsl  0.000003  0.004304
   512   cktile  0.003995  0.004376
   640   cktile  0.003990  8.005772   <-- broken
   640   flydsl  0.000002  0.004379
   768   cktile  0.003996  0.004297

The same pattern holds at E=129 topk=5.

Root cause

CK-Tile stage 2 reduces over inter_dim and indexes its E8M0 weight scales in groups of 8
blocks (8 x 32 = 256 elements). The host pads the scale group dimension up to a multiple of 8
(shuffle_scale / e8m0_shuffle), so at inter_dim % 256 != 0 the scale tensor handed to the
kernel has a wider group stride than the kernel assumes and stage 2 consumes the wrong scales.
Stage 1 reduces over model_dim and is unaffected.

This is a kernel indexing bug, not just a read of uninitialised pad bytes: pre-filling the w2
scale pad with a known byte before e8m0_shuffle changes the error but does not remove it
(at 384, uninitialised -> nan, 0x7F -> 10.239, 0x00 -> 0.686; at 512 all three are 0.0038).

Fix

Both changes are host-side. The CK-Tile HIP/CK source is not in this repository, so this PR
stops the broken shape from reaching the kernel rather than fixing the kernel.

aiter/fused_moe.py. get_2stage_cfgs gains cktile_mxfp4_ok, which gates the two CK-Tile
MXFP4 dispatch sites and routes the affected Swiglu shapes onto the same a16w4 FlyDSL kernels
SiTUv2 already uses. The guard also requires that a FlyDSL branch can actually accept the shape,
so fp16 activations — which have no FlyDSL mxfp4 kernel here — keep their current routing
instead of being left with no backend at all.

The takeover is limited to the numerically validated path: BF16 output, BF16 activation,
SEPARATED weights, both weights marked shuffled, 128-aligned inter_dim, and 256-aligned
model_dim. FP16 output and FP4/FP8 activation families are not made newly eligible by this
guard. If no safe FlyDSL route exists, _fused_moe_impl and cktile_moe_stage2 raise
NotImplementedError before CK-Tile can return a corrupt result.

Unsafe tuned, custom, and online-tuned CK-Tile stage-2 rows — including the
swiglu_mxfp4_bf16_cktile alias — are discarded before their early return and fall back to the same heuristic selection. The runtime check in cktile_moe_stage2
is the final guard for direct callers.

aiter/ops/shuffle.py. The is_guinterleave=False branch allocated the padded scale buffer
with torch.empty and never wrote the pad, so a kernel reading a whole 8-group tile consumed
stale device memory (E8M0 0xFF is NaN). It now fills with 0x7F (E8M0 1.0), matching the
is_guinterleave=True branch. This removes the nondeterminism, not the corruption.

Already-256-aligned shapes are unaffected

get_2stage_cfgs returns a field-identical MOEMetadata at inter_dim 256 / 512 / 768 — both
stage callables, every bound functools.partial keyword, block_m, ksplit and all flags —
compared against the same function with cktile_mxfp4_ok forced to True.

Dispatch tests cover the aligned and non-aligned inter_dim matrix, all six bf16/fp4/fp8
activation and SEPARATED/INTERLEAVE layout pairs, model_dim=1152, unsafe tuned CK-Tile metadata,
the packed-activation runtime guard, an explicit AITER_KSPLIT=2 reroute, and standard-layout
scale padding. Aligned MXFP4 and non-FP4 calls remain allowed.

Cost of the re-route

The re-routed shapes land on the FlyDSL heuristic fallback, because tuned_fmoe.csv has no rows
for a non-256-aligned inter_dim on this path (fallback count in a serving run goes 48 -> 72).
On MiniMax-M3-MXFP4, TP8, MI355X, against the same 512-padded baseline (vllm bench serve,
ISL 8192 / OSL 1024, concurrency 64, 2x2 interleaved paired runs):

intermediate kernel output correct throughput vs 512-padded
512 (padded) CK-Tile yes baseline
384 CK-Tile no +12.89 %
384 FlyDSL (this PR) yes +4.26 %

The gap is tuning, not a kernel limitation: it closes by adding tuned rows for non-256-aligned
inter_dim, or by fixing the CK-Tile stage-2 scale indexing so the shape can stay on CK-Tile.

Test plan

op_tests/test_moe_mxfp4_inter_dim_dispatch.py contains the dispatch and safety cases. It is at
the op_tests top level and has a pytest.main entry point, so the standard direct-python Aiter
CI runner executes it. op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py keeps the three
GPU numerics cases for FlyDSL toolchains that can compile the a16w4 port.

Reverting only the original dispatch guard fails the three dispatch and three numerics cases:

dispatch  inter_dim=128  expected flydsl, got stage1=cktile stage2=cktile
dispatch  inter_dim=384  expected flydsl, got stage1=cktile stage2=cktile
dispatch  inter_dim=640  expected flydsl, got stage1=cktile stage2=cktile
numerics  inter_dim=128  rel L2 18.193647   (gate: < 5e-2)
numerics  inter_dim=384  rel L2 10.408027
numerics  inter_dim=640  rel L2  7.897558

The aligned dispatch and CK-Tile runtime cases ensure the safety checks do not reject supported
shapes.

Limitations

  • The numbers above were produced on aiter 0.1.19 with this change applied on MI355X (gfx950),
    not on a main build. main's FlyDSL a16w4 kernel source needs a newer flydsl than the 0.2.4
    in the test image: aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm1.py fails codegen with
    TypeError: s_waitcnt() got an unexpected keyword argument 'lgkmcnt'. This is pre-existing and
    unrelated — main at 0598b04fc with zero patches fails the shipped
    test_flydsl_moe_a16wfp4.py the same way. On main this change rests on the predicate
    equivalence above, the dispatch test (which needs no kernel), and inspection.
  • gfx950 only for end-to-end numerics. No gfx942, expert-parallel (is_ep=True), or INTERLEAVE
    numerics coverage.
  • inter_dim below 256 is covered by dispatch and safety tests but not by an end-to-end model run.
  • Shapes with no compatible FlyDSL route now fail explicitly; only the kernel fix can make them
    executable on CK-Tile.

Downstream

vllm-project/vllm#55104 aligns the ROCm AITER W4A4 MoE intermediate size to 128 and depends on
this PR. It is kept as a draft until this one lands, because without this guard that alignment
change silently corrupts decode output (clean-corpus perplexity 10.936 -> 41.325).

CK-Tile's 2-stage MXFP4 stage-2 (moe_cktile2stages_gemm2) reduces over
inter_dim and indexes its e8m0 weight scales in groups of 8 blocks
(8 * 32 = 256 elements). The host pads the scale group dimension up to a
multiple of 8 groups (shuffle_scale), so when inter_dim is not a multiple of
256 the kernel reads the wrong groups. There is no error, no warning and no
NaN: the model loads, serves, is measurably faster, and only the output is
wrong. Measured rel L2 against torch_moe_stage1/2 through fused_moe:
18.19 at inter_dim=128, 10.41 at 384, 7.90 at 640, versus ~5e-3 at 256/512/768.

Steer those shapes onto the FlyDSL a16w4 kernels, which are correct at any
128-aligned inter_dim. The guard is qualified by whether a FlyDSL branch can
actually take the shape, so nothing is left without a backend -- fp16
activations have no FlyDSL mxfp4 kernel and keep their current routing. Swiglu
re-routed onto a16w4 is validated in _fused_moe_impl alongside SiTUv2, since it
inherits the same constraints; that turns a silently wrong result into an
explicit NotImplementedError for shapes that are already broken today.

Also initialise the shuffle_scale pad. The is_guinterleave=False branch
allocated with torch.empty and never wrote the pad, so a kernel reading a whole
8-group tile consumed stale device memory (e8m0 0xFF is NaN). This does not fix
the corruption on its own; it removes the nondeterminism from it.

Add op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py. The dispatch test
inspects only the MOEMetadata, so it holds on any toolchain; the numerics test
runs the re-routed shapes end to end. Both fail without this change.

Co-authored-by: Cursor <[email protected]>
@xiaofei-zheng
xiaofei-zheng requested review from a team and a lite review from Copilot September 3, 2026 07:19
@github-actions github-actions Bot changed the title [fused_moe] Do not route MXFP4 MoE to CK-Tile when inter_dim % 256 != 0 [FlyDSL] [fused_moe] Do not route MXFP4 MoE to CK-Tile when inter_dim % 256 != 0 Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5232 --add-label <label>

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 opt this PR out.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes backend dispatch and shape validation for a correctness-critical GPU MoE path, so it warrants final human review despite targeted test coverage.

Pull request overview

Host-side mitigation for incorrect MXFP4 fused_moe results by preventing dispatch to CK-Tile 2-stage MoE when inter_dim % 256 != 0, and making scale padding deterministic to avoid shape-dependent reads of uninitialized device memory.

Changes:

  • Add cktile_mxfp4_ok gating in get_2stage_cfgs to reroute affected MXFP4 shapes off CK-Tile and onto FlyDSL when a valid FlyDSL backend exists.
  • Validate the newly rerouted Swiglu shapes against the existing a16w4 FlyDSL constraints at the fused_moe call site (raising NotImplementedError instead of silently returning wrong results).
  • Initialize padded scale buffers in shuffle_scale and add a targeted dispatch/numerics regression test.
File summaries
File Description
op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py Adds dispatch and numerics regression coverage for the non-256-aligned inter_dim MXFP4 Swiglu case.
aiter/ops/shuffle.py Initializes padded scale buffers to remove nondeterminism from kernels reading full padded tiles.
aiter/fused_moe.py Adds dispatch guard (cktile_mxfp4_ok) and validates rerouted shapes against FlyDSL a16w4 constraints.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/ops/shuffle.py Resolved
@zufayu
zufayu requested a review from yadaish September 4, 2026 23:44
Picks up the revert of ROCm#4994 (ROCm#5227), which deletes
op_tests/test_fused_moe_s1_fuse_fp8q.py. That file imports
aiter.ops.flydsl.utils, a module that does not exist on main, so it failed
at import on both MI35X and MI300X shard 5 and was the sole reason the
Aiter Test Gate went red on this PR -- unrelated to the MXFP4 dispatch
guard here.

No conflicts. The guard in aiter/fused_moe.py, the shuffle_scale pad
initialisation and the new dispatch/numerics test are unchanged; the only
file main and this branch both touched is aiter/fused_moe.py, where the
revert removes the stage-1 fp8-quant fusion and merges cleanly.
Copilot AI review requested due to automatic review settings September 7, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new reroute/validation predicates should encode FlyDSL’s 128-alignment requirement for inter_dim to avoid steering unsupported shapes onto FlyDSL and failing at runtime.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

aiter/fused_moe.py:2784

  • The CK-Tile MXFP4 reroute predicate (cktile_mxfp4_ok) is based on _flydsl_can_take_over, but _flydsl_can_take_over currently does not encode FlyDSL’s K-axis alignment requirement. FlyDSL MXFP4 kernels generally require K (here inter_dim) to be divisible by 128 (e.g. aiter/ops/flydsl/batched_gemm_mxfp4.py:298,331), so shapes with inter_dim % 256 != 0 but also inter_dim % 128 != 0 could be steered off CK-Tile and then fail/behave incorrectly in FlyDSL. Consider constraining takeover to inter_dim % 128 == 0 to match the intent described in the PR.
    _flydsl_can_take_over = (
        dtype in [dtypes.bf16, dtypes.fp16]
        and q_type == QuantType.per_1x32
        and q_dtype_a in (dtypes.bf16, dtypes.fp4x2, dtypes.fp8)
        and is_shuffled
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread aiter/fused_moe.py Resolved
@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

@yadaish — thank you for picking this one up. Whenever you have a moment, could I kindly ask for your review?

CI is now fully green on the current head (f4021ced9). The two shard-5 failures in the earlier run were unrelated to this change: they came from op_tests/test_fused_moe_s1_fuse_fp8q.py, which imports aiter.ops.flydsl.utils, a module that does not exist on main. That file was removed by the revert in #5227, so merging main picked up the deletion and every required check now passes, including the Aiter Test Gate.

A short recap, in case it saves you a pass over the description:

  • MXFP4 MoE with inter_dim % 256 != 0 — e.g. 384, which is what a moe_intermediate of 3072 gives at TP8 — is silently wrong on the CK-Tile 2-stage path. Stage 2 mis-indexes its E8M0 weight scales once the host pads the scale group dimension. No error, no warning, no NaN; only the output is wrong.
  • This PR keeps those shapes off CK-Tile and routes them to the FlyDSL a16w4 kernels, which are correct at any 128-aligned inter_dim. Shapes that are already 256-aligned keep exactly the same dispatch.
  • The kernel-level defect is tracked separately in MXFP4 MoE: CK-Tile stage-2 mis-indexes E8M0 scales when inter_dim % 256 != 0, returning silently wrong results #5233. If the CK-Tile stage-2 scale indexing is fixed there, the guard added here becomes dead and should be dropped in favour of the kernel fix.

One more reason I would be grateful for your time: there is a downstream vLLM change waiting on this one. vllm-project/vllm#55104 aligns the ROCm AITER W4A4 MoE intermediate size to 128 instead of 256, which gives 25 % smaller expert weights and +4.27 % output throughput on MiniMax-M3-MXFP4 (MI355X, TP8). It is deliberately kept as a draft, because without the guard in this PR that alignment change silently corrupts decode output — clean-corpus perplexity goes from 10.936 to 41.325. I will only take it out of draft once this one lands.

Please let me know if you would like anything reworked, or the change split up differently — happy to adjust.

_flydsl_can_take_over is meant to hold only for shapes a FlyDSL branch can
actually accept, but it did not encode the K-axis alignment those kernels
require. Both gemm1 ports assert 2*D_INTER % 256 == 0 -- a 128-aligned
inter_dim -- in moe_2stage_a16wmix/gemm1.py and mxfp4_gemm1_kernels.py. An
inter_dim that is neither 128- nor 256-aligned (192, 320) was therefore steered
off CK-Tile into a kernel assertion, trading a silently wrong result for a
crash rather than for a correct one.

Add the alignment term to _flydsl_can_take_over and mirror it in
_fused_moe_impl's _is_a16w4_swiglu_rerouted, so the impl-side validation keeps
firing exactly when the shape is re-routed. Such a shape now stays on CK-Tile
and keeps the wrong result this guard exists to avoid: no backend here computes
it correctly, and the kernel-level fix tracked in ROCm#5233 is what closes it. The
gap is deliberate and now pinned by a test rather than left implicit.

Dispatch over inter_dim in {128, 192, 256, 320, 384, 512, 640, 768, 1024},
with the predicates lifted out of the source with ast so the check cannot drift
from the code: 192 and 320 move from flydsl to cktile, the other seven values
are unchanged, and _is_a16w4_swiglu_rerouted agrees with the dispatch decision
on every value.

Extend the dispatch test with NON_128_ALIGNED = [192, 320], expected to stay on
CK-Tile. It compiles no kernel, so it runs on any FlyDSL toolchain.

Raised by Copilot in review on ROCm#5232.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 10, 2026 10:47

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.

🟢 Approval recommended

The changes are tightly scoped host-side safeguards with consistent validation and targeted regression tests, and they preserve existing routing for already-256-aligned shapes.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

@zufayu — you kindly assigned @yadaish as the reviewer here on Sep 4. Could I ask for your help
moving this one along, or for a pointer to someone better placed to review it if yadaish is tied
up?

Where the PR stands, so the ask is concrete:

  • CI is fully green on the current head (c8e841b0c): 35 checks passing, none failing —
    including the Aiter Test Gate, both wheel builds, and all 16 single-GPU shards across MI35X
    and MI300X.
  • Both points Copilot raised have been addressed: the shuffle_scale pad-initialisation
    question, and in c8e841b the missing inter_dim % 128 term in the FlyDSL takeover
    predicate. Copilot's latest pass reports "Approval recommended" with no new comments.
  • The change is small and contained — 3 files, host-side only. Shapes with an already
    256-aligned inter_dim keep an identical dispatch: same kernels, same bound parameters.

Why I am nudging rather than simply waiting: this covers a silent-correctness bug
(#5233 — MXFP4 MoE returns badly wrong results with no error, no warning and no NaN
whenever inter_dim % 256 != 0, which a moe_intermediate of 3072 at TP8 hits directly). A
downstream vLLM change is also held as a draft until this lands: vllm-project/vllm#55104, which
without this guard silently corrupts decode output.

Happy to split the change up or rework anything if that would make review easier.

130 commits, no conflicts. Nine of them touch aiter/fused_moe.py, including the
MXFP4 fused-MoE work in ROCm#5300, ROCm#4526 and ROCm#4985, so the three things this guard
rests on were re-checked against the merge result:

* tuned_fmoe.csv still carries no mxfp4 row with a non-256-aligned inter_dim,
  so the tuned path cannot hand an affected shape to CK-Tile behind the guard.
* The CK-Tile stage-2 scale indexing is still unfixed (ROCm#5233 open), so the
  host-side guard is still needed.
* Dispatch is unchanged: inter_dim 128/384/640 to FlyDSL, 192/320 and the
  256-aligned values on CK-Tile, with _fused_moe_impl's validation firing on
  exactly the re-routed shapes.
Copilot AI review requested due to automatic review settings September 16, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved routing, shape-safety, tuned-configuration, and CI-collection issues remain.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py:113

  • [verified] This new test file is not collected by the standard Aiter CI: .github/scripts/split_tests.sh:53 and .github/scripts/aiter_test.sh:30 scan only op_tests at max depth 1, and no workflow references op_tests/flydsl_tests. As a result, both the dispatch and numerical regression tests can be skipped while CI remains green. Author must wire this subdirectory into a CI test target or move these tests under a collected target.
@_SKIP
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/fused_moe.py Resolved
Centralize the FlyDSL takeover constraints so bf16 INTERLEAVE layouts and model dimensions that violate the a16w4 tile-K requirement no longer get routed to an incompatible kernel. FP8 INTERLEAVE remains eligible because its registered kernel names select the interleaved variant.

Discard unsafe tuned CK-Tile stage-2 rows before their early return. Add matching checks in _fused_moe_impl and cktile_moe_stage2 so unsupported, custom, online-tuned and direct-call paths fail explicitly instead of silently returning corrupt output.

Move dispatch and safety coverage to an op_tests top-level file collected by standard Aiter CI, and add the pytest main entry point required by aiter_test.sh's direct-python runner. Keep the toolchain-dependent GPU numerics cases in flydsl_tests.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 09:43
@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

Also addressed the suppressed CI-collection finding in 7266333: dispatch, unsupported-shape, tuned-config, and CK-Tile runtime-guard coverage now lives in op_tests/test_moe_mxfp4_inter_dim_dispatch.py. The top-level file is included by split_tests.sh, and its pytest.main entry point makes the direct-python Aiter runner execute the tests rather than only import them. The toolchain-dependent GPU numerics cases remain in op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical routing correctness issues remain, along with missing coverage for standard-layout scale initialization.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (2)

aiter/ops/shuffle.py:357

  • The new initialization is not directly covered: the existing scale-padding test exercises is_guinterleave=True, while the new numerics test routes through FlyDSL and can pass without ever reading these padded bytes. A regression back to torch.empty in this standard-layout branch would therefore go unnoticed and reintroduce nondeterministic E8M0 values; add a standard-layout test that asserts padded columns/rows contain the neutral 0x7F value (and the multi-byte fallback where applicable).
        if scale_padded.element_size() == 1:
            scale_padded.view(torch.uint8).fill_(0x7F)
        else:
            scale_padded.fill_(1.0)

op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py:130

  • This comment has a grammatical error: “the CK-Tile scale mis-indexing this test guards against produces” is not a valid sentence, which makes the test rationale unclear.
    # this test guards against produces 0.7 or more.
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/fused_moe.py Resolved
Copilot AI review requested due to automatic review settings September 16, 2026 10:57
@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

Also addressed both suppressed findings in 3b901a5: the standard-layout shuffle_scale branch now has direct tests for the neutral 0x7F uint8 padding and the multi-byte 1.0 fallback, after reversing the layout transform to inspect the padded buffer. The numerics-test comment was shortened to state the measured error ranges directly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved routing paths can select incompatible layouts or bypass safe FlyDSL rerouting.

Review details

Suppressed comments (2)

aiter/fused_moe.py:3443

  • Although _can_reroute_mxfp4_to_flydsl rejects the FP8 + GateMode.SEPARATED pairing, this fallback still ignores gate_mode. For the new matrix case (q_dtype_a=fp8, gate_mode=SEPARATED, inter_dim=384), use_mxfp4_flydsl selects an _gui FP8 stage-1 kernel, which consumes GUGU weights rather than the supplied GGUU layout; the dispatch test therefore cannot enforce the stated safety contract. Apply the same exact activation/layout pairing to this non-_is_a16w4 branch so unsupported calls remain on the guarded CK-Tile path.
    use_mxfp4_flydsl = _is_a16w4 or (
        dtype in [dtypes.bf16, dtypes.fp16]
        and q_type == QuantType.per_1x32
        and (
            activation in (ActivationType.Swiglu, ActivationType.Situv2)

aiter/fused_moe.py:3431

  • This reroute is still bypassed whenever ksplit > 1: the later heuristic at lines 3530-3569 returns cktile_moe_stage2 when (ksplit > 1 or swiglu_mxfp4_bf16_cktile), and that condition does not include cktile_mxfp4_ok. For a supported bf16/SEPARATED non-256 shape with split-K enabled (including AITER_KSPLIT=2), _fused_moe_impl therefore reaches the new final guard and raises instead of selecting the safe a16w4 FlyDSL route. Gate that fallback with the safety flag or otherwise make the reroute take precedence.
    _is_a16w4_swiglu_rerouted = (
        not cktile_mxfp4_ok
        and dtype in [dtypes.bf16, dtypes.fp16]
        and q_type == QuantType.per_1x32
        and activation == ActivationType.Swiglu
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Use one activation/layout compatibility predicate in both the CK-Tile takeover decision and the generic MXFP4 FlyDSL branch. FP8 kernels are registered as INTERLEAVE-only, while bf16/fp4 kernels consume SEPARATED weights, so FP8 + SEPARATED can no longer re-enter FlyDSL after being rejected by the takeover check.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 11:15
Add a dispatch regression with AITER_KSPLIT=2. The safe FlyDSL branch returns before the later generic CK-Tile split-K fallback, so split-K does not bypass the non-256-aligned reroute.

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

Copy link
Copy Markdown
Contributor Author

Addressed the latest review on head 6b52577:\n\n* FP8 + SEPARATED could re-enter the generic FlyDSL fallback after failing the takeover check. dcb99a8 now applies one shared activation/layout predicate to both paths: bf16/fp4 use SEPARATED and fp8 uses INTERLEAVE.\n* I could not reproduce the claimed ksplit > 1 bypass. For a supported bf16/SEPARATED non-256 shape, _is_a16w4_swiglu_rerouted makes use_mxfp4_flydsl true and returns FlyDSL metadata before the later CK-Tile split-K branch is reachable. 6b52577 adds an AITER_KSPLIT=2 dispatch regression that pins this control flow.\n\nThe same test file also covers the complete six-case activation/layout matrix.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical and moderate routing-safety findings remain in aiter/fused_moe.py.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

aiter/fused_moe.py:3054

  • This filter only recognizes the cktile_ prefix, but the repository has configured MXFP4 CK-Tile rows named swiglu_mxfp4_bf16_cktile (for example aiter/configs/model_configs/gptoss_a16w4_tuned_fmoe.csv:2), and the heuristic below explicitly treats that family as the CK-Tile fallback. An unsafe tuned/custom row using that name therefore survives this check and can bypass the stage-2 safety guard; classify the alias as CK-Tile before returning configured metadata.
        if cktile_mxfp4_unsafe and kn2.startswith("cktile_"):
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread aiter/fused_moe.py Resolved
Base CK-Tile takeover on the existing both-weights-shuffled signal rather than the aggregate OR flag. This prevents a shuffled W1 from routing an unshuffled W2 into the FlyDSL stage-2 preshuffled layout.

Recognize the swiglu_mxfp4_bf16_cktile configured alias as CK-Tile stage 2 so unsafe custom rows are discarded with the regular cktile_* family. Extend dispatch coverage for one-sided shuffle state and both configured names.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 12:15
@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

Also fixed the suppressed configured-alias finding in f30bf41: unsafe stage-2 rows named either cktile_* or swiglu_mxfp4_bf16_cktile are now classified as CK-Tile and discarded before configured metadata can return. The tuned-config test is parameterized over both names.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical FP16 output-corruption path remains unresolved, and newly rerouted FP4/FP8 layout families lack numerical regression coverage.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

op_tests/test_moe_mxfp4_inter_dim_dispatch.py:118

  • The new takeover branches for q_dtype_a=fp4x2/SEPARATED and q_dtype_a=fp8/INTERLEAVE are only checked by backend-name assertions here; no test runs those newly rerouted paths through fused_moe and compares their output. A dispatch test would still pass if the activation/scale layout were wrong, which is especially risky for this silent-numerical-corruption fix. Add at least one numerical regression case for each new activation/layout family (or keep those families out of the takeover until they are validated).
def test_mxfp4_swiglu_takeover_matches_weight_layout(q_dtype_a, gate_mode, want):
    meta = _dispatch(q_dtype_a=q_dtype_a, gate_mode=gate_mode)
    assert _stage_backend(meta.stage2) == want
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread aiter/fused_moe.py Resolved
The ported a16w4 stage-2 kernel stores BF16, so routing an FP16 output buffer through it corrupts the result. Restrict the CK-Tile takeover to BF16 output with BF16 activation and SEPARATED weights, which is the path covered by the numerical regression.

FP4/FP8 activation families keep their pre-existing generic dispatch; unsafe FP8 INTERLEAVE no longer becomes newly eligible through the CK-Tile guard. Add an FP16-output regression and update the dispatch matrix.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 17, 2026 03:33
@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

Addressed the suppressed numerical-coverage finding by narrowing the change rather than claiming untested coverage. In 8a851e2, the new CK-Tile takeover applies only to the BF16-output, BF16-activation, SEPARATED path covered by test_mxfp4_swiglu_non_256_aligned_numerics. FP4/FP8 activation families are no longer newly rerouted by this mitigation; their existing generic dispatch remains unchanged. The dispatch suite adds FP16 output and updates the FP8 INTERLEAVE expectation accordingly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

GPU dispatch and numerical correctness changes require final human validation.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@xiaofei-zheng

xiaofei-zheng commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@yifehuan @coderfeli — could either of you help review this when convenient?

This is a host-side correctness guard for non-256-aligned MXFP4 MoE. All required CI is green: 35 checks passed, including all 16 MI35X/MI300X shards. The targeted dispatch and safety suite ran on MI35X with 25/25 cases passing. The latest Copilot pass reported no new findings.

The downstream vLLM change vllm-project/vllm#55104 remains blocked on this PR.

@zufayu
zufayu merged commit 224dcee into ROCm:main Sep 21, 2026
56 checks passed
Fangzhou-Ai added a commit to Fangzhou-Ai/aiter that referenced this pull request Oct 6, 2026
…_dim % 256 != 0

ROCm#5232 kept CK-Tile stage2 away from non-256-aligned MXFP4 shapes, but the
inline-sort two-stage path still accepts them. It must not: the intermediate
scales are e8m0_shuffle'd in groups of 8 columns, so stage1 writes and stage2
read them on a stride that rounds scale-N up to a multiple of 8
(kas_c_k1_for), while the buffers sized on the exact inter_dim are short of
that stride whenever inter_dim % 256 != 0. is_mxfp4_moe_shape_supported also
pads inter_dim up to 256 before its allowlist lookup, so a 1152-wide call
reports supported by matching the 1280 instance and then runs the kernel
generated for 1280.

DeepSeek-V4.1-Flash at TP2 shards moe_intermediate 2304 to 1152 and faults
during CUDA graph capture:

  Memory access fault by GPU node-4 on address 0x7f84c9d33000.
  [aiter] Error in moe_sorting: CUDA error: an illegal memory access

tuned_fmoe.csv carries 16 tuned rows at inter_dim=1152 for (expert=384,
topk=6), so the shape is actively steered onto the faulting path. TP4 (640)
only escapes because vLLM pads it to 640 from 576 and the resulting
intermediate_pad already trips the padding check.

Reject the shape at both existing gates, matching how expert_mask is handled:
in get_2stage_cfgs so the tuned row is never selected, and in
_mxfp4_inline_sort_unsupported so an invocation that reaches it falls back
through the heuristic path. The heuristic path already runs these shapes on
a4w4 FlyDSL kernels correctly, so no shape loses a4w4 and no weights grow.

Co-authored-by: Claude Opus 5
Signed-off-by: Fangzhou Ai <[email protected]>
Co-authored-by: Cursor <[email protected]>
Signed-off-by: Fangzhou Ai <[email protected]>
Co-authored-by: Cursor <[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.

3 participants