Skip to content

[BUG] quantize(embed_quant_config=...) on an unquantized model: INPUT/BOTH always crash at input capture ('Tensor.item() on meta'), OUTPUT on a tied model runs the whole quantize then fails re-tying (no lm_head=True-style upfront refusal) #5111

Closed

Description

@Qubitium

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:

  1. QuantizeEmbed.INPUT / BOTH always crash at input capture, on every model tried. looper/stage_inputs_capture.py:410-414 skips 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, so embed_tokens stays on meta. The capture forward then runs the embedding on meta and transformers' create_causal_mask → _ignore_causal_mask_sdpa calls .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 tensors
    

    The same happens with Qwen2.5-0.5B (2L and full) on CPU and ROCm, and with Llama-3.2-1B on ROCm.

  2. QuantizeEmbed.OUTPUT on a tied-embedding model runs the whole quantization and only then fails. The tied lm_head is replaced by a TorchLinear. At the end, retie_tied_weights (utils/offload.py:255-266) fails with "attribute 'weight' already exists", and quantize() 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 to embed_tokens. The equivalent GPTQConfig(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, although docs/quantization-features.md says 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_config on an unquantized model before any work and document "requantize only".
  • OUTPUT/BOTH on a tied model: apply the same _lm_head_is_tied() refusal the lm_head=True path 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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-4e3a0639ecaf finished this issue.

    Pull request: #5168

    Merged as 8a2fbeb: fresh quantize() now refuses INPUT/BOTH and tied OUTPUT/BOTH endpoint quantization before calibration; requantize() unchanged.

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