Skip to content

[AMD] [GLM-5.3-Flash Day 0] Load the MXFP4 MTP draft layer - #39779

Merged
hnyls2002 merged 7 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-mxfp4-nextn-draft
Sep 22, 2026
Merged

hnyls2002 merged 7 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-mxfp4-nextn-draft

Conversation

@Jacob0226

@Jacob0226 Jacob0226 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Serving amd/GLM-5.3-Flash-Quark-MXFP4 with MTP aborts while loading the draft: a uint8 parameter meets a bfloat16 tensor of twice its width. That ratio is an MXFP4-packed parameter meeting an unpacked weight — a block-FP8 module got built as MXFP4, its entry never found.

Two lookups miss.

  1. The export pins the draft layer's 288 experts one at a time, 864 block-FP8 entries, while SGLang builds one fused module named ...mlp.experts matching none.
  2. Names are rewritten at most once — longest matching rule, then stop — so the draft's renames competed with the target's prefix strip instead of chaining.
Draft-layer lookup before after
...layers.45.mlp.experts resolves to fp4 per_group (model default) fp8_e4m3 per_block [128,128]
...layers.45.eh_proj rewrites to model.decoder.eh_proj (no such module) model.eh_proj

Scope

_find_matched_config's per-expert resolution, and the GLM-5.3-Flash draft's name mapping. Checkpoints whose entries already match a module by name resolve exactly as before, and the FP8 build of the same model is untouched. Experts have to agree for a fused module to mean anything, so partial or conflicting coverage raises rather than handing one expert's scheme to the whole bank; can_fuse_shared_expert already reads that as cannot-fuse. The draft's rules spell out both namings instead of changing WeightsMapper semantics, to keep the change off every other model's mapping.

Test plan

