mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-03-12 16:39:49 +00:00
add_sampler_pre_cfg_function
This commit is contained in:
@@ -55,11 +55,17 @@ class PreprocessorInpaintOnly(PreprocessorInpaint):
|
||||
|
||||
unet = process.sd_model.forge_objects.unet.clone()
|
||||
|
||||
def pre_cfg(model, c, uc, x, timestep, model_options):
|
||||
noisy_latent = latent_image.to(x) + timestep.to(x) * torch.randn_like(latent_image).to(x)
|
||||
x = x * latent_mask.to(x) + noisy_latent.to(x) * (1.0 - latent_mask.to(x))
|
||||
return model, c, uc, x, timestep, model_options
|
||||
|
||||
def post_cfg(args):
|
||||
denoised = args['denoised']
|
||||
denoised = denoised * latent_mask.to(denoised) + latent_image.to(denoised) * (1.0 - latent_mask.to(denoised))
|
||||
return denoised
|
||||
|
||||
unet.add_sampler_pre_cfg_function(pre_cfg)
|
||||
unet.set_model_sampler_post_cfg_function(post_cfg)
|
||||
|
||||
process.sd_model.forge_objects.unet = unet
|
||||
|
||||
Reference in New Issue
Block a user