Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
91ed2815
Commit
91ed2815
authored
Jul 14, 2023
by
comfyanonymous
Browse files
Add a node to merge CLIP models.
parent
907c9fbf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
comfy/sd.py
comfy/sd.py
+5
-2
comfy_extras/nodes_model_merging.py
comfy_extras/nodes_model_merging.py
+22
-0
No files found.
comfy/sd.py
View file @
91ed2815
...
...
@@ -479,8 +479,8 @@ class CLIP:
def
load_from_state_dict
(
self
,
sd
):
self
.
cond_stage_model
.
load_sd
(
sd
)
def
add_patches
(
self
,
patches
,
strength
=
1.0
):
return
self
.
patcher
.
add_patches
(
patches
,
strength
)
def
add_patches
(
self
,
patches
,
strength
_patch
=
1.0
,
strength_model
=
1.0
):
return
self
.
patcher
.
add_patches
(
patches
,
strength
_patch
,
strength_model
)
def
clip_layer
(
self
,
layer_idx
):
self
.
layer_idx
=
layer_idx
...
...
@@ -514,6 +514,9 @@ class CLIP:
def
unpatch_model
(
self
):
self
.
patcher
.
unpatch_model
()
def
get_key_patches
(
self
):
return
self
.
patcher
.
get_key_patches
()
class
VAE
:
def
__init__
(
self
,
ckpt_path
=
None
,
device
=
None
,
config
=
None
):
if
config
is
None
:
...
...
comfy_extras/nodes_model_merging.py
View file @
91ed2815
...
...
@@ -23,6 +23,27 @@ class ModelMergeSimple:
m
.
add_patches
({
k
:
kp
[
k
]},
1.0
-
ratio
,
ratio
)
return
(
m
,
)
class
CLIPMergeSimple
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"clip1"
:
(
"CLIP"
,),
"clip2"
:
(
"CLIP"
,),
"ratio"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
}),
}}
RETURN_TYPES
=
(
"CLIP"
,)
FUNCTION
=
"merge"
CATEGORY
=
"advanced/model_merging"
def
merge
(
self
,
clip1
,
clip2
,
ratio
):
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
-
ratio
,
ratio
)
return
(
m
,
)
class
ModelMergeBlocks
:
@
classmethod
def
INPUT_TYPES
(
s
):
...
...
@@ -94,4 +115,5 @@ NODE_CLASS_MAPPINGS = {
"ModelMergeSimple"
:
ModelMergeSimple
,
"ModelMergeBlocks"
:
ModelMergeBlocks
,
"CheckpointSave"
:
CheckpointSave
,
"CLIPMergeSimple"
:
CLIPMergeSimple
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment