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
1abf8374
Commit
1abf8374
authored
Mar 02, 2024
by
comfyanonymous
Browse files
utils.set_attr can now be used to set any attribute.
The old set_attr has been renamed to set_attr_param.
parent
dce35553
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
comfy/controlnet.py
comfy/controlnet.py
+2
-2
comfy/model_patcher.py
comfy/model_patcher.py
+3
-4
comfy/utils.py
comfy/utils.py
+5
-2
No files found.
comfy/controlnet.py
View file @
1abf8374
...
...
@@ -287,13 +287,13 @@ class ControlLora(ControlNet):
for
k
in
sd
:
weight
=
sd
[
k
]
try
:
comfy
.
utils
.
set_attr
(
self
.
control_model
,
k
,
weight
)
comfy
.
utils
.
set_attr
_param
(
self
.
control_model
,
k
,
weight
)
except
:
pass
for
k
in
self
.
control_weights
:
if
k
not
in
{
"lora_controlnet"
}:
comfy
.
utils
.
set_attr
(
self
.
control_model
,
k
,
self
.
control_weights
[
k
].
to
(
dtype
).
to
(
comfy
.
model_management
.
get_torch_device
()))
comfy
.
utils
.
set_attr
_param
(
self
.
control_model
,
k
,
self
.
control_weights
[
k
].
to
(
dtype
).
to
(
comfy
.
model_management
.
get_torch_device
()))
def
copy
(
self
):
c
=
ControlLora
(
self
.
control_weights
,
global_average_pooling
=
self
.
global_average_pooling
)
...
...
comfy/model_patcher.py
View file @
1abf8374
...
...
@@ -176,10 +176,9 @@ class ModelPatcher:
def
patch_model
(
self
,
device_to
=
None
,
patch_weights
=
True
):
for
k
in
self
.
object_patches
:
old
=
comfy
.
utils
.
g
et_attr
(
self
.
model
,
k
)
old
=
comfy
.
utils
.
s
et_attr
(
self
.
model
,
k
,
self
.
object_patches
[
k
]
)
if
k
not
in
self
.
object_patches_backup
:
self
.
object_patches_backup
[
k
]
=
old
comfy
.
utils
.
set_attr
(
self
.
model
,
k
,
self
.
object_patches
[
k
])
if
patch_weights
:
model_sd
=
self
.
model_state_dict
()
...
...
@@ -203,7 +202,7 @@ class ModelPatcher:
if
inplace_update
:
comfy
.
utils
.
copy_to_param
(
self
.
model
,
key
,
out_weight
)
else
:
comfy
.
utils
.
set_attr
(
self
.
model
,
key
,
out_weight
)
comfy
.
utils
.
set_attr
_param
(
self
.
model
,
key
,
out_weight
)
del
temp_weight
if
device_to
is
not
None
:
...
...
@@ -342,7 +341,7 @@ class ModelPatcher:
comfy
.
utils
.
copy_to_param
(
self
.
model
,
k
,
self
.
backup
[
k
])
else
:
for
k
in
keys
:
comfy
.
utils
.
set_attr
(
self
.
model
,
k
,
self
.
backup
[
k
])
comfy
.
utils
.
set_attr
_param
(
self
.
model
,
k
,
self
.
backup
[
k
])
self
.
backup
=
{}
...
...
comfy/utils.py
View file @
1abf8374
...
...
@@ -294,8 +294,11 @@ def set_attr(obj, attr, value):
for
name
in
attrs
[:
-
1
]:
obj
=
getattr
(
obj
,
name
)
prev
=
getattr
(
obj
,
attrs
[
-
1
])
setattr
(
obj
,
attrs
[
-
1
],
torch
.
nn
.
Parameter
(
value
,
requires_grad
=
False
))
del
prev
setattr
(
obj
,
attrs
[
-
1
],
value
)
return
prev
def
set_attr_param
(
obj
,
attr
,
value
):
return
set_attr
(
obj
,
attr
,
torch
.
nn
.
Parameter
(
value
,
requires_grad
=
False
))
def
copy_to_param
(
obj
,
attr
,
value
):
# inplace update tensor instead of replacing it
...
...
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