text stringlengths 3 14.4k | source stringclasses 273
values | url stringlengths 47 172 | source_section stringlengths 0 95 | file_type stringclasses 1
value | id stringlengths 3 6 |
|---|---|---|---|---|---|
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/ | .md | 0_0 | |
[[open-in-colab]]
Getting the [`DiffusionPipeline`] to generate images in a certain style or include what you want can be tricky. Often times, you have to run the [`DiffusionPipeline`] several times before you end up with an image you're happy with. But generating something out of nothing is a computationally intensi... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#effective-and-efficient-diffusion | #effective-and-efficient-diffusion | .md | 0_1 |
<Tip>
💡 If you don't have access to a GPU, you can use one for free from a GPU provider like [Colab](https://colab.research.google.com/)!
</Tip>
One of the simplest ways to speed up inference is to place the pipeline on a GPU the same way you would with any PyTorch module:
```python
pipeline = pipeline.to("cud... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#speed | #speed | .md | 0_2 |
The other key to improving pipeline performance is consuming less memory, which indirectly implies more speed, since you're often trying to maximize the number of images generated per second. The easiest way to see how many images you can generate at once is to try out different batch sizes until you get an `OutOfMemor... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#memory | #memory | .md | 0_3 |
In the last two sections, you learned how to optimize the speed of your pipeline by using `fp16`, reducing the number of inference steps by using a more performant scheduler, and enabling attention slicing to reduce memory consumption. Now you're going to focus on how to improve the quality of generated images. | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#quality | #quality | .md | 0_4 |
The most obvious step is to use better checkpoints. The Stable Diffusion model is a good starting point, and since its official launch, several improved versions have also been released. However, using a newer version doesn't automatically mean you'll get better results. You'll still have to experiment with different c... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#better-checkpoints | #better-checkpoints | .md | 0_5 |
You can also try replacing the current pipeline components with a newer version. Let's try loading the latest [autoencoder](https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main/vae) from Stability AI into the pipeline, and generate some images:
```python
from diffusers import AutoencoderKL
vae = Autoenc... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#better-pipeline-components | #better-pipeline-components | .md | 0_6 |
The text prompt you use to generate an image is super important, so much so that it is called *prompt engineering*. Some considerations to keep during prompt engineering are:
- How is the image or similar images of the one I want to generate stored on the internet?
- What additional detail can I give that steers the ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#better-prompt-engineering | #better-prompt-engineering | .md | 0_7 |
In this tutorial, you learned how to optimize a [`DiffusionPipeline`] for computational and memory efficiency as well as improving the quality of generated outputs. If you're interested in making your pipeline even faster, take a look at the following resources:
- Learn how [PyTorch 2.0](./optimization/torch2.0) and ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/stable_diffusion.md | https://huggingface.co/docs/diffusers/en/stable_diffusion/#next-steps | #next-steps | .md | 0_8 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/community_projects.md | https://huggingface.co/docs/diffusers/en/community_projects/ | .md | 1_0 | |
Welcome to Community Projects. This space is dedicated to showcasing the incredible work and innovative applications created by our vibrant community using the `diffusers` library.
This section aims to:
- Highlight diverse and inspiring projects built with `diffusers`
- Foster knowledge sharing within our community... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/community_projects.md | https://huggingface.co/docs/diffusers/en/community_projects/#community-projects | #community-projects | .md | 1_1 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/ | .md | 2_0 | |
Diffusion models are trained to denoise random Gaussian noise step-by-step to generate a sample of interest, such as an image or audio. This has sparked a tremendous amount of interest in generative AI, and you have probably seen examples of diffusion generated images on the internet. 🧨 Diffusers is a library aimed at... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#quicktour | #quicktour | .md | 2_1 |
The [`DiffusionPipeline`] is the easiest way to use a pretrained diffusion system for inference. It is an end-to-end system containing the model and the scheduler. You can use the [`DiffusionPipeline`] out-of-the-box for many tasks. Take a look at the table below for some supported tasks, and for a complete list of sup... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#diffusionpipeline | #diffusionpipeline | .md | 2_2 |
You can also use the pipeline locally. The only difference is you need to download the weights first:
```bash
!git lfs install
!git clone https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
```
Then load the saved weights into the pipeline:
```python
>>> pipeline = DiffusionPipeline.from_pretrained... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#local-pipeline | #local-pipeline | .md | 2_3 |
Different schedulers come with different denoising speeds and quality trade-offs. The best way to find out which one works best for you is to try them out! One of the main features of 🧨 Diffusers is to allow you to easily switch between schedulers. For example, to replace the default [`PNDMScheduler`] with the [`Euler... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#swapping-schedulers | #swapping-schedulers | .md | 2_4 |
Most models take a noisy sample, and at each timestep it predicts the *noise residual* (other models learn to predict the previous sample directly or the velocity or [`v-prediction`](https://github.com/huggingface/diffusers/blob/5e5ce13e2f89ac45a0066cb3f369462a3cf1d9ef/src/diffusers/schedulers/scheduling_ddim.py#L110))... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#models | #models | .md | 2_5 |
Schedulers manage going from a noisy sample to a less noisy sample given the model output - in this case, it is the `noisy_residual`.
<Tip>
🧨 Diffusers is a toolbox for building diffusion systems. While the [`DiffusionPipeline`] is a convenient way to get started with a pre-built diffusion system, you can also cho... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#schedulers | #schedulers | .md | 2_6 |
Hopefully, you generated some cool images with 🧨 Diffusers in this quicktour! For your next steps, you can:
* Train or finetune a model to generate your own images in the [training](./tutorials/basic_training) tutorial.
* See example official and community [training or finetuning scripts](https://github.com/huggingf... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/quicktour.md | https://huggingface.co/docs/diffusers/en/quicktour/#next-steps | #next-steps | .md | 2_7 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/index.md | https://huggingface.co/docs/diffusers/en/index/ | .md | 3_0 | |
🤗 Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. Whether you're looking for a simple inference solution or want to train your own diffusion model, 🤗 Diffusers is a modular toolbox that supports both. Our library is des... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/index.md | https://huggingface.co/docs/diffusers/en/index/#diffusers | #diffusers | .md | 3_1 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/ | .md | 4_0 | |
🤗 Diffusers is tested on Python 3.8+, PyTorch 1.7.0+, and Flax. Follow the installation instructions below for the deep learning library you are using:
- [PyTorch](https://pytorch.org/get-started/locally/) installation instructions
- [Flax](https://flax.readthedocs.io/en/latest/) installation instructions | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#installation | #installation | .md | 4_1 |
You should install 🤗 Diffusers in a [virtual environment](https://docs.python.org/3/library/venv.html).
If you're unfamiliar with Python virtual environments, take a look at this [guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
A virtual environment makes it easier to manage... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#install-with-pip | #install-with-pip | .md | 4_2 |
After activating your virtual environment, with `conda` (maintained by the community):
```bash
conda install -c conda-forge diffusers
``` | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#install-with-conda | #install-with-conda | .md | 4_3 |
Before installing 🤗 Diffusers from source, make sure you have PyTorch and 🤗 Accelerate installed.
To install 🤗 Accelerate:
```bash
pip install accelerate
```
Then install 🤗 Diffusers from source:
```bash
pip install git+https://github.com/huggingface/diffusers
```
This command installs the bleeding edge `... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#install-from-source | #install-from-source | .md | 4_4 |
You will need an editable install if you'd like to:
* Use the `main` version of the source code.
* Contribute to 🤗 Diffusers and need to test changes in the code.
Clone the repository and install 🤗 Diffusers with the following commands:
```bash
git clone https://github.com/huggingface/diffusers.git
cd diffusers... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#editable-install | #editable-install | .md | 4_5 |
Model weights and files are downloaded from the Hub to a cache which is usually your home directory. You can change the cache location by specifying the `HF_HOME` or `HUGGINFACE_HUB_CACHE` environment variables or configuring the `cache_dir` parameter in methods like [`~DiffusionPipeline.from_pretrained`].
Cached fil... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#cache | #cache | .md | 4_6 |
Our library gathers telemetry information during [`~DiffusionPipeline.from_pretrained`] requests.
The data gathered includes the version of 🤗 Diffusers and PyTorch/Flax, the requested model or pipeline class,
and the path to a pretrained checkpoint if it is hosted on the Hugging Face Hub.
This usage data helps us debu... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/installation.md | https://huggingface.co/docs/diffusers/en/installation/#telemetry-logging | #telemetry-logging | .md | 4_7 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/xformers.md | https://huggingface.co/docs/diffusers/en/optimization/xformers/ | .md | 5_0 | |
We recommend [xFormers](https://github.com/facebookresearch/xformers) for both inference and training. In our tests, the optimizations performed in the attention blocks allow for both faster speed and reduced memory consumption.
Install xFormers from `pip`:
```bash
pip install xformers
```
<Tip>
The xFormers `p... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/xformers.md | https://huggingface.co/docs/diffusers/en/optimization/xformers/#xformers | #xformers | .md | 5_1 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/ | .md | 6_0 | |
🤗 Diffusers supports the latest optimizations from [PyTorch 2.0](https://pytorch.org/get-started/pytorch-2.0/) which include:
1. A memory-efficient attention implementation, scaled dot product attention, without requiring any extra dependencies such as xFormers.
2. [`torch.compile`](https://pytorch.org/tutorials/int... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#pytorch-20 | #pytorch-20 | .md | 6_1 |
[`torch.nn.functional.scaled_dot_product_attention`](https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention) (SDPA) is an optimized and memory-efficient attention (similar to xFormers) that automatically enables several other optimizations depending on the model inputs and GPU type. ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#scaled-dot-product-attention | #scaled-dot-product-attention | .md | 6_2 |
The `torch.compile` function can often provide an additional speed-up to your PyTorch code. In 🤗 Diffusers, it is usually best to wrap the UNet with `torch.compile` because it does most of the heavy lifting in the pipeline.
```python
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#torchcompile | #torchcompile | .md | 6_3 |
We conducted a comprehensive benchmark with PyTorch 2.0's efficient attention implementation and `torch.compile` across different GPUs and batch sizes for five of our most used pipelines. The code is benchmarked on 🤗 Diffusers v0.17.0.dev0 to optimize `torch.compile` usage (see [here](https://github.com/huggingface/di... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#benchmark | #benchmark | .md | 6_4 |
```python
from diffusers import DiffusionPipeline
import torch
path = "stable-diffusion-v1-5/stable-diffusion-v1-5"
run_compile = True # Set True / False
pipe = DiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16, use_safetensors=True)
pipe = pipe.to("cuda")
pipe.unet.to(memory_format=torch.channels_l... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#stable-diffusion-text-to-image | #stable-diffusion-text-to-image | .md | 6_5 |
```python
from diffusers import StableDiffusionImg2ImgPipeline
from diffusers.utils import load_image
import torch
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
init_image = load_image(url)
init_image = init_image.resize((512, 512))
p... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#stable-diffusion-image-to-image | #stable-diffusion-image-to-image | .md | 6_6 |
```python
from diffusers import StableDiffusionInpaintPipeline
from diffusers.utils import load_image
import torch
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusi... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#stable-diffusion-inpainting | #stable-diffusion-inpainting | .md | 6_7 |
```python
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from diffusers.utils import load_image
import torch
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
init_image = load_image(url)
init_image = init_image.r... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#controlnet | #controlnet | .md | 6_8 |
```python
from diffusers import DiffusionPipeline
import torch
run_compile = True # Set True / False
pipe_1 = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-M-v1.0", variant="fp16", text_encoder=None, torch_dtype=torch.float16, use_safetensors=True)
pipe_1.to("cuda")
pipe_2 = DiffusionPipeline.from_pretrained("De... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#deepfloyd-if-text-to-image--upscaling | #deepfloyd-if-text-to-image--upscaling | .md | 6_9 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 21.66 | 23.13 | 44.03 | 49.74 |
| SD - img2img | 21.81 | 22.40 | 43.92 | 46.32 |
| SD - inpaint | 22.24 | 23.23 | 43.76 ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#a100-batch-size-1 | #a100-batch-size-1 | .md | 6_10 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 11.6 | 13.12 | 14.62 | 17.27 |
| SD - img2img | 11.47 | 13.06 | 14.66 | 17.25 |
| SD - inpaint | 11.67 | 13.31 | 14.88 |... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#a100-batch-size-4 | #a100-batch-size-4 | .md | 6_11 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 3.04 | 3.6 | 3.83 | 4.68 |
| SD - img2img | 2.98 | 3.58 | 3.83 | 4.67 |
| SD - inpaint | 3.04 | 3.66 | 3.9 | 4.76 |
| SD... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#a100-batch-size-16 | #a100-batch-size-16 | .md | 6_12 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 18.99 | 19.14 | 20.95 | 22.17 |
| SD - img2img | 18.56 | 19.18 | 20.95 | 22.11 |
| SD - inpaint | 19.14 | 19.06 | 21.08 ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#v100-batch-size-1 | #v100-batch-size-1 | .md | 6_13 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 5.96 | 5.89 | 6.83 | 6.86 |
| SD - img2img | 5.90 | 5.91 | 6.81 | 6.82 |
| SD - inpaint | 5.99 | 6.03 | 6.93 | 6.95 |
| ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#v100-batch-size-4 | #v100-batch-size-4 | .md | 6_14 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 1.66 | 1.66 | 1.92 | 1.90 |
| SD - img2img | 1.65 | 1.65 | 1.91 | 1.89 |
| SD - inpaint | 1.69 | 1.69 | 1.95 | 1.93 |
| ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#v100-batch-size-16 | #v100-batch-size-16 | .md | 6_15 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 6.9 | 6.95 | 7.3 | 7.56 |
| SD - img2img | 6.84 | 6.99 | 7.04 | 7.55 |
| SD - inpaint | 6.91 | 6.7 | 7.01 | 7.37 |
| SD ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#t4-batch-size-1 | #t4-batch-size-1 | .md | 6_16 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 1.79 | 1.79 | 2.03 | 1.99 |
| SD - img2img | 1.77 | 1.77 | 2.05 | 2.04 |
| SD - inpaint | 1.81 | 1.82 | 2.09 | 2.09 |
| ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#t4-batch-size-4 | #t4-batch-size-4 | .md | 6_17 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 2.34s | 2.30s | OOM after 2nd iteration | 1.99s |
| SD - img2img | 2.35s | 2.31s | OOM after warmup | 2.00s |
| SD - inp... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#t4-batch-size-16 | #t4-batch-size-16 | .md | 6_18 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 22.56 | 22.84 | 23.84 | 25.69 |
| SD - img2img | 22.25 | 22.61 | 24.1 | 25.83 |
| SD - inpaint | 22.22 | 22.54 | 24.26 |... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-3090-batch-size-1 | #rtx-3090-batch-size-1 | .md | 6_19 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 6.46 | 6.35 | 7.29 | 7.3 |
| SD - img2img | 6.33 | 6.27 | 7.31 | 7.26 |
| SD - inpaint | 6.47 | 6.4 | 7.44 | 7.39 |
| SD... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-3090-batch-size-4 | #rtx-3090-batch-size-4 | .md | 6_20 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 1.7 | 1.69 | 1.93 | 1.91 |
| SD - img2img | 1.68 | 1.67 | 1.93 | 1.9 |
| SD - inpaint | 1.72 | 1.71 | 1.97 | 1.94 |
| SD... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-3090-batch-size-16 | #rtx-3090-batch-size-16 | .md | 6_21 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 40.5 | 41.89 | 44.65 | 49.81 |
| SD - img2img | 40.39 | 41.95 | 44.46 | 49.8 |
| SD - inpaint | 40.51 | 41.88 | 44.58 | ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-4090-batch-size-1 | #rtx-4090-batch-size-1 | .md | 6_22 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 12.62 | 12.84 | 15.32 | 15.59 |
| SD - img2img | 12.61 | 12,.79 | 15.35 | 15.66 |
| SD - inpaint | 12.65 | 12.81 | 15.3 ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-4090-batch-size-4 | #rtx-4090-batch-size-4 | .md | 6_23 |
| **Pipeline** | **torch 2.0 - <br>no compile** | **torch nightly - <br>no compile** | **torch 2.0 - <br>compile** | **torch nightly - <br>compile** |
|:---:|:---:|:---:|:---:|:---:|
| SD - txt2img | 3.17 | 3.2 | 3.84 | 3.85 |
| SD - img2img | 3.16 | 3.2 | 3.84 | 3.85 |
| SD - inpaint | 3.17 | 3.2 | 3.85 | 3.85 |
| SD ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#rtx-4090-batch-size-16 | #rtx-4090-batch-size-16 | .md | 6_24 |
* Follow this [PR](https://github.com/huggingface/diffusers/pull/3313) for more details on the environment used for conducting the benchmarks.
* For the DeepFloyd IF pipeline where batch sizes > 1, we only used a batch size of > 1 in the first IF pipeline for text-to-image generation and NOT for upscaling. That means t... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/torch2.0.md | https://huggingface.co/docs/diffusers/en/optimization/torch2.0/#notes | #notes | .md | 6_25 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/ | .md | 7_0 | |
[Core ML](https://developer.apple.com/documentation/coreml) is the model format and machine learning library supported by Apple frameworks. If you are interested in running Stable Diffusion models inside your macOS or iOS/iPadOS apps, this guide will show you how to convert existing PyTorch checkpoints into the Core ML... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#how-to-run-stable-diffusion-with-core-ml | #how-to-run-stable-diffusion-with-core-ml | .md | 7_1 |
Stable Diffusion weights (or checkpoints) are stored in the PyTorch format, so you need to convert them to the Core ML format before we can use them inside native apps.
Thankfully, Apple engineers developed [a conversion tool](https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml) based on `diffu... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#stable-diffusion-core-ml-checkpoints | #stable-diffusion-core-ml-checkpoints | .md | 7_2 |
Stable Diffusion models can be converted to different Core ML variants intended for different purposes:
- The type of attention blocks used. The attention operation is used to "pay attention" to the relationship between different areas in the image representations and to understand how the image and text representati... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#selecting-the-core-ml-variant-to-use | #selecting-the-core-ml-variant-to-use | .md | 7_3 |
Install the following libraries to run Core ML inference in Python:
```bash
pip install huggingface_hub
pip install git+https://github.com/apple/ml-stable-diffusion
``` | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#core-ml-inference-in-python | #core-ml-inference-in-python | .md | 7_4 |
To run inference in Python, use one of the versions stored in the `packages` folders because the `compiled` ones are only compatible with Swift. You may choose whether you want to use `original` or `split_einsum` attention.
This is how you'd download the `original` attention variant from the Hub to a directory called... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#download-the-model-checkpoints | #download-the-model-checkpoints | .md | 7_5 |
Once you have downloaded a snapshot of the model, you can test it using Apple's Python script.
```shell
python -m python_coreml_stable_diffusion.pipeline --prompt "a photo of an astronaut riding a horse on mars" -i ./models/coreml-stable-diffusion-v1-4_original_packages/original/packages -o </path/to/output/image> --... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#inferencepython-inference | #inferencepython-inference | .md | 7_6 |
Running inference in Swift is slightly faster than in Python because the models are already compiled in the `mlmodelc` format. This is noticeable on app startup when the model is loaded but shouldn’t be noticeable if you run several generations afterward. | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#core-ml-inference-in-swift | #core-ml-inference-in-swift | .md | 7_7 |
To run inference in Swift on your Mac, you need one of the `compiled` checkpoint versions. We recommend you download them locally using Python code similar to the previous example, but with one of the `compiled` variants:
```Python
from huggingface_hub import snapshot_download
from pathlib import Path
repo_id = "app... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#download | #download | .md | 7_8 |
To run inference, please clone Apple's repo:
```bash
git clone https://github.com/apple/ml-stable-diffusion
cd ml-stable-diffusion
```
And then use Apple's command line tool, [Swift Package Manager](https://www.swift.org/package-manager/#):
```bash
swift run StableDiffusionSample --resource-path models/coreml-sta... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#inferenceswift-inference | #inferenceswift-inference | .md | 7_9 |
The Core ML models and inference code don't support many of the features, options, and flexibility of 🧨 Diffusers. These are some of the limitations to keep in mind:
- Core ML models are only suitable for inference. They can't be used for training or fine-tuning.
- Only two schedulers have been ported to Swift, the ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#supported-diffusers-features | #supported-diffusers-features | .md | 7_10 |
One easy way to run Stable Diffusion on your own Apple hardware is to use [our open-source Swift repo](https://github.com/huggingface/swift-coreml-diffusers), based on `diffusers` and Apple's conversion and inference repo. You can study the code, compile it with [Xcode](https://developer.apple.com/xcode/) and adapt it ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/coreml.md | https://huggingface.co/docs/diffusers/en/optimization/coreml/#native-diffusers-swift-app | #native-diffusers-swift-app | .md | 7_11 |
[T-GATE](https://github.com/HaozheLiu-ST/T-GATE/tree/main) accelerates inference for [Stable Diffusion](../api/pipelines/stable_diffusion/overview), [PixArt](../api/pipelines/pixart), and [Latency Consistency Model](../api/pipelines/latent_consistency_models.md) pipelines by skipping the cross-attention calculation onc... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/tgate.md | https://huggingface.co/docs/diffusers/en/optimization/tgate/#t-gate | #t-gate | .md | 8_0 |
| Model | MACs | Param | Latency | Zero-shot 10K-FID on MS-COCO |
|-----------------------|----------|-----------|---------|---------------------------|
| SD-1.5 | 16.938T | 859.520M | 7.032s | 23.927 |
| SD-1.5 w/ T-GATE | 9.875T | 815.557M | 4.313s... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/tgate.md | https://huggingface.co/docs/diffusers/en/optimization/tgate/#benchmarks | #benchmarks | .md | 8_1 |
<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-performance.png">
</div>
<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/hunyua... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/para_attn.md | https://huggingface.co/docs/diffusers/en/optimization/para_attn/#paraattention | #paraattention | .md | 9_0 |
Caching the output of the transformers blocks in the model and reusing them in the next inference steps reduces the computation cost and makes inference faster.
However, it is hard to decide when to reuse the cache to ensure quality generated images or videos. ParaAttention directly uses the **residual difference of ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/para_attn.md | https://huggingface.co/docs/diffusers/en/optimization/para_attn/#first-block-cache | #first-block-cache | .md | 9_1 |
fp8 with dynamic quantization further speeds up inference and reduces memory usage. Both the activations and weights must be quantized in order to use the 8-bit [NVIDIA Tensor Cores](https://www.nvidia.com/en-us/data-center/tensor-cores/).
Use `float8_weight_only` and `float8_dynamic_activation_float8_weight` to quan... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/para_attn.md | https://huggingface.co/docs/diffusers/en/optimization/para_attn/#fp8-quantization | #fp8-quantization | .md | 9_2 |
Context Parallelism parallelizes inference and scales with multiple GPUs. The ParaAttention compositional design allows you to combine Context Parallelism with First Block Cache and dynamic quantization.
> [!TIP]
> Refer to the [ParaAttention](https://github.com/chengzeyi/ParaAttention/tree/main) repository for detai... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/para_attn.md | https://huggingface.co/docs/diffusers/en/optimization/para_attn/#context-parallelism | #context-parallelism | .md | 9_3 |
<hfoptions id="conclusion">
<hfoption id="FLUX-1.dev">
| GPU Type | Number of GPUs | Optimizations | Wall Time (s) | Speedup |
| - | - | - | - | - |
| NVIDIA L20 | 1 | Baseline | 26.36 | 1.00x |
| NVIDIA L20 | 1 | FBCache (rdt=0.08) | 17.01 | 1.55x |
| NVIDIA L20 | 1 | FP8 DQ | 13.40 | 1.96x |
| NVIDIA L20 | 1 | FBCa... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/para_attn.md | https://huggingface.co/docs/diffusers/en/optimization/para_attn/#benchmarks | #benchmarks | .md | 9_4 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/ | .md | 10_0 | |
A barrier to using diffusion models is the large amount of memory required. To overcome this challenge, there are several memory-reducing techniques you can use to run even some of the largest models on free-tier or consumer GPUs. Some of these techniques can even be combined to further reduce memory usage.
<Tip>
I... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#reduce-memory-usage | #reduce-memory-usage | .md | 10_1 |
Sliced VAE enables decoding large batches of images with limited VRAM or batches with 32 images or more by decoding the batches of latents one image at a time. You'll likely want to couple this with [`~ModelMixin.enable_xformers_memory_efficient_attention`] to reduce memory use further if you have xFormers installed. ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#sliced-vae | #sliced-vae | .md | 10_2 |
Tiled VAE processing also enables working with large images on limited VRAM (for example, generating 4k images on 8GB of VRAM) by splitting the image into overlapping tiles, decoding the tiles, and then blending the outputs together to compose the final image. You should also used tiled VAE with [`~ModelMixin.enable_xf... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#tiled-vae | #tiled-vae | .md | 10_3 |
Offloading the weights to the CPU and only loading them on the GPU when performing the forward pass can also save memory. Often, this technique can reduce memory consumption to less than 3GB.
To perform CPU offloading, call [`~StableDiffusionPipeline.enable_sequential_cpu_offload`]:
```Python
import torch
from diff... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#cpu-offloading | #cpu-offloading | .md | 10_4 |
<Tip>
Model offloading requires 🤗 Accelerate version 0.17.0 or higher.
</Tip>
[Sequential CPU offloading](#cpu-offloading) preserves a lot of memory but it makes inference slower because submodules are moved to GPU as needed, and they're immediately returned to the CPU when a new module runs.
Full-model offloa... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#model-offloading | #model-offloading | .md | 10_5 |
The channels-last memory format is an alternative way of ordering NCHW tensors in memory to preserve dimension ordering. Channels-last tensors are ordered in such a way that the channels become the densest dimension (storing images pixel-per-pixel). Since not all operators currently support the channels-last format, it... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#channels-last-memory-format | #channels-last-memory-format | .md | 10_6 |
Tracing runs an example input tensor through the model and captures the operations that are performed on it as that input makes its way through the model's layers. The executable or `ScriptFunction` that is returned is optimized with just-in-time compilation.
To trace a UNet:
```python
import time
import torch
from... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#tracing | #tracing | .md | 10_7 |
Recent work on optimizing bandwidth in the attention block has generated huge speed-ups and reductions in GPU memory usage. The most recent type of memory-efficient attention is [Flash Attention](https://arxiv.org/abs/2205.14135) (you can check out the original code at [HazyResearch/flash-attention](https://github.com/... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/memory.md | https://huggingface.co/docs/diffusers/en/optimization/memory/#memory-efficient-attention | #memory-efficient-attention | .md | 10_8 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/neuron.md | https://huggingface.co/docs/diffusers/en/optimization/neuron/ | .md | 11_0 | |
Diffusers functionalities are available on [AWS Inf2 instances](https://aws.amazon.com/ec2/instance-types/inf2/), which are EC2 instances powered by [Neuron machine learning accelerators](https://aws.amazon.com/machine-learning/inferentia/). These instances aim to provide better compute performance (higher throughput, ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/neuron.md | https://huggingface.co/docs/diffusers/en/optimization/neuron/#aws-neuron | #aws-neuron | .md | 11_1 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/habana.md | https://huggingface.co/docs/diffusers/en/optimization/habana/ | .md | 12_0 | |
🤗 Diffusers is compatible with Habana Gaudi through 🤗 [Optimum](https://huggingface.co/docs/optimum/habana/usage_guides/stable_diffusion). Follow the [installation](https://docs.habana.ai/en/latest/Installation_Guide/index.html) guide to install the SynapseAI and Gaudi drivers, and then install Optimum Habana:
```b... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/habana.md | https://huggingface.co/docs/diffusers/en/optimization/habana/#habana-gaudi | #habana-gaudi | .md | 12_1 |
We benchmarked Habana's first-generation Gaudi and Gaudi2 with the [Habana/stable-diffusion](https://huggingface.co/Habana/stable-diffusion) and [Habana/stable-diffusion-2](https://huggingface.co/Habana/stable-diffusion-2) Gaudi configurations (mixed precision bf16/fp32) to demonstrate their performance.
For [Stable ... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/habana.md | https://huggingface.co/docs/diffusers/en/optimization/habana/#benchmark | #benchmark | .md | 12_2 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/deepcache.md | https://huggingface.co/docs/diffusers/en/optimization/deepcache/ | .md | 13_0 | |
[DeepCache](https://huggingface.co/papers/2312.00858) accelerates [`StableDiffusionPipeline`] and [`StableDiffusionXLPipeline`] by strategically caching and reusing high-level features while efficiently updating low-level features by taking advantage of the U-Net architecture.
Start by installing [DeepCache](https://... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/deepcache.md | https://huggingface.co/docs/diffusers/en/optimization/deepcache/#deepcache | #deepcache | .md | 13_1 |
We tested how much faster DeepCache accelerates [Stable Diffusion v2.1](https://huggingface.co/stabilityai/stable-diffusion-2-1) with 50 inference steps on an NVIDIA RTX A5000, using different configurations for resolution, batch size, cache interval (I), and cache branch (B).
| **Resolution** | **Batch size** | **Or... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/deepcache.md | https://huggingface.co/docs/diffusers/en/optimization/deepcache/#benchmark | #benchmark | .md | 13_2 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/open_vino.md | https://huggingface.co/docs/diffusers/en/optimization/open_vino/ | .md | 14_0 | |
🤗 [Optimum](https://github.com/huggingface/optimum-intel) provides Stable Diffusion pipelines compatible with OpenVINO to perform inference on a variety of Intel processors (see the [full list](https://docs.openvino.ai/latest/openvino_docs_OV_UG_supported_plugins_Supported_Devices.html) of supported devices).
You'll... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/open_vino.md | https://huggingface.co/docs/diffusers/en/optimization/open_vino/#openvino | #openvino | .md | 14_1 |
To load and run inference, use the [`~optimum.intel.OVStableDiffusionPipeline`]. If you want to load a PyTorch model and convert it to the OpenVINO format on-the-fly, set `export=True`:
```python
from optimum.intel import OVStableDiffusionPipeline
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
pipeline = O... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/open_vino.md | https://huggingface.co/docs/diffusers/en/optimization/open_vino/#stable-diffusion | #stable-diffusion | .md | 14_2 |
To load and run inference with SDXL, use the [`~optimum.intel.OVStableDiffusionXLPipeline`]:
```python
from optimum.intel import OVStableDiffusionXLPipeline
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
pipeline = OVStableDiffusionXLPipeline.from_pretrained(model_id)
prompt = "sailing ship in storm by Rembra... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/open_vino.md | https://huggingface.co/docs/diffusers/en/optimization/open_vino/#stable-diffusion-xl | #stable-diffusion-xl | .md | 14_3 |
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agr... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/fp16.md | https://huggingface.co/docs/diffusers/en/optimization/fp16/ | .md | 15_0 | |
There are several ways to optimize Diffusers for inference speed, such as reducing the computational burden by lowering the data precision or using a lightweight distilled model. There are also memory-efficient attention implementations, [xFormers](xformers) and [scaled dot product attention](https://pytorch.org/docs/s... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/fp16.md | https://huggingface.co/docs/diffusers/en/optimization/fp16/#speed-up-inference | #speed-up-inference | .md | 15_1 |
On Ampere and later CUDA devices, matrix multiplications and convolutions can use the [TensorFloat-32 (tf32)](https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/) mode for faster, but slightly less accurate computations. By default, PyTorch enables tf32 mode for convolutions but not matrix multipl... | /Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/optimization/fp16.md | https://huggingface.co/docs/diffusers/en/optimization/fp16/#tensorfloat-32 | #tensorfloat-32 | .md | 15_2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.