Base rocm/sgl-dev:v0.5.19-rocm720-mi35x-20260914, sglang main plus the eight open Day-0 PRs (#39338, #39339, #39340, #39341, #38545, #38546, #38547, #39317) and #39778. This PR is the only variable. Same checkpoint, MI355X TP4, EAGLE 5 steps / 6 draft tokens, CUDA graphs on. GSM8K, 200 examples, temperature 1.0.

Build GSM8K accepted per step, of 6
baseline, MTP on server aborts while loading the draft —
this PR, MTP on 99.0% 4.00
this PR, MTP off 99.5% —

Acceptance needs #38546's weight_scale suffix match, without which the draft's expert scales stay at 1.0.

Name resolution is also checked against the checkpoint's 924-entry layer_quant_config and its six draft-layer exclude entries. Mapper only: before this PR the .experts resolution did not exist.

Draft name mapper queried from experts under model.decoder.mlp.experts draft-layer excludes hitting a runtime module
before checkpoint names 0 / 864 0 / 6
before normalized names 864 / 864 5 / 6
this PR checkpoint names 864 / 864 6 / 6
this PR normalized names 864 / 864 6 / 6

CPU unit tests cover both namings and the four coverage cases.


CI States

Latest PR Test (Base): ⏳ Run #35785429641
Latest PR Test (Extra): ❌ Run #35785429424
Latest PR Test (AMD ROCm 10): ⏳ Run #35785429575

Serving amd/GLM-5.3-Flash-Quark-MXFP4 with MTP aborts while loading the draft
model, on a shape mismatch between a uint8 parameter and a bfloat16 tensor of
twice its width. That width ratio is the signature of an MXFP4-packed parameter
meeting an unpacked weight: a module the checkpoint stores unquantized, or
stores as block FP8, was built as MXFP4 because its config was never found.

Two independent lookups miss, for different reasons.

1. Per-expert entries against a fused module. The export pins each expert
   individually, naming 864 entries for the NextN layer's 288 experts as block
   FP8, while SGLang builds one FusedMoE whose name ends in .experts. No
   pattern matches that name, so the MoE inherits the global MXFP4 scheme and
   its unpacked FP8 weights meet a half-width packed parameter. Resolving
   .experts from the experts' shared config fixes it; the experts of one layer
   have to agree for a fused module to be well defined, so disagreement raises
   rather than silently picking one.

2. The NextN mapper replaced the target's instead of composing with it. The
   quantization config is keyed on the checkpoint's own names, so the draft has
   to strip the same prefixes the target does before any lookup can match.
   Composing the two also exposes that eh_proj, enorm and hnorm are siblings of
   the transformer block rather than children of it, so they need their own
   rules alongside the catch-all that routes everything else under decoder.

With both, the draft loads and MTP is accurate: GSM8K 99.0% over 200 examples
on MI355X TP4, against 99.5% for the same checkpoint with MTP off.

One further defect remains outside this change. The draft's fused MoE scales
stay at their all-ones initial value because the scale-name normalization added
by sgl-project#38546 matches ".weight_scale" with a dot, while a fused expert parameter is
named experts.w13_weight_scale with an underscore. Accuracy is unaffected since
verification rejects the bad drafts, but acceptance drops to 1.20 of 6 and MTP
buys nothing. The one-line correction belongs on sgl-project#38546, which introduces that
helper.
@Jacob0226 Jacob0226 changed the title [AMD] Load the GLM-5.3-Flash MXFP4 NextN draft layer [AMD] [GLM-5.3-Flash Day 0] Load the MXFP4 MTP draft layer Sep 16, 2026
1am9trash pushed a commit that referenced this pull request Sep 17, 2026
Squashed from #39779, which carries the same change
against main and remains open there for review.

Co-Authored-By: Jacob Chang <[email protected]>
Co-authored-by: Cursor <[email protected]>
@Jacob0226
Jacob0226 marked this pull request as ready for review September 18, 2026 07:35
@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Sep 18, 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.

Requesting changes for the two reproduced configuration-mapping issues noted inline.

…sing

Two review findings on the MXFP4 NextN draft loading, both about a lookup
quietly resolving to something it was never told.

WeightsMapper._map_name rewrites a name at most once: it tries the longest rule
first and stops at the first hit. `|` merges rule dicts into that one loop, so
the draft's renames did not compose with the target's -- they competed. Against
the checkpoint's own names the longer `model.language_model.` rule won and the
result never reached `model.decoder`: `...layers.45.mlp.experts.7.up_proj` came
out as `model.layers.45.mlp.experts.7.up_proj`. `eh_proj` fared worse, because
`language_model.` itself ends in `model.`, so the `model.layers.45.eh_proj` rule
matched mid-string and produced `model.language_model.eh_proj`; `enorm` and
`hnorm` escaped that only by a rule-length tie broken by dict insertion order.
Working at all therefore depended on names arriving already stripped, which is
not a property this method can see. Spelling out both the checkpoint's
`model.language_model.layers.{n}` and the normalized `model.layers.{n}` removes
the dependency, and the prefixed rule being the longer one keeps the stripped
rule from matching inside it. Checked against amd/GLM-5.3-Flash-Quark-MXFP4's
924-entry layer_quant_config and 626-entry exclude list: from either naming all
864 expert entries resolve under model.decoder.mlp.experts, and all six
draft-layer exclusions land on the runtime module names, with no `language_model`
surviving in the output.

_find_matched_config's per-expert resolution accepted any non-empty match and
returned its first entry, so a checkpoint pinning one expert -- or one projection
of each -- would hand that scheme to the whole fused bank. It now requires the
coverage a fused module implies: contiguous expert indices and the same
projection set for every expert, before the existing config comparison. Partial
coverage raises, which can_fuse_shared_expert already reads as "cannot fuse", so
its stub-module lookup keeps working.

Unit tests cover both: the mapper against both namings for the transformer block
and for the eh_proj/enorm/hnorm siblings, and expert resolution for complete
uniform coverage, conflicting configs, a missing expert, partial projections, and
a fused parameter name that is not <index>.<projection>.
@Raiden-Makoto

Copy link
Copy Markdown
Contributor

LGTM

…extn-draft

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	test/registered/unit/layers/quantization/test_quark_config.py
kevin-mii and others added 2 commits September 22, 2026 14:14
- Word the per-expert coverage errors like the neighbouring packed-module
  check, one line each.
- Trim the NextN mapper comment: _map_name chains one substring rule with one
  prefix rule, so the "rules cannot be chained" premise was wrong.
- Keep one regression case per bug plus the fall-through contract; fold the
  raise cases into one table, and move the mapper rows that fail before the
  fix into test_glm5_next_modelopt.py to reuse its fixture instead of adding
  a CPU file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kevin-mii

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/e2e/models/test_glm53_flash_b200.py

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/e2e/models/test_glm53_flash_b200.py:

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_glm53_flash_b200.py

@hnyls2002
hnyls2002 merged commit c19dc43 into sgl-project:main Sep 22, 2026
105 of 150 checks passed
hdt98 added a commit to hdt98/sglang that referenced this pull request Sep 25, 2026
Adopt upstream sgl-project#39341 (k-pool DSA indexer on gfx950) and sgl-project#39779 (MXFP4 MTP
draft mapper) in the conflicted files. Keep on top of them the int64 page
index in the index-K prefix gather, and count aiter's 256-column row padding
when splitting ragged MQA logits under the 2 GiB cap.
hdt98 added a commit to hdt98/sglang that referenced this pull request Sep 25, 2026
Reset quark.py to upstream sgl-project#39779's per-expert fused config resolution and
keep only the block-FP8 activation-grouping check. Fused shared experts are
CUDA-only, so the removed shared-expert precision matching loses nothing on
ROCm.

Drop tests whose targets are now upstream code or duplicate upstream
coverage: k-pool cache layout and backend dispatch (sgl-project#39341), TileLang
zero-RoPE (sgl-project#38547), transform_index widths (sgl-project#39340), mHC HIP dispatch
(sgl-project#38545), the NextN name mapper, write-plan multi-pool, negative-slot
scatter, and the comment-only AITER runner. Keep one focused test per
production change this branch owns.
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.

5 participants