Repository navigation
[GLM 5.3 Flash] Preserve original names when saving text checkpoints - #48676
Merged
Merged
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: glm5_next |
vasqu
approved these changes
Sep 10, 2026
vasqu
left a comment
Collaborator
There was a problem hiding this comment.
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
force-pushed
the
fix-glm5-next-save-format
branch
from
September 10, 2026 07:39
6395863 to
6cdd2fa
Compare
vasqu
enabled auto-merge
September 10, 2026 07:41
Contributor
CI recapDashboard: View test results in Grafana |
|
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. |
5 tasks done
This was referenced Sep 16, 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]>
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
Fixes GLM-5.3-Flash text checkpoints saved with
save_pretrained()using Transformers-internal weight names instead of the released checkpoint layout.Glm5NextTextModeluses theglm5_next_textmodel type, while its weight conversion rules were only registered forglm5_next. As a result, the reverse conversion was not applied when saving the standalone text model.This PR makes
glm5_next_textreuse the existingglm5_nextconversion mapping. The standardsave_pretrained(save_original_format=True)path can then restore the released names and layouts for:The vision tower requires no additional mapping because its saved weight names already match the released checkpoint.
Related issue: sgl-project/sglang#38618
Changes
glm5_next_textas an alias of the existingglm5_nextconversion mapping.convolution, and routed expert weights with their original released names.
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
Glm5NextTextModelbecause its model type isglm5_next_text. The model therefore serialized its internal packed layout unchanged.