diff --git a/more_math/AudioMathNode.py b/more_math/AudioMathNode.py index 62f0023..3eb8e2a 100644 --- a/more_math/AudioMathNode.py +++ b/more_math/AudioMathNode.py @@ -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 = [] diff --git a/more_math/ClipMathNode.py b/more_math/ClipMathNode.py index 3847b9e..a1a4245 100644 --- a/more_math/ClipMathNode.py +++ b/more_math/ClipMathNode.py @@ -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: diff --git a/more_math/ConditioningMathNode.py b/more_math/ConditioningMathNode.py index 398fc6e..e974fc6 100644 --- a/more_math/ConditioningMathNode.py +++ b/more_math/ConditioningMathNode.py @@ -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 = {} diff --git a/more_math/FloatMathNode.py b/more_math/FloatMathNode.py index 1aa44bb..579c7fd 100644 --- a/more_math/FloatMathNode.py +++ b/more_math/FloatMathNode.py @@ -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) diff --git a/more_math/GuiderMathNode.py b/more_math/GuiderMathNode.py index 86772e4..08941ea 100644 --- a/more_math/GuiderMathNode.py +++ b/more_math/GuiderMathNode.py @@ -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) diff --git a/more_math/ImageMathNode.py b/more_math/ImageMathNode.py index d20ca0e..ce7d7dc 100644 --- a/more_math/ImageMathNode.py +++ b/more_math/ImageMathNode.py @@ -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 = [] diff --git a/more_math/LatentMathNode.py b/more_math/LatentMathNode.py index 7a70bd5..1d2f889 100644 --- a/more_math/LatentMathNode.py +++ b/more_math/LatentMathNode.py @@ -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 diff --git a/more_math/MaskMathNode.py b/more_math/MaskMathNode.py index ccafb24..cfc992b 100644 --- a/more_math/MaskMathNode.py +++ b/more_math/MaskMathNode.py @@ -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 = [] diff --git a/more_math/ModelMathNode.py b/more_math/ModelMathNode.py index 1f937f2..fa42e8a 100644 --- a/more_math/ModelMathNode.py +++ b/more_math/ModelMathNode.py @@ -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 diff --git a/more_math/NoiseMathNode.py b/more_math/NoiseMathNode.py index a31c0f6..f61ce37 100644 --- a/more_math/NoiseMathNode.py +++ b/more_math/NoiseMathNode.py @@ -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: diff --git a/more_math/SigmasMathNode.py b/more_math/SigmasMathNode.py index 26c8b55..cd72a94 100644 --- a/more_math/SigmasMathNode.py +++ b/more_math/SigmasMathNode.py @@ -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") diff --git a/more_math/VaeMathNode.py b/more_math/VaeMathNode.py index 7617868..eb2d158 100644 --- a/more_math/VaeMathNode.py +++ b/more_math/VaeMathNode.py @@ -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) diff --git a/more_math/VideoMathNode.py b/more_math/VideoMathNode.py index 24bb685..6a8b987 100644 --- a/more_math/VideoMathNode.py +++ b/more_math/VideoMathNode.py @@ -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))