Repository navigation
fix(hf): refuse GPT-QModel BitsAndBytes checkpoints in plain transformers (#4664) - #4706
Merged
Merged
Conversation
…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.
This was referenced Nov 17, 2026
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4664. Transformers 5 registers only
bitsandbytes_4bit/bitsandbytes_8bitand picks one fromload_in_4bit/load_in_8bit. GPT-QModel writesquant_method: "bitsandbytes"with neither flag, soAutoModelForCausalLM.from_pretrainedwarnedUnknown quantization typeand loaded the int8 codes into a bf16nn.Linear: nll 1.67 -> 15.57, argmax agreement 0%, no error. The 4-bit layout failed later with a generic size-mismatchRuntimeError.ValueErrornamingGPTQModel.loadRuntimeErrorValueErrorhf_compat_warningsnamesbitsandbytesChanges
gptqmodel/_quant_methods.py:bitsandbytesjoinsREFUSED_HF_QUANT_METHODS,REFUSED_HF_QUANT_METHOD_REMEDIES(`GPTQModel.load`), andREFUSED_HF_QUANT_METHOD_SUPPORT_ROWS(BitsAndBytes, whichdocs/support-matrix.mdalready marks ✅ / Transformers ✗ / vLLM ✗).gptqmodel/__init__.py: transformers special-cases the plainbitsandbytesname inAutoHfQuantizer.from_configbefore the mapping lookup — it demands an instance of its ownBitsAndBytesConfig— so the registered refusing quantizer never ran and the error stayed generic. The patch intercepts the plain name only;bitsandbytes_4bit/bitsandbytes_8bitare genuine transformers names and keep loading real HF bnb checkpoints.gptqmodel/utils/hf_refusing_quantizer.py: the refusal text moved intorefusal_message()so the mapping path and the guarded path emit the same actionable error.docs/hf-interop.md: drop the claim that transformers ownsbitsandbytes, and add it to the published-name list.tests/test_checkpoint_interop_4053.py:bitsandbytesjoins the from-pretrained refusal parametrization.Tests
tests/test_bnb_hf_refusal_4664.py(new, 7 tests):AutoModelForCausalLM.from_pretrainedraises for both a 4-bit and an 8-bit checkpoint;hf_compat_warningslabels a BnB save;METHODGPT-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 becausebitsandbyteswas 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 checkclean.Note
load_in_4bit/load_in_8bitare never written by GPT-QModel'sBitsAndBytesConfig, so no checkpoint of ours takes transformers'_4bit/_8bitdispatch path.Resolves #4664.