restore ability of ksamplers to process -v variation options

- supersedes PR #977
- works with both img2img and txt2img
This commit is contained in:
Lincoln Stein 2022-10-07 14:43:59 -04:00
parent 3d7bc074cf
commit 7a701506a4
2 changed files with 8 additions and 2 deletions

View File

@ -49,6 +49,7 @@ class Img2Img(Generator):
img_callback = step_callback,
unconditional_guidance_scale=cfg_scale,
unconditional_conditioning=uc,
init_latent = self.init_latent, # changes how noising is performed in ksampler
)
return self.sample_to_image(samples)

View File

@ -174,9 +174,14 @@ class KSampler(Sampler):
# sigmas are set up in make_schedule - we take the last steps items
total_steps = len(self.sigmas)
sigmas = self.sigmas[-S-1:]
# x_T is variation noise. When an init image is provided (in x0) we need to add
# more randomness to the starting image.
if x_T is not None:
x = x_T + torch.randn([batch_size, *shape], device=self.device) * sigmas[0]
if x0 is not None:
x = x_T + torch.randn_like(x0, device=self.device) * sigmas[0]
else:
x = x_T * sigmas[0]
else:
x = torch.randn([batch_size, *shape], device=self.device) * sigmas[0]