AI: add dict mode to model like nodes. TODO build grammer and check

This commit is contained in:
mcDandy
2026-09-11 10:39:02 +02:00
parent 13cce62633
commit 6be16be3fd
10 changed files with 312 additions and 21 deletions
+11 -4
View File
@@ -5,7 +5,7 @@ from .Stack import MrmthStack
from .ParseTree import MrmthParseTree
import copy
import comfy.utils
from .modelLikeCommon import calculate_patches_autogrow
from .modelLikeCommon import calculate_patches_autogrow, calculate_patches_dict_mode
class ModelMathNode(io.ComfyNode):
@@ -35,6 +35,12 @@ class ModelMathNode(io.ComfyNode):
default="error",
tooltip="How to handle mismatched layer counts. For models, this usually defaults to broadcast (zero for missing layers)."
),
io.Boolean.Input(
id="dict_mode",
default=False,
display_name="Dictionary mode",
tooltip="Evaluates model weights as dictionaries. Per-layer and dimension variables are unavailable.",
),
io.Boolean.Input(
id="use_compute_device",
default=True,
@@ -53,11 +59,11 @@ class ModelMathNode(io.ComfyNode):
tooltip = cleandoc(__doc__)
@classmethod
def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",use_compute_device=True,stack={}):
def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",use_compute_device=True,stack={},dict_mode=False):
return checkLazyNew(Expression,V,F)
@classmethod
def execute(cls, V, F, Expression, length_mismatch="tile",use_compute_device=True,stack={}) -> io.NodeOutput:
def execute(cls, V, F, Expression, length_mismatch="tile",use_compute_device=True,stack={},dict_mode=False) -> io.NodeOutput:
# Determine reference model for cloning
a = V.get("V0")
stack = copy.deepcopy(stack) if stack is not None else {}
@@ -77,7 +83,8 @@ class ModelMathNode(io.ComfyNode):
aliases = {"a": "V0", "b": "V1", "c": "V2", "d": "V3", "w": "F0", "x": "F1", "y": "F2", "z": "F3"}
patches = calculate_patches_autogrow(Expression, V=V, F=F,pbar=pbar, mapping=aliases,stack=stack,use_compute_device=use_compute_device)
calculate_patches = calculate_patches_dict_mode if dict_mode else calculate_patches_autogrow
patches = calculate_patches(Expression, V=V, F=F,pbar=pbar, mapping=aliases,stack=stack,use_compute_device=use_compute_device)
out_model = a.clone()
if patches: