diff --git a/args_manager.py b/args_manager.py index 79fe8f81..895f5b74 100644 --- a/args_manager.py +++ b/args_manager.py @@ -1,15 +1,15 @@ -from comfy.options import enable_args_parsing +from fcbh.options import enable_args_parsing enable_args_parsing(False) -import comfy.cli_args as comfy_cli +import fcbh.cli_args as fcbh_cli -comfy_cli.parser.add_argument("--share", action='store_true', help="Set whether to share on Gradio.") +fcbh_cli.parser.add_argument("--share", action='store_true', help="Set whether to share on Gradio.") -comfy_cli.args = comfy_cli.parser.parse_args() -comfy_cli.args.disable_cuda_malloc = True -comfy_cli.args.auto_launch = True +fcbh_cli.args = fcbh_cli.parser.parse_args() +fcbh_cli.args.disable_cuda_malloc = True +fcbh_cli.args.auto_launch = True -if getattr(comfy_cli.args, 'port', 8188) == 8188: - comfy_cli.args.port = None +if getattr(fcbh_cli.args, 'port', 8188) == 8188: + fcbh_cli.args.port = None -args = comfy_cli.args +args = fcbh_cli.args diff --git a/backend/headless/custom_nodes/example_node.py.example b/backend/headless/custom_nodes/example_node.py.example deleted file mode 100644 index 733014f3..00000000 --- a/backend/headless/custom_nodes/example_node.py.example +++ /dev/null @@ -1,102 +0,0 @@ -class Example: - """ - A example node - - Class methods - ------------- - INPUT_TYPES (dict): - Tell the main program input parameters of nodes. - - Attributes - ---------- - RETURN_TYPES (`tuple`): - The type of each element in the output tulple. - RETURN_NAMES (`tuple`): - Optional: The name of each output in the output tulple. - FUNCTION (`str`): - The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute() - OUTPUT_NODE ([`bool`]): - If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example. - The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected. - Assumed to be False if not present. - CATEGORY (`str`): - The category the node should appear in the UI. - execute(s) -> tuple || None: - The entry point method. The name of this method must be the same as the value of property `FUNCTION`. - For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`. - """ - def __init__(self): - pass - - @classmethod - def INPUT_TYPES(s): - """ - Return a dictionary which contains config for all input fields. - Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT". - Input types "INT", "STRING" or "FLOAT" are special values for fields on the node. - The type can be a list for selection. - - Returns: `dict`: - - Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required` - - Value input_fields (`dict`): Contains input fields config: - * Key field_name (`string`): Name of a entry-point method's argument - * Value field_config (`tuple`): - + First value is a string indicate the type of field or a list for selection. - + Secound value is a config for type "INT", "STRING" or "FLOAT". - """ - return { - "required": { - "image": ("IMAGE",), - "int_field": ("INT", { - "default": 0, - "min": 0, #Minimum value - "max": 4096, #Maximum value - "step": 64, #Slider's step - "display": "number" # Cosmetic only: display as "number" or "slider" - }), - "float_field": ("FLOAT", { - "default": 1.0, - "min": 0.0, - "max": 10.0, - "step": 0.01, - "round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding. - "display": "number"}), - "print_to_screen": (["enable", "disable"],), - "string_field": ("STRING", { - "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node - "default": "Hello World!" - }), - }, - } - - RETURN_TYPES = ("IMAGE",) - #RETURN_NAMES = ("image_output_name",) - - FUNCTION = "test" - - #OUTPUT_NODE = False - - CATEGORY = "Example" - - def test(self, image, string_field, int_field, float_field, print_to_screen): - if print_to_screen == "enable": - print(f"""Your input contains: - string_field aka input text: {string_field} - int_field: {int_field} - float_field: {float_field} - """) - #do some processing on the image, in this example I just invert it - image = 1.0 - image - return (image,) - - -# A dictionary that contains all nodes you want to export with their names -# NOTE: names should be globally unique -NODE_CLASS_MAPPINGS = { - "Example": Example -} - -# A dictionary that contains the friendly/humanly readable titles for the nodes -NODE_DISPLAY_NAME_MAPPINGS = { - "Example": "Example Node" -} diff --git a/backend/headless/comfy/checkpoint_pickle.py b/backend/headless/fcbh/checkpoint_pickle.py similarity index 100% rename from backend/headless/comfy/checkpoint_pickle.py rename to backend/headless/fcbh/checkpoint_pickle.py diff --git a/backend/headless/comfy/cldm/cldm.py b/backend/headless/fcbh/cldm/cldm.py similarity index 99% rename from backend/headless/comfy/cldm/cldm.py rename to backend/headless/fcbh/cldm/cldm.py index 25148313..abeb362e 100644 --- a/backend/headless/comfy/cldm/cldm.py +++ b/backend/headless/fcbh/cldm/cldm.py @@ -13,7 +13,7 @@ from ..ldm.modules.diffusionmodules.util import ( from ..ldm.modules.attention import SpatialTransformer from ..ldm.modules.diffusionmodules.openaimodel import UNetModel, TimestepEmbedSequential, ResBlock, Downsample from ..ldm.util import exists -import comfy.ops +import fcbh.ops class ControlledUnetModel(UNetModel): #implemented in the ldm unet @@ -54,7 +54,7 @@ class ControlNet(nn.Module): adm_in_channels=None, transformer_depth_middle=None, device=None, - operations=comfy.ops, + operations=fcbh.ops, ): super().__init__() assert use_spatial_transformer == True, "use_spatial_transformer has to be true" diff --git a/backend/headless/comfy/cli_args.py b/backend/headless/fcbh/cli_args.py similarity index 93% rename from backend/headless/comfy/cli_args.py rename to backend/headless/fcbh/cli_args.py index 35d44164..00c0a760 100644 --- a/backend/headless/comfy/cli_args.py +++ b/backend/headless/fcbh/cli_args.py @@ -1,6 +1,6 @@ import argparse import enum -import comfy.options +import fcbh.options class EnumAction(argparse.Action): """ @@ -37,10 +37,10 @@ parser.add_argument("--listen", type=str, default="127.0.0.1", metavar="IP", nar parser.add_argument("--port", type=int, default=8188, help="Set the listen port.") parser.add_argument("--enable-cors-header", type=str, default=None, metavar="ORIGIN", nargs="?", const="*", help="Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default '*'.") parser.add_argument("--extra-model-paths-config", type=str, default=None, metavar="PATH", nargs='+', action='append', help="Load one or more extra_model_paths.yaml files.") -parser.add_argument("--output-directory", type=str, default=None, help="Set the ComfyUI output directory.") -parser.add_argument("--temp-directory", type=str, default=None, help="Set the ComfyUI temp directory (default is in the ComfyUI directory).") -parser.add_argument("--input-directory", type=str, default=None, help="Set the ComfyUI input directory.") -parser.add_argument("--auto-launch", action="store_true", help="Automatically launch ComfyUI in the default browser.") +parser.add_argument("--output-directory", type=str, default=None, help="Set the fcbh_backend output directory.") +parser.add_argument("--temp-directory", type=str, default=None, help="Set the fcbh_backend temp directory (default is in the fcbh_backend directory).") +parser.add_argument("--input-directory", type=str, default=None, help="Set the fcbh_backend input directory.") +parser.add_argument("--auto-launch", action="store_true", help="Automatically launch fcbh_backend in the default browser.") parser.add_argument("--disable-auto-launch", action="store_true", help="Disable auto launching the browser.") parser.add_argument("--cuda-device", type=int, default=None, metavar="DEVICE_ID", help="Set the id of the cuda device this instance will use.") cm_group = parser.add_mutually_exclusive_group() @@ -86,7 +86,7 @@ vram_group.add_argument("--novram", action="store_true", help="When lowvram isn' vram_group.add_argument("--cpu", action="store_true", help="To use the CPU for everything (slow).") -parser.add_argument("--disable-smart-memory", action="store_true", help="Force ComfyUI to agressively offload to regular ram instead of keeping models in vram when it can.") +parser.add_argument("--disable-smart-memory", action="store_true", help="Force fcbh_backend to agressively offload to regular ram instead of keeping models in vram when it can.") parser.add_argument("--dont-print-server", action="store_true", help="Don't print server output.") @@ -95,7 +95,7 @@ parser.add_argument("--windows-standalone-build", action="store_true", help="Win parser.add_argument("--disable-metadata", action="store_true", help="Disable saving prompt metadata in files.") -if comfy.options.args_parsing: +if fcbh.options.args_parsing: args = parser.parse_args() else: args = parser.parse_args([]) diff --git a/backend/headless/comfy/clip_config_bigg.json b/backend/headless/fcbh/clip_config_bigg.json similarity index 100% rename from backend/headless/comfy/clip_config_bigg.json rename to backend/headless/fcbh/clip_config_bigg.json diff --git a/backend/headless/comfy/clip_vision.py b/backend/headless/fcbh/clip_vision.py similarity index 86% rename from backend/headless/comfy/clip_vision.py rename to backend/headless/fcbh/clip_vision.py index 1206c680..266a9375 100644 --- a/backend/headless/comfy/clip_vision.py +++ b/backend/headless/fcbh/clip_vision.py @@ -4,25 +4,25 @@ import os import torch import contextlib -import comfy.ops -import comfy.model_patcher -import comfy.model_management +import fcbh.ops +import fcbh.model_patcher +import fcbh.model_management class ClipVisionModel(): def __init__(self, json_config): config = CLIPVisionConfig.from_json_file(json_config) - self.load_device = comfy.model_management.text_encoder_device() - offload_device = comfy.model_management.text_encoder_offload_device() + self.load_device = fcbh.model_management.text_encoder_device() + offload_device = fcbh.model_management.text_encoder_offload_device() self.dtype = torch.float32 - if comfy.model_management.should_use_fp16(self.load_device, prioritize_performance=False): + if fcbh.model_management.should_use_fp16(self.load_device, prioritize_performance=False): self.dtype = torch.float16 - with comfy.ops.use_comfy_ops(offload_device, self.dtype): + with fcbh.ops.use_fcbh_ops(offload_device, self.dtype): with modeling_utils.no_init_weights(): self.model = CLIPVisionModelWithProjection(config) self.model.to(self.dtype) - self.patcher = comfy.model_patcher.ModelPatcher(self.model, load_device=self.load_device, offload_device=offload_device) + self.patcher = fcbh.model_patcher.ModelPatcher(self.model, load_device=self.load_device, offload_device=offload_device) self.processor = CLIPImageProcessor(crop_size=224, do_center_crop=True, do_convert_rgb=True, @@ -40,7 +40,7 @@ class ClipVisionModel(): img = torch.clip((255. * image), 0, 255).round().int() img = list(map(lambda a: a, img)) inputs = self.processor(images=img, return_tensors="pt") - comfy.model_management.load_model_gpu(self.patcher) + fcbh.model_management.load_model_gpu(self.patcher) pixel_values = inputs['pixel_values'].to(self.load_device) if self.dtype != torch.float32: @@ -48,7 +48,7 @@ class ClipVisionModel(): else: precision_scope = lambda a, b: contextlib.nullcontext(a) - with precision_scope(comfy.model_management.get_autocast_device(self.load_device), torch.float32): + with precision_scope(fcbh.model_management.get_autocast_device(self.load_device), torch.float32): outputs = self.model(pixel_values=pixel_values, output_hidden_states=True) for k in outputs: diff --git a/backend/headless/comfy/clip_vision_config_g.json b/backend/headless/fcbh/clip_vision_config_g.json similarity index 100% rename from backend/headless/comfy/clip_vision_config_g.json rename to backend/headless/fcbh/clip_vision_config_g.json diff --git a/backend/headless/comfy/clip_vision_config_h.json b/backend/headless/fcbh/clip_vision_config_h.json similarity index 100% rename from backend/headless/comfy/clip_vision_config_h.json rename to backend/headless/fcbh/clip_vision_config_h.json diff --git a/backend/headless/comfy/clip_vision_config_vitl.json b/backend/headless/fcbh/clip_vision_config_vitl.json similarity index 100% rename from backend/headless/comfy/clip_vision_config_vitl.json rename to backend/headless/fcbh/clip_vision_config_vitl.json diff --git a/backend/headless/comfy/controlnet.py b/backend/headless/fcbh/controlnet.py similarity index 88% rename from backend/headless/comfy/controlnet.py rename to backend/headless/fcbh/controlnet.py index ea219c7e..0f5c7b0b 100644 --- a/backend/headless/comfy/controlnet.py +++ b/backend/headless/fcbh/controlnet.py @@ -1,13 +1,13 @@ import torch import math import os -import comfy.utils -import comfy.model_management -import comfy.model_detection -import comfy.model_patcher +import fcbh.utils +import fcbh.model_management +import fcbh.model_detection +import fcbh.model_patcher -import comfy.cldm.cldm -import comfy.t2i_adapter.adapter +import fcbh.cldm.cldm +import fcbh.t2i_adapter.adapter def broadcast_image_to(tensor, target_batch_size, batched_number): @@ -37,7 +37,7 @@ class ControlBase: self.timestep_range = None if device is None: - device = comfy.model_management.get_torch_device() + device = fcbh.model_management.get_torch_device() self.device = device self.previous_controlnet = None self.global_average_pooling = False @@ -130,7 +130,7 @@ class ControlNet(ControlBase): def __init__(self, control_model, global_average_pooling=False, device=None): super().__init__(device) self.control_model = control_model - self.control_model_wrapped = comfy.model_patcher.ModelPatcher(self.control_model, load_device=comfy.model_management.get_torch_device(), offload_device=comfy.model_management.unet_offload_device()) + self.control_model_wrapped = fcbh.model_patcher.ModelPatcher(self.control_model, load_device=fcbh.model_management.get_torch_device(), offload_device=fcbh.model_management.unet_offload_device()) self.global_average_pooling = global_average_pooling def get_control(self, x_noisy, t, cond, batched_number): @@ -150,7 +150,7 @@ class ControlNet(ControlBase): if self.cond_hint is not None: del self.cond_hint self.cond_hint = None - self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, x_noisy.shape[3] * 8, x_noisy.shape[2] * 8, 'nearest-exact', "center").to(self.control_model.dtype).to(self.device) + self.cond_hint = fcbh.utils.common_upscale(self.cond_hint_original, x_noisy.shape[3] * 8, x_noisy.shape[2] * 8, 'nearest-exact', "center").to(self.control_model.dtype).to(self.device) if x_noisy.shape[0] != self.cond_hint.shape[0]: self.cond_hint = broadcast_image_to(self.cond_hint, x_noisy.shape[0], batched_number) @@ -249,24 +249,24 @@ class ControlLora(ControlNet): controlnet_config.pop("out_channels") controlnet_config["hint_channels"] = self.control_weights["input_hint_block.0.weight"].shape[1] controlnet_config["operations"] = ControlLoraOps() - self.control_model = comfy.cldm.cldm.ControlNet(**controlnet_config) + self.control_model = fcbh.cldm.cldm.ControlNet(**controlnet_config) dtype = model.get_dtype() self.control_model.to(dtype) - self.control_model.to(comfy.model_management.get_torch_device()) + self.control_model.to(fcbh.model_management.get_torch_device()) diffusion_model = model.diffusion_model sd = diffusion_model.state_dict() cm = self.control_model.state_dict() for k in sd: - weight = comfy.model_management.resolve_lowvram_weight(sd[k], diffusion_model, k) + weight = fcbh.model_management.resolve_lowvram_weight(sd[k], diffusion_model, k) try: - comfy.utils.set_attr(self.control_model, k, weight) + fcbh.utils.set_attr(self.control_model, k, weight) except: pass for k in self.control_weights: if k not in {"lora_controlnet"}: - comfy.utils.set_attr(self.control_model, k, self.control_weights[k].to(dtype).to(comfy.model_management.get_torch_device())) + fcbh.utils.set_attr(self.control_model, k, self.control_weights[k].to(dtype).to(fcbh.model_management.get_torch_device())) def copy(self): c = ControlLora(self.control_weights, global_average_pooling=self.global_average_pooling) @@ -283,18 +283,18 @@ class ControlLora(ControlNet): return out def inference_memory_requirements(self, dtype): - return comfy.utils.calculate_parameters(self.control_weights) * comfy.model_management.dtype_size(dtype) + ControlBase.inference_memory_requirements(self, dtype) + return fcbh.utils.calculate_parameters(self.control_weights) * fcbh.model_management.dtype_size(dtype) + ControlBase.inference_memory_requirements(self, dtype) def load_controlnet(ckpt_path, model=None): - controlnet_data = comfy.utils.load_torch_file(ckpt_path, safe_load=True) + controlnet_data = fcbh.utils.load_torch_file(ckpt_path, safe_load=True) if "lora_controlnet" in controlnet_data: return ControlLora(controlnet_data) controlnet_config = None if "controlnet_cond_embedding.conv_in.weight" in controlnet_data: #diffusers format - use_fp16 = comfy.model_management.should_use_fp16() - controlnet_config = comfy.model_detection.unet_config_from_diffusers_unet(controlnet_data, use_fp16) - diffusers_keys = comfy.utils.unet_to_diffusers(controlnet_config) + use_fp16 = fcbh.model_management.should_use_fp16() + controlnet_config = fcbh.model_detection.unet_config_from_diffusers_unet(controlnet_data, use_fp16) + diffusers_keys = fcbh.utils.unet_to_diffusers(controlnet_config) diffusers_keys["controlnet_mid_block.weight"] = "middle_block_out.0.weight" diffusers_keys["controlnet_mid_block.bias"] = "middle_block_out.0.bias" @@ -353,16 +353,16 @@ def load_controlnet(ckpt_path, model=None): return net if controlnet_config is None: - use_fp16 = comfy.model_management.should_use_fp16() - controlnet_config = comfy.model_detection.model_config_from_unet(controlnet_data, prefix, use_fp16, True).unet_config + use_fp16 = fcbh.model_management.should_use_fp16() + controlnet_config = fcbh.model_detection.model_config_from_unet(controlnet_data, prefix, use_fp16, True).unet_config controlnet_config.pop("out_channels") controlnet_config["hint_channels"] = controlnet_data["{}input_hint_block.0.weight".format(prefix)].shape[1] - control_model = comfy.cldm.cldm.ControlNet(**controlnet_config) + control_model = fcbh.cldm.cldm.ControlNet(**controlnet_config) if pth: if 'difference' in controlnet_data: if model is not None: - comfy.model_management.load_models_gpu([model]) + fcbh.model_management.load_models_gpu([model]) model_sd = model.model_state_dict() for x in controlnet_data: c_m = "control_model." @@ -425,7 +425,7 @@ class T2IAdapter(ControlBase): self.control_input = None self.cond_hint = None width, height = self.scale_image_to(x_noisy.shape[3] * 8, x_noisy.shape[2] * 8) - self.cond_hint = comfy.utils.common_upscale(self.cond_hint_original, width, height, 'nearest-exact', "center").float().to(self.device) + self.cond_hint = fcbh.utils.common_upscale(self.cond_hint_original, width, height, 'nearest-exact', "center").float().to(self.device) if self.channels_in == 1 and self.cond_hint.shape[1] > 1: self.cond_hint = torch.mean(self.cond_hint, 1, keepdim=True) if x_noisy.shape[0] != self.cond_hint.shape[0]: @@ -458,12 +458,12 @@ def load_t2i_adapter(t2i_data): prefix_replace["adapter.body.{}.resnets.{}.".format(i, j)] = "body.{}.".format(i * 2 + j) prefix_replace["adapter.body.{}.".format(i, j)] = "body.{}.".format(i * 2) prefix_replace["adapter."] = "" - t2i_data = comfy.utils.state_dict_prefix_replace(t2i_data, prefix_replace) + t2i_data = fcbh.utils.state_dict_prefix_replace(t2i_data, prefix_replace) keys = t2i_data.keys() if "body.0.in_conv.weight" in keys: cin = t2i_data['body.0.in_conv.weight'].shape[1] - model_ad = comfy.t2i_adapter.adapter.Adapter_light(cin=cin, channels=[320, 640, 1280, 1280], nums_rb=4) + model_ad = fcbh.t2i_adapter.adapter.Adapter_light(cin=cin, channels=[320, 640, 1280, 1280], nums_rb=4) elif 'conv_in.weight' in keys: cin = t2i_data['conv_in.weight'].shape[1] channel = t2i_data['conv_in.weight'].shape[0] @@ -475,7 +475,7 @@ def load_t2i_adapter(t2i_data): xl = False if cin == 256 or cin == 768: xl = True - model_ad = comfy.t2i_adapter.adapter.Adapter(cin=cin, channels=[channel, channel*2, channel*4, channel*4][:4], nums_rb=2, ksize=ksize, sk=True, use_conv=use_conv, xl=xl) + model_ad = fcbh.t2i_adapter.adapter.Adapter(cin=cin, channels=[channel, channel*2, channel*4, channel*4][:4], nums_rb=2, ksize=ksize, sk=True, use_conv=use_conv, xl=xl) else: return None missing, unexpected = model_ad.load_state_dict(t2i_data) diff --git a/backend/headless/comfy/diffusers_convert.py b/backend/headless/fcbh/diffusers_convert.py similarity index 100% rename from backend/headless/comfy/diffusers_convert.py rename to backend/headless/fcbh/diffusers_convert.py diff --git a/backend/headless/comfy/diffusers_load.py b/backend/headless/fcbh/diffusers_load.py similarity index 85% rename from backend/headless/comfy/diffusers_load.py rename to backend/headless/fcbh/diffusers_load.py index a52e0102..a57cb4a8 100644 --- a/backend/headless/comfy/diffusers_load.py +++ b/backend/headless/fcbh/diffusers_load.py @@ -1,7 +1,7 @@ import json import os -import comfy.sd +import fcbh.sd def first_file(path, filenames): for f in filenames: @@ -23,14 +23,14 @@ def load_diffusers(model_path, output_vae=True, output_clip=True, embedding_dire if text_encoder2_path is not None: text_encoder_paths.append(text_encoder2_path) - unet = comfy.sd.load_unet(unet_path) + unet = fcbh.sd.load_unet(unet_path) clip = None if output_clip: - clip = comfy.sd.load_clip(text_encoder_paths, embedding_directory=embedding_directory) + clip = fcbh.sd.load_clip(text_encoder_paths, embedding_directory=embedding_directory) vae = None if output_vae: - vae = comfy.sd.VAE(ckpt_path=vae_path) + vae = fcbh.sd.VAE(ckpt_path=vae_path) return (unet, clip, vae) diff --git a/backend/headless/comfy/extra_samplers/uni_pc.py b/backend/headless/fcbh/extra_samplers/uni_pc.py similarity index 100% rename from backend/headless/comfy/extra_samplers/uni_pc.py rename to backend/headless/fcbh/extra_samplers/uni_pc.py diff --git a/backend/headless/comfy/gligen.py b/backend/headless/fcbh/gligen.py similarity index 100% rename from backend/headless/comfy/gligen.py rename to backend/headless/fcbh/gligen.py diff --git a/backend/headless/comfy/k_diffusion/external.py b/backend/headless/fcbh/k_diffusion/external.py similarity index 100% rename from backend/headless/comfy/k_diffusion/external.py rename to backend/headless/fcbh/k_diffusion/external.py diff --git a/backend/headless/comfy/k_diffusion/sampling.py b/backend/headless/fcbh/k_diffusion/sampling.py similarity index 100% rename from backend/headless/comfy/k_diffusion/sampling.py rename to backend/headless/fcbh/k_diffusion/sampling.py diff --git a/backend/headless/comfy/k_diffusion/utils.py b/backend/headless/fcbh/k_diffusion/utils.py similarity index 100% rename from backend/headless/comfy/k_diffusion/utils.py rename to backend/headless/fcbh/k_diffusion/utils.py diff --git a/backend/headless/comfy/latent_formats.py b/backend/headless/fcbh/latent_formats.py similarity index 100% rename from backend/headless/comfy/latent_formats.py rename to backend/headless/fcbh/latent_formats.py diff --git a/backend/headless/comfy/ldm/models/autoencoder.py b/backend/headless/fcbh/ldm/models/autoencoder.py similarity index 97% rename from backend/headless/comfy/ldm/models/autoencoder.py rename to backend/headless/fcbh/ldm/models/autoencoder.py index 1fb7ed87..c81002ae 100644 --- a/backend/headless/comfy/ldm/models/autoencoder.py +++ b/backend/headless/fcbh/ldm/models/autoencoder.py @@ -3,11 +3,11 @@ import torch import torch.nn.functional as F from contextlib import contextmanager -from comfy.ldm.modules.diffusionmodules.model import Encoder, Decoder -from comfy.ldm.modules.distributions.distributions import DiagonalGaussianDistribution +from fcbh.ldm.modules.diffusionmodules.model import Encoder, Decoder +from fcbh.ldm.modules.distributions.distributions import DiagonalGaussianDistribution -from comfy.ldm.util import instantiate_from_config -from comfy.ldm.modules.ema import LitEma +from fcbh.ldm.util import instantiate_from_config +from fcbh.ldm.modules.ema import LitEma # class AutoencoderKL(pl.LightningModule): class AutoencoderKL(torch.nn.Module): diff --git a/backend/headless/comfy/ldm/models/diffusion/__init__.py b/backend/headless/fcbh/ldm/models/diffusion/__init__.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/__init__.py rename to backend/headless/fcbh/ldm/models/diffusion/__init__.py diff --git a/backend/headless/comfy/ldm/models/diffusion/ddim.py b/backend/headless/fcbh/ldm/models/diffusion/ddim.py similarity index 99% rename from backend/headless/comfy/ldm/models/diffusion/ddim.py rename to backend/headless/fcbh/ldm/models/diffusion/ddim.py index 433d48e3..06821bca 100644 --- a/backend/headless/comfy/ldm/models/diffusion/ddim.py +++ b/backend/headless/fcbh/ldm/models/diffusion/ddim.py @@ -4,7 +4,7 @@ import torch import numpy as np from tqdm import tqdm -from comfy.ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like, extract_into_tensor +from fcbh.ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like, extract_into_tensor class DDIMSampler(object): diff --git a/backend/headless/comfy/ldm/models/diffusion/dpm_solver/__init__.py b/backend/headless/fcbh/ldm/models/diffusion/dpm_solver/__init__.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/dpm_solver/__init__.py rename to backend/headless/fcbh/ldm/models/diffusion/dpm_solver/__init__.py diff --git a/backend/headless/comfy/ldm/models/diffusion/dpm_solver/dpm_solver.py b/backend/headless/fcbh/ldm/models/diffusion/dpm_solver/dpm_solver.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/dpm_solver/dpm_solver.py rename to backend/headless/fcbh/ldm/models/diffusion/dpm_solver/dpm_solver.py diff --git a/backend/headless/comfy/ldm/models/diffusion/dpm_solver/sampler.py b/backend/headless/fcbh/ldm/models/diffusion/dpm_solver/sampler.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/dpm_solver/sampler.py rename to backend/headless/fcbh/ldm/models/diffusion/dpm_solver/sampler.py diff --git a/backend/headless/comfy/ldm/models/diffusion/plms.py b/backend/headless/fcbh/ldm/models/diffusion/plms.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/plms.py rename to backend/headless/fcbh/ldm/models/diffusion/plms.py diff --git a/backend/headless/comfy/ldm/models/diffusion/sampling_util.py b/backend/headless/fcbh/ldm/models/diffusion/sampling_util.py similarity index 100% rename from backend/headless/comfy/ldm/models/diffusion/sampling_util.py rename to backend/headless/fcbh/ldm/models/diffusion/sampling_util.py diff --git a/backend/headless/comfy/ldm/modules/attention.py b/backend/headless/fcbh/ldm/modules/attention.py similarity index 98% rename from backend/headless/comfy/ldm/modules/attention.py rename to backend/headless/fcbh/ldm/modules/attention.py index ac0d9c8c..2c5273a3 100644 --- a/backend/headless/comfy/ldm/modules/attention.py +++ b/backend/headless/fcbh/ldm/modules/attention.py @@ -9,14 +9,14 @@ from typing import Optional, Any from .diffusionmodules.util import checkpoint from .sub_quadratic_attention import efficient_dot_product_attention -from comfy import model_management +from fcbh import model_management if model_management.xformers_enabled(): import xformers import xformers.ops -from comfy.cli_args import args -import comfy.ops +from fcbh.cli_args import args +import fcbh.ops # CrossAttn precision handling if args.dont_upcast_attention: @@ -53,7 +53,7 @@ def init_(tensor): # feedforward class GEGLU(nn.Module): - def __init__(self, dim_in, dim_out, dtype=None, device=None, operations=comfy.ops): + def __init__(self, dim_in, dim_out, dtype=None, device=None, operations=fcbh.ops): super().__init__() self.proj = operations.Linear(dim_in, dim_out * 2, dtype=dtype, device=device) @@ -63,7 +63,7 @@ class GEGLU(nn.Module): class FeedForward(nn.Module): - def __init__(self, dim, dim_out=None, mult=4, glu=False, dropout=0., dtype=None, device=None, operations=comfy.ops): + def __init__(self, dim, dim_out=None, mult=4, glu=False, dropout=0., dtype=None, device=None, operations=fcbh.ops): super().__init__() inner_dim = int(dim * mult) dim_out = default(dim_out, dim) @@ -310,7 +310,7 @@ else: optimized_attention = attention_sub_quad class CrossAttention(nn.Module): - def __init__(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0., dtype=None, device=None, operations=comfy.ops): + def __init__(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0., dtype=None, device=None, operations=fcbh.ops): super().__init__() inner_dim = dim_head * heads context_dim = default(context_dim, query_dim) @@ -340,7 +340,7 @@ class CrossAttention(nn.Module): class BasicTransformerBlock(nn.Module): def __init__(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True, - disable_self_attn=False, dtype=None, device=None, operations=comfy.ops): + disable_self_attn=False, dtype=None, device=None, operations=fcbh.ops): super().__init__() self.disable_self_attn = disable_self_attn self.attn1 = CrossAttention(query_dim=dim, heads=n_heads, dim_head=d_head, dropout=dropout, @@ -482,7 +482,7 @@ class SpatialTransformer(nn.Module): def __init__(self, in_channels, n_heads, d_head, depth=1, dropout=0., context_dim=None, disable_self_attn=False, use_linear=False, - use_checkpoint=True, dtype=None, device=None, operations=comfy.ops): + use_checkpoint=True, dtype=None, device=None, operations=fcbh.ops): super().__init__() if exists(context_dim) and not isinstance(context_dim, list): context_dim = [context_dim] * depth diff --git a/backend/headless/comfy/ldm/modules/diffusionmodules/__init__.py b/backend/headless/fcbh/ldm/modules/diffusionmodules/__init__.py similarity index 100% rename from backend/headless/comfy/ldm/modules/diffusionmodules/__init__.py rename to backend/headless/fcbh/ldm/modules/diffusionmodules/__init__.py diff --git a/backend/headless/comfy/ldm/modules/diffusionmodules/model.py b/backend/headless/fcbh/ldm/modules/diffusionmodules/model.py similarity index 94% rename from backend/headless/comfy/ldm/modules/diffusionmodules/model.py rename to backend/headless/fcbh/ldm/modules/diffusionmodules/model.py index 6576df4b..7508f847 100644 --- a/backend/headless/comfy/ldm/modules/diffusionmodules/model.py +++ b/backend/headless/fcbh/ldm/modules/diffusionmodules/model.py @@ -6,8 +6,8 @@ import numpy as np from einops import rearrange from typing import Optional, Any -from comfy import model_management -import comfy.ops +from fcbh import model_management +import fcbh.ops if model_management.xformers_enabled_vae(): import xformers @@ -48,7 +48,7 @@ class Upsample(nn.Module): super().__init__() self.with_conv = with_conv if self.with_conv: - self.conv = comfy.ops.Conv2d(in_channels, + self.conv = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, @@ -78,7 +78,7 @@ class Downsample(nn.Module): self.with_conv = with_conv if self.with_conv: # no asymmetric padding in torch conv, must do it ourselves - self.conv = comfy.ops.Conv2d(in_channels, + self.conv = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=3, stride=2, @@ -105,30 +105,30 @@ class ResnetBlock(nn.Module): self.swish = torch.nn.SiLU(inplace=True) self.norm1 = Normalize(in_channels) - self.conv1 = comfy.ops.Conv2d(in_channels, + self.conv1 = fcbh.ops.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1) if temb_channels > 0: - self.temb_proj = comfy.ops.Linear(temb_channels, + self.temb_proj = fcbh.ops.Linear(temb_channels, out_channels) self.norm2 = Normalize(out_channels) self.dropout = torch.nn.Dropout(dropout, inplace=True) - self.conv2 = comfy.ops.Conv2d(out_channels, + self.conv2 = fcbh.ops.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1) if self.in_channels != self.out_channels: if self.use_conv_shortcut: - self.conv_shortcut = comfy.ops.Conv2d(in_channels, + self.conv_shortcut = fcbh.ops.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1) else: - self.nin_shortcut = comfy.ops.Conv2d(in_channels, + self.nin_shortcut = fcbh.ops.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, @@ -199,22 +199,22 @@ class AttnBlock(nn.Module): self.in_channels = in_channels self.norm = Normalize(in_channels) - self.q = comfy.ops.Conv2d(in_channels, + self.q = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.k = comfy.ops.Conv2d(in_channels, + self.k = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.v = comfy.ops.Conv2d(in_channels, + self.v = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.proj_out = comfy.ops.Conv2d(in_channels, + self.proj_out = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, @@ -254,22 +254,22 @@ class MemoryEfficientAttnBlock(nn.Module): self.in_channels = in_channels self.norm = Normalize(in_channels) - self.q = comfy.ops.Conv2d(in_channels, + self.q = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.k = comfy.ops.Conv2d(in_channels, + self.k = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.v = comfy.ops.Conv2d(in_channels, + self.v = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.proj_out = comfy.ops.Conv2d(in_channels, + self.proj_out = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, @@ -305,22 +305,22 @@ class MemoryEfficientAttnBlockPytorch(nn.Module): self.in_channels = in_channels self.norm = Normalize(in_channels) - self.q = comfy.ops.Conv2d(in_channels, + self.q = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.k = comfy.ops.Conv2d(in_channels, + self.k = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.v = comfy.ops.Conv2d(in_channels, + self.v = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) - self.proj_out = comfy.ops.Conv2d(in_channels, + self.proj_out = fcbh.ops.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, @@ -390,14 +390,14 @@ class Model(nn.Module): # timestep embedding self.temb = nn.Module() self.temb.dense = nn.ModuleList([ - comfy.ops.Linear(self.ch, + fcbh.ops.Linear(self.ch, self.temb_ch), - comfy.ops.Linear(self.temb_ch, + fcbh.ops.Linear(self.temb_ch, self.temb_ch), ]) # downsampling - self.conv_in = comfy.ops.Conv2d(in_channels, + self.conv_in = fcbh.ops.Conv2d(in_channels, self.ch, kernel_size=3, stride=1, @@ -466,7 +466,7 @@ class Model(nn.Module): # end self.norm_out = Normalize(block_in) - self.conv_out = comfy.ops.Conv2d(block_in, + self.conv_out = fcbh.ops.Conv2d(block_in, out_ch, kernel_size=3, stride=1, @@ -539,7 +539,7 @@ class Encoder(nn.Module): self.in_channels = in_channels # downsampling - self.conv_in = comfy.ops.Conv2d(in_channels, + self.conv_in = fcbh.ops.Conv2d(in_channels, self.ch, kernel_size=3, stride=1, @@ -584,7 +584,7 @@ class Encoder(nn.Module): # end self.norm_out = Normalize(block_in) - self.conv_out = comfy.ops.Conv2d(block_in, + self.conv_out = fcbh.ops.Conv2d(block_in, 2*z_channels if double_z else z_channels, kernel_size=3, stride=1, @@ -640,7 +640,7 @@ class Decoder(nn.Module): self.z_shape, np.prod(self.z_shape))) # z to block_in - self.conv_in = comfy.ops.Conv2d(z_channels, + self.conv_in = fcbh.ops.Conv2d(z_channels, block_in, kernel_size=3, stride=1, @@ -682,7 +682,7 @@ class Decoder(nn.Module): # end self.norm_out = Normalize(block_in) - self.conv_out = comfy.ops.Conv2d(block_in, + self.conv_out = fcbh.ops.Conv2d(block_in, out_ch, kernel_size=3, stride=1, diff --git a/backend/headless/comfy/ldm/modules/diffusionmodules/openaimodel.py b/backend/headless/fcbh/ldm/modules/diffusionmodules/openaimodel.py similarity index 99% rename from backend/headless/comfy/ldm/modules/diffusionmodules/openaimodel.py rename to backend/headless/fcbh/ldm/modules/diffusionmodules/openaimodel.py index b42637c8..09d3da56 100644 --- a/backend/headless/comfy/ldm/modules/diffusionmodules/openaimodel.py +++ b/backend/headless/fcbh/ldm/modules/diffusionmodules/openaimodel.py @@ -14,8 +14,8 @@ from .util import ( timestep_embedding, ) from ..attention import SpatialTransformer -from comfy.ldm.util import exists -import comfy.ops +from fcbh.ldm.util import exists +import fcbh.ops class TimestepBlock(nn.Module): """ @@ -70,7 +70,7 @@ class Upsample(nn.Module): upsampling occurs in the inner-two dimensions. """ - def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1, dtype=None, device=None, operations=comfy.ops): + def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1, dtype=None, device=None, operations=fcbh.ops): super().__init__() self.channels = channels self.out_channels = out_channels or channels @@ -106,7 +106,7 @@ class Downsample(nn.Module): downsampling occurs in the inner-two dimensions. """ - def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1, dtype=None, device=None, operations=comfy.ops): + def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1, dtype=None, device=None, operations=fcbh.ops): super().__init__() self.channels = channels self.out_channels = out_channels or channels @@ -156,7 +156,7 @@ class ResBlock(TimestepBlock): down=False, dtype=None, device=None, - operations=comfy.ops + operations=fcbh.ops ): super().__init__() self.channels = channels @@ -316,7 +316,7 @@ class UNetModel(nn.Module): adm_in_channels=None, transformer_depth_middle=None, device=None, - operations=comfy.ops, + operations=fcbh.ops, ): super().__init__() assert use_spatial_transformer == True, "use_spatial_transformer has to be true" diff --git a/backend/headless/comfy/ldm/modules/diffusionmodules/upscaling.py b/backend/headless/fcbh/ldm/modules/diffusionmodules/upscaling.py similarity index 98% rename from backend/headless/comfy/ldm/modules/diffusionmodules/upscaling.py rename to backend/headless/fcbh/ldm/modules/diffusionmodules/upscaling.py index 709a7f52..a7684f45 100644 --- a/backend/headless/comfy/ldm/modules/diffusionmodules/upscaling.py +++ b/backend/headless/fcbh/ldm/modules/diffusionmodules/upscaling.py @@ -4,7 +4,7 @@ import numpy as np from functools import partial from .util import extract_into_tensor, make_beta_schedule -from comfy.ldm.util import default +from fcbh.ldm.util import default class AbstractLowScaleModel(nn.Module): diff --git a/backend/headless/comfy/ldm/modules/diffusionmodules/util.py b/backend/headless/fcbh/ldm/modules/diffusionmodules/util.py similarity index 98% rename from backend/headless/comfy/ldm/modules/diffusionmodules/util.py rename to backend/headless/fcbh/ldm/modules/diffusionmodules/util.py index d890c804..c27dd4f8 100644 --- a/backend/headless/comfy/ldm/modules/diffusionmodules/util.py +++ b/backend/headless/fcbh/ldm/modules/diffusionmodules/util.py @@ -15,8 +15,8 @@ import torch.nn as nn import numpy as np from einops import repeat -from comfy.ldm.util import instantiate_from_config -import comfy.ops +from fcbh.ldm.util import instantiate_from_config +import fcbh.ops def make_beta_schedule(schedule, n_timestep, linear_start=1e-4, linear_end=2e-2, cosine_s=8e-3): if schedule == "linear": @@ -233,7 +233,7 @@ def conv_nd(dims, *args, **kwargs): if dims == 1: return nn.Conv1d(*args, **kwargs) elif dims == 2: - return comfy.ops.Conv2d(*args, **kwargs) + return fcbh.ops.Conv2d(*args, **kwargs) elif dims == 3: return nn.Conv3d(*args, **kwargs) raise ValueError(f"unsupported dimensions: {dims}") @@ -243,7 +243,7 @@ def linear(*args, **kwargs): """ Create a linear module. """ - return comfy.ops.Linear(*args, **kwargs) + return fcbh.ops.Linear(*args, **kwargs) def avg_pool_nd(dims, *args, **kwargs): diff --git a/backend/headless/comfy/ldm/modules/distributions/__init__.py b/backend/headless/fcbh/ldm/modules/distributions/__init__.py similarity index 100% rename from backend/headless/comfy/ldm/modules/distributions/__init__.py rename to backend/headless/fcbh/ldm/modules/distributions/__init__.py diff --git a/backend/headless/comfy/ldm/modules/distributions/distributions.py b/backend/headless/fcbh/ldm/modules/distributions/distributions.py similarity index 100% rename from backend/headless/comfy/ldm/modules/distributions/distributions.py rename to backend/headless/fcbh/ldm/modules/distributions/distributions.py diff --git a/backend/headless/comfy/ldm/modules/ema.py b/backend/headless/fcbh/ldm/modules/ema.py similarity index 100% rename from backend/headless/comfy/ldm/modules/ema.py rename to backend/headless/fcbh/ldm/modules/ema.py diff --git a/backend/headless/comfy/ldm/modules/encoders/__init__.py b/backend/headless/fcbh/ldm/modules/encoders/__init__.py similarity index 100% rename from backend/headless/comfy/ldm/modules/encoders/__init__.py rename to backend/headless/fcbh/ldm/modules/encoders/__init__.py diff --git a/backend/headless/comfy/ldm/modules/encoders/noise_aug_modules.py b/backend/headless/fcbh/ldm/modules/encoders/noise_aug_modules.py similarity index 100% rename from backend/headless/comfy/ldm/modules/encoders/noise_aug_modules.py rename to backend/headless/fcbh/ldm/modules/encoders/noise_aug_modules.py diff --git a/backend/headless/comfy/ldm/modules/sub_quadratic_attention.py b/backend/headless/fcbh/ldm/modules/sub_quadratic_attention.py similarity index 99% rename from backend/headless/comfy/ldm/modules/sub_quadratic_attention.py rename to backend/headless/fcbh/ldm/modules/sub_quadratic_attention.py index 4d42059b..1f07431a 100644 --- a/backend/headless/comfy/ldm/modules/sub_quadratic_attention.py +++ b/backend/headless/fcbh/ldm/modules/sub_quadratic_attention.py @@ -24,7 +24,7 @@ except ImportError: from torch import Tensor from typing import List -from comfy import model_management +from fcbh import model_management def dynamic_slice( x: Tensor, diff --git a/backend/headless/comfy/ldm/util.py b/backend/headless/fcbh/ldm/util.py similarity index 100% rename from backend/headless/comfy/ldm/util.py rename to backend/headless/fcbh/ldm/util.py diff --git a/backend/headless/comfy/lora.py b/backend/headless/fcbh/lora.py similarity index 98% rename from backend/headless/comfy/lora.py rename to backend/headless/fcbh/lora.py index 3009a1c9..4c1c5684 100644 --- a/backend/headless/comfy/lora.py +++ b/backend/headless/fcbh/lora.py @@ -1,4 +1,4 @@ -import comfy.utils +import fcbh.utils LORA_CLIP_MAP = { "mlp.fc1": "mlp_fc1", @@ -183,7 +183,7 @@ def model_lora_keys_unet(model, key_map={}): key_lora = k[len("diffusion_model."):-len(".weight")].replace(".", "_") key_map["lora_unet_{}".format(key_lora)] = k - diffusers_keys = comfy.utils.unet_to_diffusers(model.model_config.unet_config) + diffusers_keys = fcbh.utils.unet_to_diffusers(model.model_config.unet_config) for k in diffusers_keys: if k.endswith(".weight"): unet_key = "diffusion_model.{}".format(diffusers_keys[k]) diff --git a/backend/headless/comfy/model_base.py b/backend/headless/fcbh/model_base.py similarity index 95% rename from backend/headless/comfy/model_base.py rename to backend/headless/fcbh/model_base.py index ed2dc83e..c5e1e399 100644 --- a/backend/headless/comfy/model_base.py +++ b/backend/headless/fcbh/model_base.py @@ -1,9 +1,9 @@ import torch -from comfy.ldm.modules.diffusionmodules.openaimodel import UNetModel -from comfy.ldm.modules.encoders.noise_aug_modules import CLIPEmbeddingNoiseAugmentation -from comfy.ldm.modules.diffusionmodules.util import make_beta_schedule -from comfy.ldm.modules.diffusionmodules.openaimodel import Timestep -import comfy.model_management +from fcbh.ldm.modules.diffusionmodules.openaimodel import UNetModel +from fcbh.ldm.modules.encoders.noise_aug_modules import CLIPEmbeddingNoiseAugmentation +from fcbh.ldm.modules.diffusionmodules.util import make_beta_schedule +from fcbh.ldm.modules.diffusionmodules.openaimodel import Timestep +import fcbh.model_management import numpy as np from enum import Enum from . import utils @@ -98,7 +98,7 @@ class BaseModel(torch.nn.Module): unet_sd = self.diffusion_model.state_dict() unet_state_dict = {} for k in unet_sd: - unet_state_dict[k] = comfy.model_management.resolve_lowvram_weight(unet_sd[k], self.diffusion_model, k) + unet_state_dict[k] = fcbh.model_management.resolve_lowvram_weight(unet_sd[k], self.diffusion_model, k) unet_state_dict = self.model_config.process_unet_state_dict_for_saving(unet_state_dict) vae_state_dict = self.model_config.process_vae_state_dict_for_saving(vae_state_dict) diff --git a/backend/headless/comfy/model_detection.py b/backend/headless/fcbh/model_detection.py similarity index 98% rename from backend/headless/comfy/model_detection.py rename to backend/headless/fcbh/model_detection.py index 787c7857..abf4b79f 100644 --- a/backend/headless/comfy/model_detection.py +++ b/backend/headless/fcbh/model_detection.py @@ -1,5 +1,5 @@ -import comfy.supported_models -import comfy.supported_models_base +import fcbh.supported_models +import fcbh.supported_models_base def count_blocks(state_dict_keys, prefix_string): count = 0 @@ -109,7 +109,7 @@ def detect_unet_config(state_dict, key_prefix, use_fp16): return unet_config def model_config_from_unet_config(unet_config): - for model_config in comfy.supported_models.models: + for model_config in fcbh.supported_models.models: if model_config.matches(unet_config): return model_config(unet_config) @@ -120,7 +120,7 @@ def model_config_from_unet(state_dict, unet_key_prefix, use_fp16, use_base_if_no unet_config = detect_unet_config(state_dict, unet_key_prefix, use_fp16) model_config = model_config_from_unet_config(unet_config) if model_config is None and use_base_if_no_match: - return comfy.supported_models_base.BASE(unet_config) + return fcbh.supported_models_base.BASE(unet_config) else: return model_config diff --git a/backend/headless/comfy/model_management.py b/backend/headless/fcbh/model_management.py similarity index 99% rename from backend/headless/comfy/model_management.py rename to backend/headless/fcbh/model_management.py index 3c390d9c..0bb74d3e 100644 --- a/backend/headless/comfy/model_management.py +++ b/backend/headless/fcbh/model_management.py @@ -1,7 +1,7 @@ import psutil from enum import Enum -from comfy.cli_args import args -import comfy.utils +from fcbh.cli_args import args +import fcbh.utils import torch import sys @@ -681,7 +681,7 @@ def soft_empty_cache(force=False): def resolve_lowvram_weight(weight, model, key): if weight.device == torch.device("meta"): #lowvram NOTE: this depends on the inner working of the accelerate library so it might break. key_split = key.split('.') # I have no idea why they don't just leave the weight there instead of using the meta device. - op = comfy.utils.get_attr(model, '.'.join(key_split[:-1])) + op = fcbh.utils.get_attr(model, '.'.join(key_split[:-1])) weight = op._hf_hook.weights_map[key_split[-1]] return weight diff --git a/backend/headless/comfy/model_patcher.py b/backend/headless/fcbh/model_patcher.py similarity index 77% rename from backend/headless/comfy/model_patcher.py rename to backend/headless/fcbh/model_patcher.py index 50b725b8..2c14e795 100644 --- a/backend/headless/comfy/model_patcher.py +++ b/backend/headless/fcbh/model_patcher.py @@ -2,8 +2,8 @@ import torch import copy import inspect -import comfy.utils -import comfy.model_management +import fcbh.utils +import fcbh.model_management class ModelPatcher: def __init__(self, model, load_device, offload_device, size=0, current_device=None): @@ -162,11 +162,11 @@ class ModelPatcher: self.backup[key] = weight.to(self.offload_device) if device_to is not None: - temp_weight = comfy.model_management.cast_to_device(weight, device_to, torch.float32, copy=True) + temp_weight = fcbh.model_management.cast_to_device(weight, device_to, torch.float32, copy=True) else: temp_weight = weight.to(torch.float32, copy=True) out_weight = self.calculate_weight(self.patches[key], temp_weight, key).to(weight.dtype) - comfy.utils.set_attr(self.model, key, out_weight) + fcbh.utils.set_attr(self.model, key, out_weight) del temp_weight if device_to is not None: @@ -193,15 +193,15 @@ class ModelPatcher: if w1.shape != weight.shape: print("WARNING SHAPE MISMATCH {} WEIGHT NOT MERGED {} != {}".format(key, w1.shape, weight.shape)) else: - weight += alpha * comfy.model_management.cast_to_device(w1, weight.device, weight.dtype) + weight += alpha * fcbh.model_management.cast_to_device(w1, weight.device, weight.dtype) elif len(v) == 4: #lora/locon - mat1 = comfy.model_management.cast_to_device(v[0], weight.device, torch.float32) - mat2 = comfy.model_management.cast_to_device(v[1], weight.device, torch.float32) + mat1 = fcbh.model_management.cast_to_device(v[0], weight.device, torch.float32) + mat2 = fcbh.model_management.cast_to_device(v[1], weight.device, torch.float32) if v[2] is not None: alpha *= v[2] / mat2.shape[0] if v[3] is not None: #locon mid weights, hopefully the math is fine because I didn't properly test it - mat3 = comfy.model_management.cast_to_device(v[3], weight.device, torch.float32) + mat3 = fcbh.model_management.cast_to_device(v[3], weight.device, torch.float32) final_shape = [mat2.shape[1], mat2.shape[0], mat3.shape[2], mat3.shape[3]] mat2 = torch.mm(mat2.transpose(0, 1).flatten(start_dim=1), mat3.transpose(0, 1).flatten(start_dim=1)).reshape(final_shape).transpose(0, 1) try: @@ -220,23 +220,23 @@ class ModelPatcher: if w1 is None: dim = w1_b.shape[0] - w1 = torch.mm(comfy.model_management.cast_to_device(w1_a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1_b, weight.device, torch.float32)) + w1 = torch.mm(fcbh.model_management.cast_to_device(w1_a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1_b, weight.device, torch.float32)) else: - w1 = comfy.model_management.cast_to_device(w1, weight.device, torch.float32) + w1 = fcbh.model_management.cast_to_device(w1, weight.device, torch.float32) if w2 is None: dim = w2_b.shape[0] if t2 is None: - w2 = torch.mm(comfy.model_management.cast_to_device(w2_a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_b, weight.device, torch.float32)) + w2 = torch.mm(fcbh.model_management.cast_to_device(w2_a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_b, weight.device, torch.float32)) else: w2 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t2, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t2, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_a, weight.device, torch.float32)) else: - w2 = comfy.model_management.cast_to_device(w2, weight.device, torch.float32) + w2 = fcbh.model_management.cast_to_device(w2, weight.device, torch.float32) if len(w2.shape) == 4: w1 = w1.unsqueeze(2).unsqueeze(2) @@ -258,19 +258,19 @@ class ModelPatcher: t1 = v[5] t2 = v[6] m1 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t1, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t1, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1a, weight.device, torch.float32)) m2 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t2, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t2, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2a, weight.device, torch.float32)) else: - m1 = torch.mm(comfy.model_management.cast_to_device(w1a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1b, weight.device, torch.float32)) - m2 = torch.mm(comfy.model_management.cast_to_device(w2a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2b, weight.device, torch.float32)) + m1 = torch.mm(fcbh.model_management.cast_to_device(w1a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1b, weight.device, torch.float32)) + m2 = torch.mm(fcbh.model_management.cast_to_device(w2a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2b, weight.device, torch.float32)) try: weight += (alpha * m1 * m2).reshape(weight.shape).type(weight.dtype) @@ -283,7 +283,7 @@ class ModelPatcher: keys = list(self.backup.keys()) for k in keys: - comfy.utils.set_attr(self.model, k, self.backup[k]) + fcbh.utils.set_attr(self.model, k, self.backup[k]) self.backup = {} diff --git a/backend/headless/comfy/ops.py b/backend/headless/fcbh/ops.py similarity index 93% rename from backend/headless/comfy/ops.py rename to backend/headless/fcbh/ops.py index 610d5458..9085e45e 100644 --- a/backend/headless/comfy/ops.py +++ b/backend/headless/fcbh/ops.py @@ -28,7 +28,7 @@ def conv_nd(dims, *args, **kwargs): raise ValueError(f"unsupported dimensions: {dims}") @contextmanager -def use_comfy_ops(device=None, dtype=None): # Kind of an ugly hack but I can't think of a better way +def use_fcbh_ops(device=None, dtype=None): # Kind of an ugly hack but I can't think of a better way old_torch_nn_linear = torch.nn.Linear force_device = device force_dtype = dtype diff --git a/backend/headless/comfy/options.py b/backend/headless/fcbh/options.py similarity index 100% rename from backend/headless/comfy/options.py rename to backend/headless/fcbh/options.py diff --git a/backend/headless/comfy/sample.py b/backend/headless/fcbh/sample.py similarity index 84% rename from backend/headless/comfy/sample.py rename to backend/headless/fcbh/sample.py index 32227276..c995e9a3 100644 --- a/backend/headless/comfy/sample.py +++ b/backend/headless/fcbh/sample.py @@ -1,7 +1,7 @@ import torch -import comfy.model_management -import comfy.samplers -import comfy.utils +import fcbh.model_management +import fcbh.samplers +import fcbh.utils import math import numpy as np @@ -29,7 +29,7 @@ def prepare_mask(noise_mask, shape, device): noise_mask = torch.nn.functional.interpolate(noise_mask.reshape((-1, 1, noise_mask.shape[-2], noise_mask.shape[-1])), size=(shape[2], shape[3]), mode="bilinear") noise_mask = noise_mask.round() noise_mask = torch.cat([noise_mask] * shape[1], dim=1) - noise_mask = comfy.utils.repeat_to_batch_size(noise_mask, shape[0]) + noise_mask = fcbh.utils.repeat_to_batch_size(noise_mask, shape[0]) noise_mask = noise_mask.to(device) return noise_mask @@ -37,7 +37,7 @@ def broadcast_cond(cond, batch, device): """broadcasts conditioning to the batch size""" copy = [] for p in cond: - t = comfy.utils.repeat_to_batch_size(p[0], batch) + t = fcbh.utils.repeat_to_batch_size(p[0], batch) t = t.to(device) copy += [[t] + p[1:]] return copy @@ -78,7 +78,7 @@ def prepare_sampling(model, noise_shape, positive, negative, noise_mask): real_model = None models, inference_memory = get_additional_models(positive, negative, model.model_dtype()) - comfy.model_management.load_models_gpu([model] + models, comfy.model_management.batch_area_memory(noise_shape[0] * noise_shape[2] * noise_shape[3]) + inference_memory) + fcbh.model_management.load_models_gpu([model] + models, fcbh.model_management.batch_area_memory(noise_shape[0] * noise_shape[2] * noise_shape[3]) + inference_memory) real_model = model.model positive_copy = broadcast_cond(positive, noise_shape[0], device) @@ -92,7 +92,7 @@ def sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative noise = noise.to(model.load_device) latent_image = latent_image.to(model.load_device) - sampler = comfy.samplers.KSampler(real_model, steps=steps, device=model.load_device, sampler=sampler_name, scheduler=scheduler, denoise=denoise, model_options=model.model_options) + sampler = fcbh.samplers.KSampler(real_model, steps=steps, device=model.load_device, sampler=sampler_name, scheduler=scheduler, denoise=denoise, model_options=model.model_options) samples = sampler.sample(noise, positive_copy, negative_copy, cfg=cfg, latent_image=latent_image, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, denoise_mask=noise_mask, sigmas=sigmas, callback=callback, disable_pbar=disable_pbar, seed=seed) samples = samples.cpu() @@ -106,7 +106,7 @@ def sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent latent_image = latent_image.to(model.load_device) sigmas = sigmas.to(model.load_device) - samples = comfy.samplers.sample(real_model, noise, positive_copy, negative_copy, cfg, model.load_device, sampler, sigmas, model_options=model.model_options, latent_image=latent_image, denoise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed) + samples = fcbh.samplers.sample(real_model, noise, positive_copy, negative_copy, cfg, model.load_device, sampler, sigmas, model_options=model.model_options, latent_image=latent_image, denoise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed) samples = samples.cpu() cleanup_additional_models(models) return samples diff --git a/backend/headless/comfy/samplers.py b/backend/headless/fcbh/samplers.py similarity index 99% rename from backend/headless/comfy/samplers.py rename to backend/headless/fcbh/samplers.py index e43f7a6f..7fe947ea 100644 --- a/backend/headless/comfy/samplers.py +++ b/backend/headless/fcbh/samplers.py @@ -2,12 +2,12 @@ from .k_diffusion import sampling as k_diffusion_sampling from .k_diffusion import external as k_diffusion_external from .extra_samplers import uni_pc import torch -from comfy import model_management +from fcbh import model_management from .ldm.models.diffusion.ddim import DDIMSampler from .ldm.modules.diffusionmodules.util import make_ddim_timesteps import math -from comfy import model_base -import comfy.utils +from fcbh import model_base +import fcbh.utils def lcm(a, b): #TODO: eventually replace by math.lcm (added in python3.9) return abs(a*b) // math.gcd(a, b) @@ -539,7 +539,7 @@ def encode_adm(model, conds, batch_size, width, height, device, prompt_type): if adm_out is not None: x[1] = x[1].copy() - x[1]["adm_encoded"] = comfy.utils.repeat_to_batch_size(adm_out, batch_size).to(device) + x[1]["adm_encoded"] = fcbh.utils.repeat_to_batch_size(adm_out, batch_size).to(device) return conds diff --git a/backend/headless/comfy/sd.py b/backend/headless/fcbh/sd.py similarity index 81% rename from backend/headless/comfy/sd.py rename to backend/headless/fcbh/sd.py index cfd6fb3c..61bf0288 100644 --- a/backend/headless/comfy/sd.py +++ b/backend/headless/fcbh/sd.py @@ -2,12 +2,12 @@ import torch import contextlib import math -from comfy import model_management +from fcbh import model_management from .ldm.util import instantiate_from_config from .ldm.models.autoencoder import AutoencoderKL import yaml -import comfy.utils +import fcbh.utils from . import clip_vision from . import gligen @@ -19,10 +19,10 @@ from . import sd1_clip from . import sd2_clip from . import sdxl_clip -import comfy.model_patcher -import comfy.lora -import comfy.t2i_adapter.adapter -import comfy.supported_models_base +import fcbh.model_patcher +import fcbh.lora +import fcbh.t2i_adapter.adapter +import fcbh.supported_models_base def load_model_weights(model, sd): m, u = model.load_state_dict(sd, strict=False) @@ -50,14 +50,14 @@ def load_clip_weights(model, sd): if ids.dtype == torch.float32: sd['cond_stage_model.transformer.text_model.embeddings.position_ids'] = ids.round() - sd = comfy.utils.transformers_convert(sd, "cond_stage_model.model.", "cond_stage_model.transformer.text_model.", 24) + sd = fcbh.utils.transformers_convert(sd, "cond_stage_model.model.", "cond_stage_model.transformer.text_model.", 24) return load_model_weights(model, sd) def load_lora_for_models(model, clip, lora, strength_model, strength_clip): - key_map = comfy.lora.model_lora_keys_unet(model.model) - key_map = comfy.lora.model_lora_keys_clip(clip.cond_stage_model, key_map) - loaded = comfy.lora.load_lora(lora, key_map) + key_map = fcbh.lora.model_lora_keys_unet(model.model) + key_map = fcbh.lora.model_lora_keys_clip(clip.cond_stage_model, key_map) + loaded = fcbh.lora.load_lora(lora, key_map) new_modelpatcher = model.clone() k = new_modelpatcher.add_patches(loaded, strength_model) new_clip = clip.clone() @@ -90,7 +90,7 @@ class CLIP: self.cond_stage_model = clip(**(params)) self.tokenizer = tokenizer(embedding_directory=embedding_directory) - self.patcher = comfy.model_patcher.ModelPatcher(self.cond_stage_model, load_device=load_device, offload_device=offload_device) + self.patcher = fcbh.model_patcher.ModelPatcher(self.cond_stage_model, load_device=load_device, offload_device=offload_device) self.layer_idx = None def clone(self): @@ -149,7 +149,7 @@ class VAE: self.first_stage_model = AutoencoderKL(**(config['params'])) self.first_stage_model = self.first_stage_model.eval() if ckpt_path is not None: - sd = comfy.utils.load_torch_file(ckpt_path) + sd = fcbh.utils.load_torch_file(ckpt_path) if 'decoder.up_blocks.0.resnets.0.norm1.weight' in sd.keys(): #diffusers format sd = diffusers_convert.convert_vae_state_dict(sd) m, u = self.first_stage_model.load_state_dict(sd, strict=False) @@ -164,29 +164,29 @@ class VAE: self.first_stage_model.to(self.vae_dtype) def decode_tiled_(self, samples, tile_x=64, tile_y=64, overlap = 16): - steps = samples.shape[0] * comfy.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x, tile_y, overlap) - steps += samples.shape[0] * comfy.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x // 2, tile_y * 2, overlap) - steps += samples.shape[0] * comfy.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x * 2, tile_y // 2, overlap) - pbar = comfy.utils.ProgressBar(steps) + steps = samples.shape[0] * fcbh.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x, tile_y, overlap) + steps += samples.shape[0] * fcbh.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x // 2, tile_y * 2, overlap) + steps += samples.shape[0] * fcbh.utils.get_tiled_scale_steps(samples.shape[3], samples.shape[2], tile_x * 2, tile_y // 2, overlap) + pbar = fcbh.utils.ProgressBar(steps) decode_fn = lambda a: (self.first_stage_model.decode(a.to(self.vae_dtype).to(self.device)) + 1.0).float() output = torch.clamp(( - (comfy.utils.tiled_scale(samples, decode_fn, tile_x // 2, tile_y * 2, overlap, upscale_amount = 8, pbar = pbar) + - comfy.utils.tiled_scale(samples, decode_fn, tile_x * 2, tile_y // 2, overlap, upscale_amount = 8, pbar = pbar) + - comfy.utils.tiled_scale(samples, decode_fn, tile_x, tile_y, overlap, upscale_amount = 8, pbar = pbar)) + (fcbh.utils.tiled_scale(samples, decode_fn, tile_x // 2, tile_y * 2, overlap, upscale_amount = 8, pbar = pbar) + + fcbh.utils.tiled_scale(samples, decode_fn, tile_x * 2, tile_y // 2, overlap, upscale_amount = 8, pbar = pbar) + + fcbh.utils.tiled_scale(samples, decode_fn, tile_x, tile_y, overlap, upscale_amount = 8, pbar = pbar)) / 3.0) / 2.0, min=0.0, max=1.0) return output def encode_tiled_(self, pixel_samples, tile_x=512, tile_y=512, overlap = 64): - steps = pixel_samples.shape[0] * comfy.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x, tile_y, overlap) - steps += pixel_samples.shape[0] * comfy.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x // 2, tile_y * 2, overlap) - steps += pixel_samples.shape[0] * comfy.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x * 2, tile_y // 2, overlap) - pbar = comfy.utils.ProgressBar(steps) + steps = pixel_samples.shape[0] * fcbh.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x, tile_y, overlap) + steps += pixel_samples.shape[0] * fcbh.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x // 2, tile_y * 2, overlap) + steps += pixel_samples.shape[0] * fcbh.utils.get_tiled_scale_steps(pixel_samples.shape[3], pixel_samples.shape[2], tile_x * 2, tile_y // 2, overlap) + pbar = fcbh.utils.ProgressBar(steps) encode_fn = lambda a: self.first_stage_model.encode((2. * a - 1.).to(self.vae_dtype).to(self.device)).sample().float() - samples = comfy.utils.tiled_scale(pixel_samples, encode_fn, tile_x, tile_y, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) - samples += comfy.utils.tiled_scale(pixel_samples, encode_fn, tile_x * 2, tile_y // 2, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) - samples += comfy.utils.tiled_scale(pixel_samples, encode_fn, tile_x // 2, tile_y * 2, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) + samples = fcbh.utils.tiled_scale(pixel_samples, encode_fn, tile_x, tile_y, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) + samples += fcbh.utils.tiled_scale(pixel_samples, encode_fn, tile_x * 2, tile_y // 2, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) + samples += fcbh.utils.tiled_scale(pixel_samples, encode_fn, tile_x // 2, tile_y * 2, overlap, upscale_amount = (1/8), out_channels=4, pbar=pbar) samples /= 3.0 return samples @@ -257,10 +257,10 @@ class StyleModel: def load_style_model(ckpt_path): - model_data = comfy.utils.load_torch_file(ckpt_path, safe_load=True) + model_data = fcbh.utils.load_torch_file(ckpt_path, safe_load=True) keys = model_data.keys() if "style_embedding" in keys: - model = comfy.t2i_adapter.adapter.StyleAdapter(width=1024, context_dim=768, num_head=8, n_layes=3, num_token=8) + model = fcbh.t2i_adapter.adapter.StyleAdapter(width=1024, context_dim=768, num_head=8, n_layes=3, num_token=8) else: raise Exception("invalid style model {}".format(ckpt_path)) model.load_state_dict(model_data) @@ -270,14 +270,14 @@ def load_style_model(ckpt_path): def load_clip(ckpt_paths, embedding_directory=None): clip_data = [] for p in ckpt_paths: - clip_data.append(comfy.utils.load_torch_file(p, safe_load=True)) + clip_data.append(fcbh.utils.load_torch_file(p, safe_load=True)) class EmptyClass: pass for i in range(len(clip_data)): if "transformer.resblocks.0.ln_1.weight" in clip_data[i]: - clip_data[i] = comfy.utils.transformers_convert(clip_data[i], "", "text_model.", 32) + clip_data[i] = fcbh.utils.transformers_convert(clip_data[i], "", "text_model.", 32) clip_target = EmptyClass() clip_target.params = {} @@ -306,11 +306,11 @@ def load_clip(ckpt_paths, embedding_directory=None): return clip def load_gligen(ckpt_path): - data = comfy.utils.load_torch_file(ckpt_path, safe_load=True) + data = fcbh.utils.load_torch_file(ckpt_path, safe_load=True) model = gligen.load_gligen(data) if model_management.should_use_fp16(): model = model.half() - return comfy.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=model_management.unet_offload_device()) + return fcbh.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=model_management.unet_offload_device()) def load_checkpoint(config_path=None, ckpt_path=None, output_vae=True, output_clip=True, embedding_directory=None, state_dict=None, config=None): #TODO: this function is a mess and should be removed eventually @@ -346,12 +346,12 @@ def load_checkpoint(config_path=None, ckpt_path=None, output_vae=True, output_cl pass if state_dict is None: - state_dict = comfy.utils.load_torch_file(ckpt_path) + state_dict = fcbh.utils.load_torch_file(ckpt_path) class EmptyClass: pass - model_config = comfy.supported_models_base.BASE({}) + model_config = fcbh.supported_models_base.BASE({}) from . import latent_formats model_config.latent_format = latent_formats.SD15(scale_factor=scale_factor) @@ -392,10 +392,10 @@ def load_checkpoint(config_path=None, ckpt_path=None, output_vae=True, output_cl w.cond_stage_model = clip.cond_stage_model load_clip_weights(w, state_dict) - return (comfy.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=offload_device), clip, vae) + return (fcbh.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=offload_device), clip, vae) def load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, output_clipvision=False, embedding_directory=None, output_model=True): - sd = comfy.utils.load_torch_file(ckpt_path) + sd = fcbh.utils.load_torch_file(ckpt_path) sd_keys = sd.keys() clip = None clipvision = None @@ -404,7 +404,7 @@ def load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, o model_patcher = None clip_target = None - parameters = comfy.utils.calculate_parameters(sd, "model.diffusion_model.") + parameters = fcbh.utils.calculate_parameters(sd, "model.diffusion_model.") fp16 = model_management.should_use_fp16(model_params=parameters) class WeightsLoader(torch.nn.Module): @@ -447,7 +447,7 @@ def load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, o print("left over keys:", left_over) if output_model: - model_patcher = comfy.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=model_management.unet_offload_device(), current_device=inital_load_device) + model_patcher = fcbh.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=model_management.unet_offload_device(), current_device=inital_load_device) if inital_load_device != torch.device("cpu"): print("loaded straight to GPU") model_management.load_model_gpu(model_patcher) @@ -456,8 +456,8 @@ def load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, o def load_unet(unet_path): #load unet in diffusers format - sd = comfy.utils.load_torch_file(unet_path) - parameters = comfy.utils.calculate_parameters(sd) + sd = fcbh.utils.load_torch_file(unet_path) + parameters = fcbh.utils.calculate_parameters(sd) fp16 = model_management.should_use_fp16(model_params=parameters) if "input_blocks.0.0.weight" in sd: #ldm model_config = model_detection.model_config_from_unet(sd, "", fp16) @@ -471,7 +471,7 @@ def load_unet(unet_path): #load unet in diffusers format print("ERROR UNSUPPORTED UNET", unet_path) return None - diffusers_keys = comfy.utils.unet_to_diffusers(model_config.unet_config) + diffusers_keys = fcbh.utils.unet_to_diffusers(model_config.unet_config) new_sd = {} for k in diffusers_keys: @@ -483,9 +483,9 @@ def load_unet(unet_path): #load unet in diffusers format model = model_config.get_model(new_sd, "") model = model.to(offload_device) model.load_model_weights(new_sd, "") - return comfy.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=offload_device) + return fcbh.model_patcher.ModelPatcher(model, load_device=model_management.get_torch_device(), offload_device=offload_device) def save_checkpoint(output_path, model, clip, vae, metadata=None): model_management.load_models_gpu([model, clip.load_model()]) sd = model.model.state_dict_for_saving(clip.get_sd(), vae.get_sd()) - comfy.utils.save_torch_file(sd, output_path, metadata=metadata) + fcbh.utils.save_torch_file(sd, output_path, metadata=metadata) diff --git a/backend/headless/comfy/sd1_clip.py b/backend/headless/fcbh/sd1_clip.py similarity index 99% rename from backend/headless/comfy/sd1_clip.py rename to backend/headless/fcbh/sd1_clip.py index 9978b6c3..45382b00 100644 --- a/backend/headless/comfy/sd1_clip.py +++ b/backend/headless/fcbh/sd1_clip.py @@ -1,7 +1,7 @@ import os from transformers import CLIPTokenizer, CLIPTextModel, CLIPTextConfig, modeling_utils -import comfy.ops +import fcbh.ops import torch import traceback import zipfile @@ -54,7 +54,7 @@ class SD1ClipModel(torch.nn.Module, ClipTokenWeightEncoder): textmodel_json_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), "sd1_clip_config.json") config = CLIPTextConfig.from_json_file(textmodel_json_config) self.num_layers = config.num_hidden_layers - with comfy.ops.use_comfy_ops(device, dtype): + with fcbh.ops.use_fcbh_ops(device, dtype): with modeling_utils.no_init_weights(): self.transformer = CLIPTextModel(config) diff --git a/backend/headless/comfy/sd1_clip_config.json b/backend/headless/fcbh/sd1_clip_config.json similarity index 100% rename from backend/headless/comfy/sd1_clip_config.json rename to backend/headless/fcbh/sd1_clip_config.json diff --git a/backend/headless/comfy/sd1_tokenizer/merges.txt b/backend/headless/fcbh/sd1_tokenizer/merges.txt similarity index 100% rename from backend/headless/comfy/sd1_tokenizer/merges.txt rename to backend/headless/fcbh/sd1_tokenizer/merges.txt diff --git a/backend/headless/comfy/sd1_tokenizer/special_tokens_map.json b/backend/headless/fcbh/sd1_tokenizer/special_tokens_map.json similarity index 100% rename from backend/headless/comfy/sd1_tokenizer/special_tokens_map.json rename to backend/headless/fcbh/sd1_tokenizer/special_tokens_map.json diff --git a/backend/headless/comfy/sd1_tokenizer/tokenizer_config.json b/backend/headless/fcbh/sd1_tokenizer/tokenizer_config.json similarity index 100% rename from backend/headless/comfy/sd1_tokenizer/tokenizer_config.json rename to backend/headless/fcbh/sd1_tokenizer/tokenizer_config.json diff --git a/backend/headless/comfy/sd1_tokenizer/vocab.json b/backend/headless/fcbh/sd1_tokenizer/vocab.json similarity index 100% rename from backend/headless/comfy/sd1_tokenizer/vocab.json rename to backend/headless/fcbh/sd1_tokenizer/vocab.json diff --git a/backend/headless/comfy/sd2_clip.py b/backend/headless/fcbh/sd2_clip.py similarity index 97% rename from backend/headless/comfy/sd2_clip.py rename to backend/headless/fcbh/sd2_clip.py index 05e50a00..e5cac64b 100644 --- a/backend/headless/comfy/sd2_clip.py +++ b/backend/headless/fcbh/sd2_clip.py @@ -1,4 +1,4 @@ -from comfy import sd1_clip +from fcbh import sd1_clip import torch import os diff --git a/backend/headless/comfy/sd2_clip_config.json b/backend/headless/fcbh/sd2_clip_config.json similarity index 100% rename from backend/headless/comfy/sd2_clip_config.json rename to backend/headless/fcbh/sd2_clip_config.json diff --git a/backend/headless/comfy/sdxl_clip.py b/backend/headless/fcbh/sdxl_clip.py similarity index 99% rename from backend/headless/comfy/sdxl_clip.py rename to backend/headless/fcbh/sdxl_clip.py index e3ac2ee0..2064ba41 100644 --- a/backend/headless/comfy/sdxl_clip.py +++ b/backend/headless/fcbh/sdxl_clip.py @@ -1,4 +1,4 @@ -from comfy import sd1_clip +from fcbh import sd1_clip import torch import os diff --git a/backend/headless/comfy/supported_models.py b/backend/headless/fcbh/supported_models.py similarity index 100% rename from backend/headless/comfy/supported_models.py rename to backend/headless/fcbh/supported_models.py diff --git a/backend/headless/comfy/supported_models_base.py b/backend/headless/fcbh/supported_models_base.py similarity index 100% rename from backend/headless/comfy/supported_models_base.py rename to backend/headless/fcbh/supported_models_base.py diff --git a/backend/headless/comfy/t2i_adapter/adapter.py b/backend/headless/fcbh/t2i_adapter/adapter.py similarity index 100% rename from backend/headless/comfy/t2i_adapter/adapter.py rename to backend/headless/fcbh/t2i_adapter/adapter.py diff --git a/backend/headless/comfy/taesd/taesd.py b/backend/headless/fcbh/taesd/taesd.py similarity index 91% rename from backend/headless/comfy/taesd/taesd.py rename to backend/headless/fcbh/taesd/taesd.py index 8df1f160..02489cdb 100644 --- a/backend/headless/comfy/taesd/taesd.py +++ b/backend/headless/fcbh/taesd/taesd.py @@ -6,7 +6,7 @@ Tiny AutoEncoder for Stable Diffusion import torch import torch.nn as nn -import comfy.utils +import fcbh.utils def conv(n_in, n_out, **kwargs): return nn.Conv2d(n_in, n_out, 3, padding=1, **kwargs) @@ -52,9 +52,9 @@ class TAESD(nn.Module): self.encoder = Encoder() self.decoder = Decoder() if encoder_path is not None: - self.encoder.load_state_dict(comfy.utils.load_torch_file(encoder_path, safe_load=True)) + self.encoder.load_state_dict(fcbh.utils.load_torch_file(encoder_path, safe_load=True)) if decoder_path is not None: - self.decoder.load_state_dict(comfy.utils.load_torch_file(decoder_path, safe_load=True)) + self.decoder.load_state_dict(fcbh.utils.load_torch_file(decoder_path, safe_load=True)) @staticmethod def scale_latents(x): diff --git a/backend/headless/comfy/utils.py b/backend/headless/fcbh/utils.py similarity index 99% rename from backend/headless/comfy/utils.py rename to backend/headless/fcbh/utils.py index df016ef9..037d7dbe 100644 --- a/backend/headless/comfy/utils.py +++ b/backend/headless/fcbh/utils.py @@ -1,7 +1,7 @@ import torch import math import struct -import comfy.checkpoint_pickle +import fcbh.checkpoint_pickle import safetensors.torch import numpy as np from PIL import Image @@ -19,7 +19,7 @@ def load_torch_file(ckpt, safe_load=False, device=None): if safe_load: pl_sd = torch.load(ckpt, map_location=device, weights_only=True) else: - pl_sd = torch.load(ckpt, map_location=device, pickle_module=comfy.checkpoint_pickle) + pl_sd = torch.load(ckpt, map_location=device, pickle_module=fcbh.checkpoint_pickle) if "global_step" in pl_sd: print(f"Global Step: {pl_sd['global_step']}") if "state_dict" in pl_sd: diff --git a/backend/headless/comfy_extras/chainner_models/__init__.py b/backend/headless/fcbh_extras/chainner_models/__init__.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/__init__.py rename to backend/headless/fcbh_extras/chainner_models/__init__.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/DAT.py b/backend/headless/fcbh_extras/chainner_models/architecture/DAT.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/DAT.py rename to backend/headless/fcbh_extras/chainner_models/architecture/DAT.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/HAT.py b/backend/headless/fcbh_extras/chainner_models/architecture/HAT.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/HAT.py rename to backend/headless/fcbh_extras/chainner_models/architecture/HAT.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-DAT b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-DAT similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-DAT rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-DAT diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-ESRGAN b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-ESRGAN similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-ESRGAN rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-ESRGAN diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-HAT b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-HAT similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-HAT rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-HAT diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-RealESRGAN b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-RealESRGAN similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-RealESRGAN rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-RealESRGAN diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SCUNet b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SCUNet similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SCUNet rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SCUNet diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SPSR b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SPSR similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SPSR rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SPSR diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SwiftSRGAN b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SwiftSRGAN similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SwiftSRGAN rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SwiftSRGAN diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-Swin2SR b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-Swin2SR similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-Swin2SR rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-Swin2SR diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SwinIR b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SwinIR similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-SwinIR rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-SwinIR diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LICENSE-lama b/backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-lama similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LICENSE-lama rename to backend/headless/fcbh_extras/chainner_models/architecture/LICENSE-lama diff --git a/backend/headless/comfy_extras/chainner_models/architecture/LaMa.py b/backend/headless/fcbh_extras/chainner_models/architecture/LaMa.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/LaMa.py rename to backend/headless/fcbh_extras/chainner_models/architecture/LaMa.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/ChannelAttention.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/ChannelAttention.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/ChannelAttention.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/ChannelAttention.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/LICENSE b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/LICENSE similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/LICENSE rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/LICENSE diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OSA.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OSA.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OSA.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OSA.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OSAG.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OSAG.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OSAG.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OSAG.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OmniSR.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OmniSR.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/OmniSR.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/OmniSR.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/esa.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/esa.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/esa.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/esa.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/layernorm.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/layernorm.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/layernorm.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/layernorm.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/OmniSR/pixelshuffle.py b/backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/pixelshuffle.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/OmniSR/pixelshuffle.py rename to backend/headless/fcbh_extras/chainner_models/architecture/OmniSR/pixelshuffle.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/RRDB.py b/backend/headless/fcbh_extras/chainner_models/architecture/RRDB.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/RRDB.py rename to backend/headless/fcbh_extras/chainner_models/architecture/RRDB.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/SCUNet.py b/backend/headless/fcbh_extras/chainner_models/architecture/SCUNet.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/SCUNet.py rename to backend/headless/fcbh_extras/chainner_models/architecture/SCUNet.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/SPSR.py b/backend/headless/fcbh_extras/chainner_models/architecture/SPSR.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/SPSR.py rename to backend/headless/fcbh_extras/chainner_models/architecture/SPSR.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/SRVGG.py b/backend/headless/fcbh_extras/chainner_models/architecture/SRVGG.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/SRVGG.py rename to backend/headless/fcbh_extras/chainner_models/architecture/SRVGG.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/SwiftSRGAN.py b/backend/headless/fcbh_extras/chainner_models/architecture/SwiftSRGAN.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/SwiftSRGAN.py rename to backend/headless/fcbh_extras/chainner_models/architecture/SwiftSRGAN.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/Swin2SR.py b/backend/headless/fcbh_extras/chainner_models/architecture/Swin2SR.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/Swin2SR.py rename to backend/headless/fcbh_extras/chainner_models/architecture/Swin2SR.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/SwinIR.py b/backend/headless/fcbh_extras/chainner_models/architecture/SwinIR.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/SwinIR.py rename to backend/headless/fcbh_extras/chainner_models/architecture/SwinIR.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/__init__.py b/backend/headless/fcbh_extras/chainner_models/architecture/__init__.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/__init__.py rename to backend/headless/fcbh_extras/chainner_models/architecture/__init__.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/block.py b/backend/headless/fcbh_extras/chainner_models/architecture/block.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/block.py rename to backend/headless/fcbh_extras/chainner_models/architecture/block.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-GFPGAN b/backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-GFPGAN similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-GFPGAN rename to backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-GFPGAN diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-RestoreFormer b/backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-RestoreFormer similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-RestoreFormer rename to backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-RestoreFormer diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-codeformer b/backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-codeformer similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/LICENSE-codeformer rename to backend/headless/fcbh_extras/chainner_models/architecture/face/LICENSE-codeformer diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/arcface_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/arcface_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/arcface_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/arcface_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/codeformer.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/codeformer.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/codeformer.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/codeformer.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/fused_act.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/fused_act.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/fused_act.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/fused_act.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/gfpgan_bilinear_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/gfpgan_bilinear_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/gfpgan_bilinear_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/gfpgan_bilinear_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/gfpganv1_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/gfpganv1_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/gfpganv1_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/gfpganv1_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/gfpganv1_clean_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/gfpganv1_clean_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/gfpganv1_clean_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/gfpganv1_clean_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/restoreformer_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/restoreformer_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/restoreformer_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/restoreformer_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_bilinear_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_bilinear_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_bilinear_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_bilinear_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_clean_arch.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_clean_arch.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/stylegan2_clean_arch.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/stylegan2_clean_arch.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/face/upfirdn2d.py b/backend/headless/fcbh_extras/chainner_models/architecture/face/upfirdn2d.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/face/upfirdn2d.py rename to backend/headless/fcbh_extras/chainner_models/architecture/face/upfirdn2d.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/timm/LICENSE b/backend/headless/fcbh_extras/chainner_models/architecture/timm/LICENSE similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/timm/LICENSE rename to backend/headless/fcbh_extras/chainner_models/architecture/timm/LICENSE diff --git a/backend/headless/comfy_extras/chainner_models/architecture/timm/drop.py b/backend/headless/fcbh_extras/chainner_models/architecture/timm/drop.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/timm/drop.py rename to backend/headless/fcbh_extras/chainner_models/architecture/timm/drop.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/timm/helpers.py b/backend/headless/fcbh_extras/chainner_models/architecture/timm/helpers.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/timm/helpers.py rename to backend/headless/fcbh_extras/chainner_models/architecture/timm/helpers.py diff --git a/backend/headless/comfy_extras/chainner_models/architecture/timm/weight_init.py b/backend/headless/fcbh_extras/chainner_models/architecture/timm/weight_init.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/architecture/timm/weight_init.py rename to backend/headless/fcbh_extras/chainner_models/architecture/timm/weight_init.py diff --git a/backend/headless/comfy_extras/chainner_models/model_loading.py b/backend/headless/fcbh_extras/chainner_models/model_loading.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/model_loading.py rename to backend/headless/fcbh_extras/chainner_models/model_loading.py diff --git a/backend/headless/comfy_extras/chainner_models/types.py b/backend/headless/fcbh_extras/chainner_models/types.py similarity index 100% rename from backend/headless/comfy_extras/chainner_models/types.py rename to backend/headless/fcbh_extras/chainner_models/types.py diff --git a/backend/headless/comfy_extras/nodes_canny.py b/backend/headless/fcbh_extras/nodes_canny.py similarity index 98% rename from backend/headless/comfy_extras/nodes_canny.py rename to backend/headless/fcbh_extras/nodes_canny.py index 94d453f2..86aa7de8 100644 --- a/backend/headless/comfy_extras/nodes_canny.py +++ b/backend/headless/fcbh_extras/nodes_canny.py @@ -3,7 +3,7 @@ import math import torch import torch.nn.functional as F -import comfy.model_management +import fcbh.model_management def get_canny_nms_kernel(device=None, dtype=None): """Utility function that returns 3x3 kernels for the Canny Non-maximal suppression.""" @@ -290,7 +290,7 @@ class Canny: CATEGORY = "image/preprocessors" def detect_edge(self, image, low_threshold, high_threshold): - output = canny(image.to(comfy.model_management.get_torch_device()).movedim(-1, 1), low_threshold, high_threshold) + output = canny(image.to(fcbh.model_management.get_torch_device()).movedim(-1, 1), low_threshold, high_threshold) img_out = output[1].cpu().repeat(1, 3, 1, 1).movedim(1, -1) return (img_out,) diff --git a/backend/headless/comfy_extras/nodes_clip_sdxl.py b/backend/headless/fcbh_extras/nodes_clip_sdxl.py similarity index 100% rename from backend/headless/comfy_extras/nodes_clip_sdxl.py rename to backend/headless/fcbh_extras/nodes_clip_sdxl.py diff --git a/backend/headless/comfy_extras/nodes_compositing.py b/backend/headless/fcbh_extras/nodes_compositing.py similarity index 93% rename from backend/headless/comfy_extras/nodes_compositing.py rename to backend/headless/fcbh_extras/nodes_compositing.py index 181b36ed..37fe60dc 100644 --- a/backend/headless/comfy_extras/nodes_compositing.py +++ b/backend/headless/fcbh_extras/nodes_compositing.py @@ -1,6 +1,6 @@ import numpy as np import torch -import comfy.utils +import fcbh.utils from enum import Enum def resize_mask(mask, shape): @@ -122,15 +122,15 @@ class PorterDuffImageComposite: if dst_alpha.shape[:2] != dst_image.shape[:2]: upscale_input = dst_alpha.unsqueeze(0).permute(0, 3, 1, 2) - upscale_output = comfy.utils.common_upscale(upscale_input, dst_image.shape[1], dst_image.shape[0], upscale_method='bicubic', crop='center') + upscale_output = fcbh.utils.common_upscale(upscale_input, dst_image.shape[1], dst_image.shape[0], upscale_method='bicubic', crop='center') dst_alpha = upscale_output.permute(0, 2, 3, 1).squeeze(0) if src_image.shape != dst_image.shape: upscale_input = src_image.unsqueeze(0).permute(0, 3, 1, 2) - upscale_output = comfy.utils.common_upscale(upscale_input, dst_image.shape[1], dst_image.shape[0], upscale_method='bicubic', crop='center') + upscale_output = fcbh.utils.common_upscale(upscale_input, dst_image.shape[1], dst_image.shape[0], upscale_method='bicubic', crop='center') src_image = upscale_output.permute(0, 2, 3, 1).squeeze(0) if src_alpha.shape != dst_alpha.shape: upscale_input = src_alpha.unsqueeze(0).permute(0, 3, 1, 2) - upscale_output = comfy.utils.common_upscale(upscale_input, dst_alpha.shape[1], dst_alpha.shape[0], upscale_method='bicubic', crop='center') + upscale_output = fcbh.utils.common_upscale(upscale_input, dst_alpha.shape[1], dst_alpha.shape[0], upscale_method='bicubic', crop='center') src_alpha = upscale_output.permute(0, 2, 3, 1).squeeze(0) out_image, out_alpha = porter_duff_composite(src_image, src_alpha, dst_image, dst_alpha, PorterDuffMode[mode]) diff --git a/backend/headless/comfy_extras/nodes_custom_sampler.py b/backend/headless/fcbh_extras/nodes_custom_sampler.py similarity index 89% rename from backend/headless/comfy_extras/nodes_custom_sampler.py rename to backend/headless/fcbh_extras/nodes_custom_sampler.py index b52ad8fb..931d17ae 100644 --- a/backend/headless/comfy_extras/nodes_custom_sampler.py +++ b/backend/headless/fcbh_extras/nodes_custom_sampler.py @@ -1,9 +1,9 @@ -import comfy.samplers -import comfy.sample -from comfy.k_diffusion import sampling as k_diffusion_sampling +import fcbh.samplers +import fcbh.sample +from fcbh.k_diffusion import sampling as k_diffusion_sampling import latent_preview import torch -import comfy.utils +import fcbh.utils class BasicScheduler: @@ -11,7 +11,7 @@ class BasicScheduler: def INPUT_TYPES(s): return {"required": {"model": ("MODEL",), - "scheduler": (comfy.samplers.SCHEDULER_NAMES, ), + "scheduler": (fcbh.samplers.SCHEDULER_NAMES, ), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), } } @@ -21,7 +21,7 @@ class BasicScheduler: FUNCTION = "get_sigmas" def get_sigmas(self, model, scheduler, steps): - sigmas = comfy.samplers.calculate_sigmas_scheduler(model.model, scheduler, steps).cpu() + sigmas = fcbh.samplers.calculate_sigmas_scheduler(model.model, scheduler, steps).cpu() return (sigmas, ) @@ -122,7 +122,7 @@ class KSamplerSelect: @classmethod def INPUT_TYPES(s): return {"required": - {"sampler_name": (comfy.samplers.SAMPLER_NAMES, ), + {"sampler_name": (fcbh.samplers.SAMPLER_NAMES, ), } } RETURN_TYPES = ("SAMPLER",) @@ -131,7 +131,7 @@ class KSamplerSelect: FUNCTION = "get_sampler" def get_sampler(self, sampler_name): - sampler = comfy.samplers.sampler_class(sampler_name)() + sampler = fcbh.samplers.sampler_class(sampler_name)() return (sampler, ) class SamplerDPMPP_2M_SDE: @@ -154,7 +154,7 @@ class SamplerDPMPP_2M_SDE: sampler_name = "dpmpp_2m_sde" else: sampler_name = "dpmpp_2m_sde_gpu" - sampler = comfy.samplers.ksampler(sampler_name, {"eta": eta, "s_noise": s_noise, "solver_type": solver_type})() + sampler = fcbh.samplers.ksampler(sampler_name, {"eta": eta, "s_noise": s_noise, "solver_type": solver_type})() return (sampler, ) @@ -178,7 +178,7 @@ class SamplerDPMPP_SDE: sampler_name = "dpmpp_sde" else: sampler_name = "dpmpp_sde_gpu" - sampler = comfy.samplers.ksampler(sampler_name, {"eta": eta, "s_noise": s_noise, "r": r})() + sampler = fcbh.samplers.ksampler(sampler_name, {"eta": eta, "s_noise": s_noise, "r": r})() return (sampler, ) class SamplerCustom: @@ -211,7 +211,7 @@ class SamplerCustom: 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, noise_seed, batch_inds) + noise = fcbh.sample.prepare_noise(latent_image, noise_seed, batch_inds) noise_mask = None if "noise_mask" in latent: @@ -220,8 +220,8 @@ class SamplerCustom: x0_output = {} callback = latent_preview.prepare_callback(model, sigmas.shape[-1] - 1, x0_output) - disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED - samples = comfy.sample.sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent_image, noise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=noise_seed) + disable_pbar = not fcbh.utils.PROGRESS_BAR_ENABLED + samples = fcbh.sample.sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent_image, noise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=noise_seed) out = latent.copy() out["samples"] = samples diff --git a/backend/headless/comfy_extras/nodes_freelunch.py b/backend/headless/fcbh_extras/nodes_freelunch.py similarity index 100% rename from backend/headless/comfy_extras/nodes_freelunch.py rename to backend/headless/fcbh_extras/nodes_freelunch.py diff --git a/backend/headless/comfy_extras/nodes_hypernetwork.py b/backend/headless/fcbh_extras/nodes_hypernetwork.py similarity index 98% rename from backend/headless/comfy_extras/nodes_hypernetwork.py rename to backend/headless/fcbh_extras/nodes_hypernetwork.py index d16c49ae..2ed8c1dc 100644 --- a/backend/headless/comfy_extras/nodes_hypernetwork.py +++ b/backend/headless/fcbh_extras/nodes_hypernetwork.py @@ -1,9 +1,9 @@ -import comfy.utils +import fcbh.utils import folder_paths import torch def load_hypernetwork_patch(path, strength): - sd = comfy.utils.load_torch_file(path, safe_load=True) + sd = fcbh.utils.load_torch_file(path, safe_load=True) activation_func = sd.get('activation_func', 'linear') is_layer_norm = sd.get('is_layer_norm', False) use_dropout = sd.get('use_dropout', False) diff --git a/backend/headless/comfy_extras/nodes_latent.py b/backend/headless/fcbh_extras/nodes_latent.py similarity index 90% rename from backend/headless/comfy_extras/nodes_latent.py rename to backend/headless/fcbh_extras/nodes_latent.py index 001de39f..1d574b03 100644 --- a/backend/headless/comfy_extras/nodes_latent.py +++ b/backend/headless/fcbh_extras/nodes_latent.py @@ -1,11 +1,11 @@ -import comfy.utils +import fcbh.utils def reshape_latent_to(target_shape, latent): if latent.shape[1:] != target_shape[1:]: latent.movedim(1, -1) - latent = comfy.utils.common_upscale(latent, target_shape[3], target_shape[2], "bilinear", "center") + latent = fcbh.utils.common_upscale(latent, target_shape[3], target_shape[2], "bilinear", "center") latent.movedim(-1, 1) - return comfy.utils.repeat_to_batch_size(latent, target_shape[0]) + return fcbh.utils.repeat_to_batch_size(latent, target_shape[0]) class LatentAdd: diff --git a/backend/headless/comfy_extras/nodes_mask.py b/backend/headless/fcbh_extras/nodes_mask.py similarity index 98% rename from backend/headless/comfy_extras/nodes_mask.py rename to backend/headless/fcbh_extras/nodes_mask.py index 9b0b289c..78f288d6 100644 --- a/backend/headless/comfy_extras/nodes_mask.py +++ b/backend/headless/fcbh_extras/nodes_mask.py @@ -1,7 +1,7 @@ import numpy as np import scipy.ndimage import torch -import comfy.utils +import fcbh.utils from nodes import MAX_RESOLUTION @@ -9,7 +9,7 @@ def composite(destination, source, x, y, mask = None, multiplier = 8, resize_sou if resize_source: source = torch.nn.functional.interpolate(source, size=(destination.shape[2], destination.shape[3]), mode="bilinear") - source = comfy.utils.repeat_to_batch_size(source, destination.shape[0]) + source = fcbh.utils.repeat_to_batch_size(source, destination.shape[0]) x = max(-source.shape[3] * multiplier, min(x, destination.shape[3] * multiplier)) y = max(-source.shape[2] * multiplier, min(y, destination.shape[2] * multiplier)) @@ -22,7 +22,7 @@ def composite(destination, source, x, y, mask = None, multiplier = 8, resize_sou else: mask = mask.clone() mask = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(source.shape[2], source.shape[3]), mode="bilinear") - mask = comfy.utils.repeat_to_batch_size(mask, source.shape[0]) + mask = fcbh.utils.repeat_to_batch_size(mask, source.shape[0]) # calculate the bounds of the source that will be overlapping the destination # this prevents the source trying to overwrite latent pixels that are out of bounds diff --git a/backend/headless/comfy_extras/nodes_model_merging.py b/backend/headless/fcbh_extras/nodes_model_merging.py similarity index 90% rename from backend/headless/comfy_extras/nodes_model_merging.py rename to backend/headless/fcbh_extras/nodes_model_merging.py index dad1dd63..63432ab6 100644 --- a/backend/headless/comfy_extras/nodes_model_merging.py +++ b/backend/headless/fcbh_extras/nodes_model_merging.py @@ -1,13 +1,13 @@ -import comfy.sd -import comfy.utils -import comfy.model_base -import comfy.model_management +import fcbh.sd +import fcbh.utils +import fcbh.model_base +import fcbh.model_management import folder_paths import json import os -from comfy.cli_args import args +from fcbh.cli_args import args class ModelMergeSimple: @classmethod @@ -128,7 +128,7 @@ class CheckpointSave: return {"required": { "model": ("MODEL",), "clip": ("CLIP",), "vae": ("VAE",), - "filename_prefix": ("STRING", {"default": "checkpoints/ComfyUI"}),}, + "filename_prefix": ("STRING", {"default": "checkpoints/fcbh_backend"}),}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},} RETURN_TYPES = () FUNCTION = "save" @@ -145,9 +145,9 @@ class CheckpointSave: metadata = {} enable_modelspec = True - if isinstance(model.model, comfy.model_base.SDXL): + if isinstance(model.model, fcbh.model_base.SDXL): metadata["modelspec.architecture"] = "stable-diffusion-xl-v1-base" - elif isinstance(model.model, comfy.model_base.SDXLRefiner): + elif isinstance(model.model, fcbh.model_base.SDXLRefiner): metadata["modelspec.architecture"] = "stable-diffusion-xl-v1-refiner" else: enable_modelspec = False @@ -162,9 +162,9 @@ class CheckpointSave: # "stable-diffusion-v2-768-v", "stable-diffusion-v2-unclip-l", "stable-diffusion-v2-unclip-h", # "v2-inpainting" - if model.model.model_type == comfy.model_base.ModelType.EPS: + if model.model.model_type == fcbh.model_base.ModelType.EPS: metadata["modelspec.predict_key"] = "epsilon" - elif model.model.model_type == comfy.model_base.ModelType.V_PREDICTION: + elif model.model.model_type == fcbh.model_base.ModelType.V_PREDICTION: metadata["modelspec.predict_key"] = "v" if not args.disable_metadata: @@ -176,7 +176,7 @@ class CheckpointSave: output_checkpoint = f"{filename}_{counter:05}_.safetensors" output_checkpoint = os.path.join(full_output_folder, output_checkpoint) - comfy.sd.save_checkpoint(output_checkpoint, model, clip, vae, metadata=metadata) + fcbh.sd.save_checkpoint(output_checkpoint, model, clip, vae, metadata=metadata) return {} class CLIPSave: @@ -186,7 +186,7 @@ class CLIPSave: @classmethod def INPUT_TYPES(s): return {"required": { "clip": ("CLIP",), - "filename_prefix": ("STRING", {"default": "clip/ComfyUI"}),}, + "filename_prefix": ("STRING", {"default": "clip/fcbh_backend"}),}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},} RETURN_TYPES = () FUNCTION = "save" @@ -206,7 +206,7 @@ class CLIPSave: for x in extra_pnginfo: metadata[x] = json.dumps(extra_pnginfo[x]) - comfy.model_management.load_models_gpu([clip.load_model()]) + fcbh.model_management.load_models_gpu([clip.load_model()]) clip_sd = clip.get_sd() for prefix in ["clip_l.", "clip_g.", ""]: @@ -230,9 +230,9 @@ class CLIPSave: output_checkpoint = f"{filename}_{counter:05}_.safetensors" output_checkpoint = os.path.join(full_output_folder, output_checkpoint) - current_clip_sd = comfy.utils.state_dict_prefix_replace(current_clip_sd, replace_prefix) + current_clip_sd = fcbh.utils.state_dict_prefix_replace(current_clip_sd, replace_prefix) - comfy.utils.save_torch_file(current_clip_sd, output_checkpoint, metadata=metadata) + fcbh.utils.save_torch_file(current_clip_sd, output_checkpoint, metadata=metadata) return {} class VAESave: @@ -242,7 +242,7 @@ class VAESave: @classmethod def INPUT_TYPES(s): return {"required": { "vae": ("VAE",), - "filename_prefix": ("STRING", {"default": "vae/ComfyUI_vae"}),}, + "filename_prefix": ("STRING", {"default": "vae/fcbh_backend_vae"}),}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},} RETURN_TYPES = () FUNCTION = "save" @@ -266,7 +266,7 @@ class VAESave: output_checkpoint = f"{filename}_{counter:05}_.safetensors" output_checkpoint = os.path.join(full_output_folder, output_checkpoint) - comfy.utils.save_torch_file(vae.get_sd(), output_checkpoint, metadata=metadata) + fcbh.utils.save_torch_file(vae.get_sd(), output_checkpoint, metadata=metadata) return {} NODE_CLASS_MAPPINGS = { diff --git a/backend/headless/comfy_extras/nodes_post_processing.py b/backend/headless/fcbh_extras/nodes_post_processing.py similarity index 97% rename from backend/headless/comfy_extras/nodes_post_processing.py rename to backend/headless/fcbh_extras/nodes_post_processing.py index 3f651e59..beb0b2c6 100644 --- a/backend/headless/comfy_extras/nodes_post_processing.py +++ b/backend/headless/fcbh_extras/nodes_post_processing.py @@ -4,7 +4,7 @@ import torch.nn.functional as F from PIL import Image import math -import comfy.utils +import fcbh.utils class Blend: @@ -35,7 +35,7 @@ class Blend: def blend_images(self, image1: torch.Tensor, image2: torch.Tensor, blend_factor: float, blend_mode: str): if image1.shape != image2.shape: image2 = image2.permute(0, 3, 1, 2) - image2 = comfy.utils.common_upscale(image2, image1.shape[2], image1.shape[1], upscale_method='bicubic', crop='center') + image2 = fcbh.utils.common_upscale(image2, image1.shape[2], image1.shape[1], upscale_method='bicubic', crop='center') image2 = image2.permute(0, 2, 3, 1) blended_image = self.blend_mode(image1, image2, blend_mode) @@ -232,7 +232,7 @@ class ImageScaleToTotalPixels: width = round(samples.shape[3] * scale_by) height = round(samples.shape[2] * scale_by) - s = comfy.utils.common_upscale(samples, width, height, upscale_method, "disabled") + s = fcbh.utils.common_upscale(samples, width, height, upscale_method, "disabled") s = s.movedim(1,-1) return (s,) diff --git a/backend/headless/comfy_extras/nodes_rebatch.py b/backend/headless/fcbh_extras/nodes_rebatch.py similarity index 100% rename from backend/headless/comfy_extras/nodes_rebatch.py rename to backend/headless/fcbh_extras/nodes_rebatch.py diff --git a/backend/headless/comfy_extras/nodes_tomesd.py b/backend/headless/fcbh_extras/nodes_tomesd.py similarity index 100% rename from backend/headless/comfy_extras/nodes_tomesd.py rename to backend/headless/fcbh_extras/nodes_tomesd.py diff --git a/backend/headless/comfy_extras/nodes_upscale_model.py b/backend/headless/fcbh_extras/nodes_upscale_model.py similarity index 72% rename from backend/headless/comfy_extras/nodes_upscale_model.py rename to backend/headless/fcbh_extras/nodes_upscale_model.py index 2b5e49a5..daeea6e6 100644 --- a/backend/headless/comfy_extras/nodes_upscale_model.py +++ b/backend/headless/fcbh_extras/nodes_upscale_model.py @@ -1,8 +1,8 @@ import os -from comfy_extras.chainner_models import model_loading -from comfy import model_management +from fcbh_extras.chainner_models import model_loading +from fcbh import model_management import torch -import comfy.utils +import fcbh.utils import folder_paths class UpscaleModelLoader: @@ -17,9 +17,9 @@ class UpscaleModelLoader: def load_model(self, model_name): model_path = folder_paths.get_full_path("upscale_models", model_name) - sd = comfy.utils.load_torch_file(model_path, safe_load=True) + sd = fcbh.utils.load_torch_file(model_path, safe_load=True) if "module.layers.0.residual_group.blocks.0.norm1.weight" in sd: - sd = comfy.utils.state_dict_prefix_replace(sd, {"module.":""}) + sd = fcbh.utils.state_dict_prefix_replace(sd, {"module.":""}) out = model_loading.load_state_dict(sd).eval() return (out, ) @@ -47,9 +47,9 @@ class ImageUpscaleWithModel: oom = True while oom: try: - steps = in_img.shape[0] * comfy.utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile, tile_y=tile, overlap=overlap) - pbar = comfy.utils.ProgressBar(steps) - s = comfy.utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap, upscale_amount=upscale_model.scale, pbar=pbar) + steps = in_img.shape[0] * fcbh.utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile, tile_y=tile, overlap=overlap) + pbar = fcbh.utils.ProgressBar(steps) + s = fcbh.utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap, upscale_amount=upscale_model.scale, pbar=pbar) oom = False except model_management.OOM_EXCEPTION as e: tile //= 2 diff --git a/backend/headless/latent_preview.py b/backend/headless/latent_preview.py index e1553c85..5b07078e 100644 --- a/backend/headless/latent_preview.py +++ b/backend/headless/latent_preview.py @@ -2,10 +2,10 @@ import torch from PIL import Image import struct import numpy as np -from comfy.cli_args import args, LatentPreviewMethod -from comfy.taesd.taesd import TAESD +from fcbh.cli_args import args, LatentPreviewMethod +from fcbh.taesd.taesd import TAESD import folder_paths -import comfy.utils +import fcbh.utils MAX_PREVIEW_RESOLUTION = 512 @@ -87,7 +87,7 @@ def prepare_callback(model, steps, x0_output_dict=None): previewer = get_previewer(model.load_device, model.model.latent_format) - pbar = comfy.utils.ProgressBar(steps) + pbar = fcbh.utils.ProgressBar(steps) def callback(step, x0, x, total_steps): if x0_output_dict is not None: x0_output_dict["x0"] = x0 diff --git a/backend/headless/nodes.py b/backend/headless/nodes.py index 208cbc84..c59c352b 100644 --- a/backend/headless/nodes.py +++ b/backend/headless/nodes.py @@ -14,20 +14,20 @@ from PIL.PngImagePlugin import PngInfo import numpy as np import safetensors.torch -sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy")) +sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "fcbh")) -import comfy.diffusers_load -import comfy.samplers -import comfy.sample -import comfy.sd -import comfy.utils -import comfy.controlnet +import fcbh.diffusers_load +import fcbh.samplers +import fcbh.sample +import fcbh.sd +import fcbh.utils +import fcbh.controlnet -import comfy.clip_vision +import fcbh.clip_vision -import comfy.model_management -from comfy.cli_args import args +import fcbh.model_management +from fcbh.cli_args import args import importlib @@ -35,10 +35,10 @@ import folder_paths import latent_preview def before_node_execution(): - comfy.model_management.throw_exception_if_processing_interrupted() + fcbh.model_management.throw_exception_if_processing_interrupted() def interrupt_processing(value=True): - comfy.model_management.interrupt_current_processing(value) + fcbh.model_management.interrupt_current_processing(value) MAX_RESOLUTION=8192 @@ -366,7 +366,7 @@ class SaveLatent: @classmethod def INPUT_TYPES(s): return {"required": { "samples": ("LATENT", ), - "filename_prefix": ("STRING", {"default": "latents/ComfyUI"})}, + "filename_prefix": ("STRING", {"default": "latents/fcbh_backend"})}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, } RETURN_TYPES = () @@ -376,7 +376,7 @@ class SaveLatent: CATEGORY = "_for_testing" - def save(self, samples, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): + def save(self, samples, filename_prefix="fcbh_backend", prompt=None, extra_pnginfo=None): full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir) # support save metadata for latent sharing @@ -406,7 +406,7 @@ class SaveLatent: output["latent_tensor"] = samples["samples"] output["latent_format_version_0"] = torch.tensor([]) - comfy.utils.save_torch_file(output, file, metadata=metadata) + fcbh.utils.save_torch_file(output, file, metadata=metadata) return { "ui": { "latents": results } } @@ -459,7 +459,7 @@ class CheckpointLoader: def load_checkpoint(self, config_name, ckpt_name, output_vae=True, output_clip=True): config_path = folder_paths.get_full_path("configs", config_name) ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name) - return comfy.sd.load_checkpoint(config_path, ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) + return fcbh.sd.load_checkpoint(config_path, ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) class CheckpointLoaderSimple: @classmethod @@ -473,7 +473,7 @@ class CheckpointLoaderSimple: def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True): ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name) - out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) + out = fcbh.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) return out[:3] class DiffusersLoader: @@ -500,7 +500,7 @@ class DiffusersLoader: model_path = path break - return comfy.diffusers_load.load_diffusers(model_path, output_vae=output_vae, output_clip=output_clip, embedding_directory=folder_paths.get_folder_paths("embeddings")) + return fcbh.diffusers_load.load_diffusers(model_path, output_vae=output_vae, output_clip=output_clip, embedding_directory=folder_paths.get_folder_paths("embeddings")) class unCLIPCheckpointLoader: @@ -515,7 +515,7 @@ class unCLIPCheckpointLoader: def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True): ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name) - out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, output_clipvision=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) + out = fcbh.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, output_clipvision=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) return out class CLIPSetLastLayer: @@ -566,10 +566,10 @@ class LoraLoader: del temp if lora is None: - lora = comfy.utils.load_torch_file(lora_path, safe_load=True) + lora = fcbh.utils.load_torch_file(lora_path, safe_load=True) self.loaded_lora = (lora_path, lora) - model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip) + model_lora, clip_lora = fcbh.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip) return (model_lora, clip_lora) class VAELoader: @@ -584,7 +584,7 @@ class VAELoader: #TODO: scale factor? def load_vae(self, vae_name): vae_path = folder_paths.get_full_path("vae", vae_name) - vae = comfy.sd.VAE(ckpt_path=vae_path) + vae = fcbh.sd.VAE(ckpt_path=vae_path) return (vae,) class ControlNetLoader: @@ -599,7 +599,7 @@ class ControlNetLoader: def load_controlnet(self, control_net_name): controlnet_path = folder_paths.get_full_path("controlnet", control_net_name) - controlnet = comfy.controlnet.load_controlnet(controlnet_path) + controlnet = fcbh.controlnet.load_controlnet(controlnet_path) return (controlnet,) class DiffControlNetLoader: @@ -615,7 +615,7 @@ class DiffControlNetLoader: def load_controlnet(self, model, control_net_name): controlnet_path = folder_paths.get_full_path("controlnet", control_net_name) - controlnet = comfy.controlnet.load_controlnet(controlnet_path, model) + controlnet = fcbh.controlnet.load_controlnet(controlnet_path, model) return (controlnet,) @@ -708,7 +708,7 @@ class UNETLoader: def load_unet(self, unet_name): unet_path = folder_paths.get_full_path("unet", unet_name) - model = comfy.sd.load_unet(unet_path) + model = fcbh.sd.load_unet(unet_path) return (model,) class CLIPLoader: @@ -723,7 +723,7 @@ class CLIPLoader: def load_clip(self, clip_name): clip_path = folder_paths.get_full_path("clip", clip_name) - clip = comfy.sd.load_clip(ckpt_paths=[clip_path], embedding_directory=folder_paths.get_folder_paths("embeddings")) + clip = fcbh.sd.load_clip(ckpt_paths=[clip_path], embedding_directory=folder_paths.get_folder_paths("embeddings")) return (clip,) class DualCLIPLoader: @@ -739,7 +739,7 @@ class DualCLIPLoader: def load_clip(self, clip_name1, clip_name2): clip_path1 = folder_paths.get_full_path("clip", clip_name1) clip_path2 = folder_paths.get_full_path("clip", clip_name2) - clip = comfy.sd.load_clip(ckpt_paths=[clip_path1, clip_path2], embedding_directory=folder_paths.get_folder_paths("embeddings")) + clip = fcbh.sd.load_clip(ckpt_paths=[clip_path1, clip_path2], embedding_directory=folder_paths.get_folder_paths("embeddings")) return (clip,) class CLIPVisionLoader: @@ -754,7 +754,7 @@ class CLIPVisionLoader: def load_clip(self, clip_name): clip_path = folder_paths.get_full_path("clip_vision", clip_name) - clip_vision = comfy.clip_vision.load(clip_path) + clip_vision = fcbh.clip_vision.load(clip_path) return (clip_vision,) class CLIPVisionEncode: @@ -784,7 +784,7 @@ class StyleModelLoader: def load_style_model(self, style_model_name): style_model_path = folder_paths.get_full_path("style_models", style_model_name) - style_model = comfy.sd.load_style_model(style_model_path) + style_model = fcbh.sd.load_style_model(style_model_path) return (style_model,) @@ -849,7 +849,7 @@ class GLIGENLoader: def load_gligen(self, gligen_name): gligen_path = folder_paths.get_full_path("gligen", gligen_name) - gligen = comfy.sd.load_gligen(gligen_path) + gligen = fcbh.sd.load_gligen(gligen_path) return (gligen,) class GLIGENTextBoxApply: @@ -991,7 +991,7 @@ class LatentUpscale: width = max(64, width) height = max(64, height) - s["samples"] = comfy.utils.common_upscale(samples["samples"], width // 8, height // 8, upscale_method, crop) + s["samples"] = fcbh.utils.common_upscale(samples["samples"], width // 8, height // 8, upscale_method, crop) return (s,) class LatentUpscaleBy: @@ -1010,7 +1010,7 @@ class LatentUpscaleBy: s = samples.copy() width = round(samples["samples"].shape[3] * scale_by) height = round(samples["samples"].shape[2] * scale_by) - s["samples"] = comfy.utils.common_upscale(samples["samples"], width, height, upscale_method, "disabled") + s["samples"] = fcbh.utils.common_upscale(samples["samples"], width, height, upscale_method, "disabled") return (s,) class LatentRotate: @@ -1126,7 +1126,7 @@ class LatentBlend: if samples1.shape != samples2.shape: samples2.permute(0, 3, 1, 2) - samples2 = comfy.utils.common_upscale(samples2, samples1.shape[3], samples1.shape[2], 'bicubic', crop='center') + samples2 = fcbh.utils.common_upscale(samples2, samples1.shape[3], samples1.shape[2], 'bicubic', crop='center') samples2.permute(0, 2, 3, 1) samples_blended = self.blend_mode(samples1, samples2, blend_mode) @@ -1195,15 +1195,15 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, 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) + noise = fcbh.sample.prepare_noise(latent_image, seed, batch_inds) noise_mask = None if "noise_mask" in latent: noise_mask = latent["noise_mask"] callback = latent_preview.prepare_callback(model, steps) - disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED - samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, + disable_pbar = not fcbh.utils.PROGRESS_BAR_ENABLED + samples = fcbh.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed) out = latent.copy() @@ -1218,8 +1218,8 @@ class KSampler: "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.5, "round": 0.01}), - "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), - "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), + "sampler_name": (fcbh.samplers.KSampler.SAMPLERS, ), + "scheduler": (fcbh.samplers.KSampler.SCHEDULERS, ), "positive": ("CONDITIONING", ), "negative": ("CONDITIONING", ), "latent_image": ("LATENT", ), @@ -1244,8 +1244,8 @@ class KSamplerAdvanced: "noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}), "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.5, "round": 0.01}), - "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), - "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), + "sampler_name": (fcbh.samplers.KSampler.SAMPLERS, ), + "scheduler": (fcbh.samplers.KSampler.SCHEDULERS, ), "positive": ("CONDITIONING", ), "negative": ("CONDITIONING", ), "latent_image": ("LATENT", ), @@ -1279,7 +1279,7 @@ class SaveImage: def INPUT_TYPES(s): return {"required": {"images": ("IMAGE", ), - "filename_prefix": ("STRING", {"default": "ComfyUI"})}, + "filename_prefix": ("STRING", {"default": "fcbh_backend"})}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, } @@ -1290,7 +1290,7 @@ class SaveImage: CATEGORY = "image" - def save_images(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): + def save_images(self, images, filename_prefix="fcbh_backend", prompt=None, extra_pnginfo=None): filename_prefix += self.prefix_append full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]) results = list() @@ -1448,7 +1448,7 @@ class ImageScale: elif height == 0: height = max(1, round(samples.shape[2] * width / samples.shape[3])) - s = comfy.utils.common_upscale(samples, width, height, upscale_method, crop) + s = fcbh.utils.common_upscale(samples, width, height, upscale_method, crop) s = s.movedim(1,-1) return (s,) @@ -1468,7 +1468,7 @@ class ImageScaleBy: samples = image.movedim(-1,1) width = round(samples.shape[3] * scale_by) height = round(samples.shape[2] * scale_by) - s = comfy.utils.common_upscale(samples, width, height, upscale_method, "disabled") + s = fcbh.utils.common_upscale(samples, width, height, upscale_method, "disabled") s = s.movedim(1,-1) return (s,) @@ -1500,7 +1500,7 @@ class ImageBatch: def batch(self, image1, image2): if image1.shape[1:] != image2.shape[1:]: - image2 = comfy.utils.common_upscale(image2.movedim(-1,1), image1.shape[2], image1.shape[1], "bilinear", "center").movedim(1,-1) + image2 = fcbh.utils.common_upscale(image2.movedim(-1,1), image1.shape[2], image1.shape[1], "bilinear", "center").movedim(1,-1) s = torch.cat((image1, image2), dim=0) return (s,) @@ -1781,7 +1781,7 @@ def load_custom_nodes(): print() def init_custom_nodes(): - extras_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras") + extras_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fcbh_extras") extras_files = [ "nodes_latent.py", "nodes_hypernetwork.py", diff --git a/backend/readme.md b/backend/readme.md new file mode 100644 index 00000000..26cbc8f7 --- /dev/null +++ b/backend/readme.md @@ -0,0 +1,5 @@ +# Fooocus' Comfy Backend Headless (FCBH) + +This is a Comfy Backend from StabilityAI. This pre-complied backend makes it easier for people who have trouble using pygit2. + +FCBH is maintained by Fooocus's reviewing upon StabilityAI's changes. diff --git a/build_chb.py b/build_chb.py new file mode 100644 index 00000000..d6592fe6 --- /dev/null +++ b/build_chb.py @@ -0,0 +1,64 @@ +import os +import shutil +import stat +import fnmatch + +from modules.launch_util import run + + +def onerror(func, path, execinfo): + os.chmod(path, stat.S_IWUSR) + func(path) + + +def get_empty_folder(path): + if os.path.isdir(path) or os.path.exists(path): + shutil.rmtree(path, onerror=onerror) + os.makedirs(path, exist_ok=True) + return path + + +def git_clone(url, dir, hash=None): + run(f'git clone {url} {dir}') + + +def findReplace(directory, find, replace, filePattern): + for path, dirs, files in os.walk(os.path.abspath(directory)): + for filename in fnmatch.filter(files, filePattern): + filepath = os.path.join(path, filename) + with open(filepath, encoding='utf-8') as f: + s = f.read() + s = s.replace(find, replace) + with open(filepath, "w", encoding='utf-8') as f: + f.write(s) + + +repo = "https://github.com/comfyanonymous/ComfyUI" +commit_hash = None + +temp_path = get_empty_folder(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend', 'temp')) +core_path = get_empty_folder(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend', 'headless')) + +git_clone(repo, temp_path, commit_hash) + + +def get_item(name, rename=None): + if rename is None: + rename = name + shutil.move(os.path.join(temp_path, name), os.path.join(core_path, rename)) + + +get_item('comfy', 'fcbh') +get_item('comfy_extras', 'fcbh_extras') +get_item('latent_preview.py') +get_item('folder_paths.py') +get_item('nodes.py') +get_item('LICENSE') + +shutil.rmtree(temp_path, onerror=onerror) + +findReplace("./backend", "comfy", "fcbh", "*.py") +findReplace("./backend", "Comfy", "FCBH", "*.py") +findReplace("./backend", "FCBHUI", "fcbh_backend", "*.py") + +print('Backend is built.') diff --git a/dev_script_build_backend.py b/dev_script_build_backend.py deleted file mode 100644 index ea217c09..00000000 --- a/dev_script_build_backend.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import shutil - - -from modules.launch_util import git_clone - - -def onerror(func, path, exc_info): - import stat - if not os.access(path, os.W_OK): - os.chmod(path, stat.S_IWUSR) - func(path) - else: - raise 'Failed to invoke "shutil.rmtree", git management failed.' - - -def get_empty_folder(path): - if os.path.isdir(path) or os.path.exists(path): - shutil.rmtree(path, onerror=onerror) - os.makedirs(path, exist_ok=True) - return path - - -comfy_repo = "https://github.com/comfyanonymous/ComfyUI" -comfy_commit_hash = None - -comfy_temp_path = get_empty_folder(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend', 'comfy_temp')) -comfy_core_path = get_empty_folder(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend', 'headless')) - -git_clone(comfy_repo, comfy_temp_path, "ComfyUI", comfy_commit_hash) - - -def get_item(name): - shutil.move(os.path.join(comfy_temp_path, name), os.path.join(comfy_core_path, name)) - - -get_item('comfy') -get_item('comfy_extras') -get_item('custom_nodes') -get_item('latent_preview.py') -get_item('folder_paths.py') -get_item('nodes.py') -get_item('LICENSE') - -shutil.rmtree(comfy_temp_path, onerror=onerror) - -print('Backend is built.') diff --git a/fooocus_extras/ip_adapter.py b/fooocus_extras/ip_adapter.py index b30a5646..ac2bed22 100644 --- a/fooocus_extras/ip_adapter.py +++ b/fooocus_extras/ip_adapter.py @@ -1,12 +1,12 @@ import torch -import comfy.clip_vision +import fcbh.clip_vision import safetensors.torch as sf -import comfy.model_management as model_management +import fcbh.model_management as model_management import contextlib -import comfy.ldm.modules.attention as attention +import fcbh.ldm.modules.attention as attention from fooocus_extras.resampler import Resampler -from comfy.model_patcher import ModelPatcher +from fcbh.model_patcher import ModelPatcher SD_V12_CHANNELS = [320] * 4 + [640] * 4 + [1280] * 4 + [1280] * 6 + [640] * 6 + [320] * 6 + [1280] * 2 @@ -81,7 +81,7 @@ class IPAdapterModel(torch.nn.Module): self.ip_layers.load_state_dict_ordered(state_dict["ip_adapter"]) -clip_vision: comfy.clip_vision.ClipVisionModel = None +clip_vision: fcbh.clip_vision.ClipVisionModel = None ip_negative: torch.Tensor = None image_proj_model: ModelPatcher = None ip_layers: ModelPatcher = None @@ -102,7 +102,7 @@ def load_ip_adapter(clip_vision_path, ip_negative_path, ip_adapter_path): return ip_negative = sf.load_file(ip_negative_path)['data'] - clip_vision = comfy.clip_vision.load(clip_vision_path) + clip_vision = fcbh.clip_vision.load(clip_vision_path) load_device = model_management.get_torch_device() offload_device = torch.device('cpu') @@ -150,7 +150,7 @@ def preprocess(img): global ip_unconds inputs = clip_vision.processor(images=img, return_tensors="pt") - comfy.model_management.load_model_gpu(clip_vision.patcher) + fcbh.model_management.load_model_gpu(clip_vision.patcher) pixel_values = inputs['pixel_values'].to(clip_vision.load_device) if clip_vision.dtype != torch.float32: @@ -158,7 +158,7 @@ def preprocess(img): else: precision_scope = lambda a, b: contextlib.nullcontext(a) - with precision_scope(comfy.model_management.get_autocast_device(clip_vision.load_device), torch.float32): + with precision_scope(fcbh.model_management.get_autocast_device(clip_vision.load_device), torch.float32): outputs = clip_vision.model(pixel_values=pixel_values, output_hidden_states=True) if ip_adapter.plus: @@ -166,10 +166,10 @@ def preprocess(img): else: cond = outputs.image_embeds.to(ip_adapter.dtype) - comfy.model_management.load_model_gpu(image_proj_model) + fcbh.model_management.load_model_gpu(image_proj_model) cond = image_proj_model.model(cond).to(device=ip_adapter.load_device, dtype=ip_adapter.dtype) - comfy.model_management.load_model_gpu(ip_layers) + fcbh.model_management.load_model_gpu(ip_layers) if ip_unconds is None: uncond = ip_negative.to(device=ip_adapter.load_device, dtype=ip_adapter.dtype) diff --git a/fooocus_extras/vae_interpose.py b/fooocus_extras/vae_interpose.py index e3c4e836..41f81927 100644 --- a/fooocus_extras/vae_interpose.py +++ b/fooocus_extras/vae_interpose.py @@ -4,9 +4,9 @@ import os import torch import safetensors.torch as sf import torch.nn as nn -import comfy.model_management +import fcbh.model_management -from comfy.model_patcher import ModelPatcher +from fcbh.model_patcher import ModelPatcher from modules.path import vae_approx_path @@ -76,17 +76,17 @@ def parse(x): model.eval() sd = sf.load_file(vae_approx_filename) model.load_state_dict(sd) - fp16 = comfy.model_management.should_use_fp16() + fp16 = fcbh.model_management.should_use_fp16() if fp16: model = model.half() vae_approx_model = ModelPatcher( model=model, - load_device=comfy.model_management.get_torch_device(), + load_device=fcbh.model_management.get_torch_device(), offload_device=torch.device('cpu') ) vae_approx_model.dtype = torch.float16 if fp16 else torch.float32 - comfy.model_management.load_model_gpu(vae_approx_model) + fcbh.model_management.load_model_gpu(vae_approx_model) x = x_origin.to(device=vae_approx_model.load_device, dtype=vae_approx_model.dtype) x = vae_approx_model.model(x) diff --git a/fooocus_version.py b/fooocus_version.py index eba47c0e..fcb81bf0 100644 --- a/fooocus_version.py +++ b/fooocus_version.py @@ -1 +1 @@ -version = '2.1.51' +version = '2.1.52' diff --git a/launch.py b/launch.py index f905d2b6..94f58dd0 100644 --- a/launch.py +++ b/launch.py @@ -83,13 +83,13 @@ def download_models(): return -def ini_comfy_args(): +def ini_cbh_args(): from args_manager import args return args prepare_environment() -ini_comfy_args() +ini_cbh_args() download_models() from webui import * diff --git a/modules/async_worker.py b/modules/async_worker.py index 9b97f833..e1d771dd 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -20,7 +20,7 @@ def worker(): import modules.flags as flags import modules.path import modules.patch - import comfy.model_management + import fcbh.model_management import fooocus_extras.preprocessors as preprocessors import modules.inpaint_worker as inpaint_worker import modules.advanced_parameters as advanced_parameters @@ -483,7 +483,7 @@ def worker(): outputs.append(['preview', (13, 'Moving model to GPU ...', None)]) execution_start_time = time.perf_counter() - comfy.model_management.load_models_gpu([pipeline.final_unet]) + fcbh.model_management.load_models_gpu([pipeline.final_unet]) moving_time = time.perf_counter() - execution_start_time print(f'Moving model to GPU: {moving_time:.2f} seconds') @@ -558,7 +558,7 @@ def worker(): log(x, d, single_line_number=3) results += imgs - except comfy.model_management.InterruptProcessingException as e: + except fcbh.model_management.InterruptProcessingException as e: if shared.last_stop == 'skip': print('User skipped') continue diff --git a/modules/core.py b/modules/core.py index dd6f5d70..a46df4f9 100644 --- a/modules/core.py +++ b/modules/core.py @@ -8,22 +8,22 @@ import einops import torch import numpy as np -import comfy.model_management -import comfy.model_detection -import comfy.model_patcher -import comfy.utils -import comfy.controlnet +import fcbh.model_management +import fcbh.model_detection +import fcbh.model_patcher +import fcbh.utils +import fcbh.controlnet import modules.sample_hijack -import comfy.samplers -import comfy.latent_formats +import fcbh.samplers +import fcbh.latent_formats -from comfy.sd import load_checkpoint_guess_config +from fcbh.sd import load_checkpoint_guess_config from nodes import VAEDecode, EmptyLatentImage, VAEEncode, VAEEncodeTiled, VAEDecodeTiled, VAEEncodeForInpaint, \ ControlNetApplyAdvanced -from comfy_extras.nodes_freelunch import FreeU -from comfy.sample import prepare_mask +from fcbh_extras.nodes_freelunch import FreeU +from fcbh.sample import prepare_mask from modules.patch import patched_sampler_cfg_function, patched_model_function_wrapper -from comfy.lora import model_lora_keys_unet, model_lora_keys_clip, load_lora +from fcbh.lora import model_lora_keys_unet, model_lora_keys_clip, load_lora opEmptyLatentImage = EmptyLatentImage() @@ -53,7 +53,7 @@ def apply_freeu(model, b1, b2, s1, s2): @torch.no_grad() @torch.inference_mode() def load_controlnet(ckpt_filename): - return comfy.controlnet.load_controlnet(ckpt_filename) + return fcbh.controlnet.load_controlnet(ckpt_filename) @torch.no_grad() @@ -78,7 +78,7 @@ def load_sd_lora(model, lora_filename, strength_model=1.0, strength_clip=1.0): if strength_model == 0 and strength_clip == 0: return model - lora = comfy.utils.load_torch_file(lora_filename, safe_load=False) + lora = fcbh.utils.load_torch_file(lora_filename, safe_load=False) if lora_filename.lower().endswith('.fooocus.patch'): loaded = lora @@ -164,7 +164,7 @@ def get_previewer(model): global VAE_approx_models from modules.path import vae_approx_path - is_sdxl = isinstance(model.model.latent_format, comfy.latent_formats.SDXL) + is_sdxl = isinstance(model.model.latent_format, fcbh.latent_formats.SDXL) vae_approx_filename = os.path.join(vae_approx_path, 'xlvaeapp.pth' if is_sdxl else 'vaeapp_sd15.pth') if vae_approx_filename in VAE_approx_models: @@ -176,14 +176,14 @@ def get_previewer(model): del sd VAE_approx_model.eval() - if comfy.model_management.should_use_fp16(): + if fcbh.model_management.should_use_fp16(): VAE_approx_model.half() VAE_approx_model.current_type = torch.float16 else: VAE_approx_model.float() VAE_approx_model.current_type = torch.float32 - VAE_approx_model.to(comfy.model_management.get_torch_device()) + VAE_approx_model.to(fcbh.model_management.get_torch_device()) VAE_approx_models[vae_approx_filename] = VAE_approx_model @torch.no_grad() @@ -207,14 +207,14 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa previewer_start=None, previewer_end=None, sigmas=None): if sigmas is not None: - sigmas = sigmas.clone().to(comfy.model_management.get_torch_device()) + sigmas = sigmas.clone().to(fcbh.model_management.get_torch_device()) latent_image = latent["samples"] 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) + noise = fcbh.sample.prepare_noise(latent_image, seed, batch_inds) noise_mask = None if "noise_mask" in latent: @@ -229,7 +229,7 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa previewer_end = steps def callback(step, x0, x, total_steps): - comfy.model_management.throw_exception_if_processing_interrupted() + fcbh.model_management.throw_exception_if_processing_interrupted() y = None if previewer is not None: y = previewer(x0, previewer_start + step, previewer_end) @@ -239,10 +239,10 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa disable_pbar = False modules.sample_hijack.current_refiner = refiner modules.sample_hijack.refiner_switch_step = refiner_switch - comfy.samplers.sample = modules.sample_hijack.sample_hacked + fcbh.samplers.sample = modules.sample_hijack.sample_hacked try: - samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, + samples = fcbh.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, diff --git a/modules/default_pipeline.py b/modules/default_pipeline.py index 52cc8425..bc900fec 100644 --- a/modules/default_pipeline.py +++ b/modules/default_pipeline.py @@ -2,11 +2,11 @@ import modules.core as core import os import torch import modules.path -import comfy.model_management -import comfy.latent_formats +import fcbh.model_management +import fcbh.latent_formats import modules.inpaint_worker -from comfy.model_base import SDXL, SDXLRefiner +from fcbh.model_base import SDXL, SDXLRefiner from modules.expansion import FooocusExpansion from modules.sample_hijack import clip_separate @@ -211,7 +211,7 @@ def prepare_text_encoder(async_call=True): # TODO: make sure that this is always called in an async way so that users cannot feel it. pass assert_model_integrity() - comfy.model_management.load_models_gpu([final_clip.patcher, final_expansion.patcher]) + fcbh.model_management.load_models_gpu([final_clip.patcher, final_expansion.patcher]) return @@ -284,7 +284,7 @@ def vae_parse(x, tiled=False, use_interpose=True): @torch.no_grad() @torch.inference_mode() def calculate_sigmas_all(sampler, model, scheduler, steps): - from comfy.samplers import calculate_sigmas_scheduler + from fcbh.samplers import calculate_sigmas_scheduler discard_penultimate_sigma = False if sampler in ['dpm_2', 'dpm_2_ancestral']: @@ -316,7 +316,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height assert refiner_swap_method in ['joint', 'separate', 'vae', 'upscale'] if final_refiner_unet is not None: - if isinstance(final_refiner_unet.model.latent_format, comfy.latent_formats.SD15) \ + if isinstance(final_refiner_unet.model.latent_format, fcbh.latent_formats.SD15) \ and refiner_swap_method != 'upscale': refiner_swap_method = 'vae' diff --git a/modules/expansion.py b/modules/expansion.py index 86ec3e9f..2145a701 100644 --- a/modules/expansion.py +++ b/modules/expansion.py @@ -1,10 +1,10 @@ import torch -import comfy.model_management as model_management +import fcbh.model_management as model_management from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed from modules.path import fooocus_expansion_path -from comfy.model_patcher import ModelPatcher +from fcbh.model_patcher import ModelPatcher fooocus_magic_split = [ diff --git a/modules/launch_util.py b/modules/launch_util.py index 360f4644..d4641aa2 100644 --- a/modules/launch_util.py +++ b/modules/launch_util.py @@ -22,49 +22,6 @@ index_url = os.environ.get('INDEX_URL', "") modules_path = os.path.dirname(os.path.realpath(__file__)) script_path = os.path.dirname(modules_path) -dir_repos = "repositories" - - -def onerror(func, path, exc_info): - import stat - if not os.access(path, os.W_OK): - os.chmod(path, stat.S_IWUSR) - func(path) - else: - raise 'Failed to invoke "shutil.rmtree", git management failed.' - - -def git_clone(url, dir, name, hash=None): - try: - try: - repo = pygit2.Repository(dir) - remote_url = repo.remotes['origin'].url - if remote_url != url: - print(f'{name} exists but remote URL will be updated.') - del repo - raise url - else: - print(f'{name} exists and URL is correct.') - except: - if os.path.isdir(dir) or os.path.exists(dir): - shutil.rmtree(dir, onerror=onerror) - os.makedirs(dir, exist_ok=True) - repo = pygit2.clone_repository(url, dir) - print(f'{name} cloned from {url}.') - - if hash is not None: - remote = repo.remotes['origin'] - remote.fetch() - commit = repo.get(hash) - repo.checkout_tree(commit, strategy=pygit2.GIT_CHECKOUT_FORCE) - repo.set_head(commit.id) - print(f'{name} checkout finished for {hash}.') - except Exception as e: - print(f'Git clone failed for {name}: {str(e)}') - - -def repo_dir(name): - return os.path.join(script_path, dir_repos, name) def is_installed(package): diff --git a/modules/patch.py b/modules/patch.py index 3ad7dcbc..bd92956d 100644 --- a/modules/patch.py +++ b/modules/patch.py @@ -1,27 +1,27 @@ import torch -import comfy.model_base -import comfy.ldm.modules.diffusionmodules.openaimodel -import comfy.samplers -import comfy.k_diffusion.external -import comfy.model_management +import fcbh.model_base +import fcbh.ldm.modules.diffusionmodules.openaimodel +import fcbh.samplers +import fcbh.k_diffusion.external +import fcbh.model_management import modules.anisotropic as anisotropic -import comfy.ldm.modules.attention -import comfy.k_diffusion.sampling -import comfy.sd1_clip +import fcbh.ldm.modules.attention +import fcbh.k_diffusion.sampling +import fcbh.sd1_clip import modules.inpaint_worker as inpaint_worker -import comfy.ldm.modules.diffusionmodules.openaimodel -import comfy.ldm.modules.diffusionmodules.model -import comfy.sd -import comfy.cldm.cldm -import comfy.model_patcher -import comfy.samplers -import comfy.cli_args +import fcbh.ldm.modules.diffusionmodules.openaimodel +import fcbh.ldm.modules.diffusionmodules.model +import fcbh.sd +import fcbh.cldm.cldm +import fcbh.model_patcher +import fcbh.samplers +import fcbh.cli_args import args_manager import modules.advanced_parameters as advanced_parameters -from comfy.k_diffusion import utils -from comfy.k_diffusion.sampling import BrownianTreeNoiseSampler, trange -from comfy.ldm.modules.diffusionmodules.openaimodel import timestep_embedding, forward_timestep_embed +from fcbh.k_diffusion import utils +from fcbh.k_diffusion.sampling import BrownianTreeNoiseSampler, trange +from fcbh.ldm.modules.diffusionmodules.openaimodel import timestep_embedding, forward_timestep_embed sharpness = 2.0 @@ -54,26 +54,26 @@ def calculate_weight_patched(self, patches, weight, key): if w1.shape != weight.shape: print("WARNING SHAPE MISMATCH {} WEIGHT NOT MERGED {} != {}".format(key, w1.shape, weight.shape)) else: - weight += alpha * comfy.model_management.cast_to_device(w1, weight.device, weight.dtype) + weight += alpha * fcbh.model_management.cast_to_device(w1, weight.device, weight.dtype) elif len(v) == 3: # fooocus - w1 = comfy.model_management.cast_to_device(v[0], weight.device, torch.float32) - w_min = comfy.model_management.cast_to_device(v[1], weight.device, torch.float32) - w_max = comfy.model_management.cast_to_device(v[2], weight.device, torch.float32) + w1 = fcbh.model_management.cast_to_device(v[0], weight.device, torch.float32) + w_min = fcbh.model_management.cast_to_device(v[1], weight.device, torch.float32) + w_max = fcbh.model_management.cast_to_device(v[2], weight.device, torch.float32) w1 = (w1 / 255.0) * (w_max - w_min) + w_min if alpha != 0.0: if w1.shape != weight.shape: print("WARNING SHAPE MISMATCH {} FOOOCUS WEIGHT NOT MERGED {} != {}".format(key, w1.shape, weight.shape)) else: - weight += alpha * comfy.model_management.cast_to_device(w1, weight.device, weight.dtype) + weight += alpha * fcbh.model_management.cast_to_device(w1, weight.device, weight.dtype) elif len(v) == 4: # lora/locon - mat1 = comfy.model_management.cast_to_device(v[0], weight.device, torch.float32) - mat2 = comfy.model_management.cast_to_device(v[1], weight.device, torch.float32) + mat1 = fcbh.model_management.cast_to_device(v[0], weight.device, torch.float32) + mat2 = fcbh.model_management.cast_to_device(v[1], weight.device, torch.float32) if v[2] is not None: alpha *= v[2] / mat2.shape[0] if v[3] is not None: # locon mid weights, hopefully the math is fine because I didn't properly test it - mat3 = comfy.model_management.cast_to_device(v[3], weight.device, torch.float32) + mat3 = fcbh.model_management.cast_to_device(v[3], weight.device, torch.float32) final_shape = [mat2.shape[1], mat2.shape[0], mat3.shape[2], mat3.shape[3]] mat2 = torch.mm(mat2.transpose(0, 1).flatten(start_dim=1), mat3.transpose(0, 1).flatten(start_dim=1)).reshape(final_shape).transpose(0, 1) @@ -94,23 +94,23 @@ def calculate_weight_patched(self, patches, weight, key): if w1 is None: dim = w1_b.shape[0] - w1 = torch.mm(comfy.model_management.cast_to_device(w1_a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1_b, weight.device, torch.float32)) + w1 = torch.mm(fcbh.model_management.cast_to_device(w1_a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1_b, weight.device, torch.float32)) else: - w1 = comfy.model_management.cast_to_device(w1, weight.device, torch.float32) + w1 = fcbh.model_management.cast_to_device(w1, weight.device, torch.float32) if w2 is None: dim = w2_b.shape[0] if t2 is None: - w2 = torch.mm(comfy.model_management.cast_to_device(w2_a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_b, weight.device, torch.float32)) + w2 = torch.mm(fcbh.model_management.cast_to_device(w2_a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_b, weight.device, torch.float32)) else: w2 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t2, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2_a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t2, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2_a, weight.device, torch.float32)) else: - w2 = comfy.model_management.cast_to_device(w2, weight.device, torch.float32) + w2 = fcbh.model_management.cast_to_device(w2, weight.device, torch.float32) if len(w2.shape) == 4: w1 = w1.unsqueeze(2).unsqueeze(2) @@ -132,19 +132,19 @@ def calculate_weight_patched(self, patches, weight, key): t1 = v[5] t2 = v[6] m1 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t1, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t1, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1a, weight.device, torch.float32)) m2 = torch.einsum('i j k l, j r, i p -> p r k l', - comfy.model_management.cast_to_device(t2, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2b, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2a, weight.device, torch.float32)) + fcbh.model_management.cast_to_device(t2, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2b, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2a, weight.device, torch.float32)) else: - m1 = torch.mm(comfy.model_management.cast_to_device(w1a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w1b, weight.device, torch.float32)) - m2 = torch.mm(comfy.model_management.cast_to_device(w2a, weight.device, torch.float32), - comfy.model_management.cast_to_device(w2b, weight.device, torch.float32)) + m1 = torch.mm(fcbh.model_management.cast_to_device(w1a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w1b, weight.device, torch.float32)) + m2 = torch.mm(fcbh.model_management.cast_to_device(w2a, weight.device, torch.float32), + fcbh.model_management.cast_to_device(w2b, weight.device, torch.float32)) try: weight += (alpha * m1 * m2).reshape(weight.shape).type(weight.dtype) @@ -205,7 +205,7 @@ def patched_model_function_wrapper(func, args): def sdxl_encode_adm_patched(self, **kwargs): global positive_adm_scale, negative_adm_scale - clip_pooled = comfy.model_base.sdxl_pooled(kwargs, self.noise_augmentor) + clip_pooled = fcbh.model_base.sdxl_pooled(kwargs, self.noise_augmentor) width = kwargs.get("width", 768) height = kwargs.get("height", 768) target_width = width @@ -453,8 +453,8 @@ def patched_unet_forward(self, x, timesteps=None, context=None, y=None, control= def text_encoder_device_patched(): - # Fooocus's style system uses text encoder much more times than comfy so this makes things much faster. - return comfy.model_management.get_torch_device() + # Fooocus's style system uses text encoder much more times than fcbh so this makes things much faster. + return fcbh.model_management.get_torch_device() def patched_get_autocast_device(dev): @@ -470,25 +470,25 @@ def patched_get_autocast_device(dev): def patch_all(): - if not comfy.model_management.DISABLE_SMART_MEMORY: - vram_inadequate = comfy.model_management.total_vram < 20 * 1024 - is_old_gpu_arch = not comfy.model_management.should_use_fp16() + if not fcbh.model_management.DISABLE_SMART_MEMORY: + vram_inadequate = fcbh.model_management.total_vram < 20 * 1024 + is_old_gpu_arch = not fcbh.model_management.should_use_fp16() if vram_inadequate or is_old_gpu_arch: # https://github.com/lllyasviel/Fooocus/issues/602 print(f'[Fooocus Smart Memory] Disabling smart memory, ' f'vram_inadequate = {vram_inadequate}, is_old_gpu_arch = {is_old_gpu_arch}.') - comfy.model_management.DISABLE_SMART_MEMORY = True + fcbh.model_management.DISABLE_SMART_MEMORY = True args_manager.args.disable_smart_memory = True - comfy.cli_args.args.disable_smart_memory = True + fcbh.cli_args.args.disable_smart_memory = True - comfy.model_management.get_autocast_device = patched_get_autocast_device - comfy.samplers.SAMPLER_NAMES += ['dpmpp_fooocus_2m_sde_inpaint_seamless'] - comfy.model_management.text_encoder_device = text_encoder_device_patched - comfy.model_patcher.ModelPatcher.calculate_weight = calculate_weight_patched - comfy.cldm.cldm.ControlNet.forward = patched_cldm_forward - comfy.ldm.modules.diffusionmodules.openaimodel.UNetModel.forward = patched_unet_forward - comfy.k_diffusion.sampling.sample_dpmpp_fooocus_2m_sde_inpaint_seamless = sample_dpmpp_fooocus_2m_sde_inpaint_seamless - comfy.k_diffusion.external.DiscreteEpsDDPMDenoiser.forward = patched_discrete_eps_ddpm_denoiser_forward - comfy.model_base.SDXL.encode_adm = sdxl_encode_adm_patched - comfy.sd1_clip.ClipTokenWeightEncoder.encode_token_weights = encode_token_weights_patched_with_a1111_method + fcbh.model_management.get_autocast_device = patched_get_autocast_device + fcbh.samplers.SAMPLER_NAMES += ['dpmpp_fooocus_2m_sde_inpaint_seamless'] + fcbh.model_management.text_encoder_device = text_encoder_device_patched + fcbh.model_patcher.ModelPatcher.calculate_weight = calculate_weight_patched + fcbh.cldm.cldm.ControlNet.forward = patched_cldm_forward + fcbh.ldm.modules.diffusionmodules.openaimodel.UNetModel.forward = patched_unet_forward + fcbh.k_diffusion.sampling.sample_dpmpp_fooocus_2m_sde_inpaint_seamless = sample_dpmpp_fooocus_2m_sde_inpaint_seamless + fcbh.k_diffusion.external.DiscreteEpsDDPMDenoiser.forward = patched_discrete_eps_ddpm_denoiser_forward + fcbh.model_base.SDXL.encode_adm = sdxl_encode_adm_patched + fcbh.sd1_clip.ClipTokenWeightEncoder.encode_token_weights = encode_token_weights_patched_with_a1111_method return diff --git a/modules/sample_hijack.py b/modules/sample_hijack.py index 15410cd0..d6640669 100644 --- a/modules/sample_hijack.py +++ b/modules/sample_hijack.py @@ -1,10 +1,10 @@ import torch -import comfy.samplers -import comfy.model_management +import fcbh.samplers +import fcbh.model_management -from comfy.model_base import SDXLRefiner, SDXL -from comfy.sample import get_additional_models -from comfy.samplers import resolve_areas_and_cond_masks, wrap_model, calculate_start_end_timesteps, \ +from fcbh.model_base import SDXLRefiner, SDXL +from fcbh.sample import get_additional_models +from fcbh.samplers import resolve_areas_and_cond_masks, wrap_model, calculate_start_end_timesteps, \ create_cond_with_same_area_if_none, pre_run_control, apply_empty_x_to_equal_area, encode_adm, \ blank_inpaint_image_like @@ -119,7 +119,7 @@ def sample_hacked(model, noise, positive, negative, cfg, device, sampler, sigmas extra_args['model_options'] = {k: {} if k == 'transformer_options' else v for k, v in extra_args['model_options'].items()} models, inference_memory = get_additional_models(positive_refiner, negative_refiner, current_refiner.model_dtype()) - comfy.model_management.load_models_gpu([current_refiner] + models, comfy.model_management.batch_area_memory( + fcbh.model_management.load_models_gpu([current_refiner] + models, fcbh.model_management.batch_area_memory( noise.shape[0] * noise.shape[2] * noise.shape[3]) + inference_memory) model_wrap.inner_model.inner_model = current_refiner.model @@ -136,4 +136,4 @@ def sample_hacked(model, noise, positive, negative, cfg, device, sampler, sigmas return model.process_latent_out(samples.to(torch.float32)) -comfy.samplers.sample = sample_hacked +fcbh.samplers.sample = sample_hacked diff --git a/modules/upscaler.py b/modules/upscaler.py index 0d12d86d..02d0fcc2 100644 --- a/modules/upscaler.py +++ b/modules/upscaler.py @@ -1,8 +1,8 @@ import os import torch -from comfy_extras.chainner_models.architecture.RRDB import RRDBNet as ESRGAN -from comfy_extras.nodes_upscale_model import ImageUpscaleWithModel +from fcbh_extras.chainner_models.architecture.RRDB import RRDBNet as ESRGAN +from fcbh_extras.nodes_upscale_model import ImageUpscaleWithModel from collections import OrderedDict from modules.path import upscale_models_path diff --git a/update_log.md b/update_log.md index 2b8adbc9..c02cba52 100644 --- a/update_log.md +++ b/update_log.md @@ -1,3 +1,7 @@ +# 2.1.52 + +* removed pygit2 dependency (expect auto update) so that people will never have permission denied problems. + # 2.1.50 * Begin to support sd1.5 as refiner. This method scale sigmas given SD15/Xl latent scale and is probably the most correct way to do it. I am going to write a discussion soon. diff --git a/webui.py b/webui.py index 6b7dde1a..101e68a4 100644 --- a/webui.py +++ b/webui.py @@ -63,13 +63,13 @@ with shared.gradio_root: stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', visible=False) def stop_clicked(): - import comfy.model_management as model_management + import fcbh.model_management as model_management shared.last_stop = 'stop' model_management.interrupt_current_processing() return [gr.update(interactive=False)] * 2 def skip_clicked(): - import comfy.model_management as model_management + import fcbh.model_management as model_management shared.last_stop = 'skip' model_management.interrupt_current_processing() return