Repository navigation
[Bugfix][fused_moe] Do not use the inline-sort MXFP4 path when inter_dim % 256 != 0 - #6184
Fangzhou-Ai wants to merge 1 commit into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
…_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]>
15f6ab9 to
4ecf522
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The aligned test controls use unsupported shapes and therefore do not verify that valid inline-sort rows remain selected.
1 open finding
What changed in this PR
Prevents non-256-aligned MXFP4 MoE shapes from using the faulting inline-sort path.
Changes:
- Adds tuned-config and invocation-time alignment guards.
- Adds dispatch tests and refactors tuned-config setup.
| File | Description |
|---|---|
aiter/fused_moe.py |
Rejects unsafe inline-sort configurations. |
op_tests/test_moe_mxfp4_inter_dim_dispatch.py |
Adds alignment coverage and shared test setup. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@aiter-bot review |
|
LGTM on the gate. The 512/1280 cases only check that the discard warning is absent. Not a merge blocker. yifehuan / Ali still need to approve. |
ROCm/aiter PR #6184 — [Bugfix][fused_moe] Do not use the inline-sort MXFP4 path when inter_dim % 256 != 0Gates the tuned inline-sort MXFP4 MoE path in fused_moe.py on inter_dim % 256 == 0 at both the tuned-row lookup and the invocation-time check, so non-256-aligned shapes (e.g. DeepSeek-V4.1-Flash TP2 inter_dim=1152, which faults in moe_sorting today) fall back to the heuristic a4w4 FlyDSL path. Review (advisory): 🔴 HIGH RISK 🔴 [verified] aiter/fused_moe.py is a stable downstream-facing MoE contract and this PR changes its default dispatch — every non-256-aligned inter_dim is rerouted off the tuned inline-sort path at fused_moe.py:3152 — yet the PR carries no maintainer review (only a bot review), so a one-approval merge lands a dispatch change for every MoE consumer unowned. Reviewer must @-mention the de-facto owner of fused_moe.py (git top committer — Felix Li/yifehuan/yadaish recently, @valarLip per the ownership snapshot) in a PR comment requesting explicit sign-off before merge. 🔴 [verified] The changed aiter/fused_moe.py dispatch is the default MoE path downstream consumes (the PR's own repro is vLLM --moe-backend aiter on DeepSeek-V4.1-Flash inter_dim=1152), but the PR carries no ci: label so every downstream job — .github/workflows/atom-test.yaml, kimi-downstream.yaml, sglang_downstream.yaml, vllm_benchmark.yaml are all label-gated — is skipped, and the PR can merge green while breaking ATOM/SGLang/vLLM invisibly. Author must add ci:all (DeepSeek is exercised by atom+sglang+vllm) and require it green before merge. |
| # width (is_mxfp4_moe_shape_supported pads before its lookup), so the call | ||
| # faults in moe_sorting instead of running slow. The heuristic fallback | ||
| # handles these shapes. | ||
| if inter % 256 != 0: |
There was a problem hiding this comment.
Thanks a lot for tracking down the TP2 crash, the write-up is really thorough! One thing I'm not sure about yet: I don't think this guard is needed in aiter, and it may end up hurting other callers.
I ran DeepSeek-V4.1-Flash at TP2 (inter_dim=1152) in ATOM on gfx950, using the same aiter without this guard. Graph capture from 512 down to 1 used the inline-sort pairs at every size, including the token-16 case from your log. There were no memory faults, and decode answered GSM8K samples correctly. The kernels also run cleanly in the op test, both eagerly and under CUDA graph.
So the fault seems specific to the vLLM DSV4 a4w4 integration. Because this guard sits in aiter's fused_moe, it would also turn off the faster inline-sort path for every other caller, including Kimi-K3 and MiniMax-M3 at I=384, which work today. It already trips CI here: MiniMax-M3 falls back to a kernel that isn't AOT-compiled.
Would you mind dumping shape, stride, dtype and is_shuffled for w1/w2/w1_scale/w2_scale at vLLM's fused_moe call site? I'm happy to share what ATOM passes so we can diff the two. Then the fix can target the exact mismatch.
|
No activity for 15 days, so this is now labelled |

Motivation
#5232 kept CK-Tile stage2 away from non-256-aligned MXFP4 shapes, and #5233 records why. The inline-sort two-stage path still accepts them, and on that path the same misalignment is a hard memory fault rather than silently wrong results.
The intermediate scales are
e8m0_shuffle'd in groups of 8 columns, so stage1 writes and stage2 reads them on a stride that rounds scale-N up to a multiple of 8 —kas_c_k1_forinmxfp4_gemm_common.pycarries that comment explicitly:The buffers sized on the exact
inter_dimare short of that stride wheneverinter_dim % 256 != 0. On top of that,is_mxfp4_moe_shape_supportedpadsinter_dimup to 256 before its allowlist lookup:MXFP4_MOE_SUPPORTED_SHAPEShas no 1152 entry, so a 1152-wide call reports supported by matching(384, 5120, 1280, 6)and then runs the aux instance code-generated for 1280.Neither existing gate catches it.
_mxfp4_inline_sort_unsupportedrejects on padding (hidden_pad or intermediate_pad) but never on alignment, and_mxfp4_moe_sort_internal_is_supported(NE, TOPK, D_HIDDEN, MB, zero_init)does not takeinter_dimat all.How it shows up
DeepSeek-V4.1-Flash shards
moe_intermediate_size 2304to 1152 at TP2. Every TP2 server dies during CUDA graph capture:With
AMD_SERIALIZE_KERNEL=3the fault lands immediately after the inline-sort pair is selected atinter_dim=1152:This is not a shape the tuner avoids:
tuned_fmoe.csvships 16 tuned rows atinter_dim=1152for(expert=384, topk=6), so the shape is actively steered onto the faulting path. TP4 escapes only by accident — its caller pads 576 up to 640, and the resulting nonzerointermediate_padalready trips the padding check, so TP4 logsinline-sort config is unsupported (hidden/intermediate padding)34440 times per boot where TP2 logs it zero times.Technical Details
Reject the shape at both existing gates, matching how
expert_maskis already handled in both places:get_2stage_cfgs: a new branch beside theis_epone, so the tuned inline-sort row is never selected. Because the lookup is cached, this also collapses the warning to once per distinct shape key (64 lines per boot instead of 25284)._mxfp4_inline_sort_unsupported: the same condition, so an invocation that still reaches it re-resolves through_resolve_metadata(disable_inline_sort=True).Nothing else changes. The heuristic fallback already runs these shapes on a4w4 FlyDSL kernels correctly — that is what TP4 does today — so no shape loses a4w4 and no weights grow. The alternative of making the caller pad
inter_dimup to 256 costs +11 % MoE weights at TP2 and +33 % at TP4 and moves both rows off every tuned row, which is strictly worse.Test Plan
Hardware: MI355X (gfx950, 256 CU), ROCm 10.0, torch 2.12.0+rocm10.0.0.
Unit, extending the suite #5232 added for exactly this shape class:
One new parametrized case,
test_tuned_inline_sort_config_honours_inter_dim_alignment, asserts a tuned inline-sort row is dropped at 384, 640 and 1152 and kept at 512 and 1280. The existingcfg_2stages/warning-capture boilerplate is factored into a_tuned_cfgcontext manager thattest_unsafe_tuned_cktile_stage2_is_discardednow shares, so the file gets shorter while covering one more behaviour.The invocation-time guard in
_mxfp4_inline_sort_unsupportedis covered end to end rather than by a unit test; faking the 18 arguments it takes was more brittle than it was worth. It is still needed because the heuristic path can select an inline-sort pair without going through a tuned row.End to end:
deepseek-ai/DeepSeek-V4.1-Flashat TP2 (inter_dim=1152), 1M context, DSparknum_speculative_tokens=5,--moe-backend aiter, MXFP4 indexer KV,VLLM_ROCM_USE_AITER_MOE_A4W4_DSV4=1,--max-cudagraph-capture-size 1024. Accuracy vialm_evallocal-chat-completionswith--apply_chat_template, all 1319 GSM8K questions, 5-shot,max_tokens=16384,temperature=0.Test Result
op_tests/test_moe_mxfp4_inter_dim_dispatch.py: 30 passed. Reverting thefused_moe.pyhunk fails exactly the three unaligned cases and leaves the two aligned controls passing.op_tests/flydsl_tests/test_moe_mxfp4_inter_dim_align.py: 3 failed, identically with and without this patch —module_moe_asmdoes not JIT-build in my worktree, so those are environmental.End to end at TP2,
inter_dim=1152:/healthThe server logs 64
discarding tuned inline-sort config at inter_dim=1152, which is not a multiple of 256lines and then runs the experts on the a4w4 FlyDSL kernels (flydsl_mxmoe_g1_a4w4_*+flydsl_moe2_layout_afp4_wfp4_bf16_*), confirming the fallback keeps a4w4 rather than dropping to a16w4.Submission Checklist
black==26.3.0, linted withruff==0.15.7; both clean on the two changed files.AI assistance (Claude Opus 5 via Cursor) was used to root-cause the fault and draft this change. I reviewed every changed line and ran every command above myself on the MI355X node.