Skip to content

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

Merged
Qubitium merged 4 commits into
mainfrom
fix/6194-issue
Nov 29, 2026
Merged

Qubitium merged 4 commits into
mainfrom
fix/6194-issue

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #6194
Fixes #6195

Problem

lm_head=True adds an implicit 8-bit/g32 dynamic override keyed by the definition-owned head name. On a text model that is lm_head, which vLLM matches directly. On a composite wrapper such as Qwen2.5-VL the Transformers runtime keeps the head at the root (lm_head), but vLLM maps the checkpoint's lm_head. tensors to language_model.lm_head.:

re.match("lm_head", "language_model.lm_head")  # None

vLLM therefore builds a 4-bit head and rejects the checkpoint's 8-bit g32 tensors.

Reproduced on CPU with a tiny Qwen2.5-VL composite (2 layers, hidden 32), GPTQ 4-bit/g32, lm_head=True. At HEAD the saved dynamic is:

{"lm_head": {"bits": 8, "group_size": 32, "sym": true, "desc_act": false, "mse": 2.4}}

Fix

BaseQModel.dynamic_module_pattern() keeps the exact definition-owned name for:

  • plain text models (lm_head, the key vLLM already accepts), and
  • heads the definition already qualifies (language_model.lm_head, thinker.lm_head).

For a root-level head on a composite wrapper (a nested text_config or a declared non-text modality) it emits a prefix-agnostic, end-anchored regex built from the same definition-owned name:

+:(?:.*\.)?lm_head$

This matches both lm_head (GPT-QModel runtime) and language_model.lm_head (vLLM). The same key form is used for the requantize endpoint defaults. The rule's bits/group_size are unchanged.

Also fixes #6195 (consolidated)

This branch now carries both #6194 and #6195. They edited the same _loop_impl lm_head block, so the two draft PRs could not both apply; #6240 is closed in favour of this one.

#6195 covers the value of the implicit rule for AWQ: AWQ consumers (vLLM, AutoAWQ, Transformers) build every quantized module from the global bits/group_size and ignore dynamic, so an 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.

Additional tests (from #6195):

  • tests/test_checkpoint_compat.py::test_awq_implicit_lm_head_uses_the_global_contract
  • tests/test_checkpoint_compat.py::test_awq_explicit_lm_head_override_is_preserved
  • tests/test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloads (extended with GPTQ 8-bit/dynamic assertions, CUDA-gated)

#6195 red evidence (its source change reverted, tests kept)

assert "lm_head" not in dynamic
E AssertionError: assert 'lm_head' not in {'lm_head': {'bits': 8, 'group_size': 32, 'sym': True, 'desc_act': False, ...}}
1 failed

Combined-tree verification

Both contracts together, CPU-only:

cd tests && CUDA_VISIBLE_DEVICES="" \
  PYTHONPATH=/root/openai-audit/issue-6194-merge:/root/openai-audit/issue-6194-merge/tests \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py test_writer_dynamic_order.py test_checkpoint_compat.py -q -rs
55 passed, 3 skipped, 1 warning in 20.40s

The 3 skips are the CUDA-only lm_head tests.

/root/venv/bin/ruff check gptqmodel/looper/module_looper.py gptqmodel/models/base.py \
  tests/test_checkpoint_compat.py tests/test_qwen2_5_vl_local_port.py tests/test_writer_dynamic_order.py
All checks passed!

Tests

  • tests/test_qwen2_5_vl_local_port.py::test_composite_lm_head_dynamic_rule_matches_vllm_prefix (new): quantizes a tiny Qwen2.5-VL composite on CPU, saves, checks both config.json and quantize_config.json, and reloads with GPT-QModel to prove the regex still selects the 8-bit g32 head.
  • tests/test_writer_dynamic_order.py::test_plain_text_model_keeps_bare_dynamic_head_key (new): plain text keeps lm_head.

Red (source reverted, test kept)

cd tests && PYTHONPATH=/root/openai-audit/issue-6194:/root/openai-audit/issue-6194/tests \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py::test_composite_lm_head_dynamic_rule_matches_vllm_prefix -q -rs
...
E AssertionError: config.json: dynamic head rule 'lm_head' does not match vLLM's Qwen2.5-VL prefix `language_model.lm_head`; vLLM builds a 4-bit head and fails to load the 8-bit g32 tensors
E assert None
E  +  where None = <function match at ...>('lm_head', 'language_model.lm_head')
1 failed in 4.96s

Green

cd tests && PYTHONPATH=/root/openai-audit/issue-6194:/root/openai-audit/issue-6194/tests \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py::test_composite_lm_head_dynamic_rule_matches_vllm_prefix \
  test_writer_dynamic_order.py -q -rs
12 passed
cd tests && PYTHONPATH=/root/openai-audit/issue-6194:/root/openai-audit/issue-6194/tests \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_vl_local_port.py qcfg/test_dynamic_config.py test_weight_only_looper.py \
  test_requant_embed_lm_head.py -q -rs
97 passed in 32.05s
cd tests && PYTHONPATH=/root/openai-audit/issue-6194:/root/openai-audit/issue-6194/tests \
  /root/venv/bin/python -m pytest \
  test_qwen2_5_omni_lm_head.py test_exl3_fractional_bits.py \
  test_model_dequant_dynamic_bits.py test_model_dequant_dense.py -q -rs
72 passed, 1 warning in 49.47s
cd tests && CUDA_VISIBLE_DEVICES="" \
  PYTHONPATH=/root/openai-audit/issue-6194:/root/openai-audit/issue-6194/tests \
  /root/venv/bin/python -m pytest test_checkpoint_compat.py -q -rs
22 passed, 3 skipped in 5.50s

The 3 skips are the CUDA-only lm_head tests (lm_head quantization needs an accelerator).

/root/venv/bin/ruff check \
  gptqmodel/models/base.py gptqmodel/looper/module_looper.py \
  tests/test_qwen2_5_vl_local_port.py tests/test_writer_dynamic_order.py
All checks passed!

Unverified

  • vLLM is not installed in the CPU venv, so I did not start a vLLM engine. The new key was checked against vLLM 0.34's matcher semantics (re.match(pattern.removeprefix("+:"), prefix)): it matches language_model.lm_head and does not match lm_head_extra.
  • GPU paths were not run (CPU-only). An unqualified test_checkpoint_compat.py run hit the shared-host mixed-GPU capability guard (cuda:0-3=8.9, cuda:4=12.0), which is unrelated to this change.

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
Addresses the code-quality bot note on #6235: json is already imported at
module scope, so the function-local import is redundant.
… 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.
@Qubitium Qubitium changed the title fix(looper): key implicit lm_head rule for nested engine heads (#6194) fix(looper): key the implicit lm_head rule per engine prefix, and drop it for AWQ (#6194, #6195) 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
Qubitium marked this pull request as ready for review November 29, 2026 04:37
@Qubitium
Qubitium merged commit f70888e into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6194-issue branch November 29, 2026 04:38
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