Repository navigation
[AMD] Quark shared-experts gate: recognise a trailing MTP layer - #36124
Merged
HaiShaw merged 4 commits intoAug 24, 2026
Merged
Conversation
Jacob0226
force-pushed
the
jacob/quark-gate-trailing-mtp-layer
branch
2 times, most recently
from
August 24, 2026 06:40
3446a0b to
92f81fd
Compare
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
force-pushed
the
jacob/quark-gate-trailing-mtp-layer
branch
from
August 24, 2026 06:45
92f81fd to
f111f84
Compare
Jacob0226
marked this pull request as ready for review
August 24, 2026 07:23
Jacob0226
requested review from
1am9trash,
HaiShaw,
hubertlu-tw,
kkHuang-amd and
yichiche
as code owners
August 24, 2026 07:23
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
approved these changes
Aug 24, 2026
This was referenced Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
can_fuse_shared_expert()recognises the MTP draft stack only by anmtp.prefix. GLM-5.2-MXFP4 spells itmodel.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 forwardedhf_config, leaving the layer count unavailable.Losing fusion costs more than the fused shared expert alone:
fused_moekeyIntroduced 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; withouthf_configthe 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 backendstilelang. The gate is the only variable.CI States
Latest PR Test (Base): ❌ Run #32702817070
Latest PR Test (Extra): ❌ Run #32702816938
Latest PR Test (AMD ROCm 7.2): ❌ Run #32702817235