Skip to content

[BUG] transformers load of GPT-QModel-made checkpoints silently ignores quantization_config["backend"] (docs/peft.md's gptq_torch, even marlin on CPU): #4084 bridge never forwards the Optimum backend #4680

Closed

Description

@Qubitium

Found on main @ 12c1273, CPU (x86-64), transformers 5.22.1, optimum (installed in the CUDA venv), PEFT.

What is wrong

docs/peft.md says to pick a trainable kernel through the HF config before training: config.quantization_config["backend"] = "gptq_torch", because "the default inference kernels do not propagate gradients through the quantized layers, so a backward pass will fail". For checkpoints made by GPT-QModel, that setting is silently ignored.

The #4084 HF load bridge replaces GPTQQuantizer.convert_model (gptqmodel/__init__.py:447-460) and calls

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

It never passes backend=self.backend. hf_gptqmodel_prepare_model_for_load has a backend parameter (gptqmodel/utils/hf_load.py:246), but it is always None, so _resolve_backend_for_checkpoint turns it into BACKEND.AUTO. Optimum-owned (third-party) checkpoints still go through original_convert_model, which does honor backend. So the user's backend choice works or not depending on who made the checkpoint.

Repro

Kernel classes after AutoModelForCausalLM.from_pretrained(path, config=cfg, device_map="cpu", dtype=torch.bfloat16) with cfg.quantization_config["backend"] = <backend> (gptqmodel imported), compared with GPTQModel.load(path, backend=<backend>):

GPT-QModel-made Qwen2.5-0.5B-Instruct GPTQ 4-bit g128 (goes through the bridge)
backend None        | HF: TorchCpuAvx512Linear | GPTQModel.load: TorchCpuAvx512Linear
backend gptq_torch  | HF: TorchCpuAvx512Linear | GPTQModel.load: TorchLinear
backend torch_fused | HF: TorchCpuAvx512Linear | GPTQModel.load: TorchFusedLinear
backend marlin      | HF: TorchCpuAvx512Linear | GPTQModel.load: ValueError: Marlin kernel requires CUDA.

Third-party gemma-1.1-2b-it-GPTQ (Optimum path)
backend gptq_torch  | HF: TorchLinear          | GPTQModel.load: TorchLinear
backend marlin      | HF: ValueError: Marlin kernel requires CUDA.

Even an impossible backend (marlin on a CPU-only host) is accepted without a word for the native checkpoint.

Impact

On a CUDA host, AUTO picks Marlin for a 4-bit GPTQ checkpoint (SUPPORTS_TRAINING = False, qlinear/marlin.py:96). Following docs/peft.md for a checkpoint quantized with GPT-QModel therefore gives a model whose kernel is not the trainable one the doc tells you to select. The documented FSDP recipe used hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4, an Optimum-path checkpoint, so it never went through the bridge. The same ignore applies to every inference-side backend choice made through transformers (for example exllama_v2 or torch_fused for determinism or performance).

I could not run the CUDA training failure on this host. The kernel-selection evidence above was gathered on CPU.

Suggested fix

Forward the quantizer's backend: hf_gptqmodel_prepare_model_for_load(model, ..., backend=getattr(self, "backend", None), ...). Add a bridge test that asserts quantization_config["backend"] selects the same kernel class as GPTQModel.load(backend=...) for a native checkpoint, and that an incompatible backend raises.

Tests that should have caught it

tests/test_hf_gptqmodel_load_bridge.py only checks that Optimum's hooks call the bridge, not that the caller's backend reaches make_quant.

Severity

Medium. An explicit user setting is silently dropped, and the documented PEFT training recipe does not do what it says for GPT-QModel-made checkpoints (regression from #4084).

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. The #4084 bridge never forwards the quantizer's backend, so quantization_config["backend"] is always resolved to AUTO for GPT-QModel-made checkpoints. Will forward it and add a bridge test asserting the selected kernel class matches GPTQModel.load(backend=...), plus that an incompatible backend raises.

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