Repository navigation
Description
Summary
With lm_head=True, the looper adds an implicit per-module override for the head (bits=8, group_size=32) and saves it as a dynamic entry whose key is the bare HF module name:
'dynamic': {'lm_head': {'bits': 8, 'group_size': 32, 'sym': True, 'desc_act': False, 'mse': 2.4}}, 'bits': 4, 'group_size': 128, 'lm_head': True
vLLM resolves dynamic with re.match(pattern, vllm_prefix), which is anchored at the start. For a text model the head prefix is lm_head, so the rule matches. That case works: TinyLlama lm_head=True gives vLLM PPL 12.334 vs GPT-QModel 12.336. For multimodal models, vLLM nests the text model, and the head prefix is language_model.lm_head (Qwen2-VL, Qwen2.5-VL, and most *ForConditionalGeneration wrappers in vLLM). re.match("lm_head", "language_model.lm_head") fails, so vLLM builds the head with the base config (4-bit, g128) and tries to load the 8-bit g32 tensors into it:
vllm/model_executor/layers/vocab_parallel_embedding.py", line 524, in weight_loader
vllm/model_executor/utils.py", line 103, in copy_weight_
return dst.copy_(src)
RuntimeError: The size of tensor a (448) must match the size of tensor b (896) at non-singleton dimension 0
RuntimeError: Engine core initialization failed.
(448 = 3584 / 8 is the 4-bit packed row count; 896 = 3584 / 4 is the 8-bit one in the checkpoint.)
save() itself says "Load this checkpoint with GPTQModel.load or vLLM" for lm_head=True, and vLLM supports quantized lm_head plus dynamic. The tensors are correct: with only the dynamic key rewritten to a prefix-agnostic regex, vLLM loads the same checkpoint and matches GPT-QModel (table below).
Introduced by
Pre-existing. The implicit lm_head rule keyed by self.gptq_model.lm_head dates from 7939d1a (#1302). It has been wrong for vLLM on VL wrappers since vLLM moved the head under language_model.. Still present at HEAD 9123364.
Location
gptqmodel/looper/module_looper.py:2189-2193 (HEAD 9123364):
lm_head_quant_config = {"bits": 8, "group_size": 32, "sym": True, "desc_act": False, "mse": 2.4}
if self.gptq_model.quantize_config.dynamic is None:
self.gptq_model.quantize_config.dynamic = {self.gptq_model.lm_head: lm_head_quant_config}
elif self.gptq_model.quantize_config.dynamic_get(self.gptq_model.lm_head, default=None) is None:
self.gptq_model.quantize_config.dynamic[self.gptq_model.lm_head] = lm_head_quant_configThe same bare-name key is used for the requantize endpoint defaults at module_looper.py:2150-2170 (missing_defaults[name] = dict(default_config)).
Reproduction (ran it: RTX 4090, GPT-QModel HEAD 9123364, vLLM 0.34.0)
from datasets import load_dataset
from gptqmodel import GPTQModel, GPTQConfig, CalibrationConfig
ds = load_dataset("allenai/c4", data_files="en/c4-train.00001-of-01024.json.gz", split="train")
calib = [r["text"] for r in ds.select(range(512)) if len(r["text"]) > 300][:128]
m = GPTQModel.load("Qwen/Qwen2.5-VL-7B-Instruct", GPTQConfig(bits=4, group_size=128, lm_head=True)) # untied head
m.quantize(CalibrationConfig(dataset=calib, batch_size=4))
m.save("qwen25vl7-gptq-lmhead")from vllm import LLM
LLM(model="qwen25vl7-gptq-lmhead", enforce_eager=True, max_model_len=2048)
# RuntimeError: The size of tensor a (448) must match the size of tensor b (896) at non-singleton dimension 0Wikitext-2 test PPL (20 x 512 tokens, vLLM prompt logprobs vs GPT-QModel's own forward). The tensors are identical in both rows:
dynamic key for the head |
vLLM | GPT-QModel |
|---|---|---|
"lm_head" (as saved) |
crash at engine init | 14.006 |
"+:(?:.*\\.)?lm_head$" (edited in both JSONs) |
14.007 | 14.006 |
The text-only control (TinyLlama-1.1B, lm_head=True) loads in vLLM and SGLang with the saved key (12.334 / 12.335 vs 12.336).
Expected vs actual
Expected: a GPT-QModel lm_head=True checkpoint of a supported VL model loads in vLLM, as text-only ones do. Actual: the implicit head override never matches vLLM's head prefix on multimodal wrappers, and engine start fails with a shape mismatch.
Suggested fix
Write the implicit head (and requantize endpoint) rules as a prefix-agnostic, end-anchored regex, e.g. +:(?:.*\.)?lm_head$ built from pcre.escape(<head name>). It still matches the GPT-QModel runtime name and also matches language_model.lm_head in vLLM/SGLang. I checked that GPTQModel.load of the edited checkpoint still builds the head as an 8-bit g32 MarlinLinear. Alternatively, emit both spellings.
Activity
fix(looper): key the implicit lm_head rule per engine prefix and drop…
test(qwen2_5_vl): place the #6194 head-rule test before the AWQ block
fix(looper): key the implicit lm_head rule per engine prefix, and dro…