Skip to content

Commit

Permalink
revert to applying mask before denoising for k-diffusion, like it was…
Browse files Browse the repository at this point in the history
… before
  • Loading branch information
AUTOMATIC1111 committed Aug 14, 2023
1 parent cda2f0a commit c1a31ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/sd_samplers_cfg_denoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, sampler):
self.sampler = sampler
self.model_wrap = None
self.p = None
self.mask_before_denoising = False

@property
def inner_model(self):
Expand Down Expand Up @@ -104,7 +105,7 @@ def forward(self, x, sigma, uncond, cond, cond_scale, s_min_uncond, image_cond):

assert not is_edit_model or all(len(conds) == 1 for conds in conds_list), "AND is not supported for InstructPix2Pix checkpoint (unless using Image CFG scale = 1.0)"

if self.mask is not None:
if self.mask_before_denoising and self.mask is not None:
x = self.init_latent * self.mask + self.nmask * x

batch_size = len(conds_list)
Expand Down Expand Up @@ -206,6 +207,9 @@ def forward(self, x, sigma, uncond, cond, cond_scale, s_min_uncond, image_cond):
else:
denoised = self.combine_denoised(x_out, conds_list, uncond, cond_scale)

if not self.mask_before_denoising and self.mask is not None:
denoised = self.init_latent * self.mask + self.nmask * denoised

self.sampler.last_latent = self.get_pred_x0(torch.cat([x_in[i:i + 1] for i in denoised_image_indexes]), torch.cat([x_out[i:i + 1] for i in denoised_image_indexes]), sigma)

if opts.live_preview_content == "Prompt":
Expand Down
1 change: 1 addition & 0 deletions modules/sd_samplers_timesteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, sampler):
super().__init__(sampler)

self.alphas = shared.sd_model.alphas_cumprod
self.mask_before_denoising = True

def get_pred_x0(self, x_in, x_out, sigma):
ts = sigma.to(dtype=int)
Expand Down

0 comments on commit c1a31ec

Please sign in to comment.