Repository navigation
fix(qwen2_vl): save GPTQ checkpoints in source layout and exclude dense vision tower (#6360) - #6374
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Key layout.
save()wrote the Transformers 5 runtime names (model.language_model.*,model.visual.*). Addedcheckpoint_key_for_save/checkpoint_key_for_loadderived from Transformers 5.23's ownQwen2VLForConditionalGenerationconversion map (^visual->model.visual,^model->model.language_model):model.language_model.<rest>model.<rest>model.visual.<rest>visual.<rest>lm_head.*qwen2_vl_text/qwen2_5_vl_textroot keyscheckpoint_key_for_loadkeeps runtime-layout keys verbatim, so checkpoints written before this fix still load.Dense vision tower. Added
prepare_quantize_config_for_save, which addsdynamic.setdefault(r"-:(?:model\.)?visual\..*", {})(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;visual.mergercovers the projector). The rule is written to bothquantize_config.jsonandconfig.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:This matches the issue's
Counter({'model.language_model': 1190, 'model.visual': 390}).After:
model.embed_tokens,model.layers,model.norm,visual.blocks,visual.merger,visual.patch_embed{"-:(?:model\\.)?visual\\..*": {}}model.language_model.layers.0.mlp.gate_up_proj.g_idxis absent andmodel.layers.0.mlp.gate_proj.g_idxis present.visual.blocks.0.mlp.gate_proj.weight/visual.blocks.0.mlp.fc1.weightstay dense (noqweight/qzeros/scales/g_idxundervisual.).Round-trip logits (probe
"The capital of France is", bf16, same backend):AutoModelForImageTextToText.from_pretrainedThe 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):save_pretrained's prefixes for both families and has nomodel.language_model./model.visual.-:vision rule is in both metadata files and matchesvisual.*but not decoder modulesGPTQModel.loadand plain HF load -> logits exactly equal the pre-save modelRed 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
The single failure is
test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloadswithdevice_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 byqwen2_vl.py/qwen2_5_vl.py) and the new test file are touched. No changes togptqmodel/models/writer.pyortests/test_qwen2_vl_local_port.py/tests/test_qwen2_5_vl_local_port.py, so this rebases cleanly over #6269.