Skip to content

[GLM 5.3 Flash] Preserve original names when saving text checkpoints - #48676

Merged
vasqu merged 1 commit into
huggingface:mainfrom
Dovis01:fix-glm5-next-save-format
Sep 10, 2026
Merged

vasqu merged 1 commit into
huggingface:mainfrom
Dovis01:fix-glm5-next-save-format

Conversation

@Dovis01

@Dovis01 Dovis01 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

Summary

Fixes GLM-5.3-Flash text checkpoints saved with save_pretrained() using Transformers-internal weight names instead of the released checkpoint layout.

Glm5NextTextModel uses the glm5_next_text model type, while its weight conversion rules were only registered for glm5_next. As a result, the reverse conversion was not applied when saving the standalone text model.

This PR makes glm5_next_text reuse the existing glm5_next conversion mapping. The standard save_pretrained(save_original_format=True) path can then restore the released names and layouts for:

  • mHC attention and FFN parameters
  • KDA forget-gate parameters
  • packed KDA q/k/v convolution weights
  • packed routed MoE expert weights

The vision tower requires no additional mapping because its saved weight names already match the released checkpoint.

Related issue: sgl-project/sglang#38618

Changes

  • Register glm5_next_text as an alias of the existing glm5_next conversion mapping.
  • Add regression coverage verifying that standalone text models save mHC, KDA,
    convolution, and routed expert weights with their original released names.
  • Preserve the existing full multimodal model and native Transformers checkpoint round
    trips.

Root cause

save_pretrained() already supports reversing complete weight conversions, including renaming, splitting concatenated tensors, and unpacking expert tensors.

However, the reverse conversion lookup returned no GLM5 mapping for Glm5NextTextModel because its model type is glm5_next_text. The model therefore serialized its internal packed layout unchanged.

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: glm5_next

@Dovis01 Dovis01 changed the title [GLM5 Next] Preserve original names when saving text checkpoints [GLM 5.3 Flash] Preserve original names when saving text checkpoints Sep 10, 2026

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

One small comment but good to go then 🫡

Register the GLM5 Next conversion mapping for the standalone text model type.
This keeps saved checkpoints compatible with the released tensor layout.
Add regression coverage for mHC, KDA, and routed expert keys.

Signed-off-by: Shijin Zhang <[email protected]>
@Dovis01
Dovis01 force-pushed the fix-glm5-next-save-format branch from 6395863 to 6cdd2fa Compare September 10, 2026 07:39
@vasqu
vasqu enabled auto-merge September 10, 2026 07:41
@vasqu
vasqu added this pull request to the merge queue Sep 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 34449799466:2
Result: success | Jobs: 16 | Tests: 187,625 | Failures: 0 | Duration: 15h 13m

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@vasqu
vasqu removed this pull request from the merge queue due to a manual request Sep 10, 2026
@vasqu
vasqu merged commit e71d8c5 into huggingface:main Sep 10, 2026
115 checks passed
@vasqu vasqu added the for patch Tag issues / labels that should be included in the next patch label Sep 10, 2026
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
…uggingface#48676)

[GLM5 Next] Preserve original text checkpoint names

Register the GLM5 Next conversion mapping for the standalone text model type.
This keeps saved checkpoints compatible with the released tensor layout.
Add regression coverage for mHC, KDA, and routed expert keys.

Signed-off-by: Shijin Zhang <[email protected]>
siliangchen-amd added a commit to siliangchen-amd/transformers that referenced this pull request Sep 17, 2026
A standalone text sub-model declares its own model_type. Unless
_MODEL_TO_CONVERSION_PATTERN maps that model_type onto the pattern its tensors
were released under, the reverse conversion is never looked up and
save_pretrained writes whatever layout the module happens to hold in memory.
huggingface#48676 fixed this for glm5_next_text. glm4v_moe_text has the same defect:
qwen2_moe packs `mlp.experts.*.gate_proj.weight` into a single
`mlp.experts.gate_up_proj`, so a standalone save leaves the routed experts
packed under names no external loader expects. Measured on a 2-layer probe,
30 keys with the experts packed becoming 40 with them unpacked per expert.

Rather than name a model, this derives the set. Every *_text model_type in
MODEL_MAPPING_NAMES is swept and an alias is required when two properties hold
of the parent's rules. They must RESTRUCTURE KEYS -- a source pattern with a
modulelist wildcard collapsing into one target -- since that is what a save has
to undo; a rule that only transforms a value under an unchanged name is already
a no-op on the child's save, which is why qwen3_vl_moe_text needs nothing
despite its parent carrying Transpose operations. And they must not RELOCATE a
tower, because get_model_conversion_mapping walks sub-modules and collects each
one's rules, so an alias re-applies the parent's rules on the parent's own save
and would shift a tensor that was already moved.

Of the 29 *_text types registered today the rule selects two: glm5_next_text,
already fixed by huggingface#48676, and glm4v_moe_text. The remaining 27 are excluded for
a reason the test derives rather than asserts -- 19 have a parent with no
conversion pattern, 6 have a parent that does not restructure keys, and 2
(cosmos3_edge_text, minimax_m3_vl_text) have a parent that relocates a tower
under `language_model.`. That the rule independently reselects the model
huggingface#48676 fixed is the check that it describes the defect rather than the fix.

Scope worth being explicit about: this is an interoperability fix, not a
correctness fix. The packed layout round-trips through transformers cleanly --
0 missing, 0 unexpected, weights bit-identical -- so nothing here is broken for
a transformers-only workflow. What breaks is a consumer reading the checkpoint
under released names, which is how the glm5_next case surfaced: a GLM-5.3
checkpoint written by save_pretrained dropped 524 of 1609 tensors in SGLang and
scored 0.000 on GSM8K against 0.907 once the names were mapped back.

Four tests. Three of them fail if the entry is removed, from independent
directions: the derived set stops matching the map, glm4v_moe_text loses its
mechanical exclusion, and the end-to-end save writes packed experts.

Co-authored-by: Claude
Signed-off-by: siliangchen-amd <[email protected]>
siliangchen-amd added a commit to siliangchen-amd/sglang that referenced this pull request Sep 24, 2026
transformers renames GLM-5.3-Flash tensors while reading the released
checkpoint (conversion_mapping.py, entry "glm5_next"). Anything written
back by save_pretrained -- a fine-tune, a merged adapter, a bf16
re-export -- therefore carries transformers module names rather than the
released ones glm5_next.py is written against. Those names miss
params_dict and the tensors are dropped without an error, starting the
server on a partly-initialised model.

On a 45-layer bf16 checkpoint that is 524 of 1609 tensors -- 304.4B
parameters, 97% of a 628 GB file: the packed routed MoE experts, the mHC
attn_hc / ffn_hc parameters, the KDA forget gate and the packed conv1d.
The server logs that it is ready, answers /health with 200, and
generates token noise. GSM8K 0.000 against 0.907 once the names are
mapped back.

Map the transformers layout onto the released one on the way in, so one
loading path serves both. The released checkpoint is unaffected: it
already ships the names this loader expects, and the conversion is a
no-op on it.

huggingface/transformers#48676 has since made save_pretrained preserve
the released names for the standalone text model, which is the right fix
for checkpoints written from now on. It does not help the ones already
on disk, nor checkpoints produced by other tooling, which is why this
stays.

Co-authored-by: Claude
Signed-off-by: siliangchen-amd <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for patch Tag issues / labels that should be included in the next patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants