Skip to content

[BUG] transformers 5.23: plain from_pretrained of GPT-QModel AWQ checkpoints with dynamic per-module group_size crashes (size mismatch) - 5.23 no longer skips the shape check for pre-quantized params, so the #4795/#4907 late-import repair never runs #5322

Closed

Description

@Qubitium

Found on main @ c03416c, RTX 4090 host. The CUDA venv has transformers 5.23.0; the ROCm venv has 5.22.1 and works. requirements.txt allows transformers>=5.22.2.

What is wrong

The supported path in docs/peft.md loads a GPT-QModel AWQ checkpoint with plain AutoModelForCausalLM.from_pretrained, without importing gptqmodel first. On transformers 5.23 that load crashes whenever the checkpoint has dynamic per-module overrides:

model.layers.1.self_attn.q_proj.qzeros | MISMATCH | Reinit due to size mismatch - ckpt: torch.Size([4, 16]) vs model:torch.Size([1, 16])
model.layers.1.self_attn.q_proj.scales | MISMATCH | Reinit due to size mismatch - ckpt: torch.Size([4, 128]) vs model:torch.Size([1, 128])
...
RuntimeError: You set `ignore_mismatched_sizes` to `False`, thus raising an error. For details look at the above report!

Root cause: in this path, transformers.integrations.awq.replace_with_awq_linear imports gptqmodel from inside the load. That is too late for the AWQ bridge's _process_model_before_weight_loading. Transformers therefore builds every module from the global group_size. GPT-QModel then relies on _post_init_with_gptqmodel_bridge → hf_gptqmodel_repair_awq_load (gptqmodel/__init__.py, #4795/#4907) to rebuild the modules from the tensors that were actually loaded.

transformers 5.23 changed core_model_loading.py. A shape mismatch used to be ignored whenever any hf_quantizer was active:

- if ref is not None and param_value.shape != expected_shape and hf_quantizer is None:
+ if (ref is not None and param_value.shape != expected_shape
+     and (hf_quantizer is None or not hf_quantizer.param_needs_quantization(model, target_name))):

For a pre-quantized checkpoint, param_needs_quantization is False. So the larger per-module qzeros/scales are now recorded as mismatched keys, and log_state_dict_report raises in _finalize_model_loading. That happens before postprocess_model, so the repair hook never runs.

Repro (fixture from tests/test_hf_awq_bridge_import_order_4795.py: 3-layer AWQ g128 with dynamic={"+:.*layers\.1\..*": {"group_size": 32}})

# fresh interpreter, gptqmodel NOT imported first (docs/peft.md flow)
import torch
from transformers import AutoModelForCausalLM
m = AutoModelForCausalLM.from_pretrained(ckpt, device_map="cpu", dtype=torch.float16)
transformers plain load import gptqmodel first
5.22.1 OK, TorchAtenAwqLinear group_size 32, qzeros (4, 16) OK
5.23.0 RuntimeError (size mismatch) OK, TorchAtenAwqLinear group_size 32, qzeros (4, 16)

These existing tests are red on any host with transformers 5.23, and pass on 5.22 (verified with the r20 baseline code 7b8f12785, so this is not a GPT-QModel regression):

  • tests/test_hf_awq_bridge_import_order_4795.py::test_plain_transformers_load_honors_dynamic_awq_on_{cpu,cuda}
  • tests/test_hf_awq_repair_train_mode_4907.py (all 4 nodes error in the fixture's plain load)

Suggested fix

Make the late-import path size modules correctly before weights load on 5.23. Options:

  • have the transformers-side import hook (replace_with_awq_linear → import gptqmodel) install the bridge and apply hf_gptqmodel_prepare_model_for_load to the model being built; or
  • override AwqQuantizer.param_needs_quantization / the mismatch path for GPT-QModel checkpoints with dynamic, so the repair still sees the checkpoint tensors.

If neither is done, cap transformers<5.23 until it is.

The GPTQ bridge may have the same exposure for dynamic GPTQ checkpoints. It was not checked here.

Severity: high for HF/PEFT users on the newest transformers. Every GPT-QModel AWQ checkpoint with per-module overrides fails to load through the documented plain-transformers path.

🤖 Generated with Claude Code

Activity

  1. ZX-ModelCloud commented on Nov 19, 2026

    @ZX-ModelCloud
    Collaborator

    Agent claim: agent-0581103633c2 is working on this issue now.

    Started 2026-11-19T01:30:54Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    Reproducing the transformers 5.23 plain from_pretrained AWQ dynamic group_size size mismatch

  2. added a commit that references this issue on Nov 19, 2026
    9447d93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions