Skip to content

[AMD] GLM-5.3-Flash: fuse shared expert and KDA projections on Quark MXFP4 - #41870

Merged
HaiShaw merged 4 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-quark-mxfp4-fusion
Oct 3, 2026
Merged

HaiShaw merged 4 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-quark-mxfp4-fusion

Conversation

@Jacob0226

@Jacob0226 Jacob0226 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On the Quark MXFP4 GLM-5.3-Flash checkpoint, two decode fusions that other checkpoints have stay off:

  1. Shared expert. [AMD] [GLM5] Fuse shared expert into AITER MoE on gfx950 #41161 runs the shared expert inside the AITER MoE as expert 288, but its check accepts only block-FP8 checkpoints. On MXFP4, every MoE layer still runs the shared expert as a separate MLP: two FP4 GEMMs, a split-K reduce, two activation quants, and an add.
  2. KDA projections. The KDA projection fusion does not accept Quark. Every KDA layer runs 7 projection GEMMs instead of 3, even though this checkpoint keeps these projections in BF16.

This PR lets Quark use both.

Decode, batch 4, one forward baseline this PR
MoE layer (×42) 14 kernels, 79.8 µs 8 kernels, 55.7 µs
KDA projections (×34) 7 GEMMs, 39.5 µs 3 GEMMs, 28.3 µs
forward 9.61 ms, 1665 launches 8.29 ms, 1277 launches

Scope

GLM-5.3-Flash on ROCm. CUDA does not change in practice. The shared-expert check is HIP-only and needs gfx950 with AITER. The KDA check has no GPU limit, but it changes only Quark checkpoints, which SGLang runs and tests on ROCm. So KDA fusion applies on any ROCm GPU, not just gfx950. FP8 and ModelOpt checkpoints do not change. Each fusion turns on only when the checkpoint allows it. Otherwise the layer is unchanged.

Fusion Turns on when Turn off
Shared expert #41161's HIP checks pass, every sparse layer has MXFP4 routed experts, no routed or shared expert is excluded, and one Quark config covers both --disable-shared-experts-fusion
KDA projections the checkpoint excludes every source projection from quantization, so a quantized projection is never fused —

To check the KDA rule without side effects, this PR adds QuantizationConfig.is_linear_unquantized. Only glm5_next calls it. Quark answers from its exclude list. Other configs keep the old check.

Test plan

