1
mirror of https://github.com/comfyanonymous/ComfyUI.git synced 2025-08-02 23:14:49 +08:00

utils.set_attr can now be used to set any attribute.

The old set_attr has been renamed to set_attr_param.
This commit is contained in:
comfyanonymous
2024-03-02 17:27:23 -05:00
parent dce3555339
commit 1abf8374ec
3 changed files with 10 additions and 8 deletions

View File

@@ -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