Skip to content

fix(init): refuse only GPT-QModel's bitsandbytes layout (#4731) - #4750

Merged
Qubitium merged 2 commits into
mainfrom
fix/bnb-guard-4731
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/bnb-guard-4731

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

_patch_transformers_refusing_quantizers refused every config whose quant_method == "bitsandbytes". transformers' own BitsAndBytesConfig carries the same plain name, so importing gptqmodel broke every genuine HF bnb load in that process — on-the-fly BitsAndBytesConfig(load_in_4bit=True) and reloading any HF-saved bnb checkpoint — with an error that blamed GPT-QModel checkpoints.

Fixes #4731 (regression from #4706).

Fix

Refuse only GPT-QModel's layout, via a new _is_gptqmodel_bitsandbytes_layout():

  • dict → GPT-QModel's only when neither load_in_4bit nor load_in_8bit is set. AutoQuantizationConfig.from_dict maps a flagged dict to a real HF BitsAndBytesConfig through the bitsandbytes_4bit/bitsandbytes_8bit names.
  • object → GPT-QModel's when it is not a transformers.BitsAndBytesConfig.

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

Evidence

  • Red on parent (source change stashed, tests kept): 3 failed — test_hf_bitsandbytes_config_is_not_refused, test_hf_saved_bitsandbytes_config_dict_is_not_refused[4], [8] — all raised the GPT-QModel refusal. 9 passed.
  • Green: tests/test_bnb_hf_refusal_4664.py → 12 passed. test_hf_refusal_remedy_4676.py + test_bnb_hf_refusal_4664.py → 48 passed.
  • Repro: object 4/8-bit and dict 4/8-bit now return Bnb4BitHfQuantizer/Bnb8BitHfQuantizer; GPT-QModel dict and object still raise the actionable ValueError.
  • ruff check gptqmodel tests clean.

Residual: test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloads fails identically on pristine origin/main (Marlin JIT, CUDA_HOME unset).

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