You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Lazy quantization fails when a tied checkpoint stores only lm_head.weight #5399
A tied Llama checkpoint can store its shared tensor under either model.embed_tokens.weight or lm_head.weight. Transformers loads both forms and reconstructs the tie. GPT-QModel's lazy path discards the declared tie when the canonical embedding key is absent, even when the head key contains the shared tensor. The input embedding stays on meta and calibration fails.
To reproduce
At 2c8717e1 with Transformers 5.23.0, save a tiny local Llama with tie_word_embeddings=True. Make a second checkpoint with the same config, tokenizer and tensors, moving the sole stored embedding tensor from model.embed_tokens.weight to lm_head.weight. Load both and quantize with GPTQ on CPU using offload_to_disk=True.
Native Transformers loads the head-only variant with the same embeddings and the expected storage tie. GPT-QModel quantizes the embedding-only variant. The head-only variant fails during calibration with RuntimeError: Tensor.item() cannot be called on meta tensors. Its LazyTurtle tie snapshot is empty. Declared tie resolution, lazy snapshot.
Suggested mitigation
The tie resolver could choose the stored member of a declared tie as its materialization source, including the reverse direction. The existing comparison for checkpoints containing two different tensors can still preserve untied weights. A tiny fixture could exercise each alias as the only saved tensor and check that lazy calibration succeeds and both modules share the loaded data. Setting offload_to_disk=False is a verified workaround on the same fixture.
Agent claim:agent-4e3a0639ecaf is working on this issue now.
Started 2026-11-19T08:50:00Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.
Make the declared-tie resolver pick whichever member the checkpoint actually stores (including the reverse direction) so the lazy snapshot is non-empty for head-only tied checkpoints, with a fixture for each alias.
A tied Llama checkpoint may store the shared tensor only as lm_head.weight; Transformers reconstructs the embedding from it. resolve_tied_weights_keys() dropped the declared pair whenever the declared source (model.embed_tokens.weight) was absent, so the lazy snapshot was empty, the embedding stayed on meta, and calibration failed with RuntimeError: Tensor.item() cannot be called on meta tensors.
LazyTurtle._resolve_checkpoint_tensor_source() falls back to the partner of a declared tie (either direction), so the omitted member is materialized from the stored one.
Verification
Tiny tied Llama with offload_to_disk=True: embedding-only stores QUANTIZED OK on both trees; head-only stores FAILED: RuntimeError Tensor.item() cannot be called on meta tensors on e84d249fd and QUANTIZED OK after the fix.
New tests/test_tied_lm_head_only_5399.py (8 tests). On e84d249fd: 3 failed / 5 passed -> 8 passed.
One existing expectation in tests/test_internvl_untied_lm_head_4799.py encoded the old "source missing means untied" rule; it now asserts the pair is kept, plus a new assertion that a checkpoint storing neither member drops it.
Activity
Qubitium commentedon Nov 19, 2026
Agent claim:
agent-4e3a0639ecafis working on this issue now.Started 2026-11-19T08:50:00Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.
Make the declared-tie resolver pick whichever member the checkpoint actually stores (including the reverse direction) so the lazy snapshot is non-empty for head-only tied checkpoints, with a fixture for each alias.
fix(tied): materialize a tie stored under either member (#5399) (#5490)
Qubitium commentedon Nov 19, 2026
Released: #5490 merged as
cdd0b2011.Root cause
lm_head.weight; Transformers reconstructs the embedding from it.resolve_tied_weights_keys()dropped the declared pair whenever the declared source (model.embed_tokens.weight) was absent, so the lazy snapshot was empty, the embedding stayed onmeta, and calibration failed withRuntimeError: Tensor.item() cannot be called on meta tensors.Fix
resolve_tied_weights_keys()keeps the declared pair when the checkpoint stores the other member and drops it only when neither is present. A checkpoint that stores both sides with different values is still refuted, so an untied head keeps its own weights ([BUG] InternVL3-hf: quantize() ties the untied lm_head to embed_tokens (LazyTurtle re-calls tie_weights() off the composite config's default tie_word_embeddings=True) and the checkpoint omits lm_head: PPL 23.59 -> 29.98 #4799).LazyTurtle._resolve_checkpoint_tensor_source()falls back to the partner of a declared tie (either direction), so the omitted member is materialized from the stored one.Verification
offload_to_disk=True: embedding-only storesQUANTIZED OKon both trees; head-only storesFAILED: RuntimeError Tensor.item() cannot be called on meta tensorsone84d249fdandQUANTIZED OKafter the fix.tests/test_tied_lm_head_only_5399.py(8 tests). One84d249fd: 3 failed / 5 passed -> 8 passed.test_structure.py+ lazy-turtle suites 61 passed; ruff clean.One existing expectation in
tests/test_internvl_untied_lm_head_4799.pyencoded the old "source missing means untied" rule; it now asserts the pair is kept, plus a new assertion that a checkpoint storing neither member drops it.Replace LazyTurtle with weight_loader CheckpointSource (#6471)
Remove accelerate: explicit WeightLoader for weight loading, placemen…