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] 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
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
importtorchfromgptqmodelimportGPTQModelfromgptqmodel.quantization.configimportFP8Config# RTNConfig / GPTQConfig behave the samem=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([nforn, tinm.model.named_parameters() ift.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.
Activity
Qubitium commentedon Nov 17, 2026
Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.
fix(offload): finish the in-session materialisation contract for resu…
Offload finalized modules as file-backed tensors instead of meta + ho…
Remove accelerate: explicit WeightLoader for weight loading, placemen…