From d1c2156bf86a89762aa6764d56a7752e61769138 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 9 Apr 2023 11:37:33 -0700 Subject: [PATCH 1/4] Organize imports, remove unused --- efficiency_nodes.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/efficiency_nodes.py b/efficiency_nodes.py index 87d9edf..2b7f592 100644 --- a/efficiency_nodes.py +++ b/efficiency_nodes.py @@ -1,7 +1,8 @@ # Efficiency Nodes - A collection of my ComfyUI custom nodes to help streamline workflows and reduce total node count. # by Luciano Cirino (Discord: TSC#9184) - April 2023 -from PIL import Image, ImageFilter, ImageEnhance, ImageOps, ImageDraw, ImageChops, ImageFont +from nodes import common_ksampler +from PIL import Image, ImageOps from PIL.PngImagePlugin import PngInfo import numpy as np import torch @@ -9,15 +10,9 @@ import torch import os import sys import json -import hashlib -import copy -import traceback import copy import folder_paths -import model_management -import importlib -import random # Get the absolute path of the parent directory of the current script my_dir = os.path.dirname(os.path.abspath(__file__)) @@ -29,7 +24,6 @@ comfy_dir = os.path.abspath(os.path.join(my_dir, '..', '..')) sys.path.append(comfy_dir) # Import functions from nodes.py in the ComfyUI directory -from nodes import common_ksampler, before_node_execution, interrupt_processing import comfy.samplers import comfy.sd import comfy.utils From efe1f6801112d2ed4a851238586c60a71ee1bc58 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 9 Apr 2023 11:39:11 -0700 Subject: [PATCH 2/4] classmethods take cls pylance warning --- efficiency_nodes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/efficiency_nodes.py b/efficiency_nodes.py index 2b7f592..525bc96 100644 --- a/efficiency_nodes.py +++ b/efficiency_nodes.py @@ -50,7 +50,7 @@ loaded_objects = { class TSC_EfficientLoader: @classmethod - def INPUT_TYPES(s): + def INPUT_TYPES(cls): return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ), "vae_name": (["Baked VAE"] + folder_paths.get_filename_list("vae"),), "clip_skip": ("INT", {"default": -1, "min": -24, "max": -1, "step": 1}), @@ -134,7 +134,7 @@ class TSC_KSampler: self.type = "temp" @classmethod - def INPUT_TYPES(s): + def INPUT_TYPES(cls): return {"required": {"sampler_state": (["Sample", "Hold"], ), "my_unique_id": ("INT", {"default": 0, "min": 0, "max": 15}), @@ -358,7 +358,7 @@ class TSC_ImageOverlay: # TSC Evaluate Integers class TSC_EvaluateInts: @classmethod - def INPUT_TYPES(s): + def INPUT_TYPES(cls): return {"required": { "python_expression": ("STRING", {"default": "((a + b) - c) / 2", "multiline": False}), "print_to_console": (["False", "True"],),}, @@ -385,7 +385,7 @@ class TSC_EvaluateInts: # TSC Evaluate Strings class TSC_EvaluateStrs: @classmethod - def INPUT_TYPES(s): + def INPUT_TYPES(cls): return {"required": { "python_expression": ("STRING", {"default": "a + b + c", "multiline": False}), "print_to_console": (["False", "True"],)}, From 3ab61366cebba26903d62e06e7c8e113d694a13b Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 9 Apr 2023 12:14:04 -0700 Subject: [PATCH 3/4] Add some typing and explicit declaration --- efficiency_nodes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/efficiency_nodes.py b/efficiency_nodes.py index 525bc96..e9aa9a8 100644 --- a/efficiency_nodes.py +++ b/efficiency_nodes.py @@ -2,6 +2,7 @@ # by Luciano Cirino (Discord: TSC#9184) - April 2023 from nodes import common_ksampler +from torch import Tensor from PIL import Image, ImageOps from PIL.PngImagePlugin import PngInfo import numpy as np @@ -10,10 +11,8 @@ import torch import os import sys import json -import copy import folder_paths - # Get the absolute path of the parent directory of the current script my_dir = os.path.dirname(os.path.abspath(__file__)) @@ -74,6 +73,10 @@ class TSC_EfficientLoader: if vae_name == "Baked VAE": output_vae = True + model: ModelPatcher | None = None + clip: CLIP | None = None + vae: VAE | None = None + # Search for tuple index that contains ckpt_name in "ckpt" array of loaded_lbjects checkpoint_found = False for i, entry in enumerate(loaded_objects["ckpt"]): @@ -115,6 +118,8 @@ class TSC_EfficientLoader: loaded_objects["vae"].append((vae_name, vae)) # CLIP skip + if not clip: + raise Exception("No CLIP found") clip = clip.clone() clip.clip_layer(clip_skip) @@ -122,7 +127,7 @@ class TSC_EfficientLoader: # TSC KSampler (Efficient) -last_helds = { +last_helds: dict[str, list] = { "results": [None for _ in range(15)], "latent": [None for _ in range(15)], "images": [None for _ in range(15)] @@ -193,6 +198,8 @@ class TSC_KSampler: last_images = empty_image else: last_images = last_helds["images"][my_unique_id] + + latent: Tensor|None = None if sampler_state == "Sample": samples = common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise) From ee66e4ba15d6a759d84788bccbea53cb19e04190 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 9 Apr 2023 12:14:16 -0700 Subject: [PATCH 4/4] Update efficiency_nodes.py --- efficiency_nodes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/efficiency_nodes.py b/efficiency_nodes.py index e9aa9a8..d1e2430 100644 --- a/efficiency_nodes.py +++ b/efficiency_nodes.py @@ -1,6 +1,7 @@ # Efficiency Nodes - A collection of my ComfyUI custom nodes to help streamline workflows and reduce total node count. # by Luciano Cirino (Discord: TSC#9184) - April 2023 +from comfy.sd import ModelPatcher, CLIP, VAE from nodes import common_ksampler from torch import Tensor from PIL import Image, ImageOps