Skip to content

fix(hf): refuse GPT-QModel BitsAndBytes checkpoints in plain transformers (#4664) - #4706

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4664-bnb-refused
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4664-bnb-refused

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4664. Transformers 5 registers only bitsandbytes_4bit/bitsandbytes_8bit and picks one from load_in_4bit/load_in_8bit. GPT-QModel writes quant_method: "bitsandbytes" with neither flag, so AutoModelForCausalLM.from_pretrained warned Unknown quantization type and loaded the int8 codes into a bf16 nn.Linear: nll 1.67 -> 15.57, argmax agreement 0%, no error. The 4-bit layout failed later with a generic size-mismatch RuntimeError.

before after
plain HF, 8-bit checkpoint warning + garbage logits ValueError naming GPTQModel.load
plain HF, 4-bit checkpoint generic size-mismatch RuntimeError same actionable ValueError
save-time warning none hf_compat_warnings names bitsandbytes

Changes

  1. gptqmodel/_quant_methods.py: bitsandbytes joins REFUSED_HF_QUANT_METHODS, REFUSED_HF_QUANT_METHOD_REMEDIES (`GPTQModel.load`), and REFUSED_HF_QUANT_METHOD_SUPPORT_ROWS (BitsAndBytes, which docs/support-matrix.md already marks ✅ / Transformers ✗ / vLLM ✗).
  2. gptqmodel/__init__.py: transformers special-cases the plain bitsandbytes name in AutoHfQuantizer.from_config before the mapping lookup — it demands an instance of its own BitsAndBytesConfig — so the registered refusing quantizer never ran and the error stayed generic. The patch intercepts the plain name only; bitsandbytes_4bit/bitsandbytes_8bit are genuine transformers names and keep loading real HF bnb checkpoints.
  3. gptqmodel/utils/hf_refusing_quantizer.py: the refusal text moved into refusal_message() so the mapping path and the guarded path emit the same actionable error.
  4. docs/hf-interop.md: drop the claim that transformers owns bitsandbytes, and add it to the published-name list.
  5. tests/test_checkpoint_interop_4053.py: bitsandbytes joins the from-pretrained refusal parametrization.

Tests

tests/test_bnb_hf_refusal_4664.py (new, 7 tests):

  • table entries (label, remedy, support row) and the refusing-quantizer registration;
  • the actionable message for a bare config;
  • AutoModelForCausalLM.from_pretrained raises for both a 4-bit and an 8-bit checkpoint;
  • hf_compat_warnings labels a BnB save;
  • coverage contract: every METHOD GPT-QModel can save is either readable by transformers or in the refusal table (this is the test the issue asked for; it fails on main because bitsandbytes was in neither).

Pre-fix on unmodified main: 6 of 7 fail. Post-fix: 7 passed.
Adjacent suites test_checkpoint_compat, test_checkpoint_interop_4053, test_hf_refusal_remedy_4676: 85 passed, 5 skipped. ruff check clean.

Note

load_in_4bit/load_in_8bit are never written by GPT-QModel's BitsAndBytesConfig, so no checkpoint of ours takes transformers' _4bit/_8bit dispatch path.

Resolves #4664.

…mers (#4664)

Transformers 5 registers only `bitsandbytes_4bit`/`bitsandbytes_8bit` and
picks one from `load_in_4bit`/`load_in_8bit`. GPT-QModel writes
`quant_method: "bitsandbytes"` with neither flag, so `AutoModelForCausalLM`
warned `Unknown quantization type` and loaded the int8 codes into a bf16
`nn.Linear` (nll 1.67 -> 15.57) with no error.

- Add `bitsandbytes` to `REFUSED_HF_QUANT_METHODS`, its remedy, and its
  support-matrix row, so save-time `hf_compat_warnings` labels the checkpoint.
- transformers special-cases the plain `bitsandbytes` name in
  `AutoHfQuantizer.from_config` *before* the mapping lookup, so the registered
  refusing quantizer never runs. Wrap that method for the plain name only:
  `bitsandbytes_4bit`/`bitsandbytes_8bit` are genuine transformers names and
  must keep loading real HF bnb checkpoints.
- Move the refusal text into `refusal_message()` so both paths agree.
- Fix the `docs/hf-interop.md` claim that transformers owns `bitsandbytes`.

Tests: `tests/test_bnb_hf_refusal_4664.py` (7 tests; 6 fail on unmodified
main) covers the table entries, the registration, the actionable message for
both 4- and 8-bit checkpoints, the save warning, and a contract test that
every saveable method is either HF-readable or refused. Adjacent suites
(`test_checkpoint_compat`, `test_checkpoint_interop_4053`,
`test_hf_refusal_remedy_4676`) -> 85 passed, 5 skipped.
@Qubitium
Qubitium merged commit 5e438b7 into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4664-bnb-refused branch November 17, 2026 10:21
Qubitium added a commit that referenced this pull request Nov 17, 2026
transformers' own `BitsAndBytesConfig` reports `quant_method == "bitsandbytes"`,
and `AutoHfQuantizer.from_config` only appends the `_4bit`/`_8bit` suffix after
the point where #4706 intercepted that name. Raising for every occurrence
therefore refused every genuine HF bnb load in a process that imported
GPT-QModel: `from_pretrained(..., quantization_config=BitsAndBytesConfig(...))`
(QLoRA) and reloading any Hub bnb checkpoint both failed with "GPT-QModel
BitsAndBytes checkpoints cannot be loaded by transformers".

The guard now refuses only GPT-QModel's layout:
- a dict is GPT-QModel's when it carries neither `load_in_4bit` nor
  `load_in_8bit` (`AutoQuantizationConfig.from_dict` maps a dict with either
  flag to a real `BitsAndBytesConfig` through `bitsandbytes_4bit`/`_8bit`);
- an object is GPT-QModel's when it is not a `transformers.BitsAndBytesConfig`.

GPT-QModel's own bnb layouts (`bits: 4` and `bits: 8`, no `load_in_*`) are still
refused with the actionable message in both the object and dict forms.

Tests: tests/test_bnb_hf_refusal_4664.py gains the positive HF cases (4-bit and
8-bit objects, 4-bit and 8-bit saved config dicts) and the negative
GPT-QModel-layout cases for both bit widths. The three positive cases fail on the
parent commit (the refusal fires) and pass here: 12 passed. Related suites:
test_hf_refusal_remedy_4676.py and test_checkpoint_compat.py -> 66 passed, 1
failed; the failure is `test_untied_lm_head_quantizes_and_reloads`, which fails
identically on pristine origin/main from the Marlin JIT build (CUDA_HOME unset).
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