Denoising is the most computationally demanding process during diffusion. Methods that optimizes this process accelerates inference speed. Try the following methods for a speed up.
Denoising is the most computationally demanding process during diffusion. Methods that optimizes this process accelerates inference speed. Try the following methods for a speed up.
- Add `.to("cuda")` to place the pipeline on a GPU. Placing a model on an accelerator, like a GPU, increases speed because it performs computations in parallel.
- Add `device_map="cuda"` to place the pipeline on a GPU. Placing a model on an accelerator, like a GPU, increases speed because it performs computations in parallel.
- Set `torch_dtype=torch.bfloat16` to execute the pipeline in half-precision. Reducing the data type precision increases speed because it takes less time to perform computations in a lower precision.
- Set `torch_dtype=torch.bfloat16` to execute the pipeline in half-precision. Reducing the data type precision increases speed because it takes less time to perform computations in a lower precision.
```py
```py
...
@@ -54,8 +57,9 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
...
@@ -54,8 +57,9 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
pipeline=DiffusionPipeline.from_pretrained(
pipeline=DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.bfloat16
torch_dtype=torch.bfloat16,
).to("cuda")
device_map="cuda
)
```
```
- Use a faster scheduler, such as [`DPMSolverMultistepScheduler`], which only requires ~20-25 steps.
- Use a faster scheduler, such as [`DPMSolverMultistepScheduler`], which only requires ~20-25 steps.
...
@@ -88,8 +92,9 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However
...
@@ -88,8 +92,9 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However
pipeline = DiffusionPipeline.from_pretrained(
pipeline = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.bfloat16
torch_dtype=torch.bfloat16,
).to("cuda")
device_map="cuda"
)
prompt = """
prompt = """
cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California
cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California
...
@@ -109,8 +114,9 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However
...
@@ -109,8 +114,9 @@ Many modern diffusion models deliver high-quality images out-of-the-box. However