Skip to content

[Fix] [AMD] moe: Keep is_shuffled on AITER-shuffled unquantized MoE weights - #48219

Merged
HaiShaw merged 1 commit into
sgl-project:mainfrom
wmlba:fix-aiter-unquant-moe-is-shuffled
Nov 12, 2026
Merged

HaiShaw merged 1 commit into
sgl-project:mainfrom
wmlba:fix-aiter-unquant-moe-is-shuffled

Conversation

@wmlba

@wmlba wmlba commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On ROCm with the AITER MoE runner, UnquantizedFusedMoEMethod.process_weights_after_loading shuffles w13_weight and w2_weight with aiter.ops.shuffle.shuffle_weight(..., (16, 16)) and stores the result with copy_or_rebind_param. shuffle_weight marks the tensor it returns with is_shuffled = True, but copy_or_rebind_param detaches it and copies the data into the existing Parameter, so the parameter that reaches aiter.fused_moe has no is_shuffled attribute.

aiter.fused_moe reads is_shuffled to choose between the preshuffle_on and preshuffle_off CK 2-stage MoE modules and to accept tuned fMoE configs (it warns that tuned kernels expect preshuffled weights). As a result, unquantized BF16 MoE models always run the preshuffle_off path on weights that were shuffled, and tuned configs for these shapes cannot be applied.

This is the same issue that #47870 fixes for the compressed-tensors W8A8 FP8 MoE path, here in the unquantized path.

Modifications

Set is_shuffled = True on layer.w13_weight and layer.w2_weight right after each copy_or_rebind_param call. Weight bytes, dtype and layout are unchanged; only the attribute that aiter.fused_moe checks is restored.

Accuracy Tests

MI350X (gfx950, 256 CUs), AITER 2bb5491. One EP rank of a BF16 MoE layer: 512 experts (256 local via expert_mask), top-10, hidden 2560, expert intermediate 640, SiLU, fused gate/up, called through aiter.fused_moe exactly as AiterRunnerCore does. Output compared with a float32 PyTorch reference:

Tokens Before: cosine / rel. error After: cosine / rel. error
1 0.99999 / 0.0046 0.99999 / 0.0044
16 0.999992 / 0.0040 0.999992 / 0.0040
256 0.999993 / 0.0038 0.999993 / 0.0038
4096 0.999992 / 0.0039 0.999992 / 0.0039

End to end (TP2 + EP2 replica, greedy, this change plus tuned fMoE rows for the shape), answers and token log-probabilities stayed within run-to-run variation (mean absolute log-prob delta vs a fixed reference: 0.0145 / 0.0146 before, 0.0151 / 0.0167 after).

Speed Tests and Profiling

Same layer, aiter.fused_moe per call (CUDA events, microseconds):

Tokens Before After
1 140.2 106.3
4 115.4 104.1
16 159.1 146.1
256 475.9 459.6
1024 593.5 571.0
4096 718.1 680.1
16384 1859.2 1857.9

With the change the engine loads module_moe_ck2stages_b16_b16_preshuffle_on_... instead of module_moe_ck2stages_b16_b16_preshuffle_off_..., and tuned fMoE rows for the shape are picked up instead of the 2-stage default. End-to-end measurements were taken on SGLang 34c4ba1 with this change applied; the code path is unchanged on main.

Checklist


CI States

Latest PR Test (Base): ❌ Run #41703663575
Latest PR Test (Extra): ❌ Run #41703662756
Latest PR Test (AMD ROCm 10): ❌ Run #41703662869

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

…eights

copy_or_rebind_param copies the shuffled weights into the existing
Parameter, which drops the is_shuffled marker set by shuffle_weight.
aiter.fused_moe uses the marker to select the preshuffled CK MoE kernels
and to apply tuned fMoE configs. Restore it after each copy, as done for
the compressed-tensors FP8 MoE path in sgl-project#47870.
@github-actions github-actions Bot added the quant LLM Quantization label Nov 3, 2026
@wmlba
wmlba marked this pull request as ready for review November 3, 2026 19:37

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@kangwangamd

Copy link
Copy Markdown
Contributor

Confirming from the CT-FP8 side (#47870) — same bug class, and your perf numbers
answer a question I left open on mine.

I measured accuracy identical with and without the tag (cos 0.999 either way) and
could not establish what the mislabel actually cost. Your 140 → 106 µs at 1 token
and the tuned-config rejection is the answer: it is a throughput bug, not a
correctness one.

Your root cause is also a step subtler than ours — shuffle_weight sets the tag
and copy_or_rebind_param drops it, whereas our path never set it. Worth a look
at whether any other scheme routes a shuffled tensor through copy_or_rebind_param.

Both PRs are two/five lines and have the same nine reviewers; might be worth
landing them together.

@kkHuang-amd kkHuang-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AITER specific

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants