Repository navigation
Description
Summary
A GPTQ checkpoint of Qwen/Qwen2.5-VL-3B-Instruct made with the default GPTQConfig(bits=4, group_size=128) loads and runs in GPTQModel.load (wikitext-2 PPL 17.753). SGLang 0.5.23 lists GPTQ and Qwen2.5-VL as supported, but it fails at engine start on this checkpoint. Two separate problems in what GPT-QModel writes cause this:
-
Key layout. Tensors are written under the Transformers 5 runtime names (
model.language_model.layers.*,model.visual.*). The hub checkpoint and Transformers' ownsave_pretrained(5.23, checked) both use the source layout (model.layers.*,visual.*,lm_head.*). SGLang's Qwen2.5-VLload_weightsonly accepts that layout:KeyError: 'model.language_model.layers.0.mlp.gate_up_proj.g_idx'The Qwen VL definitions have no
checkpoint_key_for_save. Gemma 3, Qwen2.5-Omni/Qwen3-Omni and LFM2-MoE have one, so their checkpoints are saved in the source layout. -
Vision tower not excluded. The vision tower stays dense (BF16
weight). However, the GPTQquantization_confighas nodynamicrule that excludes it ("dynamic"is absent). SGLang passesquant_configtoQwen2_5_VisionTransformerand uses GPTQdynamic-:rules to decide which layers stay unquantized. So it builds GPTQ layers forvisual.blocks.*and fails on the dense weights:KeyError: 'visual.blocks.0.mlp.gate_up_proj.weight'The Gemma 3 definition already handles this case:
prepare_quantize_config_for_saveadds-:vision_tower\..*/-:multi_modal_projector\..*with the comment "Tell vLLM's GPTQ loader not to allocate quantized linear layers for them". The Qwen2-VL / Qwen2.5-VL definitions have no equivalent.
Fixing only one of the two is not enough: with both fixes the checkpoint loads and matches GPT-QModel exactly (table below). Related: #6192 is the AWQ version of (2) (modules_to_not_convert), and it mentions (1) in a footnote. It states "GPTQ is not affected", but that is true for vLLM only. For SGLang, the GPTQ checkpoint is unusable too, and the #6192 fix (an AWQ modules_to_not_convert entry) would not change it.
Introduced by
Pre-existing. The runtime-layout save comes from the Transformers 5 port (d2dfb9385, #4620): the composite Qwen VL modules are now model.language_model / model.visual and no reverse key map is applied on save. Still present at HEAD be14824.
Location
HEAD be14824.
gptqmodel/models/definitions/base_qwen2_vl.py:26(BaseQwen2VLGPTQ),qwen2_vl.py,qwen2_5_vl.py: nocheckpoint_key_for_saveand noprepare_quantize_config_for_save.gptqmodel/models/writer.py:2956-2958: only definitions withcheckpoint_key_for_saveget their keys converted.checkpoint_key_for_save = getattr(self, "checkpoint_key_for_save", None) if callable(checkpoint_key_for_save) and checkpoint_passthrough_plan is None: state_dict = _convert_checkpoint_state_dict_keys(state_dict, checkpoint_key_for_save)
gptqmodel/models/definitions/gemma3.py:81-101: the Gemma 3 counterpart (checkpoint_key_for_save+dynamic.setdefault(r"-:vision_tower\..*", {})).
Reproduction (ran it: RTX 4090, GPT-QModel HEAD be14824, transformers 5.23, SGLang 0.5.23)
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(1024)) if len(r["text"]) > 300][:128]
m = GPTQModel.load("Qwen/Qwen2.5-VL-3B-Instruct", GPTQConfig(bits=4, group_size=128, sym=True, desc_act=False))
m.quantize(CalibrationConfig(dataset=calib, batch_size=4))
m.save("qwen25vl3b-gptq")import sglang as sgl
sgl.Engine(model_path="qwen25vl3b-gptq", disable_cuda_graph=True, context_length=2048)
# KeyError: 'model.language_model.layers.0.mlp.gate_up_proj.g_idx'Saved layout (top-level key prefixes):
Counter({'model.language_model': 1190, 'model.visual': 390})
Transformers 5.23 Qwen2_5_VLForConditionalGeneration(cfg).save_pretrained(...) writes, for comparison:
Counter({'model.layers': 12, 'visual.blocks': 12, 'visual.merger': 5, 'model.embed_tokens': 1, 'model.norm': 1, 'visual.patch_embed': 1})
A/B on the same tensors. Variants: keys renamed model.language_model. -> model., model.visual. -> visual., and/or "dynamic": {"-:visual\\..*": {}} added to config.json + quantize_config.json. Metrics: wikitext-2 test, 20 x 512 tokens; ARC-Easy, 400 test questions, log-likelihood of each choice. SGLang uses prompt logprobs, GPT-QModel its own forward.
| checkpoint variant | SGLang 0.5.23 | SGLang PPL / ARC-e | GPT-QModel PPL / ARC-e |
|---|---|---|---|
| as saved | KeyError: 'model.language_model.layers.0.mlp.gate_up_proj.g_idx' |
- | 17.753 / 0.730 |
+ -:visual\..* only |
same KeyError |
- | |
| source key layout only | KeyError: 'visual.blocks.0.mlp.gate_up_proj.weight' |
- | |
source key layout + -:visual\..* |
loads | 17.755 / 0.730 | 17.753 / 0.730 |
Greedy text with both fixes matches GPT-QModel for the first 10-20 tokens ("Paris. The capital of the United States is Washington, D.C. ...", same fibonacci body).
Expected vs actual
Expected: a GPTQ checkpoint of a supported VL model loads in SGLang like the hub-layout checkpoints Transformers writes, with the dense vision tower declared unquantized, as the Gemma 3 definition already does. Actual: SGLang can't map the runtime-layout keys. Once they are renamed, it allocates GPTQ layers for the dense vision tower. Either way, engine start fails.
Suggested fix
- Give
BaseQwen2VLGPTQ(Qwen2-VL / Qwen2.5-VL) acheckpoint_key_for_save/checkpoint_key_for_loadpair that reverses the TransformersQwen2VLForConditionalGenerationconversion (model.language_model.<->model.,model.visual.<->visual.,lm_head.unchanged), the waygemma3.pyand_omni_thinker_layout.pydo. Other definitions whose Transformers conversion map renames the top-level modules (llava-style: Mistral-3, InternVL, ...) should be checked too. - Add a
prepare_quantize_config_for_savethat declares the vision tower dense:dynamic.setdefault(r"-:(?:model\.)?visual\..*", {}). This one pattern matches both the source-layout prefix (visual.), which SGLang/vLLM use, and the runtime name. This is the GPTQ counterpart of the [BUG] AWQ export of VL models: the dense vision tower is not listed inmodules_to_not_convert, so a GPT-QModel Qwen2.5-VL AWQ checkpoint crashes infrom_pretrainedand SGLang #6192 AWQ fix. - A test that saves a tiny Qwen2.5-VL GPTQ checkpoint and checks that the key prefixes match
save_pretrained's and thatdynamichas a-:rule forvisual.
Activity
fix(qwen2_vl): save GPTQ checkpoints in the source HF layout (#6360) (#…
test: repair three stale test fixtures on main 1615acc (#6401)