Skip to content

fix(qwen2_vl): save GPTQ checkpoints in source layout and exclude dense vision tower (#6360) - #6374

Merged
Qubitium merged 1 commit into
mainfrom
fix/6360-qwen-vl-sglang
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/6360-qwen-vl-sglang

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #6360

Summary

Two independent defects made SGLang 0.5.23 reject a Qwen2-VL / Qwen2.5-VL GPT-QModel checkpoint. Both are fixed in BaseQwen2VLGPTQ; no writer change is needed.

  1. Key layout. save() wrote the Transformers 5 runtime names (model.language_model.*, model.visual.*). Added checkpoint_key_for_save / checkpoint_key_for_load derived from Transformers 5.23's own Qwen2VLForConditionalGeneration conversion map (^visual -> model.visual, ^model -> model.language_model):

    runtime checkpoint
    model.language_model.<rest> model.<rest>
    model.visual.<rest> visual.<rest>
    lm_head.* unchanged
    headless qwen2_vl_text / qwen2_5_vl_text root keys unchanged

    checkpoint_key_for_load keeps runtime-layout keys verbatim, so checkpoints written before this fix still load.

  2. Dense vision tower. Added prepare_quantize_config_for_save, which adds dynamic.setdefault(r"-:(?:model\.)?visual\..*", {}) (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; visual.merger covers the projector). The rule is written to both quantize_config.json and config.json.

Before / after (real local checkpoints, RTX 4090, transformers 5.23)

GPTQConfig(bits=4, group_size=128, sym=True, desc_act=False), 4 short text calibration rows.

Before (origin/main), Qwen2.5-VL-3B-Instruct:

PREFIXES: ['model.language_model', 'model.visual']
RUNTIME_LANG: 1190 RUNTIME_VISUAL: 390
config.json dynamic: None
quantize_config.json dynamic: None

This matches the issue's Counter({'model.language_model': 1190, 'model.visual': 390}).

After:

model saved prefixes runtime keys visual quant tensors dynamic
Qwen2.5-VL-3B-Instruct model.embed_tokens, model.layers, model.norm, visual.blocks, visual.merger, visual.patch_embed 0 0 {"-:(?:model\\.)?visual\\..*": {}}
Qwen2-VL-2B-Instruct same 0 0 same

model.language_model.layers.0.mlp.gate_up_proj.g_idx is absent and model.layers.0.mlp.gate_proj.g_idx is present. visual.blocks.0.mlp.gate_proj.weight / visual.blocks.0.mlp.fc1.weight stay dense (no qweight/qzeros/scales/g_idx under visual.).

Round-trip logits (probe "The capital of France is", bf16, same backend):

model GPTQModel reload (TORCH, same kernel as pre-save) plain HF AutoModelForImageTextToText.from_pretrained GPTQModel reload (AUTO -> Marlin)
Qwen2.5-VL-3B 0.0 0.0 0.75
Qwen2-VL-2B 0.0 0.0 1.0 (0.9375)

The AUTO/Marlin delta is kernel numerics: both loaders reproduce the pre-save model exactly when they use the same kernel as quantization.

Regression test

tests/test_qwen_vl_sglang_checkpoint_6360.py (CPU, ~12 s):

  • (a) saved key layout equals Transformers 5.23 save_pretrained's prefixes for both families and has no model.language_model. / model.visual.
  • (b) the -: vision rule is in both metadata files and matches visual.* but not decoder modules
  • (c) save -> GPTQModel.load and plain HF load -> logits exactly equal the pre-save model
  • (d) control: the same definition with both hooks shadowed saves runtime layout with no vision rule, and still reloads (reverse path)
  • mapping unit test, including runtime-layout idempotence

Red on origin/main (isolated archive copy): 4 failed / 1 passed. Both saved-layout tests fail at the runtime-prefix assertion; the mapping tests fail on the missing methods; the control passes. Green on this branch: 5 passed.

Validation

tests/test_qwen_vl_sglang_checkpoint_6360.py ......................... 5 passed
tests/test_qwen2_5_vl_local_port.py tests/test_qwen2_vl_local_port.py
tests/test_checkpoint_compat.py tests/test_checkpoint_interop_4053.py
tests/test_gemma3_vl_support.py tests/test_unlimited_ocr_local_port.py
tests/test_lfm2_moe_expert_key_names_6283.py tests/test_qwen3_omni_key_map_4881.py
= 209 passed, 1 skipped, 1 failed (environmental)

The single failure is test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloads with device_map="auto" on this mixed 4090/5090 host (kernel selection rejects mixed accelerator families). Pinned to one GPU it passes. The skip is vLLM not installed.

Ruff: ruff check gptqmodel/models/definitions/base_qwen2_vl.py tests/test_qwen_vl_sglang_checkpoint_6360.py -> All checks passed.

SGLang is not installed in this environment, so the engine start from the issue was not exercised. Validation is structural (key layout + config rule + no dense weights under a quantized prefix), as requested for the no-SGLang case.

Coordination

Only gptqmodel/models/definitions/base_qwen2_vl.py (shared by qwen2_vl.py / qwen2_5_vl.py) and the new test file are touched. No changes to gptqmodel/models/writer.py or tests/test_qwen2_vl_local_port.py / tests/test_qwen2_5_vl_local_port.py, so this rebases cleanly over #6269.

Qwen2-VL / Qwen2.5-VL GPTQ checkpoints were written with the Transformers 5
runtime names (`model.language_model.*`, `model.visual.*`), which SGLang's
Qwen VL `load_weights` cannot map, and the dense BF16 vision tower was not
declared in the saved `quantization_config`, so SGLang allocated GPTQ layers
for `visual.blocks.*` and failed on the dense weights.

Add the inverse of the `Qwen2VLForConditionalGeneration` HF conversion map to
`BaseQwen2VLGPTQ` (save and load; load keeps runtime-layout checkpoints from
before this fix verbatim), and add the `-:(?:model\.)?visual\..*` dynamic rule
for the dense vision tower to both metadata files.
@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 12:27
@Qubitium
Qubitium merged commit a4d2b18 into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6360-qwen-vl-sglang branch November 29, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant