Skip to content

[BUG] Offloaded quantize() leaves the tied lm_head of VL models (Qwen2-VL, Qwen2.5-VL) on meta: in-session .to()/generate() fail, then CUDA device-side assert (#4498 incomplete: no re-tie after base-module materialization) #4597

Closed

Description

@Qubitium

Found on main @ 4b65923, RTX 5090 (sm_120), torch 2.15 / transformers 5.22.

What is wrong

#4498 (#4450) promises that after an offloaded quantize() the in-session model is the same model offload_to_disk=False produces. For tied-embedding VL models (Qwen2-VL-2B-Instruct, Qwen2.5-VL-3B-Instruct, both tie_word_embeddings: true), lm_head stays on meta:

ERROR Offload: modules remain on the meta device after quantization (lm_head). The in-session model cannot run inference; reload the saved checkpoint before using it.

This comes from materialize_remaining_meta_modules (gptqmodel/utils/offload.py:344-385). It tries to load lm_head from the source checkpoint, but a tied checkpoint has no lm_head.weight; it only stores model.embed_tokens.weight, in the legacy key layout. The tie is never re-established after the base modules are materialized:

  • restore_offloaded_modules (offload.py:202-237) calls tie_weights() only right after restoring the captured base-module bundles.
  • The weight-only looper materializes the meta base modules afterwards (_materialize_meta_base_modules, weight_only_looper.py:913-955).
  • Nothing ties again before materialize_remaining_meta_modules gives up.

Calling m.model.tie_weights() once after quantize() fixes it completely (0 meta tensors, and generate() matches the offload_to_disk=False result). So the missing step is just a final re-tie.

The failure is worse than the logged message suggests. model.to("cuda") raises halfway (NotImplementedError: Cannot copy out of meta tensor) and leaves the model split across devices. The next generate() then fails with CUDA error: device-side assert triggered, which poisons the CUDA context for the rest of the process.

Repro

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import FP8Config   # RTNConfig / GPTQConfig behave the same

m = GPTQModel.load("Qwen/Qwen2-VL-2B-Instruct", FP8Config(), dtype=torch.bfloat16)   # offload_to_disk=True (default)
m.quantize(["hello world, this is a calibration sentence. " * 20] * 4)
print([n for n, t in m.model.named_parameters() if t.is_meta])
m.model.to("cuda:0")
m.generate(**m.tokenizer("The capital of France is", return_tensors="pt").to("cuda:0"), max_new_tokens=4)
model / method offload meta after quantize() .to("cuda") generate()
Qwen2-VL-2B FP8 on lm_head (1) NotImplementedError AcceleratorError: CUDA error: device-side assert triggered
Qwen2-VL-2B GPTQ 4-bit on lm_head (1) NotImplementedError device-side assert
Qwen2.5-VL-3B RTN 4-bit on lm_head (1) NotImplementedError device-side assert
Qwen2-VL-2B FP8 off 0 ok The capital of France is Paris. Paris is
Qwen2-VL-2B FP8, on + m.model.tie_weights() on 0 ok The capital of France is Paris. Paris is

The saved checkpoint is fine: save → load → re-save → load is byte-identical, and the reload matches.

Suggested fix

At loop exit in both ModuleLooper.loop and WeightOnlyLooper.loop, after _materialize_meta_base_modules and before _materialize_remaining_meta_modules, call model.tie_weights() when config.tie_word_embeddings (or get_text_config()) is set. Also, materialize_remaining_meta_modules should not try to read a tied output embedding from the checkpoint. If a meta module remains, raise instead of only logging: the documented log.error path leads straight into the partial .to() and the CUDA assert.

Test that should have caught it

tests/test_offload_quantized_modules_restored_4450.py uses text-only Qwen2.5, whose tie happens to survive. Add a tied VL case (a tiny Qwen2-VL config is enough) asserting zero meta tensors after an offloaded weight-only quantize() and after a GPTQ quantize().

Severity

Medium. With defaults, quantize-then-evaluate in the same process is broken for the Qwen2/2.5-VL family and other tied VL wrappers. The checkpoint on disk is correct.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

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