Repository navigation
fix(hf): forward quantization_config["backend"] through the load bridges (#4680) - #4702
Merged
Merged
Conversation
…ges (#4680) Both HF load bridges called `hf_gptqmodel_prepare_model_for_load` without the caller's backend, so `_resolve_backend_for_checkpoint` always saw `None` and resolved AUTO. `docs/peft.md` tells users to set `quantization_config["backend"] = "gptq_torch"` to get a trainable kernel; for a GPT-QModel-made checkpoint that setting was silently dropped and AUTO picked a different kernel (Marlin on CUDA, which does not support training). An impossible choice such as `marlin` on a CPU-only host was accepted without a word. Optimum-owned checkpoints kept honoring it, so behavior depended on who made the checkpoint. Forward `getattr(self, "backend", None)` from both bridges — the GPTQ one (`GPTQQuantizer.convert_model`, #4084) and the AWQ one (`AwqQuantizer._process_model_before_weight_loading`), which had the identical defect. A quantizer without the attribute still forwards `None`. Closes #4680.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
… (#4756) #4702 forwarded `getattr(self, "backend", None)` from both HF load bridges, but only Optimum's GPTQQuantizer has that attribute. transformers' AwqQuantizer keeps the choice on `quantization_config.backend`, so the AWQ bridge always passed None, _resolve_backend_for_checkpoint resolved AUTO, and every explicit AWQ backend (docs/peft.md's torch_awq training recipe, or an impossible marlin on CPU) was silently ignored. Read the quantizer's own backend first, then its quantization_config, in both bridges. The AWQ test built a bare `AwqQuantizer.__new__` and set `.backend` by hand, which a real quantizer never has; it now builds a real AwqQuantizer(AwqConfig(backend=...)), and a new end-to-end test loads a saved GPT-QModel AWQ checkpoint through AutoModelForCausalLM and asserts the installed kernel (torch_awq -> AwqTorchLinear, marlin on CPU -> ValueError).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4680
Root cause
Both HF load bridges called
hf_gptqmodel_prepare_model_for_loadwithout thecaller's backend:
hf_gptqmodel_prepare_model_for_loadhas abackendparameter, but it wasalways
None, so_resolve_backend_for_checkpointresolvedBACKEND.AUTO.docs/peft.mdtells users to setquantization_config["backend"] = "gptq_torch"to get a trainable kernel. For a GPT-QModel-made checkpoint that setting was
silently dropped: on CUDA, AUTO picks Marlin for a 4-bit GPTQ checkpoint, and
Marlin does not support training. An impossible choice (
marlinon a CPU-onlyhost) was accepted without a word. Optimum-owned checkpoints went through
original_convert_model, which does honorbackend— so behavior depended onwho made the checkpoint.
The AWQ bridge (
AwqQuantizer._process_model_before_weight_loading) had theidentical defect. Fixed both rather than leaving half the config key working.
Fix
Forward
getattr(self, "backend", None)from both bridges. A quantizer withoutthe attribute still forwards
None, so nothing changes for callers that neverset it.
Before / after
Kernel class after
from_pretrained(..., device_map="cpu")vsGPTQModel.load(backend=...), native GPT-QModel GPTQ 4-bit g128 checkpoint:AUTOselectsTorchAtenLinearfor this fixture, so the assertionsdiscriminate rather than passing by coincidence.
Tests
tests/test_hf_gptqmodel_load_bridge.py(25 passed):test_bridge_forwards_the_quantizer_backend_to_kernel_selection— end-to-endthrough the wrapper: a quantizer with
backend = "gptq_torch"must yieldTorchLinear, not AUTO'sTorchAtenLinear.test_bridge_raises_for_a_backend_the_device_cannot_run—marlinon CPUraises instead of being replaced by AUTO.
test_awq_bridge_forwards_the_quantizer_backend— the AWQ bridge forwards ittoo.
helper; they now include
"backend": None(a quantizer without the attributeforwards
None).Fail-before, with the source change reverted and the tests kept:
Pass-after:
Scope / limits
not reproduced. The evidence is kernel selection on CPU (the issue's own
evidence level), which is where the setting was being dropped.
docs/peft.mdneeds no edit: it already describes the intended behavior, whichnow holds for native checkpoints too.