Repository navigation
Read the resident tensor names only where they are used - #11159
Conversation
The push guard is the only consumer: a local save reconciles the folder it just wrote. Collecting model.state_dict() for it duplicated save_pretrained's own collection, which on an offloaded or sharded model materialises every weight and on a distributed one is a collective the other ranks are not making.
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 |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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 Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Confirmed the collection at unsloth/save.py:5662 runs for local saves too, where only save_pretrained's own state dict is written, so moving it inside the push branch looks right. Will get this reviewed. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
# Conflicts: # tests/studio/playwright_queue_localization.py
) * Read the resident tensor names only where they are used The push guard is the only consumer: a local save reconciles the folder it just wrote. Collecting model.state_dict() for it duplicated save_pretrained's own collection, which on an offloaded or sharded model materialises every weight and on a distributed one is a collective the other ranks are not making. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Follow-up to #11042, which merged before this was caught.
unsloth_generic_save's full-finetune branch collected_mtp_tensor_namesfor every save, but only the push branch consumes them: the guard hides an MTP declaration the weights do not back whilepush_to_hubserialises, because a push has no local folder to repair afterwards. A local save has one, and reconciles it throughreconcile_mtp_config(save_directory)aftersave_pretrainedhas written.So for a local
save_method = "lora"or"merged_4bit_forced"with no caller-suppliedstate_dict, the branch calledmodel.state_dict()for a list of names nothing then read, andsave_pretrainedcollected the state dict again immediately afterwards. On a large, offloaded or sharded model that materialises every weight twice, and under FSDP or DeepSpeed the collection is a collective the other ranks are not making, so it can stall rather than merely cost memory.The collection moves inside
if push_to_hub:. Nothing else changes: the same names, derived the same two ways (the caller'sstate_dictwhen there is one, the resident one otherwise,Nonewhen it cannot be read so the guard disarms), and the same_mtp_config_matching_tensorsaround the same push.What changes for an input that already succeeded
Nothing, except that a local save no longer performs one full
state_dict()collection it never used. A push is byte for byte what it was; a 16bit save still builds its state dict, because that is the dict being written.Tests
tests/test_save_mtp_policy.py:loraandmerged_4bit_forcedsave throughunsloth_generic_savenever callsmodel.state_dict(), while amerged_16bitone still does. Driven through the real function with a counting fake model, so it observes the collection rather than the source._mtp_tensor_namessits inside thepush_to_hubbranch, so it cannot drift back out.Both fail against the previous behaviour.