Skip to content

Commit 31af4d1

Browse files
mkshinganton-l
andauthored
Support LMSDiscreteScheduler in LDMPipeline (#891)
* Support LMSDiscreteScheduler in LDMPipeline This is a small change to support all schedulers such as LMSDiscreteScheduler in LDMPipeline. What's changed ------- * Add the `scale_model_input` function before `step` to ensure correct denoising (L77) * Add "scale the initial noise by the standard deviation required by the scheduler" * run `make style` Co-authored-by: Anton Lozhkov <[email protected]>
1 parent dec18c8 commit 31af4d1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/diffusers/pipelines/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def __call__(
6464
)
6565
latents = latents.to(self.device)
6666

67+
# scale the initial noise by the standard deviation required by the scheduler
68+
latents = latents * self.scheduler.init_noise_sigma
69+
6770
self.scheduler.set_timesteps(num_inference_steps)
6871

6972
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
@@ -74,8 +77,9 @@ def __call__(
7477
extra_kwargs["eta"] = eta
7578

7679
for t in self.progress_bar(self.scheduler.timesteps):
80+
latent_model_input = self.scheduler.scale_model_input(latents, t)
7781
# predict the noise residual
78-
noise_prediction = self.unet(latents, t).sample
82+
noise_prediction = self.unet(latent_model_input, t).sample
7983
# compute the previous noisy sample x_t -> x_t-1
8084
latents = self.scheduler.step(noise_prediction, t, latents, **extra_kwargs).prev_sample
8185

0 commit comments

Comments
 (0)