Skip to content

[AMD] Quark shared-experts gate: recognise a trailing MTP layer - #36124

Merged
HaiShaw merged 4 commits into
sgl-project:mainfrom
Jacob0226:jacob/quark-gate-trailing-mtp-layer
Aug 24, 2026
Merged

HaiShaw merged 4 commits into
sgl-project:mainfrom
Jacob0226:jacob/quark-gate-trailing-mtp-layer

Conversation

@Jacob0226

@Jacob0226 Jacob0226 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

can_fuse_shared_expert() recognises the MTP draft stack only by an mtp. prefix. GLM-5.2-MXFP4 spells it model.layers.78 (num_hidden_layers=78), so three excluded draft projections veto fusion for all 78 target-model layers. from_config()'s prequantized branch also never forwarded hf_config, leaving the layer count unavailable.

Losing fusion costs more than the fused shared expert alone:

fused (expected) unfused (today)
aiter fused_moe key 257 experts, topk 9 256, 8
tuned FlyDSL config hit miss — heuristic fallback

Introduced by #35200, which restored the gate after the load-time-override removal.

Scope

Quark MXFP4 checkpoints whose draft layer sits at the end of the main decoder. An mtp. prefix (Qwen3.5), a model with no draft layer, and every non-Quark path keep current behaviour; without hf_config the helper falls back to the prefix test.

Test plan

Stock rocm/sgl-dev:v0.5.17-rocm720-mi35x-20260820, no PRs applied; GLM-5.2-MXFP4, MI355X TP4, in8192 / out1024, DSA backends tilelang. The gate is the only variable.

Metric Docker0820 this PR Δ
conc4 Mean TTFT (ms) 659.42 619.54 −6.0%
conc4 Median TPOT (ms) 15.23 12.80 −16.0%
conc64 Mean TTFT (ms) 3490.83 3291.36 −5.7%
conc64 Median TPOT (ms) 57.38 52.58 −8.4%

CI States

Latest PR Test (Base): ❌ Run #32702817070
Latest PR Test (Extra): ❌ Run #32702816938
Latest PR Test (AMD ROCm 7.2): ❌ Run #32702817235

@Jacob0226
Jacob0226 force-pushed the jacob/quark-gate-trailing-mtp-layer branch 2 times, most recently from 3446a0b to 92f81fd Compare August 24, 2026 06:40
can_fuse_shared_expert() vetoes shared-expert fusion whenever an excluded
layer name contains "shared_expert", and it recognises the MTP/NextN draft
stack only by an "mtp." prefix. Qwen3.5 spells it that way; GLM-5.2-MXFP4
appends it to the main decoder as model.layers.78 with num_hidden_layers=78.
Those three projections are the only "shared_expert" entries in its
1319-entry exclude list, so one unused draft layer disabled fusion for all 78
target-model layers.

The cost is not just the fused shared expert. Unfused, aiter's fused_moe key
moves from (257 experts, topk 9) to (256, 8), which has no tuned FlyDSL
config, so the MoE also falls back to heuristic kernels. On MI355X TP4,
GLM-5.2-MXFP4 at in8192/out1024 that is median TPOT 13.83 -> 11.24 ms at
concurrency 4 and 30.79 -> 27.64 at 32.

Match an appended draft layer as well as the prefix, over the same range
get_spec_layer_idx_from_weight_name() walks in the MTP models:
model.layers.[num_hidden_layers .. + num_nextn_predict_layers). The
prequantized branch of from_config() never forwarded hf_config, so neither
count was available there and the range test could not run; pass it through.
Without hf_config, or on a checkpoint that declares no nextn layers, the
helper falls back to the prefix test and behaviour is unchanged.

Co-authored-by: Cursor <[email protected]>
@Jacob0226
Jacob0226 force-pushed the jacob/quark-gate-trailing-mtp-layer branch from 92f81fd to f111f84 Compare August 24, 2026 06:45
@Jacob0226
Jacob0226 marked this pull request as ready for review August 24, 2026 07:23
@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Aug 24, 2026
1am9trash and others added 2 commits August 24, 2026 15:39
num_nextn_predict_layers reaches QuarkConfig straight off the HF config, and
a model with no draft stack spells that field None as readily as it omits it
-- ModelConfig defaults its own copy to None, and base_spec_worker tests it
for truthiness rather than against 0. getattr(..., 0) only covers the omitted
case, so a checkpoint carrying an explicit null took range(None) and raised
TypeError while the gate was still deciding whether to fuse.

Coerce at assignment instead of guarding at every use.
@HaiShaw
HaiShaw merged commit 7bbd0dd into sgl-project:main Aug 24, 2026
104 of 117 checks passed
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.

3 participants