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
bf3f2717
"tools/vscode:/vscode.git/clone" did not exist on "180f7d00518f4a764eec233bcb1188c2983a552a"
Commit
bf3f2717
authored
Jun 20, 2023
by
comfyanonymous
Browse files
Add some nodes for basic model merging.
parent
8125b51a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
comfy_extras/nodes_model_merging.py
comfy_extras/nodes_model_merging.py
+55
-0
nodes.py
nodes.py
+1
-0
No files found.
comfy_extras/nodes_model_merging.py
0 → 100644
View file @
bf3f2717
class
ModelMergeSimple
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"model1"
:
(
"MODEL"
,),
"model2"
:
(
"MODEL"
,),
"ratio"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
}),
}}
RETURN_TYPES
=
(
"MODEL"
,)
FUNCTION
=
"merge"
CATEGORY
=
"_for_testing/model_merging"
def
merge
(
self
,
model1
,
model2
,
ratio
):
m
=
model1
.
clone
()
sd
=
model2
.
model_state_dict
()
for
k
in
sd
:
m
.
add_patches
({
k
:
(
sd
[
k
],
)},
1.0
-
ratio
,
ratio
)
return
(
m
,
)
class
ModelMergeBlocks
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"model1"
:
(
"MODEL"
,),
"model2"
:
(
"MODEL"
,),
"input"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"middle"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"out"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
})
}}
RETURN_TYPES
=
(
"MODEL"
,)
FUNCTION
=
"merge"
CATEGORY
=
"_for_testing/model_merging"
def
merge
(
self
,
model1
,
model2
,
**
kwargs
):
m
=
model1
.
clone
()
sd
=
model2
.
model_state_dict
()
default_ratio
=
next
(
iter
(
kwargs
.
values
()))
for
k
in
sd
:
ratio
=
default_ratio
k_unet
=
k
[
len
(
"diffusion_model."
):]
for
arg
in
kwargs
:
if
k_unet
.
startswith
(
arg
):
ratio
=
kwargs
[
arg
]
m
.
add_patches
({
k
:
(
sd
[
k
],
)},
1.0
-
ratio
,
ratio
)
return
(
m
,
)
NODE_CLASS_MAPPINGS
=
{
"ModelMergeSimple"
:
ModelMergeSimple
,
"ModelMergeBlocks"
:
ModelMergeBlocks
}
nodes.py
View file @
bf3f2717
...
@@ -1459,4 +1459,5 @@ def init_custom_nodes():
...
@@ -1459,4 +1459,5 @@ def init_custom_nodes():
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_post_processing.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_post_processing.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_mask.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_mask.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_rebatch.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_rebatch.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_model_merging.py"
))
load_custom_nodes
()
load_custom_nodes
()
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