Skip to content

[BUG] #4771 incomplete: the AWQ HF load bridge is still import-order dependent; plain AutoModelForCausalLM (docs/peft.md, now 'no import needed') loads dynamic AWQ ckpts silently wrong on CPU (NLL 3.97 -> 7.93), crashes on CUDA #4795

Closed

Description

@Qubitium

Found on main @ d2060d4, RTX 4090 + CPU (x86-64 AVX512), transformers 5.22.1, optimum 2.3.0.

What is wrong

#4771 (fix for #4749) makes the Optimum GPTQ load bridge independent of import order. It retries the install from GptqHfQuantizer's hooks. The AWQ bridge (_patch_transformers_awq_gptqmodel_load_bridge, gptqmodel/__init__.py:657-730) has the same import-order dependency, and #4771 did not change it:

  • In the plain-Transformers flow, gptqmodel is first imported by transformers itself, inside AwqQuantizer._process_model_before_weight_loading → integrations/awq.py::replace_with_awq_linear (from gptqmodel.quantization import METHOD). AwqQuantizer.validate_environment only calls is_gptqmodel_available() (find_spec), which does not import the package.
  • So the patch replaces _process_model_before_weight_loading while the original is already running. The bridge's prepare step never runs for that load. The patched _process_model_after_weight_loading then finds no _gptqmodel_hf_load_context and falls back to the original as well.
  • Result: transformers' own replace_with_awq_linear builds every module with the global bits / group_size. Per-module dynamic overrides are ignored, and a group-size override loads silently wrong on the CPU AUTO kernel.

#4771 also changed docs/peft.md:7 to say: "Loading a native GPTQ checkpoint ... does not require importing gptqmodel first ... No import gptqmodel line is needed in these examples." The training example right below handles both methods (trainable_backends = {"gptq": "gptq_torch", "awq": "torch_awq"}). For AWQ that statement is wrong. hf_compat_warnings (gptqmodel/models/writer.py) has no warning for a dynamic AWQ checkpoint either. The only AWQ warning covers per-expert MoE tensors.

Repro

A GPT-QModel AWQ checkpoint with a per-module group-size override (Qwen2.5-0.5B-Instruct, 16 C4 rows):

m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct",
                   AWQConfig(bits=4, group_size=128, dynamic={r"+:.*layers\.(1|5|9)\..*": {"group_size": 32}}))
m.quantize(CalibrationConfig(dataset=c4_rows)); m.save("awqdyn")

Fresh process, the docs/peft.md flow (no import gptqmodel), compared with import gptqmodel first. NLL is over the same 512 C4 tokens:

import sys, torch
if sys.argv[1] == "import_first":
    import gptqmodel
from transformers import AutoModelForCausalLM
m = AutoModelForCausalLM.from_pretrained("awqdyn", device_map=sys.argv[2], dtype=torch.float16)
q = m.model.layers[1].self_attn.q_proj
print(type(q).__name__, q.group_size, tuple(q.qweight.shape), m(ids, labels=ids).loss.item())
load device layer-1 q_proj NLL
GPTQModel.load cuda AwqMarlinLinear gs=32 3.9650
import gptqmodel first, then AutoModelForCausalLM cuda AwqMarlinLinear gs=32 3.9677
import gptqmodel first, then AutoModelForCausalLM cpu TorchAtenAwqLinear gs=32 3.9678
plain AutoModelForCausalLM (docs/peft.md) cpu TorchCpuAvx512AwqLinear gs=128 7.9344
plain AutoModelForCausalLM (docs/peft.md) cuda raises ValueError: AWQ qzeros shape must be (7, 112), got (28, 112). n/a

On CPU the load report lists only the usual qzeros_format | MISSING rows. The gs=32 scales/qzeros are not reported as MISMATCH, and there is no error or warning, but NLL doubles. The same checkpoint on the GPTQ side (#4749's mixed-bit RTN repro) now loads correctly in the plain flow on both CPU and CUDA (NLL 4.0175, the same as GPTQModel.load). So the gap is AWQ only.

The same missing bridge applies to the AWQ MoE case from #4661: the experts are randomly initialized in the plain flow. hf-interop.md documents that row as "Unchanged", but docs/peft.md now tells AWQ users they don't need the import.

Suggested fix

  • Make the AWQ bridge import-order independent the way fix(load): install the Optimum GPTQ bridge regardless of import order (#4749) #4771 did for GPTQ. replace_with_awq_linear calls hf_select_quant_linear_v2 before it builds any module, and fix(load): install the Optimum GPTQ bridge regardless of import order (#4749) #4771 already added a retry hook at that entry point. From there, or from the patched _process_model_after_weight_loading when it finds no context, detect a GPT-QModel-native AWQ checkpoint with dynamic overrides or per-expert modules. Then either rebuild through hf_gptqmodel_prepare_model_for_load or raise an actionable error. Do not leave the load silently wrong.
  • Until then: limit the docs/peft.md sentence to GPTQ, keep import gptqmodel in the AWQ example, and add a dynamic group-size/bits override to hf_compat_warnings for AWQ.

Test that should have caught it

tests/test_hf_optimum_bridge_import_order.py (added in #4771) covers only a GPTQ/RTN checkpoint. Add the same subprocess test for an AWQ checkpoint with a dynamic group-size override: plain AutoModelForCausalLM.from_pretrained without import gptqmodel, and assert that the per-module group_size and the logits match GPTQModel.load.

Severity

Medium-high. On CPU, a documented load path (docs/peft.md, which #4771 now says needs no import) silently gives wrong logits (NLL 3.97 → 7.93) for dynamic AWQ checkpoints. On CUDA it crashes. AWQ MoE checkpoints load with random experts in the same flow.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    A/B: the AWQ plain-flow result is identical at the pre-#4771 commit (3eb422b3f^): TorchCpuAvx512AwqLinear gs=128, NLL 7.9344. #4771 did not cause the AWQ gap; it fixed only the GPTQ side and changed docs/peft.md so the examples now tell AWQ users they don't need import gptqmodel. GPTQ control, same A/B: plain CPU NLL 16.52 before, 4.0175 after.

    🤖 Generated with Claude Code

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4839

    AWQ HF load bridge still import-order dependent; plain AutoModel ignores dynamic AWQ; worktree /root/work-4795

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