Repository navigation
fix(models): restore temporarily offloaded weights after loading - #15026
Open
Shenrui-Ma wants to merge 1 commit into
Open
Shenrui-Ma wants to merge 1 commit into
Shenrui-Ma wants to merge 1 commit into
Conversation
Temporary CPU state-dict offloading can leave a model unusable when no weights remain permanently on disk. Restore temporary weights independently of permanent disk placement and clean up the temporary directory, while preserving the fallback without Accelerate. Tested: CPU model-loading suite with current and minimum supported PyTorch/Accelerate; sharded, parallel and permanent-disk controls Not-tested: CUDA and distributed loading; additional Hub checks remain undiagnosed Scope-risk: narrow
Contributor
|
Hi @Shenrui-Ma, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
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?
Loading with
offload_state_dict=Truebut no permanent disk offloading can leave the model's parameters onmeta, causing inference or CPU device dispatch to fail. Temporary weight files are also left behind.Restoration and cleanup currently run only when permanent disk-offload entries exist. Move them outside that condition, skipping restoration for empty temporary indexes so loading without Accelerate still works.
Fixes #15018 (awaiting maintainer acknowledgment).
Testing
DIFFUSERS_TEST_DEVICE=cpu pytest tests/models/test_modeling_common.py -q— 29 passed, 5 skipped on macOS arm64.The regressions check saved weights, inference output, and temporary-directory cleanup. Affected cases fail on the original loader; permanent-disk-offload controls pass on both versions.
Quality and copy checks pass. Repository-consistency checks fail on both the baseline and this branch. Additional Hub loading checks remain unsuccessful and undiagnosed; CUDA and distributed loading were not tested.
Self-review
Reviewed the full diff with the project's self-review skill. No blocking or non-blocking code findings remain, and no dead code was introduced. Verdict: READY for code review, with the verification gaps above still open.
Before submitting