Skip to content

Commit 77b2f7c

Browse files
authored
Add context windows callback for custom cond handling (#11208)
Co-authored-by: ozbayb <[email protected]>
1 parent 43e0d4e commit 77b2f7c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

comfy/context_windows.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class IndexListCallbacks:
8787
COMBINE_CONTEXT_WINDOW_RESULTS = "combine_context_window_results"
8888
EXECUTE_START = "execute_start"
8989
EXECUTE_CLEANUP = "execute_cleanup"
90+
RESIZE_COND_ITEM = "resize_cond_item"
9091

9192
def init_callbacks(self):
9293
return {}
@@ -166,6 +167,18 @@ def get_resized_cond(self, cond_in: list[dict], x_in: torch.Tensor, window: Inde
166167
new_cond_item = cond_item.copy()
167168
# when in dictionary, look for tensors and CONDCrossAttn [comfy/conds.py] (has cond attr that is a tensor)
168169
for cond_key, cond_value in new_cond_item.items():
170+
# Allow callbacks to handle custom conditioning items
171+
handled = False
172+
for callback in comfy.patcher_extension.get_all_callbacks(
173+
IndexListCallbacks.RESIZE_COND_ITEM, self.callbacks
174+
):
175+
result = callback(cond_key, cond_value, window, x_in, device, new_cond_item)
176+
if result is not None:
177+
new_cond_item[cond_key] = result
178+
handled = True
179+
break
180+
if handled:
181+
continue
169182
if isinstance(cond_value, torch.Tensor):
170183
if (self.dim < cond_value.ndim and cond_value(self.dim) == x_in.size(self.dim)) or \
171184
(cond_value.ndim < self.dim and cond_value.size(0) == x_in.size(self.dim)):

0 commit comments

Comments
 (0)