From 85b97cc49c4766cb47306e71e552871a0791ea29 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 13 Sep 2022 20:12:24 +0300 Subject: [PATCH] bandaid for broken ddim sampling #389 --- modules/sd_samplers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/sd_samplers.py b/modules/sd_samplers.py index 95d24299..7ef507f1 100644 --- a/modules/sd_samplers.py +++ b/modules/sd_samplers.py @@ -97,7 +97,7 @@ class VanillaStableDiffusionSampler: def sample_img2img(self, p, x, noise, conditioning, unconditional_conditioning): t_enc = int(min(p.denoising_strength, 0.999) * p.steps) - # existing code fails with cetin step counts, like 9 + # existing code fails with cetain step counts, like 9 try: self.sampler.make_schedule(ddim_num_steps=p.steps, verbose=False) except Exception: @@ -122,7 +122,12 @@ class VanillaStableDiffusionSampler: self.nmask = None self.init_latent = None - samples_ddim, _ = self.sampler.sample(S=p.steps, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=p.cfg_scale, unconditional_conditioning=unconditional_conditioning, x_T=x) + # existing code fails with cetin step counts, like 9 + try: + samples_ddim, _ = self.sampler.sample(S=p.steps, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=p.cfg_scale, unconditional_conditioning=unconditional_conditioning, x_T=x) + except Exception: + samples_ddim, _ = self.sampler.sample(S=p.steps+1, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=p.cfg_scale, unconditional_conditioning=unconditional_conditioning, x_T=x) + return samples_ddim