mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-25 15:55:18 +00:00
add docstrings
This commit is contained in:
parent
8d2de420d3
commit
5818539743
@ -2,22 +2,21 @@ import torch
|
|||||||
import comfy.model_management
|
import comfy.model_management
|
||||||
|
|
||||||
|
|
||||||
def prepare_noise(latent, seed, disable_noise):
|
def prepare_noise(latent, seed):
|
||||||
|
"""creates random noise given a LATENT and a seed"""
|
||||||
latent_image = latent["samples"]
|
latent_image = latent["samples"]
|
||||||
if disable_noise:
|
batch_index = 0
|
||||||
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
|
if "batch_index" in latent:
|
||||||
else:
|
batch_index = latent["batch_index"]
|
||||||
batch_index = 0
|
|
||||||
if "batch_index" in latent:
|
|
||||||
batch_index = latent["batch_index"]
|
|
||||||
|
|
||||||
generator = torch.manual_seed(seed)
|
generator = torch.manual_seed(seed)
|
||||||
for i in range(batch_index):
|
for i in range(batch_index):
|
||||||
noise = torch.randn([1] + list(latent_image.size())[1:], dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
noise = torch.randn([1] + list(latent_image.size())[1:], dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
||||||
noise = torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
noise = torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
|
||||||
return noise
|
return noise
|
||||||
|
|
||||||
def create_mask(latent, noise):
|
def create_mask(latent, noise):
|
||||||
|
"""creates a mask for a given LATENT and noise"""
|
||||||
noise_mask = None
|
noise_mask = None
|
||||||
device = comfy.model_management.get_torch_device()
|
device = comfy.model_management.get_torch_device()
|
||||||
if "noise_mask" in latent:
|
if "noise_mask" in latent:
|
||||||
@ -30,6 +29,7 @@ def create_mask(latent, noise):
|
|||||||
return noise_mask
|
return noise_mask
|
||||||
|
|
||||||
def broadcast_cond(cond, noise):
|
def broadcast_cond(cond, noise):
|
||||||
|
"""broadcasts conditioning to the noise batch size"""
|
||||||
device = comfy.model_management.get_torch_device()
|
device = comfy.model_management.get_torch_device()
|
||||||
copy = []
|
copy = []
|
||||||
for p in cond:
|
for p in cond:
|
||||||
@ -41,6 +41,7 @@ def broadcast_cond(cond, noise):
|
|||||||
return copy
|
return copy
|
||||||
|
|
||||||
def load_c_nets(positive, negative):
|
def load_c_nets(positive, negative):
|
||||||
|
"""loads control nets in positive and negative conditioning"""
|
||||||
def get_models(cond):
|
def get_models(cond):
|
||||||
models = []
|
models = []
|
||||||
for c in cond:
|
for c in cond:
|
||||||
@ -53,10 +54,12 @@ def load_c_nets(positive, negative):
|
|||||||
return get_models(positive) + get_models(negative)
|
return get_models(positive) + get_models(negative)
|
||||||
|
|
||||||
def load_additional_models(positive, negative):
|
def load_additional_models(positive, negative):
|
||||||
|
"""loads additional models in positive and negative conditioning"""
|
||||||
models = load_c_nets(positive, negative)
|
models = load_c_nets(positive, negative)
|
||||||
comfy.model_management.load_controlnet_gpu(models)
|
comfy.model_management.load_controlnet_gpu(models)
|
||||||
return models
|
return models
|
||||||
|
|
||||||
def cleanup_additional_models(models):
|
def cleanup_additional_models(models):
|
||||||
|
"""cleanup additional models that were loaded"""
|
||||||
for m in models:
|
for m in models:
|
||||||
m.cleanup()
|
m.cleanup()
|
6
nodes.py
6
nodes.py
@ -744,7 +744,11 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,
|
|||||||
device = comfy.model_management.get_torch_device()
|
device = comfy.model_management.get_torch_device()
|
||||||
latent_image = latent["samples"]
|
latent_image = latent["samples"]
|
||||||
|
|
||||||
noise = comfy.sample.prepare_noise(latent, seed, disable_noise)
|
if disable_noise:
|
||||||
|
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
|
||||||
|
else:
|
||||||
|
noise = comfy.sample.prepare_noise(latent, seed)
|
||||||
|
|
||||||
noise_mask = comfy.sample.create_mask(latent, noise)
|
noise_mask = comfy.sample.create_mask(latent, noise)
|
||||||
|
|
||||||
real_model = None
|
real_model = None
|
||||||
|
Loading…
Reference in New Issue
Block a user