Skip to content

fix(hf): forward quantization_config["backend"] through the load bridges (#4680) - #4702

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4680-hf-bridge-backend
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4680-hf-bridge-backend

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4680

Root cause

Both HF load bridges called hf_gptqmodel_prepare_model_for_load without the
caller's backend:

context = hf_gptqmodel_prepare_model_for_load(
    model,
    checkpoint_files=kwargs.get("checkpoint_files"),
    device_map=kwargs.get("device_map"),
    dtype=kwargs.get("dtype"),
)

hf_gptqmodel_prepare_model_for_load has a backend parameter, but it was
always None, so _resolve_backend_for_checkpoint resolved BACKEND.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: on CUDA, AUTO picks Marlin for a 4-bit GPTQ checkpoint, and
Marlin does not support training. An impossible choice (marlin on a CPU-only
host) was accepted without a word. Optimum-owned checkpoints went through
original_convert_model, which does honor backend — so behavior depended on
who made the checkpoint.

The AWQ bridge (AwqQuantizer._process_model_before_weight_loading) had the
identical defect. Fixed both rather than leaving half the config key working.

Fix

Forward getattr(self, "backend", None) from both bridges. A quantizer without
the attribute still forwards None, so nothing changes for callers that never
set it.

Before / after

Kernel class after from_pretrained(..., device_map="cpu") vs
GPTQModel.load(backend=...), native GPT-QModel GPTQ 4-bit g128 checkpoint:

=== BEFORE ===
backend None        | HF: TorchAtenLinear | GPTQModel.load: TorchAtenLinear
backend gptq_torch  | HF: TorchAtenLinear | GPTQModel.load: TorchLinear      <-- ignored
backend torch_fused | HF: TorchAtenLinear | GPTQModel.load: TorchFusedLinear <-- ignored
backend marlin      | HF: TorchAtenLinear | GPTQModel.load: ValueError (CPU)  <-- ignored

=== AFTER ===
backend gptq_torch  | HF: TorchLinear       (matches GPTQModel.load)
backend torch_fused | HF: TorchFusedLinear  (matches GPTQModel.load)
backend marlin      | ValueError: Marlin kernel requires CUDA.
backend None        | TorchAtenLinear       (unchanged)

AUTO selects TorchAtenLinear for this fixture, so the assertions
discriminate 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-end
    through the wrapper: a quantizer with backend = "gptq_torch" must yield
    TorchLinear, not AUTO's TorchAtenLinear.
  • test_bridge_raises_for_a_backend_the_device_cannot_run — marlin on CPU
    raises instead of being replaced by AUTO.
  • test_awq_bridge_forwards_the_quantizer_backend — the AWQ bridge forwards it
    too.
  • Two existing tests asserted the exact kwargs dict passed to the prepare
    helper; they now include "backend": None (a quantizer without the attribute
    forwards None).

Fail-before, with the source change reverted and the tests kept:

$ pytest tests/test_hf_gptqmodel_load_bridge.py -q
5 failed, 20 passed

Pass-after:

$ pytest tests/test_hf_gptqmodel_load_bridge.py -q
25 passed

$ ruff check gptqmodel tests docs/eora setup.py
All checks passed!

Scope / limits

  • One-kwarg forwarding plus tests; no change to kernel selection itself.
  • No CUDA host was available, so the training failure the doc warns about was
    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.md needs no edit: it already describes the intended behavior, which
    now holds for native checkpoints too.

…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.
@Qubitium
Qubitium merged commit 04be2e6 into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4680-hf-bridge-backend branch November 17, 2026 10:13
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant