Skip to content
Closed
Show file tree
Hide file tree
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: 2 additions & 2 deletions examples/community/composable_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def disable_vae_slicing(self):
"""
self.vae.disable_slicing()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -190,7 +190,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae]:
if cpu_offloaded_model is not None:
Expand Down
8 changes: 4 additions & 4 deletions examples/community/lpw_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def disable_vae_tiling(self):
self.vae.disable_tiling()

# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_sequential_cpu_offload
def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -580,7 +580,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand All @@ -593,7 +593,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_model_cpu_offload
def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -605,7 +605,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down
4 changes: 2 additions & 2 deletions examples/community/sd_text2img_k_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def disable_attention_slicing(self):
# set slice_size = `None` to disable `attention slicing`
self.enable_attention_slicing(None)

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -157,7 +157,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae, self.safety_checker]:
if cpu_offloaded_model is not None:
Expand Down
8 changes: 4 additions & 4 deletions examples/community/stable_diffusion_controlnet_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def disable_vae_slicing(self):
"""
self.vae.disable_slicing()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae, controlnet, and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -212,15 +212,15 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae, self.controlnet]:
cpu_offload(cpu_offloaded_model, device)

if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -232,7 +232,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

hook = None
for cpu_offloaded_model in [self.text_encoder, self.unet, self.vae]:
Expand Down
8 changes: 4 additions & 4 deletions examples/community/stable_diffusion_controlnet_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def disable_vae_slicing(self):
"""
self.vae.disable_slicing()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae, controlnet, and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -311,15 +311,15 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae, self.controlnet]:
cpu_offload(cpu_offloaded_model, device)

if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -331,7 +331,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

hook = None
for cpu_offloaded_model in [self.text_encoder, self.unet, self.vae]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def disable_vae_slicing(self):
"""
self.vae.disable_slicing()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae, controlnet, and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -296,15 +296,15 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae, self.controlnet]:
cpu_offload(cpu_offloaded_model, device)

if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -316,7 +316,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

hook = None
for cpu_offloaded_model in [self.text_encoder, self.unet, self.vae]:
Expand Down
8 changes: 4 additions & 4 deletions examples/community/stable_diffusion_ipex.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def disable_vae_tiling(self):
"""
self.vae.disable_tiling()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -354,7 +354,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand All @@ -366,7 +366,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -378,7 +378,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down
8 changes: 4 additions & 4 deletions examples/community/stable_diffusion_repaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def __init__(
self.register_to_config(requires_safety_checker=requires_safety_checker)

# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_sequential_cpu_offload
def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -289,7 +289,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand All @@ -302,7 +302,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_model_cpu_offload
def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -314,7 +314,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down
4 changes: 2 additions & 2 deletions examples/community/unclip_image_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _encode_image(self, image, device, num_images_per_prompt, image_embeddings:
return image_embeddings

# Copied from diffusers.pipelines.unclip.pipeline_unclip_image_variation.UnCLIPImageVariationPipeline.enable_sequential_cpu_offload
def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, the pipeline's
models have their state dicts saved to CPU and then are moved to a `torch.device('meta') and loaded to GPU only
Expand All @@ -215,7 +215,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

models = [
self.decoder,
Expand Down
4 changes: 2 additions & 2 deletions examples/community/unclip_text_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _encode_prompt(
return prompt_embeds, text_encoder_hidden_states, text_mask

# Copied from diffusers.pipelines.unclip.pipeline_unclip.UnCLIPPipeline.enable_sequential_cpu_offload
def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, the pipeline's
models have their state dicts saved to CPU and then are moved to a `torch.device('meta') and loaded to GPU only
Expand All @@ -223,7 +223,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

# TODO: self.prior.post_process_latents is not covered by the offload hooks, so it fails if added to the list
models = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def disable_vae_tiling(self):
"""
self.vae.disable_tiling()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -239,7 +239,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand All @@ -251,7 +251,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -263,7 +263,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def __init__(
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
self.register_to_config(requires_safety_checker=requires_safety_checker)

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
Expand All @@ -237,7 +237,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand All @@ -249,7 +249,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
if self.safety_checker is not None:
cpu_offload(self.safety_checker, execution_device=device, offload_buffers=True)

def enable_model_cpu_offload(self, gpu_id=0):
def enable_model_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
Expand All @@ -261,7 +261,7 @@ def enable_model_cpu_offload(self, gpu_id=0):
else:
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

if self.device.type != "cpu":
self.to("cpu", silence_dtype_warnings=True)
Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/pipelines/audioldm/pipeline_audioldm.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def disable_vae_slicing(self):
"""
self.vae.disable_slicing()

def enable_sequential_cpu_offload(self, gpu_id=0):
def enable_sequential_cpu_offload(self, gpu="cuda", gpu_id=0):
r"""
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and vocoder have their state dicts saved to CPU and then are moved to a `torch.device('meta')
Expand All @@ -119,7 +119,7 @@ def enable_sequential_cpu_offload(self, gpu_id=0):
else:
raise ImportError("Please install accelerate via `pip install accelerate`")

device = torch.device(f"cuda:{gpu_id}")
device = torch.device(f"{gpu}:{gpu_id}")

for cpu_offloaded_model in [self.unet, self.text_encoder, self.vae, self.vocoder]:
cpu_offload(cpu_offloaded_model, device)
Expand Down
Loading