提交 1d2510b6 编写于 作者: M Megvii Engine Team

fix(module): fix module dumped in old version without _short_name attr

GitOrigin-RevId: a1c815f613b34ddf7e4a4a2aeec41f353bdfb679
上级 cf5e9488
...@@ -138,7 +138,11 @@ class Module(metaclass=ABCMeta): ...@@ -138,7 +138,11 @@ class Module(metaclass=ABCMeta):
return HookHandler(self._forward_hooks, hook) return HookHandler(self._forward_hooks, hook)
def __call__(self, *inputs, **kwargs): def __call__(self, *inputs, **kwargs):
AutoNaming.push_scope(self.name if self.name is not None else self._short_name) AutoNaming.push_scope(
self.name
if self.name is not None
else (self._short_name if hasattr(self, "_short_name") else self._name)
)
for hook in self._forward_pre_hooks.values(): for hook in self._forward_pre_hooks.values():
modified_inputs = hook(self, inputs) modified_inputs = hook(self, inputs)
if modified_inputs is not None: if modified_inputs is not None:
......
...@@ -222,7 +222,7 @@ class _ModuleList(Module, MutableSequence): ...@@ -222,7 +222,7 @@ class _ModuleList(Module, MutableSequence):
def __setattr__(self, key, value): def __setattr__(self, key, value):
# clear mod name to avoid warning in Module's setattr # clear mod name to avoid warning in Module's setattr
if isinstance(value, Module): if isinstance(value, Module):
value._name = None value._short_name = None
super().__setattr__(key, value) super().__setattr__(key, value)
def __setitem__(self, idx: int, mod: Module): def __setitem__(self, idx: int, mod: Module):
...@@ -291,7 +291,7 @@ class _ModuleDict(Module, MutableMapping): ...@@ -291,7 +291,7 @@ class _ModuleDict(Module, MutableMapping):
def __setattr__(self, key, value): def __setattr__(self, key, value):
# clear mod name to avoid warning in Module's setattr # clear mod name to avoid warning in Module's setattr
if isinstance(value, Module): if isinstance(value, Module):
value._name = None value._short_name = None
super().__setattr__(key, value) super().__setattr__(key, value)
def __setitem__(self, key, value): def __setitem__(self, key, value):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册