From 1f6aecba328dfde52b40283c4e344ee3a1d85040 Mon Sep 17 00:00:00 2001 From: IDGallagher Date: Sun, 28 Apr 2024 21:54:33 +0100 Subject: [PATCH 1/3] Fix error when an IPAdapter has already been added to the model --- .../CrossAttentionPatchImport.py | 20 +++++++++++++++++++ .../ComfyUI_IPAdapter_plus/IPAdapterPlus.py | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/imports/ComfyUI_IPAdapter_plus/CrossAttentionPatchImport.py b/imports/ComfyUI_IPAdapter_plus/CrossAttentionPatchImport.py index c615970..cb1b6eb 100644 --- a/imports/ComfyUI_IPAdapter_plus/CrossAttentionPatchImport.py +++ b/imports/ComfyUI_IPAdapter_plus/CrossAttentionPatchImport.py @@ -25,6 +25,26 @@ class CrossAttentionPatchImport: self.k_key = str(self.number*2+1) + "_to_k_ip" self.v_key = str(self.number*2+1) + "_to_v_ip" + @classmethod + def from_cross_attention_patch(cls, patch): + instance = cls(ipadapter = patch.ipadapters[0]) + instance.weights = patch.weights + instance.ipadapters = patch.ipadapters + instance.conds = patch.conds + instance.conds_alt = patch.conds_alt + instance.unconds = patch.unconds + instance.weight_types = patch.weight_types + instance.masks = patch.masks + instance.sigma_starts = patch.sigma_starts + instance.sigma_ends = patch.sigma_ends + instance.unfold_batch = patch.unfold_batch + instance.embeds_scaling = patch.embeds_scaling + instance.number = patch.number + instance.layers = patch.layers + instance.k_key = patch.k_key + instance.v_key = patch.v_key + return instance + def set_new_condition(self, ipadapter=None, number=0, weight=1.0, cond=None, cond_alt=None, uncond=None, weight_type="linear", mask=None, sigma_start=0.0, sigma_end=1.0, unfold_batch=False, image_schedule=None, embeds_scaling='V only'): self.weights.append(weight) self.ipadapters.append(ipadapter) diff --git a/imports/ComfyUI_IPAdapter_plus/IPAdapterPlus.py b/imports/ComfyUI_IPAdapter_plus/IPAdapterPlus.py index a6c84b8..16d64ae 100644 --- a/imports/ComfyUI_IPAdapter_plus/IPAdapterPlus.py +++ b/imports/ComfyUI_IPAdapter_plus/IPAdapterPlus.py @@ -142,7 +142,11 @@ def set_model_patch_replace(model, patch_kwargs, key): if key not in to["patches_replace"]["attn2"]: to["patches_replace"]["attn2"][key] = CrossAttentionPatchImport(**patch_kwargs) else: - to["patches_replace"]["attn2"][key].set_new_condition(**patch_kwargs) + if isinstance(to["patches_replace"]["attn2"][key], CrossAttentionPatchImport): + to["patches_replace"]["attn2"][key].set_new_condition(**patch_kwargs) + else: + to["patches_replace"]["attn2"][key] = CrossAttentionPatchImport.from_cross_attention_patch(to["patches_replace"]["attn2"][key]) + to["patches_replace"]["attn2"][key].set_new_condition(**patch_kwargs) def ipadapter_execute(model, ipadapter, From 199b1cc17b61be305644a3605cf17c0908fd6e16 Mon Sep 17 00:00:00 2001 From: IDGallagher Date: Sun, 28 Apr 2024 22:11:52 +0100 Subject: [PATCH 2/3] Fix error when ipa_weight is set to 0 on base --- SteerableMotion.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SteerableMotion.py b/SteerableMotion.py index 7fdac30..9d990c9 100644 --- a/SteerableMotion.py +++ b/SteerableMotion.py @@ -533,20 +533,21 @@ class BatchCreativeInterpolationNode: else: big_negative_noise = None - # Fill up bins with image frames. Bins will automatically be created when needed but all the frames should be able to be packed into two bins - active_index = -1 - # Find a bin that we can fit the next image into - for i, bin in enumerate(bins): - if bin.length() <= ipa_frame_numbers[0]: - active_index = i - break - # If we didn't find a suitable bin, add a new one - if active_index == -1: - bins.append(IPBin()) - active_index = len(bins) - 1 + if len(ipa_frame_numbers) > 0: + # Fill up bins with image frames. Bins will automatically be created when needed but all the frames should be able to be packed into two bins + active_index = -1 + # Find a bin that we can fit the next image into + for i, bin in enumerate(bins): + if bin.length() <= ipa_frame_numbers[0]: + active_index = i + break + # If we didn't find a suitable bin, add a new one + if active_index == -1: + bins.append(IPBin()) + active_index = len(bins) - 1 - # Add the image to the bin - bins[active_index].add(prepped_image, image.unsqueeze(0), negative_noise, big_negative_noise, image_index, ipa_frame_numbers, ipa_weights) + # Add the image to the bin + bins[active_index].add(prepped_image, image.unsqueeze(0), negative_noise, big_negative_noise, image_index, ipa_frame_numbers, ipa_weights) # for i, bin in enumerate(bins): # print(f"{i} schedule {bin.image_schedule}") From e277e2e86f0366a6ea5c71f2f3fbe27d981362ac Mon Sep 17 00:00:00 2001 From: IDGallagher Date: Sun, 28 Apr 2024 22:17:07 +0100 Subject: [PATCH 3/3] Stop base ipa_weight being applied twice. Its now applied when creating the IPA --- SteerableMotion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteerableMotion.py b/SteerableMotion.py index 9d990c9..e1a888e 100644 --- a/SteerableMotion.py +++ b/SteerableMotion.py @@ -500,7 +500,7 @@ class BatchCreativeInterpolationNode: frame_numbers = np.concatenate([first_half_frame_numbers, second_half_frame_numbers]) # PROCESS WEIGHTS - ipa_frame_numbers, ipa_weights = process_weights(frame_numbers, weights, base_ipa_advanced_settings["ipa_weight"]) + ipa_frame_numbers, ipa_weights = process_weights(frame_numbers, weights, 1.0) # print(f'i {i} image index {image_index} ====') # # print(f"frame numbers {frame_numbers}")