pick up preivously set attributes (#905)

This commit is contained in:
Awni Hannun
2024-03-26 11:19:59 -07:00
committed by GitHub
parent 9948eddf11
commit 570f2bf29e
2 changed files with 20 additions and 0 deletions

View File

@@ -138,6 +138,11 @@ class Module(dict):
def __setattr__(self, key: str, val: Any):
if isinstance(val, (mx.array, dict, list, tuple)):
# If attribute was previously set but not in the
# dictionary, delete it so we pick it up in future
# calls to __getattr__
if hasattr(self, key) and key not in self:
delattr(self, key)
self[key] = val
else:
super(Module, self).__setattr__(key, val)