fix commonLazy missing w,x,y,z and remove MathNodeBase
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import torch
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor, prepare_inputs, commonLazy
|
||||
|
||||
from comfy_api.latest import io
|
||||
|
||||
|
||||
from .MathNodeBase import MathNodeBase
|
||||
|
||||
|
||||
class AudioMathNode(MathNodeBase):
|
||||
class AudioMathNode(io.ComfyNode):
|
||||
"""
|
||||
Enables math expressions on Audio tensors.
|
||||
|
||||
@@ -41,13 +38,16 @@ class AudioMathNode(MathNodeBase):
|
||||
io.Audio.Output(),
|
||||
],
|
||||
)
|
||||
@classmethod
|
||||
def check_lazy_status(cls, AudioExpr, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return commonLazy(AudioExpr, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, AudioExpr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
av = a["waveform"]
|
||||
sample_rate = a["sample_rate"]
|
||||
|
||||
a, b, c, d = cls.prepare_inputs(a, b, c, d)
|
||||
a, b, c, d = prepare_inputs(a, b, c, d)
|
||||
|
||||
bv, cv, dv = b["waveform"], c["waveform"], d["waveform"]
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from comfy_api.latest import io
|
||||
from .modelLikeCommon import calculate_patches
|
||||
from inspect import cleandoc
|
||||
from .helper_functions import comonLazy
|
||||
from .helper_functions import commonLazy
|
||||
|
||||
|
||||
class CLIPMathNode(io.ComfyNode):
|
||||
@@ -35,7 +35,7 @@ class CLIPMathNode(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return comonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
return commonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput:
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
from inspect import cleandoc
|
||||
|
||||
from .helper_functions import comonLazy, eval_tensor_expr, generate_dim_variables, as_tensor
|
||||
from .helper_functions import commonLazy, eval_tensor_expr, generate_dim_variables, as_tensor, prepare_inputs
|
||||
|
||||
from comfy_api.latest import io
|
||||
|
||||
|
||||
from .MathNodeBase import MathNodeBase
|
||||
|
||||
|
||||
class ConditioningMathNode(MathNodeBase):
|
||||
class ConditioningMathNode(io.ComfyNode):
|
||||
"""
|
||||
Enables math operations on conditionings.
|
||||
|
||||
@@ -51,14 +49,14 @@ class ConditioningMathNode(MathNodeBase):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Tensor, pooled_output, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
tensor_needs = set(comonLazy(Tensor, a, b, c, d))
|
||||
pooled_needs = set(comonLazy(pooled_output, a, b, c, d))
|
||||
tensor_needs = set(commonLazy(Tensor, a, b, c, d, w, x, y, z))
|
||||
pooled_needs = set(commonLazy(pooled_output, a, b, c, d, w, x, y, z))
|
||||
return list(tensor_needs.union(pooled_needs))
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Tensor, pooled_output, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
# Default missing conditionings to zero
|
||||
a, b, c, d = cls.prepare_inputs(a, b, c, d)
|
||||
a, b, c, d = prepare_inputs(a, b, c, d)
|
||||
|
||||
# Extract tensors
|
||||
ta, tb, tc, td = a[0][0], b[0][0], c[0][0], d[0][0]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from inspect import cleandoc
|
||||
|
||||
from .helper_functions import comonLazy, eval_float_expr
|
||||
from .helper_functions import commonLazy, eval_float_expr
|
||||
from comfy_api.latest import io
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class FloatMathNode(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, FloatFunc, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return comonLazy(FloatFunc, a, b, c, d)
|
||||
return commonLazy(FloatFunc, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, FloatFunc, a, b=0.0, c=0.0, d=0.0, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor,prepare_inputs,commonLazy
|
||||
|
||||
from comfy_api.latest import io
|
||||
|
||||
|
||||
from .MathNodeBase import MathNodeBase
|
||||
|
||||
|
||||
class ImageMathNode(MathNodeBase):
|
||||
class ImageMathNode(io.ComfyNode):
|
||||
"""
|
||||
Enables math expressions on Images.
|
||||
|
||||
@@ -40,10 +37,12 @@ class ImageMathNode(MathNodeBase):
|
||||
io.Image.Output(),
|
||||
],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Image, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return commonLazy(Image, a, b, c, d, w, x, y, z)
|
||||
@classmethod
|
||||
def execute(cls, Image, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
a, b, c, d = cls.prepare_inputs(a, b, c, d)
|
||||
a, b, c, d = prepare_inputs(a, b, c, d)
|
||||
|
||||
variables = {
|
||||
"a": a,
|
||||
|
||||
@@ -10,10 +10,10 @@ from .helper_functions import (
|
||||
make_zero_like,
|
||||
as_tensor,
|
||||
)
|
||||
from .MathNodeBase import MathNodeBase
|
||||
from .helper_functions import commonLazy
|
||||
|
||||
|
||||
class LatentMathNode(MathNodeBase):
|
||||
class LatentMathNode(io.ComfyNode):
|
||||
"""
|
||||
This node enables the use of math expressions on Latents.
|
||||
inputs:
|
||||
@@ -58,6 +58,10 @@ class LatentMathNode(MathNodeBase):
|
||||
# RETURN_NAMES = ("image_output_name",)
|
||||
tooltip = cleandoc(__doc__)
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Latent, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return commonLazy(Latent, a, b, c, d, w, x, y, z)
|
||||
|
||||
# OUTPUT_NODE = False
|
||||
# OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node
|
||||
@classmethod
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, as_tensor,commonLazy
|
||||
|
||||
from comfy_api.latest import io
|
||||
|
||||
|
||||
from .MathNodeBase import MathNodeBase
|
||||
|
||||
|
||||
class MaskMathNode(MathNodeBase):
|
||||
class MaskMathNode(io.ComfyNode):
|
||||
"""
|
||||
Enables math expressions on Images.
|
||||
|
||||
@@ -40,7 +37,9 @@ class MaskMathNode(MathNodeBase):
|
||||
io.Mask.Output(),
|
||||
],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Mask, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return commonLazy(Mask, a, b, c, d, w, x, y, z)
|
||||
@classmethod
|
||||
def execute(cls, Mask, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
a, b, c, d = cls.prepare_inputs(a, b, c, d)
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
from comfy_api.latest import io
|
||||
from .helper_functions import comonLazy, make_zero_like
|
||||
|
||||
|
||||
class MathNodeBase(io.ComfyNode):
|
||||
"""
|
||||
Base class for More Math nodes providing common utilities.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, **kwargs):
|
||||
"""
|
||||
Generic check_lazy_status implementation.
|
||||
Finds the first argument name that isn't a known variable (a-d, w-z) and assumes it's the expression.
|
||||
"""
|
||||
# Known variable inputs (and internal ones we might ignore)
|
||||
known_vars = {"a", "b", "c", "d", "w", "x", "y", "z", "pooled_output"}
|
||||
|
||||
# Heuristic: The expression is usually the first argument that is not a known variable.
|
||||
# But `comonLazy` takes (expr, a, b, c, d, w, x, y, z).
|
||||
# We need to extract the values from kwargs correctly.
|
||||
|
||||
expr_key = None
|
||||
# Try finding the expression key
|
||||
for k in kwargs:
|
||||
if k not in known_vars and isinstance(kwargs[k], str):
|
||||
expr_key = k
|
||||
break
|
||||
|
||||
# If we can't find it heuristically (e.g. standard naming), fallback or error?
|
||||
# Let's try to be safe. If we can't find it, we might be in a node with custom logic like ConditioningMathNode.
|
||||
# ConditioningMathNode has 'Tensor' and 'pooled_output' as expressions.
|
||||
|
||||
if expr_key:
|
||||
expr = kwargs[expr_key]
|
||||
a = kwargs.get("a", None)
|
||||
b = kwargs.get("b", [])
|
||||
c = kwargs.get("c", [])
|
||||
d = kwargs.get("d", [])
|
||||
w = kwargs.get("w", 0)
|
||||
x = kwargs.get("x", 0)
|
||||
y = kwargs.get("y", 0)
|
||||
z = kwargs.get("z", 0)
|
||||
return comonLazy(expr, a, b, c, d, w, x, y, z)
|
||||
|
||||
# Fallback/Empty return if we can't determine dependencies automatically
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def prepare_inputs(a, b, c, d):
|
||||
"""
|
||||
Ensures optional inputs b, c, d are zero-initialized like a if None.
|
||||
Returns the prepared (a, b, c, d).
|
||||
"""
|
||||
b = b if b is not None else make_zero_like(a)
|
||||
c = c if c is not None else make_zero_like(a)
|
||||
d = d if d is not None else make_zero_like(a)
|
||||
return a, b, c, d
|
||||
@@ -1,6 +1,6 @@
|
||||
from inspect import cleandoc
|
||||
from comfy_api.latest import io
|
||||
from .helper_functions import comonLazy
|
||||
from .helper_functions import commonLazy
|
||||
from .modelLikeCommon import calculate_patches
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class ModelMathNode(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return comonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
return commonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput:
|
||||
|
||||
@@ -5,7 +5,7 @@ import torch
|
||||
from .helper_functions import (
|
||||
generate_dim_variables,
|
||||
getIndexTensorAlongDim,
|
||||
comonLazy,
|
||||
commonLazy,
|
||||
parse_expr,
|
||||
eval_tensor_expr_with_tree,
|
||||
make_zero_like,
|
||||
@@ -68,7 +68,7 @@ class NoiseMathNode(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Noise, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return comonLazy(Noise, a, b, c, d, w, x, y, z)
|
||||
return commonLazy(Noise, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Noise, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
|
||||
@@ -2,7 +2,7 @@ from inspect import cleandoc
|
||||
from comfy_api.latest import io
|
||||
import copy
|
||||
from .modelLikeCommon import calculate_patches
|
||||
from .helper_functions import comonLazy
|
||||
from .helper_functions import commonLazy
|
||||
|
||||
|
||||
class VAEMathNode(io.ComfyNode):
|
||||
@@ -36,7 +36,7 @@ class VAEMathNode(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Model, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
return comonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
return commonLazy(Model, a, b, c, d, w, x, y, z)
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Model, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput:
|
||||
|
||||
@@ -5,13 +5,9 @@ from comfy_api.input_impl import VideoFromComponents
|
||||
from comfy_api.util import VideoComponents
|
||||
|
||||
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, make_zero_like
|
||||
from .helper_functions import generate_dim_variables, getIndexTensorAlongDim, eval_tensor_expr, make_zero_like, commonLazy
|
||||
|
||||
|
||||
from .MathNodeBase import MathNodeBase
|
||||
|
||||
|
||||
class VideoMathNode(MathNodeBase):
|
||||
class VideoMathNode(io.ComfyNode):
|
||||
"""
|
||||
Enables math expressions on Video (images + audio).
|
||||
|
||||
@@ -50,6 +46,12 @@ class VideoMathNode(MathNodeBase):
|
||||
|
||||
tooltip = cleandoc(__doc__)
|
||||
|
||||
@classmethod
|
||||
def check_lazy_status(cls, Audio, Images, a, b=[], c=[], d=[], w=0, x=0, y=0, z=0):
|
||||
tensor_needs = set(commonLazy(Audio, a, b, c, d, w, x, y, z))
|
||||
pooled_needs = set(commonLazy(Images, a, b, c, d, w, x, y, z))
|
||||
return list(tensor_needs.union(pooled_needs))
|
||||
|
||||
@classmethod
|
||||
def execute(cls, Audio, Images, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0) -> io.NodeOutput:
|
||||
ac = a.get_components()
|
||||
|
||||
@@ -77,7 +77,7 @@ def getIndexTensorAlongDim(tensor, dim):
|
||||
return values.expand(*shape)
|
||||
|
||||
|
||||
def comonLazy(expr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
def commonLazy(expr, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
|
||||
"""Determine which lazy inputs are needed based on expression variables."""
|
||||
variables = {"a": a, "b": b, "c": c, "d": d, "w": w, "x": x, "y": y, "z": z}
|
||||
need_eval = []
|
||||
@@ -99,6 +99,16 @@ def generate_dim_variables(tensor: torch.Tensor):
|
||||
variables[f"S{dim}"] = torch.full(tensor.shape, fill_value=size, dtype=torch.float32, device=tensor.device)
|
||||
return variables
|
||||
|
||||
@staticmethod
|
||||
def prepare_inputs(a, b, c, d):
|
||||
"""
|
||||
Ensures optional inputs b, c, d are zero-initialized like a if None.
|
||||
Returns the prepared (a, b, c, d).
|
||||
"""
|
||||
b = b if b is not None else make_zero_like(a)
|
||||
c = c if c is not None else make_zero_like(a)
|
||||
d = d if d is not None else make_zero_like(a)
|
||||
return a, b, c, d
|
||||
|
||||
def make_zero_like(ref):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user