Remove additional noise in final sample of DDIM inference process

This commit is contained in:
hugojarkoff 2024-01-18 18:31:00 +01:00 committed by hugojarkoff
parent a1f50f3f9d
commit 17d9701dde
2 changed files with 7 additions and 3 deletions

View file

@ -52,6 +52,12 @@ class DDIM(Scheduler):
),
)
predicted_x = (x - sqrt(1 - current_scale_factor**2) * noise) / current_scale_factor
denoised_x = previous_scale_factor * predicted_x + sqrt(1 - previous_scale_factor**2) * noise
noise_factor = sqrt(1 - previous_scale_factor**2)
# Do not add noise at the last step to avoid visual artifacts.
if step == self.num_inference_steps - 1:
noise_factor = 0
denoised_x = previous_scale_factor * predicted_x + noise_factor * noise
return denoised_x

View file

@ -46,7 +46,6 @@ def test_ddim_diffusers():
beta_schedule="scaled_linear",
beta_start=0.00085,
num_train_timesteps=1000,
set_alpha_to_one=False,
steps_offset=1,
clip_sample=False,
)
@ -103,7 +102,6 @@ def test_scheduler_remove_noise():
beta_schedule="scaled_linear",
beta_start=0.00085,
num_train_timesteps=1000,
set_alpha_to_one=False,
steps_offset=1,
clip_sample=False,
)