Fix missing attribute when loading model from older version (#42242) (#42290)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/42242
Pull Request resolved: https://github.com/pytorch/pytorch/pull/42290
Reviewed By: VitalyFedyunin
Differential Revision: D22844096
Pulled By: albanD
fbshipit-source-id: 707e552e0ed581fbe00f1527ab7426880edaed64
diff --git a/torch/nn/modules/module.py b/torch/nn/modules/module.py
index 5899ec0..934cbd4 100644
--- a/torch/nn/modules/module.py
+++ b/torch/nn/modules/module.py
@@ -758,6 +758,8 @@
self._state_dict_hooks = OrderedDict()
if '_load_state_dict_pre_hooks' not in self.__dict__:
self._load_state_dict_pre_hooks = OrderedDict()
+ if '_non_persistent_buffers_set' not in self.__dict__:
+ self._non_persistent_buffers_set = set()
def __getattr__(self, name: str) -> Union[Tensor, 'Module']:
if '_parameters' in self.__dict__: