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_flux to V3 schema (#10122)

Alexander Piskun90853fb9cd42
diff --git a/comfy_extras/nodes_flux.py b/comfy_extras/nodes_flux.py
index 25e029ffd..ce1b2e89f 100644
--- a/comfy_extras/nodes_flux.py
+++ b/comfy_extras/nodes_flux.py
@@ -1,60 +1,80 @@
import node_helpers
import comfy.utils
+from typing_extensions import override
+from comfy_api.latest import ComfyExtension, io
+
+
+class CLIPTextEncodeFlux(io.ComfyNode):
+ @classmethod
+ def define_schema(cls):
+ return io.Schema(
+ node_id="CLIPTextEncodeFlux",
+ category="advanced/conditioning/flux",
+ inputs=[
+ io.Clip.Input("clip"),
+ io.String.Input("clip_l", multiline=True, dynamic_prompts=True),
+ io.String.Input("t5xxl", multiline=True, dynamic_prompts=True),
+ io.Float.Input("guidance", default=3.5, min=0.0, max=100.0, step=0.1),
+ ],
+ outputs=[
+ io.Conditioning.Output(),
+ ],
+ )
-class CLIPTextEncodeFlux:
@classmethod
- def INPUT_TYPES(s):
- return {"required": {
- "clip": ("CLIP", ),
- "clip_l": ("STRING", {"multiline": True, "dynamicPrompts": True}),
- "t5xxl": ("STRING", {"multiline": True, "dynamicPrompts": True}),
- "guidance": ("FLOAT", {"default": 3.5, "min": 0.0, "max": 100.0, "step": 0.1}),
- }}
- RETURN_TYPES = ("CONDITIONING",)
- FUNCTION = "encode"
-
- CATEGORY = "advanced/conditioning/flux"
-
- def encode(self, clip, clip_l, t5xxl, guidance):
+ def execute(cls, clip, clip_l, t5xxl, guidance) -> io.NodeOutput:
tokens = clip.tokenize(clip_l)
tokens["t5xxl"] = clip.tokenize(t5xxl)["t5xxl"]
- return (clip.encode_from_tokens_scheduled(tokens, add_dict={"guidance": guidance}), )
+ return io.NodeOutput(clip.encode_from_tokens_scheduled(tokens, add_dict={"guidance": guidance}))
-class FluxGuidance:
- @classmethod
- def INPUT_TYPES(s):
- return {"required": {
- "conditioning": ("CONDITIONING", ),
- "guidance": ("FLOAT", {"default": 3.5, "min": 0.0, "max": 100.0, "step": 0.1}),
- }}
+ encode = execute # TODO: remove
- RETURN_TYPES = ("CONDITIONING",)
- FUNCTION = "append"
- CATEGORY = "advanced/conditioning/flux"
+class FluxGuidance(io.ComfyNode):
+ @classmethod
+ def define_schema(cls):
+ return io.Schema(
+ node_id="FluxGuidance",
+ category="advanced/conditioning/flux",
+ inputs=[
+ io.Conditioning.Input("conditioning"),
+ io.Float.Input("guidance", default=3.5, min=0.0, max=100.0, step=0.1),
+ ],
+ outputs=[
+ io.Conditioning.Output(),
+ ],
+ )
- def append(self, conditioning, guidance):
+ @classmethod
+ def execute(cls, conditioning, guidance) -> io.NodeOutput:
c = node_helpers.conditioning_set_values(conditioning, {"guidance": guidance})
- return (c, )
+ return io.NodeOutput(c)
+ append = execute # TODO: remove
-class FluxDisableGuidance:
- @classmethod
- def INPUT_TYPES(s):
- return {"required": {
- "conditioning": ("CONDITIONING", ),
- }}
-
- RETURN_TYPES = ("CONDITIONING",)
- FUNCTION = "append"
- CATEGORY = "advanced/conditioning/flux"
- DESCRIPTION = "This node completely disables the guidance embed on Flux and Flux like models"
+class FluxDisableGuidance(io.ComfyNode):
+ @classmethod
+ def define_schema(cls):
+ return io.Schema(
+ node_id="FluxDisableGuidance",
+ category="advanced/conditioning/flux",
+ description="This node completely disables the guidance embed on Flux and Flux like models",
+ inputs=[
+ io.Conditioning.Input("conditioning"),
+ ],
+ outputs=[
+ io.Conditioning.Output(),
+ ],
+ )
- def append(self, conditioning):
+ @classmethod
+ def execute(cls, conditioning) -> io.NodeOutput:
c = node_helpers.conditioning_set_values(conditioning, {"guidance": None})
- return (c, )
+ return io.NodeOutput(c)
+
+ append = execute # TODO: remove
PREFERED_KONTEXT_RESOLUTIONS = [
@@ -78,52 +98,73 @@ PREFERED_KONTEXT_RESOLUTIONS = [
]
-class FluxKontextImageScale:
+class FluxKontextImageScale(io.ComfyNode):
@classmethod
- def INPUT_TYPES(s):
- return {"required": {"image": ("IMAGE", ),
- },
- }
-
- RETURN_TYPES = ("IMAGE",)
- FUNCTION = "scale"
+ def define_schema(cls):
+ return io.Schema(
+ node_id="FluxKontextImageScale",
+ category="advanced/conditioning/flux",
+ description="This node resizes the image to one that is more optimal for flux kontext.",
+ inputs=[
+ io.Image.Input("image"),
+ ],
+ outputs=[
+ io.Image.Output(),
+ ],
+ )
- CATEGORY = "advanced/conditioning/flux"
- DESCRIPTION = "This node resizes the image to one that is more optimal for flux kontext."
-
- def scale(self, image):
+ @classmethod
+ def execute(cls, image) -> io.NodeOutput:
width = image.shape[2]
height = image.shape[1]
aspect_ratio = width / height
_, width, height = min((abs(aspect_ratio - w / h), w, h) for w, h in PREFERED_KONTEXT_RESOLUTIONS)
image = comfy.utils.common_upscale(image.movedim(-1, 1), width, height, "lanczos", "center").movedim(1, -1)
- return (image, )
-
+ return io.NodeOutput(image)
-class FluxKontextMultiReferenceLatentMethod:
- @classmethod
- def INPUT_TYPES(s):
- return {"required": {
- "conditioning": ("CONDITIONING", ),
- "reference_latents_method": (("offset", "index", "uxo/uno"), ),
- }}
+ scale = execute # TODO: remove
- RETURN_TYPES = ("CONDITIONING",)
- FUNCTION = "append"
- EXPERIMENTAL = True
- CATEGORY = "advanced/conditioning/flux"
+class FluxKontextMultiReferenceLatentMethod(io.ComfyNode):
+ @classmethod
+ def define_schema(cls):
+ return io.Schema(
+ node_id="FluxKontextMultiReferenceLatentMethod",
+ category="advanced/conditioning/flux",
+ inputs=[
+ io.Conditioning.Input("conditioning"),
+ io.Combo.Input(
+ "reference_latents_method",
+ options=["offset", "index", "uxo/uno"],
+ ),
+ ],
+ outputs=[
+ io.Conditioning.Output(),
+ ],
+ is_experimental=True,
+ )
- def append(self, conditioning, reference_latents_method):
+ @classmethod
+ def execute(cls, conditioning, reference_latents_method) -> io.NodeOutput:
if "uxo" in reference_latents_method or "uso" in reference_latents_method:
reference_latents_method = "uxo"
c = node_helpers.conditioning_set_values(conditioning, {"reference_latents_method": reference_latents_method})
- return (c, )
-
-NODE_CLASS_MAPPINGS = {
- "CLIPTextEncodeFlux": CLIPTextEncodeFlux,
- "FluxGuidance": FluxGuidance,
- "FluxDisableGuidance": FluxDisableGuidance,
- "FluxKontextImageScale": FluxKontextImageScale,
- "FluxKontextMultiReferenceLatentMethod": FluxKontextMultiReferenceLatentMethod,
-}
+ return io.NodeOutput(c)
+
+ append = execute # TODO: remove
+
+
+class FluxExtension(ComfyExtension):
+ @override
+ async def get_node_list(self) -> list[type[io.ComfyNode]]:
+ return [
+ CLIPTextEncodeFlux,
+ FluxGuidance,
+ FluxDisableGuidance,
+ FluxKontextImageScale,
+ FluxKontextMultiReferenceLatentMethod,
+ ]
+
+
+async def comfy_entrypoint() -> FluxExtension:
+ return FluxExtension()