Baseline rocm/sgl-dev:v0.5.20-rocm10-mi35x-20260928 (sglang 0318a8d0af), no other PRs. Both builds add a router GEMM config (ROCm/aiter#5933). This PR also applies cleanly to main. amd/GLM-5.3-Flash-Quark-MXFP4, MI355X TP4.

in8192 / out1024, at this PR's head:

Concurrency Mean TTFT base (ms) this PR Δ Median ITL base (ms) this PR Δ
4 300.30 298.52 −0.6% 8.62 7.45 −13.6%
16 539.94 525.30 −2.7% 10.59 9.48 −10.5%
64 1350.55 1337.09 −1.0% 14.39 12.98 −9.8%

in70000 / out300, measured with the opt-in env since removed (same code path):

Concurrency Mean TTFT base (ms) this PR Δ Median ITL base (ms) this PR Δ
4 2537.07 2535.92 −0.0% 8.73 7.59 −13.1%
16 5258.50 5469.16 +4.0% 10.67 9.60 −10.0%
64 14862.36 14772.32 −0.6% 14.79 13.30 −10.1%

Each decode step saves about 1.1–1.5 ms, so the relative gain shrinks as batches grow. Summary traces: HIP-graph decode, baseline TP0, this PR TP1.

Unit test (CPU) Cases added
test_shared_experts_fusion_gates.py Quark MXFP4 is accepted; excluded, block-FP8, or mismatched target-layer experts are rejected; the MTP layer's FP8 experts do not block it
test_glm5_next_bfg_fusion.py Quark fuses only projections the checkpoint keeps in BF16; QuarkConfig.is_linear_unquantized answers from the exclude list, counts excluded layers kept in FP8 as quantized, and registers no quantized layer

Accuracy: GSM8K 0.965 → 0.967, single scoring pass each — within what one pass resolves.


CI States

Latest PR Test (Base): ✅ Run #36847184493
Latest PR Test (Extra): ❌ Run #36847184428
Latest PR Test (AMD ROCm 10): ❌ Run #36847184568

@Jacob0226 Jacob0226 changed the title [AMD] GLM-5.3-Flash: fuse the shared expert and KDA projections on Quark MXFP4 checkpoints [AMD] GLM-5.3-Flash: fuse Quark MXFP4 shared expert and KDA Sep 30, 2026
@Jacob0226 Jacob0226 changed the title [AMD] GLM-5.3-Flash: fuse Quark MXFP4 shared expert and KDA [AMD] GLM-5.3-Flash: fuse shared expert and KDA projections on Quark MXFP4 Sep 30, 2026
@Jacob0226
Jacob0226 force-pushed the jacob/glm53-quark-mxfp4-fusion branch 2 times, most recently from 02a2c97 to 2f42a18 Compare October 1, 2026 08:21
Jacob0226 and others added 3 commits October 1, 2026 09:13
PR sgl-project#41161 runs the shared expert inside the AITER MoE as
expert 288, but only for block-FP8 checkpoints. On the Quark MXFP4
checkpoint the gate logs "requires serialized dynamic 128x128 block-FP8
experts" and every MoE layer still runs the shared expert as its own
MLP: two FP4 GEMMs, a split-K reduce, SiLU, two activation quants and
the add that merges it back, 7 launches per layer on decode.

The gate now also accepts a Quark checkpoint when, for every sparse
layer, neither the routed nor the shared experts are excluded from
quantization, the routed experts are MXFP4, and both resolve to the
same Quark layer config. Anything else keeps the separate shared-expert
path, and --disable-shared-experts-fusion still turns it off.

Co-authored-by: Cursor <[email protected]>
_can_fuse_proj only admits fp8, mxfp8 and the modelopt configs, so a
Quark checkpoint runs the KDA input projections as seven GEMMs per
layer on decode instead of three (fused_qkvbfg_a_proj, fused_fg_b_proj
and o_proj). The Quark GLM-5.3-Flash checkpoint keeps these projections
in BF16, so the fused GEMM reads the same BF16 weights; only the
kernel that multiplies them changes.

_can_fuse_proj decided by probing get_quant_method for an
UnquantizedLinearMethod, but Quark's get_quant_method registers every
non-excluded prefix as an online-quantized layer, so the probe would
create quantized layers as a side effect. Add
QuantizationConfig.is_linear_unquantized, a query that must not
register the layer: the base implementation is the same probe, and
QuarkConfig answers from its exclude list (an excluded layer that a
mixed-precision export keeps in FP8 is still quantized). _can_fuse_proj
now asks that and admits quark; no other model calls it.

Co-authored-by: Cursor <[email protected]>
Builds QuarkConfig from an export shaped like
amd/GLM-5.3-Flash-Quark-MXFP4 (MXFP4 by default, the MTP layer's
experts pinned to block-FP8 one by one) and maps its names the way the
loader does, so the gates see what they see at load time.

Shared expert: admitted, and rejected when a target layer's routed or
shared experts are excluded, block-FP8, or quantized differently from
each other; the MTP layer's FP8 experts do not veto it.

KDA: fused only when every source projection is excluded from
quantization, and a rejected probe registers no online-quantized layer.
@Jacob0226
Jacob0226 force-pushed the jacob/glm53-quark-mxfp4-fusion branch from 2f42a18 to 074497b Compare October 1, 2026 09:14
@Jacob0226
Jacob0226 marked this pull request as ready for review October 1, 2026 09:35
@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Oct 1, 2026

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

LGTM

@Jacob0226

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Jacob0226

Copy link
Copy Markdown
Contributor Author
image NV CI all green

@HaiShaw
HaiShaw merged commit af1bef3 into sgl-project:main Oct 3, 2026
254 of 283 checks passed
Raiden-Makoto added a commit to Raiden-Makoto/squidward that referenced this pull request Oct 14, 2026
Enable sgl-project#38764 PTPC (qkv/f_a/g_a/o), leave DSA sub-backends to the HIP
default so sgl-project#41615 selects Triton, and let sgl-project#41870 shared-expert fusion
auto-enable. Run the checkout the script lives in and pin TP4 INT4
QuickReduce over the image's inherited INT8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants