fix runtime errors + stack passing for noise

This commit is contained in:
mcDandy
2026-02-10 17:29:21 +01:00
parent 5f6f648636
commit 0ba8c8cf26
13 changed files with 32 additions and 20 deletions
+3 -2
View File
@@ -16,6 +16,7 @@ from .Parser.MathExprParser import MathExprParser
import re
import torch
from .Stack import MrmthStack
import copy
class AudioMathNode(io.ComfyNode):
"""
@@ -91,7 +92,7 @@ class AudioMathNode(io.ComfyNode):
tensor_keys = [k for k, v in V.items() if v is not None and isinstance(v, dict) and "waveform" in v]
if not tensor_keys:
raise ValueError("At least one audio input is required.")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
waveforms = {k: V[k]["waveform"] for k in tensor_keys}
sample_rates = {k + "sr": V[k].get("sample_rate", 44100) for k in tensor_keys}
@@ -154,7 +155,7 @@ class AudioMathNode(io.ComfyNode):
visitor = UnifiedMathVisitor(variables, a_w.shape,a_w.device,state_storage=stack)
result = visitor.visit(tree)
result = as_tensor(result, a_w.shape)
if batching and batching > 0:
res = torch.split(result, batching, dim=0)
res_list = []
+3 -1
View File
@@ -5,6 +5,8 @@ from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
import re
from .Stack import MrmthStack
import copy
class CLIPMathNode(io.ComfyNode):
@@ -75,7 +77,7 @@ class CLIPMathNode(io.ComfyNode):
def execute(cls, V, F, Expression, length_mismatch="tile",stack={}) -> io.NodeOutput:
# Determine reference CLIP
a = V.get("V0")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
if a is None:
for m in V.values():
if m is not None:
+1 -1
View File
@@ -90,7 +90,7 @@ class ConditioningMathNode(io.ComfyNode):
tensor_keys = [k for k, v in V.items() if v is not None and isinstance(v, list) and len(v) > 0]
if not tensor_keys:
raise ValueError("At least one input is required.")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Extract tensors and pooled outputs
tensors = {}
+3 -2
View File
@@ -10,6 +10,8 @@ from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
import re
from .Stack import MrmthStack
import copy
class FloatMathNode(io.ComfyNode):
@@ -84,7 +86,7 @@ class FloatMathNode(io.ComfyNode):
variables["x"] = V.get("V5", 0.0)
variables["y"] = V.get("V6", 0.0)
variables["z"] = V.get("V7", 0.0)
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Populate all V inputs
for k, val in V.items():
@@ -98,7 +100,6 @@ class FloatMathNode(io.ComfyNode):
tree = parse_expr(FloatFunc);
# scalar execution
# UnifiedMathVisitor expects variables and a shape. Shape [1] for scalar?
visitor = UnifiedMathVisitor(variables, [1],state_storage=stack)
result = visitor.visit(tree)
# Result might be float or tensor(scalar)
+2 -1
View File
@@ -20,6 +20,7 @@ import comfy.utils
import comfy.hooks
import comfy.samplers
from .Stack import MrmthStack
import copy
class GuiderMathNode(io.ComfyNode):
@@ -83,7 +84,7 @@ class GuiderMathNode(io.ComfyNode):
@classmethod
def execute(cls, V, F, Expression,Expression1,stack={}):
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
return (MathGuider(V, F, Expression,Expression1),stack)
+4 -2
View File
@@ -7,6 +7,8 @@ from .Parser.MathExprParser import MathExprParser
import re
import torch
from .Stack import MrmthStack
import copy
class ImageMathNode(io.ComfyNode):
"""
@@ -86,7 +88,7 @@ class ImageMathNode(io.ComfyNode):
raise ValueError("At least one input is required.")
tensors = [V[k] for k in tensor_keys]
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Normalize all tensors together to find the common target shape
normalized_tensors = normalize_to_common_shape(*tensors, mode=length_mismatch)
@@ -154,7 +156,7 @@ class ImageMathNode(io.ComfyNode):
visitor = UnifiedMathVisitor(variables, ae.shape,ae.device,state_storage=stack)
result = visitor.visit(tree)
result = as_tensor(result, ae.shape)
if batching and batching > 0:
res = torch.split(result, batching, dim=0)
res_list = []
+2 -1
View File
@@ -18,6 +18,7 @@ from .Parser.MathExprParser import MathExprParser
import re
from comfy.nested_tensor import NestedTensor
from .Stack import MrmthStack
import copy
class LatentMathNode(io.ComfyNode):
"""
@@ -100,7 +101,7 @@ class LatentMathNode(io.ComfyNode):
if ref_latent is None:
raise ValueError("At least one input is required.")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Identify if any input is a NestedTensor and track original sizes for restoration
stacked = False
+3 -2
View File
@@ -7,6 +7,7 @@ from .Parser.MathExprParser import MathExprParser
import re
import torch
from .Stack import MrmthStack
import copy
class MaskMathNode(io.ComfyNode):
@@ -85,7 +86,7 @@ class MaskMathNode(io.ComfyNode):
raise ValueError("At least one input is required.")
tensors = [V[k] for k in tensor_keys]
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Normalize all tensors together
normalized_tensors = normalize_to_common_shape(*tensors, mode=length_mismatch)
V_norm = dict(zip(tensor_keys, normalized_tensors))
@@ -148,7 +149,7 @@ class MaskMathNode(io.ComfyNode):
visitor = UnifiedMathVisitor(variables, ae.shape,ae.device,state_storage=stack)
result = visitor.visit(tree)
result = as_tensor(result, ae.shape)
if batching and batching > 0:
res = torch.split(result, batching, dim=0)
res_list = []
+2 -1
View File
@@ -5,6 +5,7 @@ from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
import re
from .Stack import MrmthStack
import copy
class ModelMathNode(io.ComfyNode):
"""
@@ -76,7 +77,7 @@ class ModelMathNode(io.ComfyNode):
def execute(cls, V, F, Expression, length_mismatch="tile",stack={}) -> io.NodeOutput:
# Determine reference model for cloning
a = V.get("V0")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
if a is None:
# Try finding first valid model
+3 -2
View File
@@ -6,6 +6,7 @@ from .Parser.MathExprLexer import MathExprLexer
import re
from .Parser.UnifiedMathVisitor import UnifiedMathVisitor
from .Stack import MrmthStack
import copy
class NoiseMathNode(io.ComfyNode):
"""
@@ -74,8 +75,8 @@ class NoiseMathNode(io.ComfyNode):
@classmethod
def execute(cls, Noise, V,F,stack={}):
stack = stack.deepcopy() if stack is not None else {}
return (NoiseExecutor(V,F, Noise,stack),)
stack = copy.deepcopy(stack) if stack is not None else {}
return (NoiseExecutor(V,F, Noise,stack),stack)
class NoiseExecutor:
+2 -1
View File
@@ -6,6 +6,7 @@ from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
import re
from .Stack import MrmthStack
import copy
class SigmasMathNode(io.ComfyNode):
"""
@@ -87,7 +88,7 @@ class SigmasMathNode(io.ComfyNode):
if ref_image is None:
raise ValueError("At least one input is required.")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
a = V.get("V0")
b = V.get("V1")
c = V.get("V2")
+2 -3
View File
@@ -83,8 +83,7 @@ class VAEMathNode(io.ComfyNode):
break
if a is None:
raise ValueError("At least one input VAE is required.")
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Prepare VAE patchers for calculation
# We need to map VAE wrappers to their patchers for `calculate_patches`
@@ -106,4 +105,4 @@ class VAEMathNode(io.ComfyNode):
if patches:
out_vae.patcher.add_patches(patches, 1.0, 1.0)
return (out_vae,)
return (out_vae,stack)
+2 -1
View File
@@ -6,6 +6,7 @@ from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
import re
from .Stack import MrmthStack
import copy
class VideoMathNode(io.ComfyNode):
"""
@@ -95,7 +96,7 @@ class VideoMathNode(io.ComfyNode):
# Use first normalized tensor to establish the reference shape
ref_tensor = normalized_tensors[0]
common_shape = ref_tensor.shape
stack = stack.deepcopy() if stack is not None else {}
stack = copy.deepcopy(stack) if stack is not None else {}
# Setup legacy variables a, b, c, d
ae = V_norm.get("V0", make_zero_like(ref_tensor))