Skip to content

Commit c87ed08

Browse files
committed
feedback
1 parent 4d13a63 commit c87ed08

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/source/en/using-diffusers/scheduler_features.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,49 @@ image = pipeline(
6868
</div>
6969
</div>
7070

71+
## Timestep spacing
72+
73+
The way sample steps are selected in the schedule can affect the quality of the generated image, especially with respect to [rescaling the noise schedule](#rescale-noise-schedule), which can enable a model to generate much brighter or darker images. Diffusers provides three timestep spacing methods:
74+
75+
- `leading` creates evenly spaced steps
76+
- `linspace` includes the first and last steps and evenly selects the remaining intermediate steps
77+
- `trailing` only includes the last step and evenly selects the remaining intermediate steps starting from the end
78+
79+
It is recommended to use the `trailing` spacing method because it generates higher quality images with more details when there are fewer sample steps. But the difference in quality is not as obvious for more standard sample step values.
80+
81+
```py
82+
import torch
83+
from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler
84+
85+
pipeline = StableDiffusionXLPipeline.from_pretrained(
86+
"SG161222/RealVisXL_V4.0",
87+
torch_dtype=torch.float16,
88+
variant="fp16",
89+
).to("cuda")
90+
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config, timestep_spacing="trailing")
91+
92+
prompt = "A cinematic shot of a cute little black cat sitting on a pumpkin at night"
93+
generator = torch.Generator(device="cpu").manual_seed(2487854446)
94+
image = pipeline(
95+
prompt=prompt,
96+
negative_prompt="",
97+
generator=generator,
98+
num_inference_steps=5,
99+
).images[0]
100+
image
101+
```
102+
103+
<div class="flex gap-4">
104+
<div>
105+
<img class="rounded-xl" src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/trailing_spacing.png"/>
106+
<figcaption class="mt-2 text-center text-sm text-gray-500">trailing spacing after 5 steps</figcaption>
107+
</div>
108+
<div>
109+
<img class="rounded-xl" src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/leading_spacing.png"/>
110+
<figcaption class="mt-2 text-center text-sm text-gray-500">leading spacing after 5 steps</figcaption>
111+
</div>
112+
</div>
113+
71114
## Sigmas
72115

73116
The `sigmas` parameter is the amount of noise added at each timestep according to the timestep schedule. Like the `timesteps` parameter, you can customize the `sigmas` parameter to control how much noise is added at each step. When you use a custom `sigmas` value, the `timesteps` are calculated from the custom `sigmas` value and the default scheduler configuration is ignored.

0 commit comments

Comments
 (0)