The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
load_unet -> load_diffusion_model with a model_options argument.
comfyanonymousa562c17e8ac5
diff --git a/comfy/diffusers_load.py b/comfy/diffusers_load.pyindex 98b888a19..56e63a756 100644--- a/comfy/diffusers_load.py+++ b/comfy/diffusers_load.py@@ -22,7 +22,7 @@ def load_diffusers(model_path, output_vae=True, output_clip=True, embedding_direif text_encoder2_path is not None:text_encoder_paths.append(text_encoder2_path)- unet = comfy.sd.load_unet(unet_path)+ unet = comfy.sd.load_diffusion_model(unet_path)clip = Noneif output_clip:diff --git a/comfy/sd.py b/comfy/sd.pyindex c8a2f086c..13909d674 100644--- a/comfy/sd.py+++ b/comfy/sd.py@@ -590,7 +590,8 @@ def load_state_dict_guess_config(sd, output_vae=True, output_clip=True, output_creturn (model_patcher, clip, vae, clipvision)-def load_unet_state_dict(sd, dtype=None): #load unet in diffusers or regular format+def load_diffusion_model_state_dict(sd, model_options={}): #load unet in diffusers or regular format+ dtype = model_options.get("dtype", None)#Allow loading unets from checkpoint filesdiffusion_model_prefix = model_detection.unet_prefix_from_state_dict(sd)@@ -632,6 +633,7 @@ def load_unet_state_dict(sd, dtype=None): #load unet in diffusers or regular formanual_cast_dtype = model_management.unet_manual_cast(unet_dtype, load_device, model_config.supported_inference_dtypes)model_config.set_inference_dtype(unet_dtype, manual_cast_dtype)+ model_config.custom_operations = model_options.get("custom_operations", None)model = model_config.get_model(new_sd, "")model = model.to(offload_device)model.load_model_weights(new_sd, "")@@ -640,14 +642,23 @@ def load_unet_state_dict(sd, dtype=None): #load unet in diffusers or regular forlogging.info("left over keys in unet: {}".format(left_over))return comfy.model_patcher.ModelPatcher(model, load_device=load_device, offload_device=offload_device)-def load_unet(unet_path, dtype=None):++def load_diffusion_model(unet_path, model_options={}):sd = comfy.utils.load_torch_file(unet_path)- model = load_unet_state_dict(sd, dtype=dtype)+ model = load_diffusion_model_state_dict(sd, model_options=model_options)if model is None:logging.error("ERROR UNSUPPORTED UNET {}".format(unet_path))raise RuntimeError("ERROR: Could not detect model type of: {}".format(unet_path))return model+def load_unet(unet_path, dtype=None):+ print("WARNING: the load_unet function has been deprecated and will be removed please switch to: load_diffusion_model")+ return load_diffusion_model(unet_path, model_options={"dtype": dtype})++def load_unet_state_dict(sd, dtype=None):+ print("WARNING: the load_unet_state_dict function has been deprecated and will be removed please switch to: load_diffusion_model_state_dict")+ return load_diffusion_model_state_dict(sd, model_options={"dtype": dtype})+def save_checkpoint(output_path, model, clip=None, vae=None, clip_vision=None, metadata=None, extra_keys={}):clip_sd = Noneload_models = [model]diff --git a/nodes.py b/nodes.pyindex e296597c5..525b28d85 100644--- a/nodes.py+++ b/nodes.py@@ -826,14 +826,14 @@ class UNETLoader:CATEGORY = "advanced/loaders"def load_unet(self, unet_name, weight_dtype):- dtype = None+ model_options = {}if weight_dtype == "fp8_e4m3fn":- dtype = torch.float8_e4m3fn+ model_options["dtype"] = torch.float8_e4m3fnelif weight_dtype == "fp8_e5m2":- dtype = torch.float8_e5m2+ model_options["dtype"] = torch.float8_e5m2unet_path = folder_paths.get_full_path("unet", unet_name)- model = comfy.sd.load_unet(unet_path, dtype=dtype)+ model = comfy.sd.load_diffusion_model(unet_path, model_options=model_options)return (model,)class CLIPLoader: