Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

convert nodes_freelunch.py to the V3 schema (#10904)

Alexander Piskun117bf3f2bd92
diff --git a/comfy_extras/nodes_freelunch.py b/comfy_extras/nodes_freelunch.py
index e3ac58447..3429b731e 100644
--- a/comfy_extras/nodes_freelunch.py
+++ b/comfy_extras/nodes_freelunch.py
@@ -2,6 +2,8 @@
import torch
import logging
+from typing_extensions import override
+from comfy_api.latest import ComfyExtension, IO
def Fourier_filter(x, threshold, scale):
# FFT
@@ -22,21 +24,26 @@ def Fourier_filter(x, threshold, scale):
return x_filtered.to(x.dtype)
-class FreeU:
+class FreeU(IO.ComfyNode):
@classmethod
- def INPUT_TYPES(s):
- return {"required": { "model": ("MODEL",),
- "b1": ("FLOAT", {"default": 1.1, "min": 0.0, "max": 10.0, "step": 0.01}),
- "b2": ("FLOAT", {"default": 1.2, "min": 0.0, "max": 10.0, "step": 0.01}),
- "s1": ("FLOAT", {"default": 0.9, "min": 0.0, "max": 10.0, "step": 0.01}),
- "s2": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 10.0, "step": 0.01}),
- }}
- RETURN_TYPES = ("MODEL",)
- FUNCTION = "patch"
-
- CATEGORY = "model_patches/unet"
-
- def patch(self, model, b1, b2, s1, s2):
+ def define_schema(cls):
+ return IO.Schema(
+ node_id="FreeU",
+ category="model_patches/unet",
+ inputs=[
+ IO.Model.Input("model"),
+ IO.Float.Input("b1", default=1.1, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("b2", default=1.2, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("s1", default=0.9, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("s2", default=0.2, min=0.0, max=10.0, step=0.01),
+ ],
+ outputs=[
+ IO.Model.Output(),
+ ],
+ )
+
+ @classmethod
+ def execute(cls, model, b1, b2, s1, s2) -> IO.NodeOutput:
model_channels = model.model.model_config.unet_config["model_channels"]
scale_dict = {model_channels * 4: (b1, s1), model_channels * 2: (b2, s2)}
on_cpu_devices = {}
@@ -59,23 +66,31 @@ class FreeU:
m = model.clone()
m.set_model_output_block_patch(output_block_patch)
- return (m, )
+ return IO.NodeOutput(m)
+
+ patch = execute # TODO: remove
+
+
+class FreeU_V2(IO.ComfyNode):
+ @classmethod
+ def define_schema(cls):
+ return IO.Schema(
+ node_id="FreeU_V2",
+ category="model_patches/unet",
+ inputs=[
+ IO.Model.Input("model"),
+ IO.Float.Input("b1", default=1.3, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("b2", default=1.4, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("s1", default=0.9, min=0.0, max=10.0, step=0.01),
+ IO.Float.Input("s2", default=0.2, min=0.0, max=10.0, step=0.01),
+ ],
+ outputs=[
+ IO.Model.Output(),
+ ],
+ )
-class FreeU_V2:
@classmethod
- def INPUT_TYPES(s):
- return {"required": { "model": ("MODEL",),
- "b1": ("FLOAT", {"default": 1.3, "min": 0.0, "max": 10.0, "step": 0.01}),
- "b2": ("FLOAT", {"default": 1.4, "min": 0.0, "max": 10.0, "step": 0.01}),
- "s1": ("FLOAT", {"default": 0.9, "min": 0.0, "max": 10.0, "step": 0.01}),
- "s2": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 10.0, "step": 0.01}),
- }}
- RETURN_TYPES = ("MODEL",)
- FUNCTION = "patch"
-
- CATEGORY = "model_patches/unet"
-
- def patch(self, model, b1, b2, s1, s2):
+ def execute(cls, model, b1, b2, s1, s2) -> IO.NodeOutput:
model_channels = model.model.model_config.unet_config["model_channels"]
scale_dict = {model_channels * 4: (b1, s1), model_channels * 2: (b2, s2)}
on_cpu_devices = {}
@@ -105,9 +120,19 @@ class FreeU_V2:
m = model.clone()
m.set_model_output_block_patch(output_block_patch)
- return (m, )
+ return IO.NodeOutput(m)
+
+ patch = execute # TODO: remove
+
+
+class FreelunchExtension(ComfyExtension):
+ @override
+ async def get_node_list(self) -> list[type[IO.ComfyNode]]:
+ return [
+ FreeU,
+ FreeU_V2,
+ ]
+
-NODE_CLASS_MAPPINGS = {
- "FreeU": FreeU,
- "FreeU_V2": FreeU_V2,
-}
+async def comfy_entrypoint() -> FreelunchExtension:
+ return FreelunchExtension()
diff --git a/comfy_extras/nodes_model_downscale.py b/comfy_extras/nodes_model_downscale.py
index f7ca9699d..dec2ae841 100644
--- a/comfy_extras/nodes_model_downscale.py
+++ b/comfy_extras/nodes_model_downscale.py
@@ -53,11 +53,6 @@ class PatchModelAddDownscale(io.ComfyNode):
return io.NodeOutput(m)
-NODE_DISPLAY_NAME_MAPPINGS = {
- # Sampling
- "PatchModelAddDownscale": "",
-}
-
class ModelDownscaleExtension(ComfyExtension):
@override
async def get_node_list(self) -> list[type[io.ComfyNode]]: