Skip to content

Commit 554b374

Browse files
Merge branch 'main' of https://github.com/huggingface/diffusers into main
2 parents d5ab55e + a052019 commit 554b374

File tree

76 files changed

+2328
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2328
-473
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,6 @@ tags
163163
*.lock
164164

165165
# DS_Store (MacOS)
166-
.DS_Store
166+
.DS_Store
167+
# RL pipelines may produce mp4 outputs
168+
*.mp4

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,7 @@ it before the pipeline and pass it to `from_pretrained`.
152152
```python
153153
from diffusers import LMSDiscreteScheduler
154154

155-
lms = LMSDiscreteScheduler.from_config("CompVis/stable-diffusion-v1-4", subfolder="scheduler")
156-
157-
pipe = StableDiffusionPipeline.from_pretrained(
158-
"runwayml/stable-diffusion-v1-5",
159-
revision="fp16",
160-
torch_dtype=torch.float16,
161-
scheduler=lms,
162-
)
163-
pipe = pipe.to("cuda")
155+
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
164156

165157
prompt = "a photo of an astronaut riding a horse on mars"
166158
image = pipe(prompt).images[0]

docs/source/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- sections:
1111
- local: using-diffusers/loading
1212
title: "Loading Pipelines, Models, and Schedulers"
13+
- local: using-diffusers/schedulers
14+
title: "Using different Schedulers"
1315
- local: using-diffusers/configuration
1416
title: "Configuring Pipelines, Models, and Schedulers"
1517
- local: using-diffusers/custom_pipeline_overview

docs/source/api/configuration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ specific language governing permissions and limitations under the License.
1515
In Diffusers, schedulers of type [`schedulers.scheduling_utils.SchedulerMixin`], and models of type [`ModelMixin`] inherit from [`ConfigMixin`] which conveniently takes care of storing all parameters that are
1616
passed to the respective `__init__` methods in a JSON-configuration file.
1717

18-
TODO(PVP) - add example and better info here
19-
2018
## ConfigMixin
19+
2120
[[autodoc]] ConfigMixin
21+
- load_config
2222
- from_config
2323
- save_config

docs/source/api/models.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ The models are built on the base class ['ModelMixin'] that is a `torch.nn.module
2222
## UNet2DOutput
2323
[[autodoc]] models.unet_2d.UNet2DOutput
2424

25-
## UNet1DModel
26-
[[autodoc]] UNet1DModel
27-
2825
## UNet2DModel
2926
[[autodoc]] UNet2DModel
3027

28+
## UNet1DOutput
29+
[[autodoc]] models.unet_1d.UNet1DOutput
30+
31+
## UNet1DModel
32+
[[autodoc]] UNet1DModel
33+
3134
## UNet2DConditionOutput
3235
[[autodoc]] models.unet_2d_condition.UNet2DConditionOutput
3336

docs/source/api/pipelines/cycle_diffusion.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ from diffusers import CycleDiffusionPipeline, DDIMScheduler
3939
# load the pipeline
4040
# make sure you're logged in with `huggingface-cli login`
4141
model_id_or_path = "CompVis/stable-diffusion-v1-4"
42-
scheduler = DDIMScheduler.from_config(model_id_or_path, subfolder="scheduler")
42+
scheduler = DDIMScheduler.from_pretrained(model_id_or_path, subfolder="scheduler")
4343
pipe = CycleDiffusionPipeline.from_pretrained(model_id_or_path, scheduler=scheduler).to("cuda")
4444

4545
# let's download an initial image

docs/source/api/pipelines/repaint.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ original_image = download_image(img_url).resize((256, 256))
5454
mask_image = download_image(mask_url).resize((256, 256))
5555

5656
# Load the RePaint scheduler and pipeline based on a pretrained DDPM model
57-
scheduler = RePaintScheduler.from_config("google/ddpm-ema-celebahq-256")
57+
scheduler = RePaintScheduler.from_pretrained("google/ddpm-ema-celebahq-256")
5858
pipe = RePaintPipeline.from_pretrained("google/ddpm-ema-celebahq-256", scheduler=scheduler)
5959
pipe = pipe.to("cuda")
6060

docs/source/api/pipelines/stable_diffusion.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ For more details about how Stable Diffusion works and how it differs from the ba
3434
### How to load and use different schedulers.
3535

3636
The stable diffusion pipeline uses [`PNDMScheduler`] scheduler by default. But `diffusers` provides many other schedulers that can be used with the stable diffusion pipeline such as [`DDIMScheduler`], [`LMSDiscreteScheduler`], [`EulerDiscreteScheduler`], [`EulerAncestralDiscreteScheduler`] etc.
37-
To use a different scheduler, you can pass the `scheduler` argument to `from_pretrained` method of the pipeline. For example, to use the [`EulerDiscreteScheduler`], you can do the following:
37+
To use a different scheduler, you can either change it via the [`ConfigMixin.from_config`] method or pass the `scheduler` argument to the `from_pretrained` method of the pipeline. For example, to use the [`EulerDiscreteScheduler`], you can do the following:
3838

3939
```python
40-
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
40+
>>> from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
4141

42-
euler_scheduler = EulerDiscreteScheduler.from_config("CompVis/stable-diffusion-v1-4", subfolder="scheduler")
43-
pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=euler_scheduler)
42+
>>> pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
43+
>>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
44+
45+
>>> # or
46+
>>> euler_scheduler = EulerDiscreteScheduler.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="scheduler")
47+
>>> pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=euler_scheduler)
4448
```
4549
4650

docs/source/quicktour.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ In this guide though, you'll use [`DiffusionPipeline`] for text-to-image generat
4141
```python
4242
>>> from diffusers import DiffusionPipeline
4343

44-
>>> generator = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
44+
>>> pipeline = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
4545
```
4646
4747
The [`DiffusionPipeline`] downloads and caches all modeling, tokenization, and scheduling components.
4848
Because the model consists of roughly 1.4 billion parameters, we strongly recommend running it on GPU.
4949
You can move the generator object to GPU, just like you would in PyTorch.
5050
5151
```python
52-
>>> generator.to("cuda")
52+
>>> pipeline.to("cuda")
5353
```
5454

55-
Now you can use the `generator` on your text prompt:
55+
Now you can use the `pipeline` on your text prompt:
5656

5757
```python
58-
>>> image = generator("An image of a squirrel in Picasso style").images[0]
58+
>>> image = pipeline("An image of a squirrel in Picasso style").images[0]
5959
```
6060

6161
The output is by default wrapped into a [PIL Image object](https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class).
@@ -82,7 +82,7 @@ just like we did before only that now you need to pass your `AUTH_TOKEN`:
8282
```python
8383
>>> from diffusers import DiffusionPipeline
8484

85-
>>> generator = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=AUTH_TOKEN)
85+
>>> pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=AUTH_TOKEN)
8686
```
8787

8888
If you do not pass your authentication token you will see that the diffusion system will not be correctly
@@ -102,7 +102,7 @@ token. Assuming that `"./stable-diffusion-v1-5"` is the local path to the cloned
102102
you can also load the pipeline as follows:
103103

104104
```python
105-
>>> generator = DiffusionPipeline.from_pretrained("./stable-diffusion-v1-5")
105+
>>> pipeline = DiffusionPipeline.from_pretrained("./stable-diffusion-v1-5")
106106
```
107107

108108
Running the pipeline is then identical to the code above as it's the same model architecture.
@@ -115,19 +115,20 @@ Running the pipeline is then identical to the code above as it's the same model
115115

116116
Diffusion systems can be used with multiple different [schedulers](./api/schedulers) each with their
117117
pros and cons. By default, Stable Diffusion runs with [`PNDMScheduler`], but it's very simple to
118-
use a different scheduler. *E.g.* if you would instead like to use the [`LMSDiscreteScheduler`] scheduler,
118+
use a different scheduler. *E.g.* if you would instead like to use the [`EulerDiscreteScheduler`] scheduler,
119119
you could use it as follows:
120120

121121
```python
122-
>>> from diffusers import LMSDiscreteScheduler
122+
>>> from diffusers import EulerDiscreteScheduler
123123

124-
>>> scheduler = LMSDiscreteScheduler.from_config("runwayml/stable-diffusion-v1-5", subfolder="scheduler")
124+
>>> pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=AUTH_TOKEN)
125125

126-
>>> generator = StableDiffusionPipeline.from_pretrained(
127-
... "runwayml/stable-diffusion-v1-5", scheduler=scheduler, use_auth_token=AUTH_TOKEN
128-
... )
126+
>>> # change scheduler to Euler
127+
>>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
129128
```
130129

130+
For more in-detail information on how to change between schedulers, please refer to the [Using Schedulers](./using-diffusers/schedulers) guide.
131+
131132
[Stability AI's](https://stability.ai/) Stable Diffusion model is an impressive image generation model
132133
and can do much more than just generating images from text. We have dedicated a whole documentation page,
133134
just for Stable Diffusion [here](./conceptual/stable_diffusion).

docs/source/using-diffusers/loading.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In the following we explain in-detail how to easily load:
1919

2020
- *Complete Diffusion Pipelines* via the [`DiffusionPipeline.from_pretrained`]
2121
- *Diffusion Models* via [`ModelMixin.from_pretrained`]
22-
- *Schedulers* via [`ConfigMixin.from_config`]
22+
- *Schedulers* via [`SchedulerMixin.from_pretrained`]
2323

2424
## Loading pipelines
2525

@@ -137,15 +137,15 @@ from diffusers import DiffusionPipeline, EulerDiscreteScheduler, DPMSolverMultis
137137

138138
repo_id = "runwayml/stable-diffusion-v1-5"
139139

140-
scheduler = EulerDiscreteScheduler.from_config(repo_id, subfolder="scheduler")
140+
scheduler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
141141
# or
142-
# scheduler = DPMSolverMultistepScheduler.from_config(repo_id, subfolder="scheduler")
142+
# scheduler = DPMSolverMultistepScheduler.from_pretrained(repo_id, subfolder="scheduler")
143143

144144
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, scheduler=scheduler)
145145
```
146146

147147
Three things are worth paying attention to here.
148-
- First, the scheduler is loaded with [`ConfigMixin.from_config`] since it only depends on a configuration file and not any parameterized weights
148+
- First, the scheduler is loaded with [`SchedulerMixin.from_pretrained`]
149149
- Second, the scheduler is loaded with a function argument, called `subfolder="scheduler"` as the configuration of stable diffusion's scheduling is defined in a [subfolder of the official pipeline repository](https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main/scheduler)
150150
- Third, the scheduler instance can simply be passed with the `scheduler` keyword argument to [`DiffusionPipeline.from_pretrained`]. This works because the [`StableDiffusionPipeline`] defines its scheduler with the `scheduler` attribute. It's not possible to use a different name, such as `sampler=scheduler` since `sampler` is not a defined keyword for [`StableDiffusionPipeline.__init__`]
151151

@@ -337,8 +337,8 @@ model = UNet2DModel.from_pretrained(repo_id)
337337

338338
## Loading schedulers
339339

340-
Schedulers cannot be loaded via a `from_pretrained` method, but instead rely on [`ConfigMixin.from_config`]. Schedulers are **not parameterized** or **trained**, but instead purely defined by a configuration file.
341-
Therefore the loading method was given a different name here.
340+
Schedulers rely on [`SchedulerMixin.from_pretrained`]. Schedulers are **not parameterized** or **trained**, but instead purely defined by a configuration file.
341+
For consistency, we use the same method name as we do for models or pipelines, but no weights are loaded in this case.
342342

343343
In constrast to pipelines or models, loading schedulers does not consume any significant amount of memory and the same configuration file can often be used for a variety of different schedulers.
344344
For example, all of:
@@ -367,13 +367,13 @@ from diffusers import (
367367

368368
repo_id = "runwayml/stable-diffusion-v1-5"
369369

370-
ddpm = DDPMScheduler.from_config(repo_id, subfolder="scheduler")
371-
ddim = DDIMScheduler.from_config(repo_id, subfolder="scheduler")
372-
pndm = PNDMScheduler.from_config(repo_id, subfolder="scheduler")
373-
lms = LMSDiscreteScheduler.from_config(repo_id, subfolder="scheduler")
374-
euler_anc = EulerAncestralDiscreteScheduler.from_config(repo_id, subfolder="scheduler")
375-
euler = EulerDiscreteScheduler.from_config(repo_id, subfolder="scheduler")
376-
dpm = DPMSolverMultistepScheduler.from_config(repo_id, subfolder="scheduler")
370+
ddpm = DDPMScheduler.from_pretrained(repo_id, subfolder="scheduler")
371+
ddim = DDIMScheduler.from_pretrained(repo_id, subfolder="scheduler")
372+
pndm = PNDMScheduler.from_pretrained(repo_id, subfolder="scheduler")
373+
lms = LMSDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
374+
euler_anc = EulerAncestralDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
375+
euler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
376+
dpm = DPMSolverMultistepScheduler.from_pretrained(repo_id, subfolder="scheduler")
377377

378378
# replace `dpm` with any of `ddpm`, `ddim`, `pndm`, `lms`, `euler`, `euler_anc`
379379
pipeline = StableDiffusionPipeline.from_pretrained(repo_id, scheduler=dpm)

0 commit comments

Comments
 (0)