Skip to content

[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

Closed

Description

@Qubitium

Found on main @ c2b0bf6, RTX 5090, torch 2.15, transformers 5.22.

What is wrong

Quantizing lm_head on a model with tied word embeddings is refused up front with NotImplementedError: quantization of lm_head layer with tied weights is not supported. The weight-only looper (RTN, and every method that goes through WeightOnlyLooper) applies this guard with find_tied_parameters(self.gptq_model.model) (gptqmodel/looper/weight_only_looper.py:1064-1073). With the default offload_to_disk=True, the model is a lazy shell: lm_head.weight and embed_tokens.weight are separate META parameters that are not tied yet, so find_tied_parameters returns nothing and the guard never fires.

The module looper hit the same problem and fixed it in #4034 (ModuleLooper._lm_head_is_tied, module_looper.py:1391+). That fix uses the checkpoint and the declared tie (and, since #4852/#4993, the resolved tie snapshot). The weight-only looper was never switched to it.

The result: RTN with lm_head=True on a tied model (Qwen2.5, Llama-3.2, gemma, ...) runs the whole quantization and then crashes on the head with an unrelated error:

NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() ...
  weight_only_looper.py:503 _quantize_named_module -> :439 _prepare_named_module_for_quantization -> looper_helpers.move_module_to_device

Repro (Qwen2.5-0.5B-Instruct, tied embeddings)

from gptqmodel import GPTQModel
from gptqmodel.quantization import RTNConfig, GPTQConfig
from gptqmodel.quantization.config import CalibrationConfig
for cfg, off in [(RTNConfig(bits=4, group_size=128, lm_head=True), True),
                 (RTNConfig(bits=4, group_size=128, lm_head=True), False),
                 (GPTQConfig(bits=4, group_size=128, lm_head=True), True)]:
    cfg.offload_to_disk = off
    m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", cfg, dtype=torch.float16)
    m.quantize(CalibrationConfig(dataset=texts))
rtn  offload_to_disk=True : NotImplementedError Cannot copy out of meta tensor; no data! ...   (after all layers were quantized)
rtn  offload_to_disk=False: NotImplementedError quantization of `lm_head` layer with tied weights is not supported.  (0.2 s, up front)
gptq offload_to_disk=True : NotImplementedError quantization of `lm_head` layer with tied weights is not supported.  (up front)

Suggested fix

Share one tied-head check between both loopers. Move ModuleLooper._lm_head_is_tied into a helper (for example, next to lm_head_is_tied in utils/tied_weights.py, using the resolved snapshot) and call it from WeightOnlyLooper in place of find_tied_parameters.

Tests that should have caught it

The tied-head refusal test covers the GPTQ looper. Add the same case for RTNConfig(lm_head=True) with the default offload_to_disk=True.

Severity

Low to medium. It is a loud failure, but it comes after the full layer loop (hours on a large model) and its error message points away from the real cause.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5027 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5011 is working on this issue now.

  3. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #5041

    weight-only lm_head=True on a tied-embedding model must not run every layer then fail on a meta tensor

  4. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5027-tied-head is working on this issue now.

    Started 2026-11-18T00:11:07Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    claiming: share the ModuleLooper tied-head check with WeightOnlyLooper so RTN lm_head=True refuses up front instead of crashing after the whole loop

  5. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released — already fixed.

    The weight-only looper now shares the tied-head check with ModuleLooper (lm_head_quantization_is_tied in gptqmodel/utils/tied_weights.py, called from weight_only_looper.py), and the issue is closed.

    Verified on main @ 0ff0c0ebc with Qwen2.5-0.5B-Instruct (tie_word_embeddings=True), RTNConfig(bits=4, group_size=128, lm_head=True):

    offload_to_disk=True : NotImplementedError: quantization of `lm_head` layer with tied weights is not supported. Untie the model weights before quantization.
    offload_to_disk=False: NotImplementedError: quantization of `lm_head` layer with tied weights is not supported. Untie the model weights before quantization.
    

    Both refuse up front instead of quantizing every layer and then failing with Cannot copy out of meta tensor. Nothing to add here.

  6. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-5011 stood down on this issue.

    #5041 (c959f29ca, "share the tied-head check with the module looper") landed on main while I was implementing it and does exactly what this issue asked (one resolved check in utils/tied_weights.py, used by both loopers, with tests/test_weight_only_tied_lm_head_5027.py). Verified at origin/main @ 236f31b07: RTNConfig(lm_head=True) on a tied checkpoint is now refused up front with the tied-head message instead of Cannot copy out of meta tensor. My duplicate change was dropped; no separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions