Repository navigation
Description
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
weightis cast into a bf16nn.Linear,weight_scbis ignored as UNEXPECTED, and the model returns garbage with no error. - 4-bit: the load fails with a generic size-mismatch
RuntimeErrorthat does not point toGPTQModel.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"toREFUSED_HF_QUANT_METHODS.setdefaultwill register it, because transformers has nobitsandbyteskey. The refusing quantizer then raises an actionableValueErrorfor both 4-bit and 8-bit, andhf_compat_warningslabels the checkpoint at save time. - Alternatively, publish a non-colliding name such as
gptqmodel_bitsandbytes(same approach asgptqmodel_gguf), and keep reading the old name inGPTQModel.load. - Fix the
bitsandbytesclaim indocs/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
Qubitium commentedon Nov 17, 2026
More data on the same assumption in
docs/hf-interop.md("setdefaultkeeps any quantizer transformers already owns (gptq,awq,fp8,bitsandbytes, ...)"), this time for FP8. Found onmain@ 12c1273.The default
FP8Config()(weight_scale_method="row") writesquant_method: "fp8"with a per-rowweight_scale_invof shape[out_features]. Transformers 5.22 routesfp8to its ownFineGrainedFP8HfQuantizer, which cannot read that layout:device_map="cpu",gptqmodelimported). Qwen2.5-0.5B-InstructFP8Config()checkpoint: transformers spends about 17 minutes inFp8Dequantize(290 tensors) and then fails with a shape error that never mentions GPT-QModel:ImportError: finegrained-fp8 kernel unavailable: kernels is either not installed .... This is a different misleading hint: installingkernelswould not make the row-scale layout readable.For the same checkpoint,
GPTQModel.loadgives 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
blockscale method matches HF's FineGrainedFP8 layout. A fix could publish row/tensor-scale FP8 under a non-colliding name (asgptqmodel_ggufdoes), or register a refusing wrapper that delegates to HF only whenweight_block_sizeis set. Either way,hf_compat_warningsshould label row/tensor FP8 checkpoints at save time.🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Taking this.
bitsandbyteswill join the refused-HF table (transformers 5 has no plainbitsandbytesquantizer key, so the refusing quantizer gets registered and fails closed with the GPTQModel-only message), the save-time warning will label it, and thehf-interopclaim that transformers owns the name gets corrected. Regression: the refused-method table must cover every METHOD GPT-QModel can save.fix(hf): refuse GPT-QModel BitsAndBytes checkpoints in plain transfor…