Skip to content

[BUG] QuantizeEmbedConfig is never validated: a misspelled embed_quant_mode ('inptu') makes requantize() replay every layer and return success with nothing quantized; embed_only='False' is truthy #5124

Closed

Description

@Qubitium

Found on main @ 7b8f127, ROCm (R9700). Qwen2.5-0.5B-Instruct GPTQ 4-bit (gptq_v2) quantized on this box.

What is wrong

QuantizeEmbedConfig (gptqmodel/quantization/config.py:242-245) is a plain @dataclass with no __post_init__. BaseQModel._normalize_embed_quant_config (models/base.py:2884-2901) returns a passed instance unchanged. Every consumer compares the mode with in (QuantizeEmbed.INPUT, QuantizeEmbed.BOTH) / (OUTPUT, BOTH) (module_looper.py:2005-2009, 2148-2149, stage_layer.py:575-576, weight_only_looper.py:842-848), and embed_only is tested for truthiness (stage_layer.py:1051 embed_only is not False, weight_only_looper.py:1083 bool(...) and self.embed_only). As a result:

QuantizeEmbed is a str enum, so the correctly spelled lower-case string "input" works, which makes the typo case easy to hit.

Repro

import torch
from gptqmodel import GPTQModel, QuantizeEmbedConfig, CalibrationConfig
m = GPTQModel.load(gptq_ckpt, device_map={"": "cuda:0"}, dtype=torch.float16)
dyn = dict(m.quantize_config.dynamic or {})
dyn[m.get_input_embeddings_name()] = {"bits": 4, "group_size": 32, "sym": True, "desc_act": False}
m.quantize_config.dynamic = dyn
r = m.requantize(CalibrationConfig(dataset=c4_rows[:8]), embed_quant_config=QuantizeEmbedConfig(embed_quant_mode="inptu"))
print(type(r).__name__, type(m.get_input_embeddings()).__name__)

Output (fresh process per line):

QuantizeEmbedConfig(embed_quant_mode="inptu") -> returned dict, embed = Embedding (nothing quantized, no warning)
QuantizeEmbedConfig(embed_quant_mode="input") -> returned dict, embed = TorchQuantEmbeddings
QuantizeEmbedConfig(embed_quant_mode=None)    -> ValueError layer module item `self_attn.q_proj` not found in model, please check your model config.

Suggested fix

Add __post_init__ to QuantizeEmbedConfig: coerce embed_quant_mode with QuantizeEmbed(value) (raising on unknown or None, with the valid values listed), and require type(embed_only) is bool through the same _require_bool_value helper #4668 uses.

Severity

Low-medium. A typo costs a full calibration replay and reports success with the embeddings untouched, so the user saves a checkpoint they believe has quantized endpoints.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5124-embed-config is working on this issue now.

    Started 2026-11-18T05:25:43Z. 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: fix: validate QuantizeEmbedConfig (embed_quant_mode via QuantizeEmbed, embed_only as a real bool) so a typo cannot silently quantize nothing

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-root-5124-embed-config finished this issue.
    Pull request: #5136

    QuantizeEmbedConfig is now validated at construction: embed_quant_mode is coerced through QuantizeEmbed (unknown values and None raise a ValueError that lists 'input', 'output', 'both') and embed_only goes through the #4668 _require_bool_value helper, so "False" can no longer behave as True. BaseQModel._normalize_embed_quant_config re-validates a passed instance, so both quantize(embed_quant_config=...) and requantize(embed_quant_config=...) reject a bad or mutated config before dataset preparation, offload or any layer replay instead of replaying every layer and quantizing nothing. Regression tests cover construction, coercion and both entry points, plus a cached-checkpoint CUDA case; the mechanism and before/after flows are documented in docs/embedding-quantization-config.md.

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