Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/diffusers/pipelines/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ def enable_model_cpu_offload(self, gpu_id: Optional[int] = None, device: Union[t

device_type = torch_device.type
device = torch.device(f"{device_type}:{self._offload_gpu_id}")
self._offload_device = device

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down Expand Up @@ -1472,7 +1473,7 @@ def maybe_free_model_hooks(self):
hook.remove()

# make sure the model is in the same state as before calling it
self.enable_model_cpu_offload()
self.enable_model_cpu_offload(device=getattr(self, "_offload_device", "cuda"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think it's a non-breaking change since we default to "cuda" for device in enable_model_cpu_offload().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok too :)


def enable_sequential_cpu_offload(self, gpu_id: Optional[int] = None, device: Union[torch.device, str] = "cuda"):
r"""
Expand Down Expand Up @@ -1508,6 +1509,7 @@ def enable_sequential_cpu_offload(self, gpu_id: Optional[int] = None, device: Un

device_type = torch_device.type
device = torch.device(f"{device_type}:{self._offload_gpu_id}")
self._offload_device = device

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down