From efa53c9e928f5d693ef4b75ebbc95cff8f2af6c1 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Fri, 8 Sep 2023 01:38:00 -0700 Subject: [PATCH] generate predictable noise in batches Such that if seed=1, batchsize=2, it generates one image of seed=1 and one image of seed=2, where previously it generated one image of seed=1 and one image of seed=unobtanium --- comfy/sample.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/comfy/sample.py b/comfy/sample.py index e4730b18..1fd99163 100644 --- a/comfy/sample.py +++ b/comfy/sample.py @@ -10,12 +10,15 @@ def prepare_noise(latent_image, seed, noise_inds=None): creates random noise given a latent image and a seed. optional arg skip can be used to skip and discard x number of noise generations for a given seed """ - generator = torch.manual_seed(seed) - if noise_inds is None: - return torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu") - - unique_inds, inverse = np.unique(noise_inds, return_inverse=True) noises = [] + if noise_inds is None: + for i in range(latent_image.size()[0]): + generator = torch.manual_seed(seed + i) + noises.append(torch.randn(latent_image[i].size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")) + return torch.stack(noises, axis=0) + + generator = torch.manual_seed(seed) + unique_inds, inverse = np.unique(noise_inds, return_inverse=True) for i in range(unique_inds[-1]+1): noise = torch.randn([1] + list(latent_image.size())[1:], dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu") if i in unique_inds: