Repository navigation
Description
Found on main @ b225a43, CPU (x86-64, AVX512) + transformers 5.22.1, peft 0.21.2, optimum 2.3.0.
What is wrong
#4702 (fix for #4680) forwards the caller's backend from both HF load bridges with backend=getattr(self, "backend", None) (gptqmodel/__init__.py:487 and :562). That only works for the GPTQ bridge. There, self is Optimum's GPTQQuantizer, which does have a .backend.
In the AWQ bridge (_prepare_with_gptqmodel_bridge, gptqmodel/__init__.py:555-565), self is transformers' AwqQuantizer, an HfQuantizer. It has no backend attribute. The backend lives on self.quantization_config.backend (AwqConfig.backend, an AwqBackend such as "torch_awq"). So getattr(self, "backend", None) is always None, _resolve_backend_for_checkpoint resolves AUTO, and the user's quantization_config["backend"] is still dropped silently for every GPT-QModel-made AWQ checkpoint. This is the #4680 defect, still present on the AWQ side.
docs/peft.md tells users to set config.quantization_config["backend"] = "torch_awq" for AWQ LoRA training ("The default inference kernels do not propagate gradients through the quantized layers, so a backward pass will fail"). That setting has no effect: you get whatever AUTO selects. A deliberately impossible choice (marlin on a CPU-only host) is also accepted without a word, while the GPTQ bridge correctly raises.
The regression test tests/test_hf_gptqmodel_load_bridge.py::test_awq_bridge_forwards_the_quantizer_backend (line 788-789) builds AwqQuantizer.__new__(AwqQuantizer) and then sets quantizer.backend = "awq_torch" by hand. A real AwqQuantizer never has that attribute, so the test passes against code that cannot work.
Repro (CPU only)
Make a GPT-QModel AWQ checkpoint with the docs/quantization-guide.md recipe (AWQConfig(bits=4, group_size=128, sym=False), Qwen2.5-0.5B-Instruct, 16 C4 rows) and a GPTQ checkpoint (RTNConfig(bits=4, group_size=128)) as a control. Then:
import sys, torch
import gptqmodel # noqa: F401
from transformers import AutoConfig, AutoModelForCausalLM
path, be = sys.argv[1], sys.argv[2]
config = AutoConfig.from_pretrained(path)
config.quantization_config["backend"] = be
try:
m = AutoModelForCausalLM.from_pretrained(path, config=config, device_map="cpu", dtype=torch.float16)
print(path, be, "->", type(m.model.layers[0].self_attn.q_proj).__name__)
except Exception as e:
print(path, be, "-> raised", type(e).__name__, str(e)[:150])Output:
awq-ckpt torch_awq -> TorchAtenAwqLinear # expected AwqTorchLinear (BACKEND.AWQ_TORCH)
awq-ckpt marlin -> TorchAtenAwqLinear # expected ValueError (Marlin requires CUDA)
gptq-ckpt gptq_torch -> TorchLinear # GPTQ bridge honours it
gptq-ckpt marlin -> raised ValueError Marlin kernel requires CUDA.
A call stack taken while TorchAtenAwqLinear.__init__ runs shows the path: AwqQuantizer.preprocess_model -> gptqmodel/__init__.py:555 _prepare_with_gptqmodel_bridge -> hf_load.py:340 make_quant(backend=AUTO). The selector itself is correct when it receives the backend: hf_select_quant_linear_v2(..., backend="torch_awq", quant_method=METHOD.AWQ) returns AwqTorchLinear for every device_map.
On CPU and on ROCm (AUTO picks AwqGEMMTritonLinear), the AUTO kernels fall back to a differentiable path, and input gradients match AWQ_TORCH exactly. So the effect there is "wrong kernel, silently". On CUDA, AUTO picks Marlin/GEMM, which is the case the doc warns will not train. I have not measured that on this box.
Suggested fix
In the AWQ bridge, read the config's backend:
backend=getattr(getattr(self, "quantization_config", None), "backend", None). Do the same in the GPTQ bridge as a fallback if Optimum ever drops .backend. Normalize AwqBackend.AUTO / "auto_trainable" the way the GPTQ path does.
Test that should have caught it
test_awq_bridge_forwards_the_quantizer_backend should build a real AwqQuantizer(AwqConfig(..., backend="torch_awq")), or better, run AutoModelForCausalLM.from_pretrained on a tiny GPT-QModel AWQ checkpoint, and assert the installed kernel class.
Severity
Medium. A documented training recipe (docs/peft.md) silently loads a different kernel, an explicit invalid backend is accepted, and the fix PR's claim ("the AWQ one ... had the identical defect", now fixed) does not hold.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4756
AWQ HF load bridge ignores quantization_config['backend']
fix(load): forward the AWQ bridge's quantization_config backend (#4729)…