Repository navigation
Rename block_swap_layers to offload_layers - #12705
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. |
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 632ab65d24
ℹ️ 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".
| def legacy_offload_layers(kwargs, offload_layers = 0): | ||
| """`offload_layers`, accepting its original name `block_swap_layers` from `kwargs`.""" | ||
| legacy = kwargs.pop("block_swap_layers", None) | ||
| return legacy if legacy is not None and not offload_layers else offload_layers |
There was a problem hiding this comment.
Honor an explicit zero for
offload_layers
When both names are supplied and the new value is 0 or False, this truthiness check lets the legacy value win; for example, offload_layers=0, block_swap_layers=4 resolves to 4 and unexpectedly enables CPU layer streaming. This can occur when a new default/config is merged with a persisted legacy setting, and contradicts the stated precedence that offload_layers wins whenever both are passed; presence rather than truthiness must determine precedence.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e5d0d7b: offload_layers now defaults to None in from_pretrained and both get_peft_model signatures, and block_swap_layers is used only when offload_layers was not given, so offload_layers = 0 with block_swap_layers = 4 resolves to 0. Checked on Qwen3-0.6B: no layers offloaded with that pair or with neither name, layers 6, 13, 20, 27 with block_swap_layers = 4 alone.
…block_swap_layers
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 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". |
Renames the
block_swap_layersargument (added in #11832) tooffload_layers, which says what it does: decoder layers are offloaded to CPU RAM and streamed back to the GPU for each step.Changes
offload_layersreplacesblock_swap_layersinFastLanguageModel/FastModelfrom_pretrainedandget_peft_model, and in every message Unsloth prints about it.block_swap_layersstill works as an alias through a smalllegacy_offload_layershelper, so code written against main keeps working. If both are passed,offload_layerswins.attach_block_swap_layersis renamedattach_offload_layers(internal, onlyllama.pycalls it). Internal names likeBlockSwap,plan_block_swapand theunsloth_zoo.block_swapmodule are unchanged.Companion zoo PR: unslothai/unsloth-zoo#1559 renames the two messages zoo prints and makes the MLX loader drop either name. The two PRs do not depend on each other.
Testing
Qwen3-0.6B on one GPU, 3 SFT steps, 4 layers offloaded each way:
offload_layers = 4from_pretrainedoffload_layers = 4get_peft_modelblock_swap_layers = 4from_pretrainedblock_swap_layers = 4get_peft_modelFastModelwith gemma-3-270m:offload_layers = 4at load andblock_swap_layers = 4inget_peft_modelboth offload layers 3, 8, 12, 17 with the same loss.tests/test_block_swap_install.pyandtests/test_offload_tied_autodisable.pypass (82), including a new test for the alias.