Skip to content

fix(writer): HF/vLLM interop for dense towers, excluded linears and defused MLPs (#6192, #6163, #6166) - #6269

Merged
Qubitium merged 2 commits into
mainfrom
fix/writer-interop-consolidated
Nov 29, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/writer-interop-consolidated

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Consolidates three draft PRs that all edit gptqmodel/models/writer.py at the same helper-insertion point: #6230, #6232 and #6233. Each change is preserved in full (helpers, docstrings, tests, docs) on one conflict-free branch.

Fixes #6192
Fixes #6163
Fixes #6166

Fixes

  1. AWQ dense towers ([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, from fix(awq): publish definition-owned dense towers in modules_to_not_convert (#6192) #6230). _awq_dense_base_modules() reads the definition's get_base_modules() inventory and adds containers that still own a dense nn.Linear and contain no BaseQuantLinear to modules_to_not_convert before config.json/quantize_config.json are written. This is definition-derived, not a per-model list, so Qwen2-VL/2.5-VL publish model.visual and Gemma 3 publishes its vision tower/projector.

  2. Definition-excluded GPTQ linears ([BUG] writer/HF interop: GPTQ checkpoints of models whose definition keeps a decoder nn.Linear unquantized (LFM3 self_attn.g_proj) omit modules_in_block_to_quantize, so AutoModelForCausalLM.from_pretrained fails on them #6163, from fix(writer): list definition-excluded linears for GPTQ HF interop #6232; the broader modules_in_block_to_quantize interop work was [BUG] writer/HF interop: GPTQ checkpoints never record block_name_to_quantize, so from_pretrained fails with "Block pattern could not be match" for SmolVLM2 (and other models whose decoder is not at model.layers) #6182). _definition_dense_decoder_linears() walks block-resident nn.Linear modules and resolves each layer-relative path through the compiled ModulePlan, returning leaves whose spec has quantize=False (a :! leaf). _gptq_explicit_quantized_modules() now emits the explicit Optimum inclusion list when either dynamic -: exclusions or definition-declared dense decoder linears exist; the writer passes owner=self. docs/quantization-features.md documents the new source.

  3. Defused dense gate/up MLP warning ([BUG] writer/HF interop: Phi-3/Phi-3.5/Phi-4 and GLM-OCR GPTQ checkpoints save the defused mlp.gate_proj/up_proj, so AutoModelForCausalLM.from_pretrained randomly initializes gate_up_proj (PPL 1e11) and save() gives no warning #6166, from fix(writer): warn when a defused dense gate/up MLP cannot load in HF (#6166) #6233). _defuser_split_gate_up_class_names() reads Defuser's _STANDARD_SPLIT_GATE_UP_CLASSES registry and _defused_dense_gate_up_modules() detects parents carrying gate_proj/up_proj without gate_up_proj, using Defuser's runtime split marker or the class registry. hf_compat_warnings() then warns with the exact split keys and the fused key that plain HF reports as MISSING/UNEXPECTED, and points at GPTQModel.load.

Conflict resolution

All three PRs inserted a helper into the same writer.py block, and #6232 also edited _gptq_explicit_quantized_modules() next to #6230's helper. The combined tree keeps all helpers with docstrings intact:

No helper, test or doc line was dropped or renamed.

Files

  • gptqmodel/models/writer.py
  • docs/quantization-features.md
  • tests/test_qwen2_5_vl_local_port.py
  • tests/test_qwen2_vl_local_port.py
  • tests/test_lfm3_local_port.py
  • tests/test_checkpoint_compat.py

Test commands

CPU-only (CUDA_VISIBLE_DEVICES=""), from tests/:

cd tests
PYTHONPATH=<repo>:<repo>/tests CUDA_VISIBLE_DEVICES="" \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py test_qwen2_vl_local_port.py \
  test_lfm3_local_port.py test_checkpoint_compat.py -q -rs -p no:cacheprovider

PYTHONPATH=<repo>:<repo>/tests CUDA_VISIBLE_DEVICES="" \
  /root/venv/bin/python -m pytest \
  test_writer_dynamic_order.py test_save_dispatch.py \
  test_hf_refusal_remedy_4676.py test_bnb_hf_refusal_4664.py \
  test_module_replacement_generation_config_5387.py -q -rs -p no:cacheprovider

Per-PR named nodes:

PYTHONPATH=<repo>:<repo>/tests CUDA_VISIBLE_DEVICES="" \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py::test_awq_export_publishes_definition_dense_vision_tower \
  test_lfm3_local_port.py::test_gptq_save_declares_definition_excluded_gate_for_plain_hf \
  test_checkpoint_compat.py::test_hf_compat_warning_for_defused_dense_gate_up_module \
  test_checkpoint_compat.py::test_defused_dense_gate_up_checkpoint_warns_and_keeps_split_keys \
  -q -rs -p no:cacheprovider

Green evidence (combined tree, HEAD cf7aee0)

4 touched files: 122 passed, 3 skipped in 57.86s
writer-focused set: 50 passed in 7.64s
three PRs' named nodes: 4 passed in 8.09s
ruff check gptqmodel/models/writer.py tests/test_qwen2_5_vl_local_port.py \
  tests/test_qwen2_vl_local_port.py tests/test_lfm3_local_port.py \
  tests/test_checkpoint_compat.py
# All checks passed!

Red evidence (combined writer.py reverted to main, tests kept)

git checkout origin/main -- gptqmodel/models/writer.py, then the four named nodes:

4 failed in 4.51s

# #6230 node: no tower exclusion seeded
E       assert declared
E       assert []

# #6232 node: no explicit inclusion list
E       AssertionError: GPTQ checkpoint omitted the definition-declared dense `self_attn.g_proj`
E       assert 'modules_in_block_to_quantize' in {...}

# #6233 nodes (both): no defused-MLP warning
E       assert len(warnings) == 1
E       assert 0 == 1

The writer.py change was restored immediately after the red run; the worktree is clean.

Skips / unverified

  • test_checkpoint_compat.py skips 3 lm_head quantization tests that need an accelerator.
  • No GPU/real-checkpoint run: the Qwen2.5-VL AWQ, LFM3 GPTQ and tiny Phi-3 defused cases are exercised on CPU-only tiny models. Real Transformers/vLLM/SGLang from_pretrained and CUDA Marlin loads are not covered here.
  • docs/quantization-features.md is Markdown, so ruff check does not lint it; all changed Python files pass.

Rebase verification

@Qubitium Qubitium changed the title fix(writer): HF/vLLM interop for dense towers, excluded linears and defused MLPs (#6192, #6182, #6166) fix(writer): HF/vLLM interop for dense towers, excluded linears and defused MLPs (#6192, #6163, #6166) Nov 29, 2026
Qubitium added a commit that referenced this pull request Nov 29, 2026
Both this PR and the writer-interop PR (#6269) appended a test at the end of
this file, which made the two diffs conflict on the same EOF anchor. Moving
the head-rule test next to the other composite-head coverage keeps the file
readable and removes the overlap; no test content changed.
Qubitium added a commit that referenced this pull request Nov 29, 2026
…p it for AWQ (#6194, #6195) (#6235)

* fix(looper): key implicit lm_head rule for nested engine heads (#6194)

lm_head=True adds an implicit 8-bit/g32 head override keyed by the
definition-owned head name. On a text model that is lm_head, which vLLM
matches directly. A composite wrapper such as Qwen2.5-VL keeps the head at
the Transformers root but vLLM re-homes it under language_model, so the
bare key never matched and vLLM built a 4-bit head before loading the
8-bit tensors.

Emit a prefix-agnostic, end-anchored regex for a root-level head on a
composite model. It still matches the runtime name and now matches the
engine prefix (language_model.lm_head). Plain text models and heads the
definition already qualifies keep their exact name. Apply the same key
form to the requantize endpoint defaults.

Fixes #6194

* test(qwen2_5_vl): drop redundant local json import

Addresses the code-quality bot note on #6235: json is already imported at
module scope, so the function-local import is redundant.

* fix(looper): key the implicit lm_head rule per engine prefix and drop it for AWQ (#6194, #6195)

Two draft PRs changed the same `_loop_impl` lm_head block and could not both
apply. This commit carries both contracts on one branch.

#6194: the implicit `lm_head` dynamic rule used the definition-owned module
name. A composite wrapper keeps the text tower at a nested runtime path while
vLLM/SGLang re-home the head under `language_model`, so a root-level `lm_head`
key never matched. `BaseQModel.dynamic_module_pattern()` now returns the
engine-facing, end-anchored regex for such a model and the bare name otherwise;
`missing_defaults` uses it too.

#6195: AWQ consumers (vLLM, AutoAWQ, Transformers) build every quantized module
from the global `bits`/`group_size` and ignore `dynamic`, so the implicit
8-bit/g32 head produced a checkpoint they cannot read. AWQ now leaves the head
at the base contract via `_implicit_lm_head_dynamic()`; GPTQ keeps the 8-bit
default and explicit user overrides are still honored.

Combined, AWQ emits no implicit head rule at all and GPTQ emits it under the
engine-facing key.

* test(qwen2_5_vl): place the #6194 head-rule test before the AWQ block

Both this PR and the writer-interop PR (#6269) appended a test at the end of
this file, which made the two diffs conflict on the same EOF anchor. Moving
the head-rule test next to the other composite-head coverage keeps the file
readable and removes the overlap; no test content changed.
@Qubitium
Qubitium force-pushed the fix/writer-interop-consolidated branch from cf7aee0 to 90af7b2 Compare November 29, 2026 08:26
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Rebased onto cc10a7a5. Only one conflict: the ..utils.model import block; kept both main's MODALITY and this PR's FUSED_PROJECTION_UNITS. No hunks dropped or adapted. Verified with CUDA_VISIBLE_DEVICES="" on the four changed test files: 124 passed, 3 skipped, 1 failed — the failure is test_checkpoint_compat.py::test_gptq_block_name_loads_through_plain_hf, which fails identically on pristine cc10a7a5 because #6323 now refuses Optimum's shape-blind grouped-kernel selection (upstream Optimum does not forward in_features); it is not caused by this rebase. ruff check passes on all changed Python files.

…efused MLPs (#6192, #6163, #6166)

Rebased onto be14824 so the HF bridge uses the
current shape-safe AUTO fallback; the checkpoint_compat plain-HF load is
green again.
…efix

A definition may rename its keys on save: the Qwen VL port writes the
Transformers source layout (`visual.*`, `model.layers.*`) instead of the
runtime names (`model.visual.*`, `model.language_model.*`). The #6192
regression pinned the runtime prefix, so it failed as soon as a key map
existed even though the checkpoint was correct.

Match the dense vision weight and the packed decoder projection by suffix so
the assertion holds for both layouts, and keep the `modules_to_not_convert`
assertions in runtime spelling: `should_convert_module` is start-anchored
against the live module names, so that list must stay in runtime form.
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Cross-PR note for #6192, fixed here in ea7747afb.

#6374 (fix/6360-qwen-vl-sglang) gives the Qwen VL definitions a
checkpoint_key_for_save, so their checkpoints are written in the Transformers
source layout (visual.*, model.layers.*) instead of the runtime names
(model.visual.*, model.language_model.*). The #6192 regression asserted the
runtime prefix on the saved tensors, so it failed on the combined tree even
though the checkpoint was correct.

Two conclusions, both now encoded in the test:

  1. The tensor assertions must be layout-agnostic — they now match the dense
    vision weight and the packed decoder projection by suffix, so they hold for
    either layout.

  2. modules_to_not_convert must stay in runtime spelling. Transformers'
    should_convert_module is start-anchored against the live module names
    (re.match(rf"(?:{key}){boundary}", full_name) plus a suffix rule), so with
    runtime modules model.visual.* the entry has to be model.visual;
    translating it to the checkpoint spelling would make the exclusion miss and
    quantize the dense tower. I verified that with should_convert_module
    directly:

    declared=['model.visual'] -> model.visual.blocks.0.attn.qkv: convert=False   # skip
    declared=['visual']       -> model.visual.blocks.0.attn.qkv: convert=True    # would quantize
    

    GPTQModel's own loader tolerates either spelling ((?:^|.*\.) prefix), so
    runtime form is the safe one for both consumers.

Combined-tree evidence (main + #6269 + #6374): the whole
test_qwen2_5_vl_local_port.py file is green (21 passed), and on #6269 alone
the file is green too (21 passed), so the fix is layout-independent.

@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 12:39
@Qubitium
Qubitium merged commit 34ffadb into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/writer-interop-consolidated branch November 29, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment