Skip to content

Commit

Permalink
Added additional nodes for CLIP merging
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonRide303 committed Mar 9, 2024
1 parent a9ee958 commit 4656273
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions comfy_extras/nodes_model_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,50 @@ def merge(self, clip1, clip2, ratio):
m.add_patches({k: kp[k]}, 1.0 - ratio, ratio)
return (m, )


class CLIPSubtract:
@classmethod
def INPUT_TYPES(s):
return {"required": { "clip1": ("CLIP",),
"clip2": ("CLIP",),
"multiplier": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
}}
RETURN_TYPES = ("CLIP",)
FUNCTION = "merge"

CATEGORY = "advanced/model_merging"

def merge(self, clip1, clip2, multiplier):
m = clip1.clone()
kp = clip2.get_key_patches()
for k in kp:
if k.endswith(".position_ids") or k.endswith(".logit_scale"):
continue
m.add_patches({k: kp[k]}, - multiplier, multiplier)
return (m, )


class CLIPAdd:
@classmethod
def INPUT_TYPES(s):
return {"required": { "clip1": ("CLIP",),
"clip2": ("CLIP",),
}}
RETURN_TYPES = ("CLIP",)
FUNCTION = "merge"

CATEGORY = "advanced/model_merging"

def merge(self, clip1, clip2):
m = clip1.clone()
kp = clip2.get_key_patches()
for k in kp:
if k.endswith(".position_ids") or k.endswith(".logit_scale"):
continue
m.add_patches({k: kp[k]}, 1.0, 1.0)
return (m, )


class ModelMergeBlocks:
@classmethod
def INPUT_TYPES(s):
Expand Down Expand Up @@ -279,6 +323,8 @@ def save(self, vae, filename_prefix, prompt=None, extra_pnginfo=None):
"ModelMergeAdd": ModelAdd,
"CheckpointSave": CheckpointSave,
"CLIPMergeSimple": CLIPMergeSimple,
"CLIPMergeSubtract": CLIPSubtract,
"CLIPMergeAdd": CLIPAdd,
"CLIPSave": CLIPSave,
"VAESave": VAESave,
}

0 comments on commit 4656273

Please sign in to comment.