Skip to content

fix(models): restore temporarily offloaded weights after loading - #15026

Open
Shenrui-Ma wants to merge 1 commit into
huggingface:mainfrom
Shenrui-Ma:fix/restore-temporarily-offloaded-weights
Open

Shenrui-Ma wants to merge 1 commit into
huggingface:mainfrom
Shenrui-Ma:fix/restore-temporarily-offloaded-weights

Conversation

@Shenrui-Ma

@Shenrui-Ma Shenrui-Ma commented Oct 14, 2026 •

Copy link
Copy Markdown

What does this PR do?

Loading with offload_state_dict=True but no permanent disk offloading can leave the model's parameters on meta, 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

  • AI-assisted; contribution and AI guides read.
  • Final self-review completed and included above.
  • Necessary regression tests added and run.
  • Discussed with a maintainer in an issue or forum thread.

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
@github-actions github-actions Bot added models tests size/M PR with diff < 200 LOC labels Oct 14, 2026
@github-actions

Copy link
Copy Markdown
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. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

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 no-issue-needed label), you can ignore this message — it stays here as a comment, but it no longer applies.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

offload_state_dict=True leaves CPU model weights on meta after loading

1 participant