fuíxed list OP tensor when first dim of tensor is the same size as list lenght

This commit is contained in:
mcDandy
2026-02-19 22:33:46 +01:00
parent edb7908328
commit fa018e6e4f
9 changed files with 1671 additions and 1646 deletions
+2 -1
View File
@@ -331,6 +331,7 @@ FLOW_APPLY: 'flow_apply';
BATCH_SHUFFLE: 'batch_shuffle' | 'shuffle';
MOTION_MASK: 'motion_mask';
FLOW_TO_IMAGE: 'flow_to_image';
OVERLAY: 'overlay';
PAD: 'pad';
CROSS: 'cross';
MATMUL: 'matmul';
@@ -367,7 +368,7 @@ UNIQUE: 'unique';
FLIP: 'flip';
COV: 'cov';
CROP: 'crop';
NONE: 'none';
NONE: 'none'|'None'|'null'|'NULL';
NOISE: 'noise' | 'randn' | 'random_normal';
RAND: 'rand' | 'randu' | 'random_uniform';
File diff suppressed because one or more lines are too long
+145 -144
View File
@@ -87,92 +87,93 @@ FLOW_APPLY=86
BATCH_SHUFFLE=87
MOTION_MASK=88
FLOW_TO_IMAGE=89
PAD=90
CROSS=91
MATMUL=92
RIFE=93
BNOT=94
BITCOUNT=95
SHAPE=96
BAND=97
XOR=98
BOR=99
TENSOR=100
PUSH=101
POP=102
CLEAR=103
HAS=104
GET=105
IF=106
ELSE=107
WHILE=108
FOR=109
IN=110
BREAK=111
CONTINUE=112
RETURN=113
TIMESTAMP=114
SORT=115
ARGSORT=116
ARGMIN=117
ARGMAX=118
SOFTMAX=119
SOFTMIN=120
UNIQUE=121
FLIP=122
COV=123
CROP=124
NONE=125
NOISE=126
RAND=127
CAUCHY=128
EXPONENTIAL=129
LOGNORMAL=130
BERNOULLI=131
POISSON=132
GAMMADIST=133
BETADIST=134
LAPLACEDIST=135
GUMBELDIST=136
WEIBULLDIST=137
CHI2DIST=138
STUDENTTDIST=139
PERLIN=140
CELLULAR=141
PLASMA=142
PLUS=143
MINUS=144
MULT=145
DIV=146
MOD=147
POW=148
LSHIFT=149
RSHIFT=150
GE=151
GT=152
LE=153
LT=154
EQ=155
EQUEALS=156
NE=157
PIPE=158
LPAREN=159
RPAREN=160
COMMA=161
SEMICOLON=162
ARROW=163
LBRACKET=164
RBRACKET=165
QUESTION=166
COLON=167
LBRACE=168
RBRACE=169
NUMBER=170
CONSTANT=171
VARIABLE=172
SL_COMMENT=173
ML_COMMENT=174
WS=175
OVERLAY=90
PAD=91
CROSS=92
MATMUL=93
RIFE=94
BNOT=95
BITCOUNT=96
SHAPE=97
BAND=98
XOR=99
BOR=100
TENSOR=101
PUSH=102
POP=103
CLEAR=104
HAS=105
GET=106
IF=107
ELSE=108
WHILE=109
FOR=110
IN=111
BREAK=112
CONTINUE=113
RETURN=114
TIMESTAMP=115
SORT=116
ARGSORT=117
ARGMIN=118
ARGMAX=119
SOFTMAX=120
SOFTMIN=121
UNIQUE=122
FLIP=123
COV=124
CROP=125
NONE=126
NOISE=127
RAND=128
CAUCHY=129
EXPONENTIAL=130
LOGNORMAL=131
BERNOULLI=132
POISSON=133
GAMMADIST=134
BETADIST=135
LAPLACEDIST=136
GUMBELDIST=137
WEIBULLDIST=138
CHI2DIST=139
STUDENTTDIST=140
PERLIN=141
CELLULAR=142
PLASMA=143
PLUS=144
MINUS=145
MULT=146
DIV=147
MOD=148
POW=149
LSHIFT=150
RSHIFT=151
GE=152
GT=153
LE=154
LT=155
EQ=156
EQUEALS=157
NE=158
PIPE=159
LPAREN=160
RPAREN=161
COMMA=162
SEMICOLON=163
ARROW=164
LBRACKET=165
RBRACKET=166
QUESTION=167
COLON=168
LBRACE=169
RBRACE=170
NUMBER=171
CONSTANT=172
VARIABLE=173
SL_COMMENT=174
ML_COMMENT=175
WS=176
'sin'=1
'cos'=2
'tan'=3
@@ -244,61 +245,61 @@ WS=175
'flow_apply'=86
'motion_mask'=88
'flow_to_image'=89
'pad'=90
'cross'=91
'matmul'=92
'rife'=93
'shape'=96
'tensor'=100
'stack_push'=101
'stack_pop'=102
'stack_clear'=103
'stack_has'=104
'stack_get'=105
'if'=106
'else'=107
'while'=108
'for'=109
'in'=110
'break'=111
'continue'=112
'return'=113
'timestamp'=114
'sort'=115
'argsort'=116
'argmin'=117
'argmax'=118
'softmax'=119
'softmin'=120
'unique'=121
'flip'=122
'cov'=123
'crop'=124
'none'=125
'+'=143
'-'=144
'*'=145
'/'=146
'%'=147
'^'=148
'<<'=149
'>>'=150
'>='=151
'>'=152
'<='=153
'<'=154
'=='=155
'='=156
'!='=157
'|'=158
'('=159
')'=160
','=161
';'=162
'->'=163
'['=164
']'=165
'?'=166
':'=167
'{'=168
'}'=169
'overlay'=90
'pad'=91
'cross'=92
'matmul'=93
'rife'=94
'shape'=97
'tensor'=101
'stack_push'=102
'stack_pop'=103
'stack_clear'=104
'stack_has'=105
'stack_get'=106
'if'=107
'else'=108
'while'=109
'for'=110
'in'=111
'break'=112
'continue'=113
'return'=114
'timestamp'=115
'sort'=116
'argsort'=117
'argmin'=118
'argmax'=119
'softmax'=120
'softmin'=121
'unique'=122
'flip'=123
'cov'=124
'crop'=125
'+'=144
'-'=145
'*'=146
'/'=147
'%'=148
'^'=149
'<<'=150
'>>'=151
'>='=152
'>'=153
'<='=154
'<'=155
'=='=156
'='=157
'!='=158
'|'=159
'('=160
')'=161
','=162
';'=163
'->'=164
'['=165
']'=166
'?'=167
':'=168
'{'=169
'}'=170
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+145 -144
View File
@@ -87,92 +87,93 @@ FLOW_APPLY=86
BATCH_SHUFFLE=87
MOTION_MASK=88
FLOW_TO_IMAGE=89
PAD=90
CROSS=91
MATMUL=92
RIFE=93
BNOT=94
BITCOUNT=95
SHAPE=96
BAND=97
XOR=98
BOR=99
TENSOR=100
PUSH=101
POP=102
CLEAR=103
HAS=104
GET=105
IF=106
ELSE=107
WHILE=108
FOR=109
IN=110
BREAK=111
CONTINUE=112
RETURN=113
TIMESTAMP=114
SORT=115
ARGSORT=116
ARGMIN=117
ARGMAX=118
SOFTMAX=119
SOFTMIN=120
UNIQUE=121
FLIP=122
COV=123
CROP=124
NONE=125
NOISE=126
RAND=127
CAUCHY=128
EXPONENTIAL=129
LOGNORMAL=130
BERNOULLI=131
POISSON=132
GAMMADIST=133
BETADIST=134
LAPLACEDIST=135
GUMBELDIST=136
WEIBULLDIST=137
CHI2DIST=138
STUDENTTDIST=139
PERLIN=140
CELLULAR=141
PLASMA=142
PLUS=143
MINUS=144
MULT=145
DIV=146
MOD=147
POW=148
LSHIFT=149
RSHIFT=150
GE=151
GT=152
LE=153
LT=154
EQ=155
EQUEALS=156
NE=157
PIPE=158
LPAREN=159
RPAREN=160
COMMA=161
SEMICOLON=162
ARROW=163
LBRACKET=164
RBRACKET=165
QUESTION=166
COLON=167
LBRACE=168
RBRACE=169
NUMBER=170
CONSTANT=171
VARIABLE=172
SL_COMMENT=173
ML_COMMENT=174
WS=175
OVERLAY=90
PAD=91
CROSS=92
MATMUL=93
RIFE=94
BNOT=95
BITCOUNT=96
SHAPE=97
BAND=98
XOR=99
BOR=100
TENSOR=101
PUSH=102
POP=103
CLEAR=104
HAS=105
GET=106
IF=107
ELSE=108
WHILE=109
FOR=110
IN=111
BREAK=112
CONTINUE=113
RETURN=114
TIMESTAMP=115
SORT=116
ARGSORT=117
ARGMIN=118
ARGMAX=119
SOFTMAX=120
SOFTMIN=121
UNIQUE=122
FLIP=123
COV=124
CROP=125
NONE=126
NOISE=127
RAND=128
CAUCHY=129
EXPONENTIAL=130
LOGNORMAL=131
BERNOULLI=132
POISSON=133
GAMMADIST=134
BETADIST=135
LAPLACEDIST=136
GUMBELDIST=137
WEIBULLDIST=138
CHI2DIST=139
STUDENTTDIST=140
PERLIN=141
CELLULAR=142
PLASMA=143
PLUS=144
MINUS=145
MULT=146
DIV=147
MOD=148
POW=149
LSHIFT=150
RSHIFT=151
GE=152
GT=153
LE=154
LT=155
EQ=156
EQUEALS=157
NE=158
PIPE=159
LPAREN=160
RPAREN=161
COMMA=162
SEMICOLON=163
ARROW=164
LBRACKET=165
RBRACKET=166
QUESTION=167
COLON=168
LBRACE=169
RBRACE=170
NUMBER=171
CONSTANT=172
VARIABLE=173
SL_COMMENT=174
ML_COMMENT=175
WS=176
'sin'=1
'cos'=2
'tan'=3
@@ -244,61 +245,61 @@ WS=175
'flow_apply'=86
'motion_mask'=88
'flow_to_image'=89
'pad'=90
'cross'=91
'matmul'=92
'rife'=93
'shape'=96
'tensor'=100
'stack_push'=101
'stack_pop'=102
'stack_clear'=103
'stack_has'=104
'stack_get'=105
'if'=106
'else'=107
'while'=108
'for'=109
'in'=110
'break'=111
'continue'=112
'return'=113
'timestamp'=114
'sort'=115
'argsort'=116
'argmin'=117
'argmax'=118
'softmax'=119
'softmin'=120
'unique'=121
'flip'=122
'cov'=123
'crop'=124
'none'=125
'+'=143
'-'=144
'*'=145
'/'=146
'%'=147
'^'=148
'<<'=149
'>>'=150
'>='=151
'>'=152
'<='=153
'<'=154
'=='=155
'='=156
'!='=157
'|'=158
'('=159
')'=160
','=161
';'=162
'->'=163
'['=164
']'=165
'?'=166
':'=167
'{'=168
'}'=169
'overlay'=90
'pad'=91
'cross'=92
'matmul'=93
'rife'=94
'shape'=97
'tensor'=101
'stack_push'=102
'stack_pop'=103
'stack_clear'=104
'stack_has'=105
'stack_get'=106
'if'=107
'else'=108
'while'=109
'for'=110
'in'=111
'break'=112
'continue'=113
'return'=114
'timestamp'=115
'sort'=116
'argsort'=117
'argmin'=118
'argmax'=119
'softmax'=120
'softmin'=121
'unique'=122
'flip'=123
'cov'=124
'crop'=125
'+'=144
'-'=145
'*'=146
'/'=147
'%'=148
'^'=149
'<<'=150
'>>'=151
'>='=152
'>'=153
'<='=154
'<'=155
'=='=156
'='=157
'!='=158
'|'=159
'('=160
')'=161
','=162
';'=163
'->'=164
'['=165
']'=166
'?'=167
':'=168
'{'=169
'}'=170
File diff suppressed because it is too large Load Diff
+5 -4
View File
@@ -7,6 +7,7 @@ from . import optical_flow_utils as ofu
from antlr4 import TerminalNode
from .MathExprVisitor import MathExprVisitor
from ..helper_functions import generate_dim_variables
from ..noise_utils import NoiseUtils
import struct
@@ -115,7 +116,7 @@ class UnifiedMathVisitor(MathExprVisitor):
if self._is_tensor(a) and self._is_list(b):
if a.shape[0] == len(b):
A = torch.split(a, 1)
results = [self._bin_op(x.squeeze(0), y, torch_op, scalar_op) for x, y in zip(A, b)]
results = [self._bin_op(x, y, torch_op, scalar_op) for x, y in zip(A, b)]
# Ensure all results are tensors
results = [self._promote_to_tensor(r) if not self._is_tensor(r) else r for r in results]
return torch.cat([r.unsqueeze(0) if r.ndim == 0 else r for r in results], dim=0)
@@ -125,7 +126,7 @@ class UnifiedMathVisitor(MathExprVisitor):
if self._is_list(a) and self._is_tensor(b):
if b.shape[0] == len(a):
B = torch.split(b, 1)
results = [self._bin_op(x, y.squeeze(0), torch_op, scalar_op) for x, y in zip(a, B)]
results = [self._bin_op(x, y, torch_op, scalar_op) for x, y in zip(a, B)]
results = [self._promote_to_tensor(r) if not self._is_tensor(r) else r for r in results]
return torch.cat([r.unsqueeze(0) if r.ndim == 0 else r for r in results], dim=0)
results = [self._bin_op(x, b, torch_op, scalar_op) for x in a]
@@ -2397,7 +2398,7 @@ class UnifiedMathVisitor(MathExprVisitor):
if self._is_tensor(a) and self._is_list(b):
if a.shape[0] == len(b):
A = torch.split(a, 1)
results = [self._bitwise_op(x.squeeze(0), y, torch_op, scalar_op) for x, y in zip(A, b)]
results = [self._bitwise_op(x, y, torch_op, scalar_op) for x, y in zip(A, b)]
results = [self._promote_to_tensor(r) if not self._is_tensor(r) else r for r in results]
return torch.cat([r.unsqueeze(0) if r.ndim == 0 else r for r in results], dim=0)
results = [self._bitwise_op(a, x, torch_op, scalar_op) for x in b]
@@ -2406,7 +2407,7 @@ class UnifiedMathVisitor(MathExprVisitor):
if self._is_list(a) and self._is_tensor(b):
if b.shape[0] == len(a):
B = torch.split(b, 1)
results = [self._bitwise_op(x, y.squeeze(0), torch_op, scalar_op) for x, y in zip(a, B)]
results = [self._bitwise_op(x, y, torch_op, scalar_op) for x, y in zip(a, B)]
results = [self._promote_to_tensor(r) if not self._is_tensor(r) else r for r in results]
return torch.cat([r.unsqueeze(0) if r.ndim == 0 else r for r in results], dim=0)
results = [self._bitwise_op(x, b, torch_op, scalar_op) for x in a]
+14 -10
View File
@@ -22,21 +22,26 @@ def calculate_patches_autogrow(Expr, V, F,pbar, mapping=None,stack = []):
if F is None: F = {}
if mapping is None: mapping = {}
# Collect all unique keys from all models
all_keys = set()
# Collect all unique keys from all models, preserving order from first model
all_keys_list = [] # Preserves order
seen_keys = set() # Fast O(1) duplicate checking
models = [v for v in V.values() if v is not None]
if not models:
return {}
for m in models:
if hasattr(m, "model") and hasattr(m.model, "state_dict"):
all_keys.update(m.model.state_dict().keys())
sd_keys = m.model.state_dict().keys()
elif hasattr(m, "state_dict"): # VAE might have state_dict directly?
all_keys.update(m.state_dict().keys())
elif hasattr(m, "patches"): # Mock object or raw patcher
# If it's just a patcher without underlying model access?
# Usually patcher.model.state_dict() is the way.
pass
sd_keys = m.state_dict().keys()
else:
sd_keys = []
for key in sd_keys:
if key not in seen_keys:
seen_keys.add(key)
all_keys_list.append(key)
# Function to get weight from a valid object
def get_weight(obj, key):
@@ -53,12 +58,11 @@ def calculate_patches_autogrow(Expr, V, F,pbar, mapping=None,stack = []):
# Progress bar if possible (comfy.utils.ProgressBar might assume unthreaded?)
# Just skip for utility or use if substantial.
all_keys_list = list(all_keys)
layer_count = len(all_keys_list)
for layer_idx, key in enumerate(all_keys_list):
variables = {}
print(key)
# Populate F variables (constants for all keys)
for k, val in F.items():
variables[k] = val if val is not None else 0.0