Repository navigation
Conversation
A skip-list entry that names a module stopped covering the layers inside it in v5.0, when huggingface#42711 moved bitsandbytes onto should_convert_module. Pre-quantized checkpoints rely on it: Unsloth's vision-language repos list "merger", "visual" or "vision_tower" and store those modules unquantized, so on main they are built as Linear4bit and generation fails; the Jamba docs example llm_int8_skip_modules=["mamba"] quantizes every Mamba layer. The suffix rule now also checks the modules containing a layer (v4's `key + "." in name`).
This branch has not been deployed
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.
What does this PR do?
A skip-list entry that names a module stopped covering the layers inside it in v5.0. #42711 moved bitsandbytes onto
should_convert_module, which matches an entry from the start of the name, as a regex, or as a suffix of the layer's own name. v4 also skipped a layer whenkey + "."appeared anywhere in its name, somergercoveredmodel.visual.merger.mlp.0. This looks unintended: #42711 (and #42776 for AWQ) describe the move as a simplification, and the v5 migration guide's quantization section doesn't list it.Pre-quantized checkpoints rely on that. Unsloth's vision-language repos list
["lm_head", "multi_modal_projector", "merger", "modality_projection", ...](newer ones add"visual"and"vision_tower") and store those modules unquantized. Onmainthey are built asLinear4bitand generation fails with a bareAssertionErrorfrom bitsandbytes. unslothai/unsloth-zoo#491 patchesshould_convert_moduleat import, so this only shows up with plain Transformers. Qwen's own AWQ releases rely on it too: the seven official Qwen2-VL / Qwen2.5-VL AWQ checkpoints (about 1.75M downloads a month together;Qwen/Qwen2.5-VL-3B-Instruct-AWQalone about 878k) setmodules_to_not_convert: ["visual"]and store the vision tower unquantized. Onmain,Qwen/Qwen2.5-VL-3B-Instruct-AWQfails to load (NotImplementedError: ... out_features: 3420 must be divisible by [8]), andQwen/Qwen2-VL-2B-Instruct-AWQloads with its 130 stored vision weights unused and the vision layers left uninitialized, so it answers "What color is the left half?" about a red/blue image with "The left half of the image is white." With this PR both build the vision tower unquantized and answer "Red", as on 4.57.6 (checked with gptqmodel 7.14's torch AWQ backend; the other five have the same list and vision tower but were not loaded). The Jamba docs example (llm_int8_skip_modules=["mamba"],model_doc/jamba.md) hits the same rule: onmainit quantizes all 112 Mamba linears of the default config.Linear, then a description of the image.main(ce585bc):Linear4bit, thenAssertionErrorinfix_4bit_weight_quant_state_from_module(bitsandbytes/nn/modules.py:498).Linear, then a description.Fix. The suffix rule also checks the modules that contain the layer (
f"{key}." in full_name, v4's check). #49771's boundaries don't change:mlp.gatedoesn't matchmlp.gate_proj,layers.1doesn't matchlayers.10, andmergerdoesn't matchdeepstack_merger_list. The skip-modules docs page describes the new suffix rule.Behaviour change. An entry now covers every layer inside a module whose name ends with it, for every method that uses
should_convert_module. Like v4, it doesn't need a.before it (mergeralso coverspatch_merger). With the default skip-lists, only GIT changes among the module-name methods: its head is namedoutput, so 12*.output.denselayers are skipped, as in v4. torchao matches parameter names, so_keep_in_fp32_modulesleaf entries such as T5'swotake effect there again. This is separate from #49774, which matches skip-lists against checkpoint names: that would also cover the Qwen AWQvisualentries (stored asvisual.*), but not entries naming an inner module (merger, stored asvisual.merger.*; Jamba'smamba) or checkpoints saved with v5 names (Qwen3-VL, Gemma 4).Checked against what checkpoints store
For the 100 most-downloaded repos named
*bnb-4bit*(99 of them Unsloth's; 98 readable), I compared, layer by layer, whichLinearlayers each rule converts with which ones the checkpoint stores in 4-bit (<layer>.weight.absmaxpresent). The comparison used the safetensors headers and a meta-device model from each config, with the repo's skip-list plus_keep_in_fp32_modules.mainkey + "." in name).required before the entryNo layer is right on
mainand wrong with this PR. The 18 include Unsloth's Gemma 4 (E2B, E4B, 31B), Qwen3-VL (4B, 8B), Qwen2.5-VL (3B, 7B), Qwen2-VL and Ministral 3 repos. Of the 4 left, 3 are Gemma 3 / MedGemma repos whose skip-lists use the pre-v5 names (language_model.model.layers.N.mlp); that is a separate problem (skip-list entries aren't renamed along with the checkpoint keys). The fourth,unsloth/gemma-4-E2B-unsloth-bnb-4bit, was quantized whilemodel.language_model.layers.1still matched layers 10 to 19, before #49771. Layers whose names don't line up between checkpoint and model weren't counted (some Gemma 3 and LLaVA vision towers).The same comparison on the 23 most-downloaded fine-grained FP8 checkpoints (stored dtype per layer) shows no decision changed.
Tests. New cases in
tests/quantization/test_quantizers_utils.pyfail onmainand pass here.tests/quantizationCPU suites (bnb, finegrained_fp8, mxfp4, torchao, autoawq) give the same results onmainand this branch; the failures on both need an accelerator, Triton or compile, which this machine lacks.ruff check,ruff format --check(0.14.10) and the noisy-comment checker pass on the changed files. On GPU (RTX 3060 Ti, bitsandbytes 0.50.2),unsloth/Qwen2-VL-2B-Instruct-bnb-4bitandunsloth/Qwen3-VL-4B-Instruct-unsloth-bnb-4bitload with the same layer types as 4.57.6 and generate.Found and fixed with Claude Code (Claude Opus 5.5). The reproducer, the survey and the tests were run on my machine.
Who can review?
Quantization: @SunMarc (cc @IlyasMoutawwakil, #49771/#49774)