Skip to content

[BUG] Regression from #4706: importing gptqmodel makes every HF-native bitsandbytes load fail (BitsAndBytesConfig(load_in_4bit=True) / any HF bnb checkpoint refused as a 'GPT-QModel BitsAndBytes checkpoint') #4731

Closed

Description

@Qubitium

Found on main @ b225a43, RTX 4090, torch 2.15 + CUDA 13.2, transformers 5.22.1, bitsandbytes 0.50.2.

What is wrong

#4706 (fix for #4664) wraps transformers.quantizers.auto.AutoHfQuantizer.from_config (gptqmodel/__init__.py:~300-313) and raises the GPT-QModel refusal for every config whose quant_method == "bitsandbytes":

if method == "bitsandbytes":
    raise ValueError(refusal_message(method))

transformers' own BitsAndBytesConfig also has quant_method == QuantizationMethod.BITS_AND_BYTES == "bitsandbytes". The plain name is what transformers itself uses, and it writes it to config.json for every HF bnb checkpoint, together with load_in_4bit / load_in_8bit. from_config only adds the _4bit / _8bit suffix after this point (transformers/quantizers/auto.py:210-218). The comment in the PR says "Intercept the plain name only: bitsandbytes_4bit / bitsandbytes_8bit are genuine transformers names". Those suffixed names never reach from_config as quant_method, though, so the guard also refuses every genuine HF bitsandbytes load.

Result: once gptqmodel is imported (including indirectly, e.g. through Optimum's GPTQ path or PEFT's GPT-QModel helpers), plain transformers can no longer load or quantize any bitsandbytes model in that process. That breaks the standard QLoRA flow: from_pretrained(..., quantization_config=BitsAndBytesConfig(load_in_4bit=True)), and reloading any HF-saved bnb checkpoint from the Hub.

Repro

import sys, torch
if sys.argv[1] == "import":
    import gptqmodel
from transformers import AutoModelForCausalLM, BitsAndBytesConfig

for kind in ("4bit", "8bit"):
    q = BitsAndBytesConfig(load_in_4bit=(kind == "4bit"), load_in_8bit=(kind == "8bit"))
    try:
        m = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct", quantization_config=q,
                                                 device_map="cuda:0", dtype=torch.bfloat16)
        print(kind, "on-the-fly HF bnb load OK:", type(m.model.layers[0].self_attn.q_proj).__name__)
        if sys.argv[1] == "noimport":
            m.save_pretrained(f"hfbnb_{kind}")          # a normal HF bnb checkpoint
    except Exception as e:
        print(kind, "on-the-fly HF bnb load FAILED:", type(e).__name__, str(e)[:160])
    if sys.argv[1] == "import":
        try:
            AutoModelForCausalLM.from_pretrained(f"hfbnb_{kind}", device_map="cuda:0")
            print(kind, "reload of HF-saved bnb checkpoint OK")
        except Exception as e:
            print(kind, "reload of HF-saved bnb checkpoint FAILED:", type(e).__name__, str(e)[:160])

python repro.py noimport, then python repro.py import, on main @ b225a43:

4bit on-the-fly HF bnb load OK: Linear4bit                      # without gptqmodel
8bit on-the-fly HF bnb load OK: Linear8bitLt
---
4bit on-the-fly HF bnb load FAILED: ValueError GPT-QModel BitsAndBytes checkpoints cannot be loaded by `transformers`; load them with `GPTQModel.load`. (quant_method: <QuantizationMethod.BITS_AND_BYTES: 'bitsandbytes'>)
4bit reload of HF-saved bnb checkpoint FAILED: ValueError GPT-QModel BitsAndBytes checkpoints cannot be loaded by `transformers`; ...
8bit on-the-fly HF bnb load FAILED: ValueError GPT-QModel BitsAndBytes checkpoints cannot be loaded by `transformers`; ...
8bit reload of HF-saved bnb checkpoint FAILED: ValueError GPT-QModel BitsAndBytes checkpoints cannot be loaded by `transformers`; ...

The HF-saved checkpoint's config.json has "quant_method": "bitsandbytes", "load_in_4bit": true.

The same import run at the pre-fix commit 12c1273 loads all four (Linear4bit / Linear8bitLt, reload OK). This is a regression from #4706.

Suggested fix

Refuse only GPT-QModel's layout. After AutoQuantizationConfig.from_dict, a genuine HF bnb config is an instance of transformers.BitsAndBytesConfig. A GPT-QModel checkpoint (plain name, no load_in_* flag) resolves to the registered GPTQModelRefusingQuantizationConfig. So the guard should be:

if method == "bitsandbytes" and not isinstance(quantization_config, transformers.BitsAndBytesConfig):
    raise ValueError(refusal_message(method))

For the dict form, refuse only when neither load_in_4bit nor load_in_8bit is set.

Test that should have caught it

tests/test_bnb_hf_refusal_4664.py only checks that GPT-QModel layouts are refused. Add the positive case: with gptqmodel imported, AutoHfQuantizer.from_config(transformers.BitsAndBytesConfig(load_in_4bit=True)) and from_config({"quant_method": "bitsandbytes", "load_in_8bit": True}) must return Bnb4BitHfQuantizer / Bnb8BitHfQuantizer. Both are CPU-only checks; no GPU is needed.

Severity

High. Importing gptqmodel makes every transformers bitsandbytes load (QLoRA, any bnb checkpoint on the Hub) fail in that process, with an error that blames GPT-QModel checkpoints.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4750

    Restricting the #4706 bnb refusal to GPT-QModel layouts so HF BitsAndBytesConfig loads work after import

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