Skip to content

[Fix] [AMD] ct-fp8-moe: Mark the pre-shuffled CT FP8 MoE weights is_shuffled - #47870

Merged
HaiShaw merged 14 commits into
sgl-project:mainfrom
kangwangamd:amd/ct-fp8-moe-is-shuffled
Nov 12, 2026
Merged

HaiShaw merged 14 commits into
sgl-project:mainfrom
kangwangamd:amd/ct-fp8-moe-is-shuffled

Conversation

@kangwangamd

@kangwangamd kangwangamd commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

CompressedTensorsW8A8Fp8MoE.process_weights_after_loading already pre-shuffles
the expert weights for AITER. The shuffle was introduced in #17503 (2026-02-16)
and later narrowed to the AITER runner in #45486; is_shuffled has never been
set in this file:

layer.w13_weight = torch.nn.Parameter(
    shuffle_weight(layer.w13_weight.data, (16, 16)), requires_grad=False)
layer.w2_weight  = torch.nn.Parameter(
    shuffle_weight(layer.w2_weight.data,  (16, 16)), requires_grad=False)

but it never sets the is_shuffled marker that AITER reads to pick a kernel.
aiter/fused_moe.py resolves the flag with

is_shuffled=getattr(w1, "is_shuffled", False) and getattr(w2, "is_shuffled", False)

so the default False wins and AITER has no way to know the weights are
already in its shuffled layout.
The sibling Quark scheme
(quark/schemes/quark_w8a8_fp8_moe.py) performs the identical shuffle and
sets the marker; this path is the only AITER MoE scheme that shuffles without
tagging.

Two consequences:

  1. Today, silently: AITER dispatches the preshuffle_off CK instance for
    weights that are shuffled — kernel and data layout disagree. Visible in
    the log as
    module_moe_ck2stages_f8_f8_preshuffle_off_b16_silu_per_token_mulWeightStage2.
  2. With a newer AITER: ROCm/aiter#6736
    added _require_shuffled_gfx950_fp8, which rejects an unshuffled-looking
    per_Tensor/per_Token fp8 MoE call on gfx950. Because this path reports
    is_shuffled=False, the call now raises:
RuntimeError: gfx950 fp8 CK MoE reads the shuffle_weight() layout on both w1
and w2; unshuffled per_Tensor and per_Token weights are unsupported

This is how the problem surfaced: it fails
test/registered/unit/layers/quantization/test_compressed_tensors_fp8_moe_layout.py::test_aiter
on all three ROCm flavors in the AMD AITER Scout run that pins AITER to
bd4ff1c70, and it blocks advancing the AITER pin past 285579b62.

The AITER-side guard is behaving correctly — it caught a real mislabel on our
side. Tagging the tensors is the fix.

Modifications

Set is_shuffled = True on w13_weight and w2_weight immediately after the
existing shuffle_weight() calls, matching
quark_w8a8_fp8_moe.process_weights_after_loading. No change to the shuffle
itself, to the quantization, or to any non-AITER path — the block is already
gated on strategy == CHANNEL and _use_aiter and runner_backend.is_aiter().

Accuracy Tests

Offline on MI355X (gfx950), one GPU, container
rocm/sgl-dev:v0.5.23-rocm724-mi35x-20261030, SGLang tree pinned to the Scout's
01fde5cb6. Every AITER pin verified three ways (aiter/_version.py,
git rev-parse HEAD, importlib.metadata) before each run.

AITER this patch test_compressed_tensors_fp8_moe_layout.py CK instance AITER loaded
285579b62 (current pin) no ✅ OK (2 tests) …preshuffle_**off**…
bd4ff1c70 (Scout candidate) no ❌ FAILED — the RuntimeError above — (guard raises)
bd4ff1c70 (Scout candidate) yes ✅ OK …preshuffle_**on**…
285579b62 (current pin) yes ✅ OK …preshuffle_**on**…

The kernel name is the point: the weight bytes are identical in every row, only
the marker changes, and AITER switches to the instance that matches the layout
this scheme already produces. Row 4 shows the patch is safe on the currently
pinned AITER — it is not coupled to the pin bump.

