Unverified Commit 0ab63ff6 authored by Tolga Cangöz's avatar Tolga Cangöz Committed by GitHub
Browse files

Fix CPU Offloading Usage & Typos (#8230)

* Fix typos

* Fix `pipe.enable_model_cpu_offload()` usage

* Fix cpu offloading

* Update numbers
parent db33af06
...@@ -77,7 +77,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi ...@@ -77,7 +77,7 @@ Please refer to the [How to use Stable Diffusion in Apple Silicon](https://huggi
## Quickstart ## Quickstart
Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 22000+ checkpoints): Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the `from_pretrained` method to load any pretrained diffusion model (browse the [Hub](https://huggingface.co/models?library=diffusers&sort=downloads) for 25.000+ checkpoints):
```python ```python
from diffusers import DiffusionPipeline from diffusers import DiffusionPipeline
...@@ -219,7 +219,7 @@ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz9 ...@@ -219,7 +219,7 @@ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz9
- https://github.com/deep-floyd/IF - https://github.com/deep-floyd/IF
- https://github.com/bentoml/BentoML - https://github.com/bentoml/BentoML
- https://github.com/bmaltais/kohya_ss - https://github.com/bmaltais/kohya_ss
- +9000 other amazing GitHub repositories 💪 - +11.000 other amazing GitHub repositories 💪
Thank you for using us ❤️. Thank you for using us ❤️.
......
...@@ -6,7 +6,7 @@ Before you begin, make sure you install T-GATE. ...@@ -6,7 +6,7 @@ Before you begin, make sure you install T-GATE.
```bash ```bash
pip install tgate pip install tgate
pip install -U pytorch diffusers transformers accelerate DeepCache pip install -U torch diffusers transformers accelerate DeepCache
``` ```
......
...@@ -249,13 +249,13 @@ controlnet = ControlNetModel.from_pretrained( ...@@ -249,13 +249,13 @@ controlnet = ControlNetModel.from_pretrained(
controlnet_id, controlnet_id,
torch_dtype=torch.float16, torch_dtype=torch.float16,
variant="fp16", variant="fp16",
).to(device) )
pipe = StableDiffusionXLControlNetPipeline.from_pretrained( pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
base_model_id, base_model_id,
controlnet=controlnet, controlnet=controlnet,
torch_dtype=torch.float16, torch_dtype=torch.float16,
variant="fp16", variant="fp16",
).to(device) )
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config) pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
...@@ -301,13 +301,13 @@ controlnet = ControlNetModel.from_pretrained( ...@@ -301,13 +301,13 @@ controlnet = ControlNetModel.from_pretrained(
controlnet_id, controlnet_id,
torch_dtype=torch.float16, torch_dtype=torch.float16,
variant="fp16", variant="fp16",
).to(device) )
pipe = StableDiffusionXLControlNetPipeline.from_pretrained( pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
base_model_id, base_model_id,
controlnet=controlnet, controlnet=controlnet,
torch_dtype=torch.float16, torch_dtype=torch.float16,
variant="fp16", variant="fp16",
).to(device) )
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config) pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
......
...@@ -230,7 +230,7 @@ from diffusers.utils import load_image, make_image_grid ...@@ -230,7 +230,7 @@ from diffusers.utils import load_image, make_image_grid
pipeline = AutoPipelineForInpainting.from_pretrained( pipeline = AutoPipelineForInpainting.from_pretrained(
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16" "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16"
).to("cuda") )
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention() pipeline.enable_xformers_memory_efficient_attention()
...@@ -255,7 +255,7 @@ from diffusers.utils import load_image, make_image_grid ...@@ -255,7 +255,7 @@ from diffusers.utils import load_image, make_image_grid
pipeline = AutoPipelineForInpainting.from_pretrained( pipeline = AutoPipelineForInpainting.from_pretrained(
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16" "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16"
).to("cuda") )
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention() pipeline.enable_xformers_memory_efficient_attention()
...@@ -296,7 +296,7 @@ from diffusers.utils import load_image, make_image_grid ...@@ -296,7 +296,7 @@ from diffusers.utils import load_image, make_image_grid
pipeline = AutoPipelineForInpainting.from_pretrained( pipeline = AutoPipelineForInpainting.from_pretrained(
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16" "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16"
).to("cuda") )
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention() pipeline.enable_xformers_memory_efficient_attention()
...@@ -319,7 +319,7 @@ from diffusers.utils import load_image, make_image_grid ...@@ -319,7 +319,7 @@ from diffusers.utils import load_image, make_image_grid
pipeline = AutoPipelineForInpainting.from_pretrained( pipeline = AutoPipelineForInpainting.from_pretrained(
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16" "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16"
).to("cuda") )
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention() pipeline.enable_xformers_memory_efficient_attention()
......
...@@ -1032,7 +1032,7 @@ image = pipe().images[0] ...@@ -1032,7 +1032,7 @@ image = pipe().images[0]
Make sure you have @crowsonkb's <https://github.com/crowsonkb/k-diffusion> installed: Make sure you have @crowsonkb's <https://github.com/crowsonkb/k-diffusion> installed:
``` ```sh
pip install k-diffusion pip install k-diffusion
``` ```
...@@ -1854,13 +1854,13 @@ To use this pipeline, you need to: ...@@ -1854,13 +1854,13 @@ To use this pipeline, you need to:
You can simply use pip to install IPEX with the latest version. You can simply use pip to install IPEX with the latest version.
```python ```sh
python -m pip install intel_extension_for_pytorch python -m pip install intel_extension_for_pytorch
``` ```
**Note:** To install a specific version, run with the following command: **Note:** To install a specific version, run with the following command:
``` ```sh
python -m pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu python -m pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu
``` ```
...@@ -1958,13 +1958,13 @@ To use this pipeline, you need to: ...@@ -1958,13 +1958,13 @@ To use this pipeline, you need to:
You can simply use pip to install IPEX with the latest version. You can simply use pip to install IPEX with the latest version.
```python ```sh
python -m pip install intel_extension_for_pytorch python -m pip install intel_extension_for_pytorch
``` ```
**Note:** To install a specific version, run with the following command: **Note:** To install a specific version, run with the following command:
``` ```sh
python -m pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu python -m pip install intel_extension_for_pytorch==<version_name> -f https://developer.intel.com/ipex-whl-stable-cpu
``` ```
...@@ -3010,8 +3010,8 @@ This code implements a pipeline for the Stable Diffusion model, enabling the div ...@@ -3010,8 +3010,8 @@ This code implements a pipeline for the Stable Diffusion model, enabling the div
### Sample Code ### Sample Code
``` ```py
from from examples.community.regional_prompting_stable_diffusion import RegionalPromptingStableDiffusionPipeline from examples.community.regional_prompting_stable_diffusion import RegionalPromptingStableDiffusionPipeline
pipe = RegionalPromptingStableDiffusionPipeline.from_single_file(model_path, vae=vae) pipe = RegionalPromptingStableDiffusionPipeline.from_single_file(model_path, vae=vae)
rp_args = { rp_args = {
...@@ -4131,7 +4131,7 @@ This implementation is based on [Diffusers](https://huggingface.co/docs/diffuser ...@@ -4131,7 +4131,7 @@ This implementation is based on [Diffusers](https://huggingface.co/docs/diffuser
## Example Usage ## Example Usage
``` ```py
import os import os
import torch import torch
......
...@@ -896,7 +896,6 @@ def main(): ...@@ -896,7 +896,6 @@ def main():
images = [] images = []
if args.validation_prompts is not None: if args.validation_prompts is not None:
logger.info("Running inference for collecting generated images...") logger.info("Running inference for collecting generated images...")
pipeline = pipeline.to(accelerator.device)
pipeline.torch_dtype = weight_dtype pipeline.torch_dtype = weight_dtype
pipeline.set_progress_bar_config(disable=True) pipeline.set_progress_bar_config(disable=True)
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
......
...@@ -642,7 +642,7 @@ class LoraIntegrationTests(unittest.TestCase): ...@@ -642,7 +642,7 @@ class LoraIntegrationTests(unittest.TestCase):
This test simply checks that loading a LoRA with an empty network alpha works fine This test simply checks that loading a LoRA with an empty network alpha works fine
See: https://github.com/huggingface/diffusers/issues/5606 See: https://github.com/huggingface/diffusers/issues/5606
""" """
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to(torch_device) pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipeline.enable_sequential_cpu_offload() pipeline.enable_sequential_cpu_offload()
civitai_path = hf_hub_download("ybelkada/test-ahi-civitai", "ahi_lora_weights.safetensors") civitai_path = hf_hub_download("ybelkada/test-ahi-civitai", "ahi_lora_weights.safetensors")
pipeline.load_lora_weights(civitai_path, adapter_name="ahri") pipeline.load_lora_weights(civitai_path, adapter_name="ahri")
......
...@@ -243,7 +243,6 @@ class I2VGenXLPipelineSlowTests(unittest.TestCase): ...@@ -243,7 +243,6 @@ class I2VGenXLPipelineSlowTests(unittest.TestCase):
def test_i2vgen_xl(self): def test_i2vgen_xl(self):
pipe = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16") pipe = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
pipe = pipe.to(torch_device)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
image = load_image( image = load_image(
......
...@@ -612,10 +612,10 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin): ...@@ -612,10 +612,10 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
def test_instant_style_multiple_masks(self): def test_instant_style_multiple_masks(self):
image_encoder = CLIPVisionModelWithProjection.from_pretrained( image_encoder = CLIPVisionModelWithProjection.from_pretrained(
"h94/IP-Adapter", subfolder="models/image_encoder", torch_dtype=torch.float16 "h94/IP-Adapter", subfolder="models/image_encoder", torch_dtype=torch.float16
).to("cuda") )
pipeline = StableDiffusionXLPipeline.from_pretrained( pipeline = StableDiffusionXLPipeline.from_pretrained(
"RunDiffusion/Juggernaut-XL-v9", torch_dtype=torch.float16, image_encoder=image_encoder, variant="fp16" "RunDiffusion/Juggernaut-XL-v9", torch_dtype=torch.float16, image_encoder=image_encoder, variant="fp16"
).to("cuda") )
pipeline.enable_model_cpu_offload() pipeline.enable_model_cpu_offload()
pipeline.load_ip_adapter( pipeline.load_ip_adapter(
......
...@@ -420,7 +420,6 @@ class StableDiffusion2VPredictionPipelineIntegrationTests(unittest.TestCase): ...@@ -420,7 +420,6 @@ class StableDiffusion2VPredictionPipelineIntegrationTests(unittest.TestCase):
pipe.scheduler = DDIMScheduler.from_config( pipe.scheduler = DDIMScheduler.from_config(
pipe.scheduler.config, timestep_spacing="trailing", rescale_betas_zero_snr=True pipe.scheduler.config, timestep_spacing="trailing", rescale_betas_zero_snr=True
) )
pipe.to(torch_device)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
......
...@@ -534,7 +534,6 @@ class StableVideoDiffusionPipelineSlowTests(unittest.TestCase): ...@@ -534,7 +534,6 @@ class StableVideoDiffusionPipelineSlowTests(unittest.TestCase):
variant="fp16", variant="fp16",
torch_dtype=torch.float16, torch_dtype=torch.float16,
) )
pipe = pipe.to(torch_device)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
image = load_image( image = load_image(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment