Description
Found on main @ 7b8f127, CPU and ROCm (R9700). Qwen2.5-0.5B-Instruct (full and 2-layer), Llama-3.2-1B-Instruct.
What is wrong
quantize() accepts embed_quant_config= / embed_quant_mode= on an unquantized model (docs/calibration-config.md lists both as quantize() keywords), but neither mode works in a fresh quantize:
-
QuantizeEmbed.INPUT/BOTHalways crash at input capture, on every model tried.looper/stage_inputs_capture.py:410-414skips materializing the input embedding when the mode is INPUT/BOTH (added for requantize in support lm-head/embed requant #3050, where the loaded quantized model already holds a real embedding). In a fresh quantize the model is a LazyTurtle shell, soembed_tokensstays onmeta. The capture forward then runs the embedding on meta and transformers'create_causal_mask→_ignore_causal_mask_sdpacalls.item()on a meta tensor:File "gptqmodel/models/base.py", line 3574, in run_input_capture File ".../transformers/models/qwen2/modeling_qwen2.py", line 370, in forward File ".../transformers/masking_utils.py", line 271, in _ignore_causal_mask_sdpa RuntimeError: Tensor.item() cannot be called on meta tensorsThe same happens with Qwen2.5-0.5B (2L and full) on CPU and ROCm, and with Llama-3.2-1B on ROCm.
-
QuantizeEmbed.OUTPUTon a tied-embedding model runs the whole quantization and only then fails. The tiedlm_headis replaced by aTorchLinear. At the end,retie_tied_weights(utils/offload.py:255-266) fails with"attribute 'weight' already exists", andquantize()raises:RuntimeError: Offload: base modules remain on the meta device after quantization (<tie_weights>). The in-session model cannot run inference; reload the saved checkpoint before using it.The model is left with
quantized=True, quantized decoder layers and a quantized head no longer tied toembed_tokens. The equivalentGPTQConfig(lm_head=True)request is refused up front (module_looper.py:2036-2043,"quantization of lm_head layer with tied weights is not supported"). The embedding path has no such guard, althoughdocs/quantization-features.mdsays these flows are fail-closed.
Repro
import torch
from gptqmodel import GPTQModel, QuantizeEmbed, QuantizeEmbedConfig
from gptqmodel.quantization.config import GPTQConfig, CalibrationConfig
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", GPTQConfig(bits=4, group_size=128),
dtype=torch.bfloat16, device="cuda:0") # or dtype=float32 on CPU
calib = [...] # 16 C4 rows of ~1000 chars
m.quantize(CalibrationConfig(dataset=calib, batch_size=4),
embed_quant_config=QuantizeEmbedConfig(embed_quant_mode=QuantizeEmbed.INPUT))Output:
INPUT (Qwen2.5-0.5B full, ROCm) -> RuntimeError Tensor.item() cannot be called on meta tensors (model.quantized=False)
INPUT (Llama-3.2-1B full, ROCm) -> RuntimeError Tensor.item() cannot be called on meta tensors
INPUT (Qwen2.5-0.5B 2L, CPU fp32) -> RuntimeError Tensor.item() cannot be called on meta tensors
OUTPUT (Qwen2.5-0.5B full, ROCm) -> after all 24 layers: RuntimeError Offload: base modules remain on the meta device after quantization (<tie_weights>)
model.quantized=True, lm_head=TorchLinear, embed_tokens=Embedding
GPTQConfig(lm_head=True), same tied model -> NotImplementedError up front (expected behavior)
Suggested fix
- INPUT/BOTH in a fresh quantize: materialize the input embedding for the capture forward (it is the pseudo-layer's source, so it must hold real weights), or refuse
embed_quant_configon an unquantized model before any work and document "requantize only". - OUTPUT/BOTH on a tied model: apply the same
_lm_head_is_tied()refusal thelm_head=Truepath uses, before calibration.
Test that should have caught it
tests/test_requant_embed_lm_head_e2e.py only covers requantize() on a loaded quantized checkpoint. No test calls quantize(embed_quant_config=...) on a LazyTurtle-loaded model.
Severity
Medium. A public quantize() option crashes for every model (INPUT/BOTH), or wastes a full run and leaves an unusable in-session model (OUTPUT on tied models, the common case for small models).
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-4e3a0639ecaffinished this issue.Pull request: #5168
Merged as 8a2fbeb: fresh quantize() now refuses INPUT/BOTH and tied OUTPUT/BOTH endpoint quantization before calibration; requantize() unchanged.
fix(embed): refuse fresh endpoint quantize before calibration (#5111)
fix(embed): refuse fresh endpoint quantize before calibration (#5111) (…