mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 02:15:17 +00:00
Fix nondeterministic results when add_noise==disable
This commit is contained in:
parent
f257fc999f
commit
fa87f263ce
@ -5,12 +5,15 @@ import comfy.utils
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import logging
|
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.
|
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
|
optional arg skip can be used to skip and discard x number of noise generations for a given seed
|
||||||
"""
|
"""
|
||||||
generator = torch.manual_seed(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:
|
if noise_inds is None:
|
||||||
return torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
return torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ class Noise_EmptyNoise:
|
|||||||
|
|
||||||
def generate_noise(self, input_latent):
|
def generate_noise(self, input_latent):
|
||||||
latent_image = input_latent["samples"]
|
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:
|
class Noise_RandomNoise:
|
||||||
|
5
nodes.py
5
nodes.py
@ -1381,11 +1381,8 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,
|
|||||||
latent_image = latent["samples"]
|
latent_image = latent["samples"]
|
||||||
latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)
|
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
|
batch_inds = latent["batch_index"] if "batch_index" in latent else None
|
||||||
noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds)
|
noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds, disable_noise)
|
||||||
|
|
||||||
noise_mask = None
|
noise_mask = None
|
||||||
if "noise_mask" in latent:
|
if "noise_mask" in latent:
|
||||||
|
Loading…
Reference in New Issue
Block a user