mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-23 08:13:58 +00:00
fix ddim inpaint
This commit is contained in:
@@ -158,9 +158,7 @@ class CFGDenoiser(torch.nn.Module):
|
||||
if classic_ddim_eps_estimation:
|
||||
acd = self.inner_model.inner_model.alphas_cumprod
|
||||
fake_sigmas = ((1 - acd) / acd) ** 0.5
|
||||
tid = sigma.round().long().clip(0, int(fake_sigmas.shape[0]))
|
||||
real_sigma = fake_sigmas[tid]
|
||||
sqrt_alpha_cumprod = torch.sqrt(acd[tid])
|
||||
real_sigma = fake_sigmas[sigma.round().long().clip(0, int(fake_sigmas.shape[0]))]
|
||||
real_sigma_data = 1.0
|
||||
x = x * (real_sigma ** 2.0 + real_sigma_data ** 2.0) ** 0.5
|
||||
sigma = real_sigma
|
||||
@@ -174,24 +172,19 @@ class CFGDenoiser(torch.nn.Module):
|
||||
|
||||
# If we use masks, blending between the denoised and original latent images occurs here.
|
||||
def apply_blend(current_latent):
|
||||
init_latent = self.init_latent
|
||||
|
||||
if classic_ddim_eps_estimation:
|
||||
init_latent = init_latent / sqrt_alpha_cumprod
|
||||
|
||||
blended_latent = current_latent * self.nmask + init_latent * self.mask
|
||||
blended_latent = current_latent * self.nmask + self.init_latent * self.mask
|
||||
|
||||
if self.p.scripts is not None:
|
||||
from modules import scripts
|
||||
mba = scripts.MaskBlendArgs(current_latent, self.nmask, init_latent, self.mask, blended_latent, denoiser=self, sigma=sigma)
|
||||
mba = scripts.MaskBlendArgs(current_latent, self.nmask, self.init_latent, self.mask, blended_latent, denoiser=self, sigma=sigma)
|
||||
self.p.scripts.on_mask_blend(self.p, mba)
|
||||
blended_latent = mba.blended_latent
|
||||
|
||||
return blended_latent
|
||||
|
||||
# Blend in the original latents (before)
|
||||
if self.mask_before_denoising and self.mask is not None:
|
||||
x = apply_blend(x)
|
||||
# # Blend in the original latents (before, wrong method)
|
||||
# if self.mask is not None:
|
||||
# x = apply_blend(x)
|
||||
|
||||
denoiser_params = CFGDenoiserParams(x, image_cond, sigma, state.sampling_step, state.sampling_steps, cond, uncond, self)
|
||||
cfg_denoiser_callback(denoiser_params)
|
||||
@@ -199,8 +192,8 @@ class CFGDenoiser(torch.nn.Module):
|
||||
denoised = forge_sampler.forge_sample(self, denoiser_params=denoiser_params,
|
||||
cond_scale=cond_scale, cond_composition=cond_composition)
|
||||
|
||||
# Blend in the original latents (after)
|
||||
if not self.mask_before_denoising and self.mask is not None:
|
||||
# Blend in the original latents (after, correct method)
|
||||
if self.mask is not None:
|
||||
denoised = apply_blend(denoised)
|
||||
|
||||
preview = self.sampler.last_latent = denoised
|
||||
|
||||
Reference in New Issue
Block a user