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
8125b51a
"doc/vscode:/vscode.git/clone" did not exist on "b94c88a9267ccbd514a1b32bba20b9f3eff4cefe"
Commit
8125b51a
authored
Jun 20, 2023
by
comfyanonymous
Browse files
Keep a set of model_keys for faster add_patches.
parent
45beebd3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
comfy/sd.py
comfy/sd.py
+4
-3
No files found.
comfy/sd.py
View file @
8125b51a
...
...
@@ -302,12 +302,14 @@ class ModelPatcher:
t
=
model_sd
[
k
]
size
+=
t
.
nelement
()
*
t
.
element_size
()
self
.
size
=
size
self
.
model_keys
=
set
(
model_sd
.
keys
())
return
size
def
clone
(
self
):
n
=
ModelPatcher
(
self
.
model
,
self
.
size
)
n
.
patches
=
self
.
patches
[:]
n
.
model_options
=
copy
.
deepcopy
(
self
.
model_options
)
n
.
model_keys
=
self
.
model_keys
return
n
def
set_model_tomesd
(
self
,
ratio
):
...
...
@@ -349,9 +351,8 @@ class ModelPatcher:
def
add_patches
(
self
,
patches
,
strength_patch
=
1.0
,
strength_model
=
1.0
):
p
=
{}
model_sd
=
self
.
model
.
state_dict
()
for
k
in
patches
:
if
k
in
model_s
d
:
if
k
in
self
.
model_
key
s
:
p
[
k
]
=
patches
[
k
]
self
.
patches
+=
[(
strength_patch
,
p
,
strength_model
)]
return
p
.
keys
()
...
...
@@ -365,7 +366,7 @@ class ModelPatcher:
return
sd
def
patch_model
(
self
):
model_sd
=
self
.
model
.
state_dict
()
model_sd
=
self
.
model
_
state_dict
()
for
p
in
self
.
patches
:
for
k
in
p
[
1
]:
v
=
p
[
1
][
k
]
...
...
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