MCPcopy Create free account
hub / github.com/pytorch/pytorch / test_serialization

Method test_serialization

test/test_subclass.py:77–91  ·  view source on GitHub ↗
(self, tensor_cls, as_param)

Source from the content-addressed store, hash-verified

75 @parametrize_tensor_cls
76 @parametrize("as_param", [False, True])
77 def test_serialization(self, tensor_cls, as_param):
78 with tempfile.TemporaryFile() as f:
79 x = self._create_tensor(tensor_cls)
80 if as_param:
81 x = nn.Parameter(x)
82 torch.save(x, f)
83 f.seek(0)
84 x_loaded = torch.load(f)
85
86 self.assertEqual(x, x_loaded)
87 self.assertIsNot(x, x_loaded)
88 self.assertIsInstance(x_loaded, tensor_cls)
89 if as_param:
90 # Serialization should preserve both custom type and "parameter-ness".
91 self.assertIsInstance(x_loaded, nn.Parameter)
92
93 @skipIfTorchDynamo("Visible only with functorch as functorch monkeypatches tensor str")
94 @parametrize_tensor_cls

Callers

nothing calls this directly

Calls 5

_create_tensorMethod · 0.95
seekMethod · 0.80
saveMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected