Repository navigation
fix(looper): detect tied lm_head from storage identity, not nested config (#4369) - #4410
Merged
Merged
Conversation
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.
Fixes #4369.
Problem
ModuleLooper._lm_head_is_tied()treated a nestedtext_config.tie_word_embeddings=Trueas proof thatlm_headis tied. Composite/VLM models routinely leave that nested flag at its defaultTruewhile the loaded model keeps independent input/output embeddings — Qwen3-VL-30B-A3B-Instruct has top-leveltie_word_embeddings=False,text_configTrue, andfind_tied_parameters() == []. Withlm_head=True,quantize()then raisedNotImplementedError("quantization of lm_head layer with tied weights is not supported").untie_word_embeddings()cleared only the top-level flag, so the false positive survived it too.Fix
_lm_head_is_tied()now decides in this order:data_ptr() == 0).find_tied_parameters), unchanged.lm_head.weight, unchanged.model.config.tie_word_embeddingsplus the declared_tied_weights_keysentry, for checkpoints that do storelm_head.weightwhile the loader still ties it (Qwen3).The nested-
text_configwalker (_config_declares_tied_embeddings) is deleted: it described a sub-config, not the loaded model's storage.Tests
tests/test_lm_head_tied_detection.py:text_config=Truewith independent embeddings → untied (fails before the fix);text_config=Truebut genuinely shared storage → still tied;tests/test_lm_head_tied_detection.py tests/test_requant_embed_lm_head.py tests/test_pre_lm_head_norm_resolution.py→ 40 passed, 12 skipped.ruff check→ clean.Also checked against the real
Qwen/Qwen3-VL-30B-A3B-Instructconfig:top_tie=False,text_tie=True, storage identityFalse,_lm_head_is_tied → False.Residual risk
tie_word_embeddings=Truebut genuinely independent storage. The reported Qwen3-VL case (rootFalse) is fixed.find_tied_parameters()compares materialized parameters only; the meta-shell fallback still relies on the checkpoint's missinglm_head.weight.