Repository navigation
fix(weight-only): share the tied-head check with the module looper (#5027) - #5041
Merged
Merged
Conversation
…5027) `WeightOnlyLooper` refused `lm_head=True` on a tied model with `find_tied_parameters(model)`, which only compares materialized parameters. With the default `offload_to_disk=True` the model is a lazy shell whose `lm_head.weight` and `embed_tokens.weight` are independent META parameters, so the guard never fired: the run quantized every layer and then died on the head's meta tensor (`Cannot copy out of meta tensor; no data!`), an error that points away from the real cause. The module looper had already been fixed in #4034. Move `ModuleLooper._lm_head_is_tied` into `utils.tied_weights.lm_head_quantization_is_tied()` and call it from both loopers, so one check decides the answer: real storage identity, then accelerate's tied report, then the lazy-shell checkpoint evidence, then the resolved tie snapshot, then the root config declaration. Fixes #5027
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 #5027
Root cause
WeightOnlyLooperrefusedlm_head=Trueon a tied model withfind_tied_parametersonly compares materialized parameters. With the defaultoffload_to_disk=Truethe model is a lazy shell:lm_head.weightandembed_tokens.weightare independent META parameters that are not tied yet, so the guard never fired. The run quantized every layer and then died on the head with an unrelated error:The module looper hit the same problem and fixed it in #4034; the weight-only looper was never switched over.
Changes
ModuleLooper._lm_head_is_tied's body moved togptqmodel/utils/tied_weights.pyaslm_head_quantization_is_tied(gptq_model, lm_head_name=None)(deferred imports to avoid theutils.modelcycle). The decision order is unchanged: real storage identity → accelerate's tied report → lazy-shell checkpoint evidence → resolved tie snapshot (fix(vl): keep an untied InternVL lm_head through lazy load and save (#4799) #4852/fix(vl): tie an InternVL head from the wrapper flag and checkpoint evidence (#4973) #4993) → root config declaration.ModuleLooper._lm_head_is_tied()delegates to it.WeightOnlyLoopercalls the same helper instead offind_tied_parameters; the now-unused accelerate import is gone.Verification
New
tests/test_weight_only_tied_lm_head_5027.py(6 tests):unit: a materialized tied pair is tied; a materialized untied pair is not;
unit: a lazy shell whose checkpoint omits
lm_head.weightis tied (the [BUG] RTN/weight-only quantize with lm_head=True on a tied-embedding model runs every layer then crashes 'Cannot copy out of meta tensor': WeightOnlyLooper tie guard uses find_tied_parameters, blind on the lazy shell (#4034 fixed only ModuleLooper) #5027 shape); a lazy shell with an independent head tensor is not;end-to-end,
RTNConfig(bits=4, group_size=32, lm_head=True)on a real tiny tiedLlamaForCausalLM, parametrized overoffload_to_diskTrue/False:quantize()raisesNotImplementedError: ... tied weights is not supportedandlayers[0].self_attn.q_projis still annn.Linear, proving the refusal happens before the layer loop.New file: 6 passed.
Red on parent (
git checkout origin/main -- gptqmodel/looper/weight_only_looper.py, then restored): 1 failed, 5 passed —test_rtn_lm_head_on_a_tied_model_is_refused_before_any_layer[True], i.e. exactly the default-offload path this issue is about; theoffload_to_disk=Falsecase already worked.Neighbours:
tests/test_weight_only_looper.py tests/test_lm_head_tied_detection.py tests/test_internvl_tied_head_4973.py tests/test_cpu_offload_tied_both_copies_4943.py→ 56 passed, 1 failed; the failure is the pre-existingtest_weight_only_looper_respects_dense_and_moe_vram_strategy_devices, which expects three GPUs and fails identically on the parent on this single-GPU host. Post-merge re-run of the new file plus the tied-head detection suite: 13 passed.ruff check gptqmodel testsclean.Residual risk
lm_head=Truewas not executed here.get_output_embeddings()may return a wrapper (not a tensor-holding module) for some architectures; that path already fell through tofind_tied_parametersbefore this change and is unchanged.