Repository navigation
Point a 4-bit load that does not fit the GPU at offload_layers = "auto" - #13052
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…oads, report the requested offload
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…e under max_memory
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84011293bf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _offload_layers_requested, | ||
| device_map = device_map, | ||
| load_in_8bit = load_in_8bit, | ||
| quantization_config = _quantization_config_requested, |
There was a problem hiding this comment.
Detect bundled 8-bit configs before suggesting offload
For a prequantized 8-bit checkpoint whose config.json supplies model_config.quantization_config (or a caller-supplied config containing that setting), load_in_8bit can remain false and _quantization_config_requested is None, even though Transformers performs an 8-bit load and can raise this spill error. The current version still passes only the original quantization_config kwarg here, so the helper incorrectly recommends offload_layers="auto", which is not supported for effective 8-bit loads; pass the resolved model configuration's quantization mode so this case receives the 4-bit/smaller-model remedy instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar for this message: bundled 8-bit bnb checkpoints are rare, and if such a user follows the hint, the loader refuses offload_layers with its own printed reason (refuse_block_swap_load), so nothing silently misleads.
| 'Pass `offload_layers = "auto"` to from_pretrained to keep the decoder layers the GPU ' | ||
| "cannot hold in host RAM and stream them in during training (slower, but it trains), " |
There was a problem hiding this comment.
Avoid suggesting offload for ineligible load modes
For a 4-bit spill from a load using state_dict, use_safetensors=False, or a classification head via num_labels, this unconditional hint recommends offload_layers="auto", but the same loader explicitly refuses layer offload for those modes in llama.py lines 2753-2767 and 3026-3029. Following the advice therefore disables the requested offload and reaches the spill again; propagate whether block-swap loading is eligible and offer only the smaller-model/free-memory remedies when it is not.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar for this message: state_dict / use_safetensors=False / num_labels spills are long-tail, and following the hint there hits refuse_block_swap_load, which prints exactly why offload_layers is declined for that mode.
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #1629
When a 4-bit (or 8-bit) bitsandbytes load does not fit on the GPU, transformers' automatic device map spills part of the model to the CPU and its bitsandbytes quantizer refuses with:
That advice keeps the spilled weights unquantized in fp32 on the CPU, which does not get a user to training. Unsloth already has the right tool for this case,
offload_layers = "auto", which keeps the decoder layers that do not fit in host RAM and streams them in during training. This PR re-raises the spill error (chained to the original) from bothFastLanguageModelandFastModelwith a message that names the model, the free GPU memory, and points atoffload_layers = "auto":(The latest wording says "slower, and it needs that much free system RAM" instead of "slower, but it trains".)
The hint adapts to what the caller passed:
offload_layers = "auto"already set suggests a shortermax_seq_lengthor batch; a numericoffload_layerssuggests more layers or"auto"; 8-bit loads suggest 4-bit; a caller's ownquantization_configsuggestsload_in_4bit = Truewithoffload_layers. A caller's own dict,"cpu"or diskdevice_mapkeeps the transformers error unchanged (on transformers 4.x an all-CPU map raises it too). The free-memory figure reads only the current GPU, and is skipped under a caller'smax_memory. Every other error, and every load that fits, is untouched: the handler only matches aValueErrorstarting with the bitsandbytes quantizers' own prefix (a test pins that prefix against the installed transformers 4-bit and 8-bit quantizer sources).Testing
Single GPU with free memory capped (both what accelerate reads and what the allocator allows), 4-bit,
max_seq_length = 2048, LoRA r=16 + 2 training steps where it loads:offload_layers = "auto"Real Colab T4 (14.9 GB free), Qwen3-32B 4-bit:
cuda:0 has 14.35 GB free8-bit Qwen3-14B at 7 GB on this PR gets the load_in_4bit hint.
tests/test_bnb_cpu_spill_message.py: 14 passed, including an AST check that both loaders route load errors through the helper (fails when the wiring is reverted).