Repository navigation
Description
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,
gptqmodelis first imported by transformers itself, insideAwqQuantizer._process_model_before_weight_loading→integrations/awq.py::replace_with_awq_linear(from gptqmodel.quantization import METHOD).AwqQuantizer.validate_environmentonly callsis_gptqmodel_available()(find_spec), which does not import the package. - So the patch replaces
_process_model_before_weight_loadingwhile the original is already running. The bridge's prepare step never runs for that load. The patched_process_model_after_weight_loadingthen finds no_gptqmodel_hf_load_contextand falls back to the original as well. - Result: transformers' own
replace_with_awq_linearbuilds every module with the globalbits/group_size. Per-moduledynamicoverrides 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_linearcallshf_select_quant_linear_v2before 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_loadingwhen it finds no context, detect a GPT-QModel-native AWQ checkpoint withdynamicoverrides or per-expert modules. Then either rebuild throughhf_gptqmodel_prepare_model_for_loador raise an actionable error. Do not leave the load silently wrong. - Until then: limit the docs/peft.md sentence to GPTQ, keep
import gptqmodelin the AWQ example, and add adynamicgroup-size/bits override tohf_compat_warningsfor 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
Qubitium commentedon Nov 17, 2026
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 needimport gptqmodel. GPTQ control, same A/B: plain CPU NLL 16.52 before, 4.0175 after.🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4839
AWQ HF load bridge still import-order dependent; plain AutoModel ignores dynamic AWQ; worktree /root/work-4795
fix(hf): install and repair the AWQ load bridge independent of import…