Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions comfy/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import numpy as np
import logging

def prepare_noise(latent_image, seed, noise_inds=None):
def prepare_noise(latent_image, seed, noise_inds=None, disable_noise=False):
"""
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 disable_noise:
return torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")

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 = []
for i in range(unique_inds[-1]+1):
Expand Down
2 changes: 1 addition & 1 deletion comfy_extras/nodes_custom_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def __init__(self):

def generate_noise(self, input_latent):
latent_image = input_latent["samples"]
return torch.zeros(latent_image.shape, dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
return comfy.sample.prepare_noise(latent_image, self.seed, disable_noise=True)


class Noise_RandomNoise:
Expand Down
7 changes: 2 additions & 5 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,8 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,
latent_image = latent["samples"]
latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)

if disable_noise:
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
else:
batch_inds = latent["batch_index"] if "batch_index" in latent else None
noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds)
batch_inds = latent["batch_index"] if "batch_index" in latent else None
noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds, disable_noise)

noise_mask = None
if "noise_mask" in latent:
Expand Down
Loading