Skip to content

[BUG] writer / SGLang interop: Qwen2.5-VL (and Qwen2-VL) GPTQ checkpoints can't be loaded by SGLang: tensors are saved in the runtime key layout, and the dense vision tower is not excluded in dynamic #6360

Done

Description

@Qubitium

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:

  1. Key layout. Tensors are written under the Transformers 5 runtime names (model.language_model.layers.*, model.visual.*). The hub checkpoint and Transformers' own save_pretrained (5.23, checked) both use the source layout (model.layers.*, visual.*, lm_head.*). SGLang's Qwen2.5-VL load_weights only 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.

  2. Vision tower not excluded. The vision tower stays dense (BF16 weight). However, the GPTQ quantization_config has no dynamic rule that excludes it ("dynamic" is absent). SGLang passes quant_config to Qwen2_5_VisionTransformer and uses GPTQ dynamic -: rules to decide which layers stay unquantized. So it builds GPTQ layers for visual.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_save adds -: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: no checkpoint_key_for_save and no prepare_quantize_config_for_save.
  • gptqmodel/models/writer.py:2956-2958: only definitions with checkpoint_key_for_save get 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) a checkpoint_key_for_save / checkpoint_key_for_load pair that reverses the Transformers Qwen2VLForConditionalGeneration conversion (model.language_model. <-> model., model.visual. <-> visual., lm_head. unchanged), the way gemma3.py and _omni_thinker_layout.py do. 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_save that 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 in modules_to_not_convert, so a GPT-QModel Qwen2.5-VL AWQ checkpoint crashes in from_pretrained and 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 that dynamic has a -: rule for visual.
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