You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
offload_state_dict=True leaves CPU model weights on meta after loading #15018
UNet2DModel.from_pretrained(..., offload_state_dict=True) can return a model whose parameters remain on meta; its next forward pass fails. With device_map={"": "cpu"}, loading itself fails with “Cannot copy out of meta tensor”. Temporary weight files are also left behind. The same checkpoint loads and runs normally with offload_state_dict=False.
This reproduces on current main with a small, locally created model; no downloaded weights are needed:
Expected: temporary CPU-state offloading reduces loading memory without changing the resulting model's usability or weights.
Actual: RuntimeError: Tensor on device meta is not on the expected device cpu!
The restoration in _load_pretrained_model is nested under the condition for a nonempty permanent disk-offload index. Temporary CPU weight offloading does not require permanent disk placement, so that condition skips both restoration and cleanup.
I have prepared a local fix that restores a populated temporary index independently of the permanent index and always removes the temporary directory after successful loading. It also preserves the no-Accelerate fallback. Tests cover single-file/sharded checkpoints, serial/parallel loading, CPU placement, and CPU+disk placement with real inference comparisons. Would this scope be suitable for a PR?
Environment reproduced: Diffusers 0.41.0.dev0, PyTorch 2.14.1, Accelerate 1.15.0, Python 3.11.15, macOS arm64. The fix also passes the focused model-loading tests with PyTorch 2.6.0, Accelerate 0.31.0, and Python 3.10.20.
I independently reproduced this on current main with the small UNet2DModel in the report. I also have a local fix that restores the temporary CPU offload index independently of the permanent disk-offload index and always cleans up the temporary folder; the focused tests cover single-file/sharded checkpoints, serial/parallel loading, and default/CPU device maps.
@Shenrui-Ma mentioned having a prepared fix. If they are not planning to open a PR, I am happy to submit one. If a maintainer can confirm that this scope is acceptable, I will open a PR linked to this issue.
Activity
px12811 commentedon Oct 14, 2026
I independently reproduced this on current
mainwith the small UNet2DModel in the report. I also have a local fix that restores the temporary CPU offload index independently of the permanent disk-offload index and always cleans up the temporary folder; the focused tests cover single-file/sharded checkpoints, serial/parallel loading, and default/CPU device maps.@Shenrui-Ma mentioned having a prepared fix. If they are not planning to open a PR, I am happy to submit one. If a maintainer can confirm that this scope is acceptable, I will open a PR linked to this issue.