Also verified: reverting only 44b4fea64 (the aiter#6736 commit) on the
candidate restores the pass without this patch, confirming the attribution.

Speed Tests and Profiling

Not measured. The change selects the CK instance that matches the data layout
rather than the mismatched one, so a throughput difference is plausible; this PR
does not claim one.

What this does not cover

The shuffle block is gated on QuantizationStrategy.CHANNEL. A TENSOR-strategy
CT FP8 MoE still reaches AITER with genuinely unshuffled weights, and on a newer
AITER would hit the same guard legitimately. That case needs either a shuffle for
the tensor-strategy path or an explicit non-AITER route; it is out of scope here
and no regression is introduced for it.

Checklist



CI States

Latest PR Test (Base): ❌ Run #41410341187
Latest PR Test (Extra): ❌ Run #41410341144
Latest PR Test (AMD ROCm 10): ❌ Run #41410341013

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

kangwangamd and others added 13 commits September 3, 2026 18:32
[AMD] Update ROCm AITER pin to 4ad9983
…huffled

process_weights_after_loading already calls shuffle_weight() on w13 and w2 for
the AITER runner -- since sgl-project#17503 -- but has never set the is_shuffled marker.
aiter.fused_moe reads
that marker -- getattr(w, "is_shuffled", False) -- so it sees False and
dispatches the preshuffle_off CK instance for weights that are in fact
shuffled. The Quark w8a8 fp8 MoE scheme does the same shuffle and does set the
marker; this is the only AITER MoE scheme that omits it.

With AITER past ROCm/aiter#6736 the mislabel is no longer silent:
_require_shuffled_gfx950_fp8 rejects an unshuffled-looking per_Tensor or
per_Token fp8 MoE call on gfx950, so the call raises instead of running the
wrong kernel. That fails test_compressed_tensors_fp8_moe_layout.py::test_aiter
on all three ROCm flavors and blocks advancing the AITER pin.

Set is_shuffled=True on both tensors after the existing shuffle. Verified on
MI355X: with the current pin 285579b62 the test passes before and after; with
candidate bd4ff1c70 it fails without this change and passes with it, and the
loaded CK instance moves from preshuffle_off to preshuffle_on.
@kangwangamd
kangwangamd requested a review from ch-wan as a code owner November 2, 2026 07:42

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

@bingxche bingxche added the run-ci CI: run the baseline test suite on this PR label Nov 2, 2026
@kangwangamd

Copy link
Copy Markdown
Contributor Author

@lunarwhite — your #45486 added test_compressed_tensors_fp8_moe_layout.py and
narrowed this shuffle block to the AITER runner, so you have the freshest
context here.

One thing I could not determine: the unpatched path still passes your test on
the currently pinned AITER (cos 0.999), so preshuffle_off on shuffled weights
is not visibly wrong. Either AITER reconciles the layout internally on that
instance, or it is correct by accident. If you know which, it would sharpen
this PR.

@ch-wan — flagging you as author of the AITER MoE runner abstraction (#23597);
if the runner rather than the quant scheme should own this marker, happy to
move it.

@kangwangamd

Copy link
Copy Markdown
Contributor Author

stage-b-test-1-gpu-small-amd-mi35x (rocm10) is green on the current head —
test_compressed_tensors_fp8_moe_layout.py passes (13 s), 86 files in that shard,
0 failures. The CI log shows the CK instance is now
module_moe_ck2stages_f8_f8_preshuffle_on_..., matching what the offline 2×2
measured: same weight bytes, only the marker changes, and AITER switches to the
instance that matches the layout this scheme already produces.

Remaining red is unrelated — the base-b cluster cascaded from an
API rate limit exceeded for installation in check-pr-test-health (no test
step ran in any of them), and stage-b-...-disaggregation-amd has been failing
on RDMA context setup failed: fork compatibility since 10-28.

@lunarwhite @ch-wan — ready for review whenever you have a moment.

wmlba added a commit to wmlba/sglang that referenced this pull request Nov 3, 2026
…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.
@kangwangamd

Copy link
Copy Markdown
Contributor Author

Related: #48219 fixes the same bug class in the unquantized BF16 MoE path (layers/quantization/unquant.py). Different mechanism — there shuffle_weight does set the marker and copy_or_rebind_param drops it when copying into the existing Parameter, whereas this path never set it at all.

@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

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants