Skip to content

Commit 61dec53

Browse files
Improve pipeline_stable_diffusion_inpaint_legacy.py (huggingface#1585)
* update inpaint_legacy to allow the use of predicted noise to construct intermediate diffused images * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py Co-authored-by: Patrick von Platen <[email protected]> Co-authored-by: Patrick von Platen <[email protected]>
1 parent badddee commit 61dec53

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def __call__(
430430
guidance_scale: Optional[float] = 7.5,
431431
negative_prompt: Optional[Union[str, List[str]]] = None,
432432
num_images_per_prompt: Optional[int] = 1,
433+
add_predicted_noise: Optional[bool] = False,
433434
eta: Optional[float] = 0.0,
434435
generator: Optional[torch.Generator] = None,
435436
output_type: Optional[str] = "pil",
@@ -471,6 +472,9 @@ def __call__(
471472
if `guidance_scale` is less than `1`).
472473
num_images_per_prompt (`int`, *optional*, defaults to 1):
473474
The number of images to generate per prompt.
475+
add_predicted_noise (`bool`, *optional*, defaults to True):
476+
Use predicted noise instead of random noise when constructing noisy versions of the original image in
477+
the reverse diffusion process
474478
eta (`float`, *optional*, defaults to 0.0):
475479
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
476480
[`schedulers.DDIMScheduler`], will be ignored for others.
@@ -561,7 +565,12 @@ def __call__(
561565
# compute the previous noisy sample x_t -> x_t-1
562566
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs).prev_sample
563567
# masking
564-
init_latents_proper = self.scheduler.add_noise(init_latents_orig, noise, torch.tensor([t]))
568+
if add_predicted_noise:
569+
init_latents_proper = self.scheduler.add_noise(
570+
init_latents_orig, noise_pred_uncond, torch.tensor([t])
571+
)
572+
else:
573+
init_latents_proper = self.scheduler.add_noise(init_latents_orig, noise, torch.tensor([t]))
565574

566575
latents = (init_latents_proper * mask) + (latents * (1 - mask))
567576

0 commit comments

Comments
 (0)