Fix slightly different output with old backend

This commit is contained in:
Sergey Borisov 2024-07-21 18:31:30 +03:00
parent e046e60e1c
commit 5772965f09

View File

@ -100,8 +100,10 @@ class StableDiffusionBackend:
if isinstance(guidance_scale, list):
guidance_scale = guidance_scale[ctx.step_index]
return torch.lerp(ctx.negative_noise_pred, ctx.positive_noise_pred, guidance_scale)
# return ctx.negative_noise_pred + guidance_scale * (ctx.positive_noise_pred - ctx.negative_noise_pred)
# Note: Although logically it same, it seams that precision errors differs.
# This sometimes results in slightly different output.
# return torch.lerp(ctx.negative_noise_pred, ctx.positive_noise_pred, guidance_scale)
return ctx.negative_noise_pred + guidance_scale * (ctx.positive_noise_pred - ctx.negative_noise_pred)
def run_unet(self, ctx: DenoiseContext, ext_manager: ExtensionsManager, conditioning_mode: ConditioningMode):
sample = ctx.latent_model_input