Skip to content

[BUG] BitsAndBytes checkpoints silently load as garbage in plain transformers (8-bit: nll 1.67 -> 15.57) even with gptqmodel imported: quant_method "bitsandbytes" is unknown to transformers 5 and missing from REFUSED_HF_QUANT_METHODS #4664

Closed

Description

@Qubitium

Found on main @ 12c1273, CPU (x86-64), transformers 5.22.1, bitsandbytes 0.50.2.

What is wrong

GPT-QModel BitsAndBytes checkpoints set quantization_config.quant_method = "bitsandbytes" with no load_in_4bit / load_in_8bit keys. Transformers 5.x has no quantizer registered under the plain name bitsandbytes. Its registry keys are bitsandbytes_4bit / bitsandbytes_8bit, and AutoQuantizationConfig.from_dict only adds the suffix when load_in_4bit / load_in_8bit is present (transformers/quantizers/auto.py:164-166). So AutoModelForCausalLM.from_pretrained warns Unknown quantization type, got bitsandbytes ... we will skip the quantization and loads the packed tensors into plain nn.Linear:

  • 8-bit: the int8 weight is cast into a bf16 nn.Linear, weight_scb is ignored as UNEXPECTED, and the model returns garbage with no error.
  • 4-bit: the load fails with a generic size-mismatch RuntimeError that does not point to GPTQModel.load.

This happens even when gptqmodel is imported. _patch_transformers_refusing_quantizers (gptqmodel/__init__.py:283-288) only registers the names in REFUSED_HF_QUANT_METHODS (gptqmodel/_quant_methods.py:22), and bitsandbytes is not in that list. docs/hf-interop.md:179-181 assumes that transformers already owns bitsandbytes: "setdefault keeps any quantizer transformers already owns (gptq, awq, fp8, bitsandbytes, ...)". That is not true in transformers 5.22. hf_compat_warnings (gptqmodel/models/writer.py:292) also emits nothing for BnB at save time. docs/support-matrix.md lists BitsAndBytes as unsupported in Transformers, so loading it there should fail closed, as the other GPT-QModel-only layouts do since #4053/#4099. Today it silently returns garbage.

The checkpoint layout is also not HF bnb's: GPT-QModel writes weight_scb, weight_absmax (U8), weight_quant_map, weight_nested_* and weight_quant_state. So adding load_in_8bit is not a fix on its own.

Repro

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import BitsAndBytesConfig
from transformers import AutoModelForCausalLM, AutoTokenizer

src = "Qwen/Qwen2.5-0.5B-Instruct"
out = "qwen05_bnb8"
m = GPTQModel.load(src, BitsAndBytesConfig(bits=8), dtype=torch.bfloat16, device="cpu")
m.quantize(None); m.save(out); del m

tok = AutoTokenizer.from_pretrained(out)
ids = tok("The capital of France is Paris. The capital of Germany is Berlin. The capital of Italy is", return_tensors="pt").input_ids
nll = lambda lo: torch.nn.functional.cross_entropy(lo[0, :-1].float(), ids[0, 1:]).item()

g = GPTQModel.load(out, device="cpu", dtype=torch.bfloat16)
a = g.model(ids).logits
h = AutoModelForCausalLM.from_pretrained(out, dtype=torch.bfloat16, device_map="cpu")   # gptqmodel already imported
b = h(ids).logits
print(nll(a), tok.decode(a[0, -1].argmax()))
print(nll(b), tok.decode(b[0, -1].argmax()), type(h.model.layers[0].self_attn.q_proj).__name__)

Output:

[transformers] Unknown quantization type, got bitsandbytes - supported types are: ['awq', 'bitsandbytes_4bit', 'bitsandbytes_8bit', ..., 'gptqmodel_gguf', 'exl3', 'macaq', 'paroquant', 'qqq', 'nf12', 'tt-blockfloat']. Hence, we will skip the quantization.
model.layers.{0...23}.self_attn.q_proj.weight_scb | UNEXPECTED   (all 7 projections)
GPTQModel.load : nll 1.668  next ' Rome'
transformers   : nll 15.567 next ' erfolgre'  q_proj: Linear (bf16)

