The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Fix model_management import so it doesn't get executed twice.
comfyanonymous73c3e11e83f6
diff --git a/comfy/ldm/modules/attention.py b/comfy/ldm/modules/attention.pyindex 92b3eca7c..c83387348 100644--- a/comfy/ldm/modules/attention.py+++ b/comfy/ldm/modules/attention.py@@ -9,7 +9,7 @@ from typing import Optional, Anyfrom ldm.modules.diffusionmodules.util import checkpointfrom .sub_quadratic_attention import efficient_dot_product_attention-import model_management+from comfy import model_managementfrom . import tomesddiff --git a/comfy/ldm/modules/diffusionmodules/model.py b/comfy/ldm/modules/diffusionmodules/model.pyindex 788a6fc4f..1599d386e 100644--- a/comfy/ldm/modules/diffusionmodules/model.py+++ b/comfy/ldm/modules/diffusionmodules/model.py@@ -7,7 +7,7 @@ from einops import rearrangefrom typing import Optional, Anyfrom ldm.modules.attention import MemoryEfficientCrossAttention-import model_management+from comfy import model_managementif model_management.xformers_enabled_vae():import xformersdiff --git a/comfy/ldm/modules/sub_quadratic_attention.py b/comfy/ldm/modules/sub_quadratic_attention.pyindex f3c83f387..573cce74f 100644--- a/comfy/ldm/modules/sub_quadratic_attention.py+++ b/comfy/ldm/modules/sub_quadratic_attention.py@@ -24,7 +24,7 @@ except ImportError:from torch import Tensorfrom typing import List-import model_management+from comfy import model_managementdef dynamic_slice(x: Tensor,diff --git a/comfy/samplers.py b/comfy/samplers.pyindex 93f5d361b..ed36442a9 100644--- a/comfy/samplers.py+++ b/comfy/samplers.py@@ -3,7 +3,7 @@ from .k_diffusion import external as k_diffusion_externalfrom .extra_samplers import uni_pcimport torchimport contextlib-import model_management+from comfy import model_managementfrom .ldm.models.diffusion.ddim import DDIMSamplerfrom .ldm.modules.diffusionmodules.util import make_ddim_timestepsdiff --git a/comfy/sd.py b/comfy/sd.pyindex d6d45fef6..9c632e240 100644--- a/comfy/sd.py+++ b/comfy/sd.py@@ -4,7 +4,7 @@ import copyimport sd1_clipimport sd2_clip-import model_management+from comfy import model_managementfrom .ldm.util import instantiate_from_configfrom .ldm.models.autoencoder import AutoencoderKLimport yaml@@ -388,7 +388,7 @@ class CLIP:return conddef encode(self, text):- tokens = self.tokenizer.tokenize_with_weights(text)+ tokens = self.tokenize(text)return self.encode_from_tokens(tokens)class VAE:diff --git a/comfy_extras/nodes_upscale_model.py b/comfy_extras/nodes_upscale_model.pyindex 6a7d0e516..d8754698c 100644--- a/comfy_extras/nodes_upscale_model.py+++ b/comfy_extras/nodes_upscale_model.py@@ -1,6 +1,6 @@import osfrom comfy_extras.chainner_models import model_loading-import model_management+from comfy import model_managementimport torchimport comfy.utilsimport folder_pathsdiff --git a/nodes.py b/nodes.pyindex 6468ac6b8..e6ad9434f 100644--- a/nodes.py+++ b/nodes.py@@ -21,16 +21,16 @@ import comfy.utilsimport comfy.clip_vision-import model_management+import comfy.model_managementimport importlibimport folder_pathsdef before_node_execution():- model_management.throw_exception_if_processing_interrupted()+ comfy.model_management.throw_exception_if_processing_interrupted()def interrupt_processing(value=True):- model_management.interrupt_current_processing(value)+ comfy.model_management.interrupt_current_processing(value)MAX_RESOLUTION=8192@@ -241,7 +241,7 @@ class DiffusersLoader:model_path = os.path.join(search_path, model_path)break- return comfy.diffusers_convert.load_diffusers(model_path, fp16=model_management.should_use_fp16(), output_vae=output_vae, output_clip=output_clip, embedding_directory=folder_paths.get_folder_paths("embeddings"))+ return comfy.diffusers_convert.load_diffusers(model_path, fp16=comfy.model_management.should_use_fp16(), output_vae=output_vae, output_clip=output_clip, embedding_directory=folder_paths.get_folder_paths("embeddings"))class unCLIPCheckpointLoader:@@ -680,7 +680,7 @@ class SetLatentNoiseMask:def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False):latent_image = latent["samples"]noise_mask = None- device = model_management.get_torch_device()+ device = comfy.model_management.get_torch_device()if disable_noise:noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")@@ -696,7 +696,7 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,noise_mask = noise_mask.to(device)real_model = None- model_management.load_model_gpu(model)+ comfy.model_management.load_model_gpu(model)real_model = model.modelnoise = noise.to(device)@@ -726,7 +726,7 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,control_net_models = []for x in control_nets:control_net_models += x.get_control_models()- model_management.load_controlnet_gpu(control_net_models)+ comfy.model_management.load_controlnet_gpu(control_net_models)if sampler_name in comfy.samplers.KSampler.SAMPLERS:sampler = comfy.samplers.KSampler(real_model, steps=steps, device=device, sampler=sampler_name, scheduler=scheduler, denoise=denoise, model_options=model.model_options)