Skip to content

fix(awq): publish definition-owned dense towers in modules_to_not_convert (#6192) - #6230

Closed
Qubitium wants to merge 1 commit into
mainfrom
fix/6192-issue
Closed

Qubitium wants to merge 1 commit into
mainfrom
fix/6192-issue

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

AWQ only quantizes the decoder tree, so a model definition's vision tower stays dense. HF Transformers, vLLM and SGLang learn that solely from modules_to_not_convert; GPT-QModel's AWQ writer published only -:/declared exclusions, so a Qwen2.5-VL AWQ checkpoint had no key and from_pretrained built AWQ layers for the dense vision MLPs.

This change makes the writer add the definition's own dense base-module containers to modules_to_not_convert before config.json / quantize_config.json are written. The names come from the model definition's get_base_modules() inventory (the same declaration used for base-module offload), filtered to containers that still own a dense nn.Linear and contain no quantized layer. It is not a hardcoded per-model list: Qwen2-VL/2.5-VL publish model.visual, Gemma 3 publishes model.vision_tower / model.multi_modal_projector, etc.

Fixes #6192.

Overlap with #6190

#6190 (already on main) rewrote the -: translation. This PR does not touch _dynamic_exclusion_patterns, excluded_module_patterns or the -: translation logic. It only seeds the existing modules_to_not_convert compatibility field from the definition inventory; #6190's resolve_excluded_modules() then turns the added container into the concrete dense module names for vLLM/SGLang. On the rebased tree the saved key is e.g.:

"modules_to_not_convert": [
  "model.visual.blocks.0.attn.qkv",
  "model.visual.blocks.0.attn.proj",
  "model.visual.blocks.0.mlp.gate_proj",
  "model.visual.blocks.0.mlp.up_proj",
  "model.visual.blocks.0.mlp.down_proj",
  "model.visual.merger.mlp.0",
  "model.visual.merger.mlp.2"
]

Reproduction (HEAD b95b4c6, CPU)

Tiny Qwen2.5-VL composite, AWQ W4G16, quantize + save:

config.json modules_to_not_convert: None
quantize_config.json modules_to_not_convert: None
dynamic: None
should_convert model.visual.blocks.0.mlp.gate_proj -> True
should_convert model.visual.merger.mlp.0 -> True
should_convert model.language_model.layers.0.mlp.gate_proj -> True

transformers.integrations.awq.replace_with_awq_linear on the saved config then tries to build an AWQ layer for the dense vision MLP and fails:

NotImplementedError: <class 'gptqmodel.nn_modules.qlinear.torch_cpu_avx512_awq.TorchCpuAvx512AwqLinear'>:
`out_features`: 48 must be divisible by [32].

Red test

cd tests
PYTHONPATH=<clone>:<clone>/tests /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py::test_awq_export_publishes_definition_dense_vision_tower -q -rs
>       assert "model.visual" in declared
E       AssertionError: assert 'model.visual' in []
1 failed in 5.10s

Green evidence (rebased on 2d3261d)

PYTHONPATH=<clone>:<clone>/tests /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py::test_awq_export_publishes_definition_dense_vision_tower -q -rs
1 passed

The test asserts:

  • config.json and quantize_config.json carry the same tower exclusion;
  • should_convert_module is False for model.visual.* and True for the decoder projection (the exact predicate replace_with_awq_linear uses);
  • the published tensors keep model.visual.*.weight dense and only the decoder stores qweight;
  • GPTQModel.load + re-save preserves the exclusion and keeps model.visual dense.

Manual post-fix consumer check with the saved config:

declared: ['model.visual.blocks.0.attn.qkv', ..., 'model.visual.merger.mlp.2']
replace_with_awq_linear(model, quantization_config=..., modules_to_not_convert=declared)
vision gate: Linear
vision merger: Linear
decoder gate: TorchCpuAvx512AwqLinear

Test runs

CPU-only (CUDA_VISIBLE_DEVICES=""):

pytest test_qwen2_5_vl_local_port.py -q -rs
26 passed

pytest test_qwen2_vl_local_port.py::test_public_awq_pack_and_two_reloads -q -rs
6 passed

pytest test_checkpoint_compat.py test_awq_modules_to_not_convert_4195.py \
  test_awq_modules_to_not_convert_lifecycle_4309.py test_external_exclusion_translation_4196.py \
  test_checkpoint_interop_4053.py test_gemma3_vl_support.py qcfg/test_config_serialization.py -q -rs
125 passed, 9 skipped

Skips are CUDA-only tests (Marlin/ExLlamaV2/lm_head quantization) under the CPU-only run. Lint:

ruff check gptqmodel/models/writer.py tests/test_qwen2_5_vl_local_port.py tests/test_qwen2_vl_local_port.py
All checks passed!

Not verified

  • A real Qwen/Qwen2.5-VL-3B-Instruct AWQ run and actual transformers / SGLang from_pretrained were not run (CPU-only, no GPU); the loader predicate and the replace_with_awq_linear replacement pass were exercised on tiny CPU models instead.
  • When all shared GPUs are visible, test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloads fails in kernel selection because the device map spans compute capabilities 8.9 and 12.0. That test is GPTQ, not AWQ, and is unrelated to this change; it skips in the CPU-only run.

AWQ only quantizes the decoder tree, so a definition's vision tower stays dense. HF/vLLM/SGLang learn that solely from modules_to_not_convert; without it Transformers builds AWQ layers for the dense vision MLPs and fails on kernel shape constraints.

Resolve the definition's get_base_modules() inventory at save time and add every container that still owns a dense nn.Linear and no quantized layer to modules_to_not_convert. This is definition-owned (Qwen2-VL/2.5-VL visual, Gemma 3 vision_tower/projector, etc.) rather than a name list. The existing #6190 resolver turns the added container into the concrete dense module names for vLLM/SGLang.

Test: Qwen2.5-VL composite AWQ quantize+save publishes the tower, the saved tensors keep dense vision weights, transformers' should_convert_module skips them, and a load+resave round trip preserves the exclusion. Qwen2-VL AWQ export and the text-model control are covered too.
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Consolidated into #6269, which combines #6230, #6232 and #6233 on one branch because all three insert a helper into the same gptqmodel/models/writer.py block. All changes and tests from this PR are preserved there. Closing this draft in favor of the consolidated PR.

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