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
37a08a41
Commit
37a08a41
authored
Jun 13, 2024
by
comfyanonymous
Browse files
Support setting weight offsets in weight patcher.
parent
605e64f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
comfy/model_patcher.py
comfy/model_patcher.py
+20
-4
No files found.
comfy/model_patcher.py
View file @
37a08a41
...
...
@@ -209,11 +209,18 @@ class ModelPatcher:
p
=
set
()
model_sd
=
self
.
model
.
state_dict
()
for
k
in
patches
:
if
k
in
model_sd
:
offset
=
None
if
isinstance
(
k
,
str
):
key
=
k
else
:
offset
=
k
[
1
]
key
=
k
[
0
]
if
key
in
model_sd
:
p
.
add
(
k
)
current_patches
=
self
.
patches
.
get
(
k
,
[])
current_patches
.
append
((
strength_patch
,
patches
[
k
],
strength_model
))
self
.
patches
[
k
]
=
current_patches
current_patches
=
self
.
patches
.
get
(
k
ey
,
[])
current_patches
.
append
((
strength_patch
,
patches
[
k
],
strength_model
,
offset
))
self
.
patches
[
k
ey
]
=
current_patches
self
.
patches_uuid
=
uuid
.
uuid4
()
return
list
(
p
)
...
...
@@ -339,6 +346,12 @@ class ModelPatcher:
strength
=
p
[
0
]
v
=
p
[
1
]
strength_model
=
p
[
2
]
offset
=
p
[
3
]
old_weight
=
None
if
offset
is
not
None
:
old_weight
=
weight
weight
=
weight
.
narrow
(
offset
[
0
],
offset
[
1
],
offset
[
2
])
if
strength_model
!=
1.0
:
weight
*=
strength_model
...
...
@@ -488,6 +501,9 @@ class ModelPatcher:
else
:
logging
.
warning
(
"patch type not recognized {} {}"
.
format
(
patch_type
,
key
))
if
old_weight
is
not
None
:
weight
=
old_weight
return
weight
def
unpatch_model
(
self
,
device_to
=
None
,
unpatch_weights
=
True
):
...
...
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