The full-text comparison on the same 8-bit checkpoint gave nll 2.918 (GPTQModel) vs 16.515 (HF), max logit diff 33.8, and argmax agreement 0%.
With BitsAndBytesConfig(bits=4), HF raises RuntimeError: You set ignore_mismatched_sizes to False, thus raising an error. That error does not say the layout is GPT-QModel-only.

Suggested fix

  • Add "bitsandbytes": "BitsAndBytes" to REFUSED_HF_QUANT_METHODS. setdefault will register it, because transformers has no bitsandbytes key. The refusing quantizer then raises an actionable ValueError for both 4-bit and 8-bit, and hf_compat_warnings labels the checkpoint at save time.
  • Alternatively, publish a non-colliding name such as gptqmodel_bitsandbytes (same approach as gptqmodel_gguf), and keep reading the old name in GPTQModel.load.
  • Fix the bitsandbytes claim in docs/hf-interop.md.

Tests that should have caught it

tests/test_checkpoint_interop_4053.py::test_hf_from_pretrained_refuses_every_gptqmodel_only_method and tests/test_checkpoint_compat.py::test_every_gptqmodel_only_method_registers_a_refusing_quantizer iterate only over the table. Neither checks that every METHOD GPT-QModel can save is either readable by transformers or refused.

Severity

High: silent garbage from plain transformers for the 8-bit format, with gptqmodel imported. This is the failure class the refusal table was added to close.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    More data on the same assumption in docs/hf-interop.md ("setdefault keeps any quantizer transformers already owns (gptq, awq, fp8, bitsandbytes, ...)"), this time for FP8. Found on main @ 12c1273.

    The default FP8Config() (weight_scale_method="row") writes quant_method: "fp8" with a per-row weight_scale_inv of shape [out_features]. Transformers 5.22 routes fp8 to its own FineGrainedFP8HfQuantizer, which cannot read that layout:

    • CPU (device_map="cpu", gptqmodel imported). Qwen2.5-0.5B-Instruct FP8Config() checkpoint: transformers spends about 17 minutes in Fp8Dequantize (290 tensors) and then fails with a shape error that never mentions GPT-QModel:
      model.layers.{0...23}.mlp.down_proj.weight | CONVERSION |
      RuntimeError: shape '[896, 4864]' is invalid for input of size 3904897024
      Error: Fp8Dequantize on tensors destined for model.layers.23.mlp.down_proj.weight. Ckpt contains: 2
      RuntimeError: We encountered some issues during automatic conversion of the weights.
      
    • GPU (ROCm): ImportError: finegrained-fp8 kernel unavailable: kernels is either not installed .... This is a different misleading hint: installing kernels would not make the row-scale layout readable.

    For the same checkpoint, GPTQModel.load gives nll 2.900 on the same text.

    FP8 is not silent like BnB 8-bit, but it has the same root cause: the refusal table assumes that a name transformers registers implies a layout it can read. Only the block scale method matches HF's FineGrainedFP8 layout. A fix could publish row/tensor-scale FP8 under a non-colliding name (as gptqmodel_gguf does), or register a refusing wrapper that delegates to HF only when weight_block_size is set. Either way, hf_compat_warnings should label row/tensor FP8 checkpoints at save time.

    🤖 Generated with Claude Code

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Taking this. bitsandbytes will join the refused-HF table (transformers 5 has no plain bitsandbytes quantizer key, so the refusing quantizer gets registered and fails closed with the GPTQModel-only message), the save-time warning will label it, and the hf-interop claim that transformers owns the name gets corrected. Regression: the refused-method table must cover every METHOD GPT-QModel can save.

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