Skip to content

Commit f5fbb50

Browse files
Revert "[follow-up] Python Attr Serialization (#88913)"
This reverts commit 086b251. Reverted #88913 on behalf of https://github.com/facebook-github-bot due to Diff reverted internally
1 parent 78bdb85 commit f5fbb50

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

test/test_serialization.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,11 @@ def _test_save_load_attr(t):
948948

949949
t = torch.zeros(3, 3)
950950
_test_save_load_attr(t)
951-
_test_save_load_attr(torch.nn.Parameter(t))
951+
# This should start failing once Parameter
952+
# supports saving Python Attribute.
953+
err_msg = "'Parameter' object has no attribute"
954+
with self.assertRaisesRegex(AttributeError, err_msg):
955+
_test_save_load_attr(torch.nn.Parameter(t))
952956

953957
def test_weights_only_assert(self):
954958
class HelloWorld:

torch/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ def _rebuild_parameter(data, requires_grad, backward_hooks):
352352
return param
353353

354354

355+
# TODO(kshitij12345): Support serializing nn.Parameter with Python Attributes.
356+
# NOTE: We are just defining it here now for future use.
355357
def _rebuild_parameter_with_state(data, requires_grad, backward_hooks, state):
356358
param = torch.nn.Parameter(data, requires_grad)
357359
# NB: This line exists only for backwards compatibility; the

torch/nn/parameter.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,11 @@ def __repr__(self):
6060
return 'Parameter containing:\n' + super(Parameter, self).__repr__()
6161

6262
def __reduce_ex__(self, proto):
63-
state = torch._utils._get_obj_state(self)
64-
63+
# TODO(kshitij12345): Support saving Python Attribute
6564
# See Note [Don't serialize hooks]
66-
hooks = OrderedDict()
67-
if not state:
68-
return (
69-
torch._utils._rebuild_parameter,
70-
(self.data, self.requires_grad, hooks)
71-
)
72-
7365
return (
74-
torch._utils._rebuild_parameter_with_state,
75-
(self.data, self.requires_grad, hooks, state)
66+
torch._utils._rebuild_parameter,
67+
(self.data, self.requires_grad, OrderedDict())
7668
)
7769

7870
__torch_function__ = _disabled_torch_function_impl

0 commit comments

Comments
 (0)