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

Method test_serialization_offset

test/test_serialization.py:857–879  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

855 self._test_serialization_container('filelike', BytesIOContext)
856
857 def test_serialization_offset(self):
858 a = torch.randn(5, 5)
859 b = torch.randn(1024, 1024, 512, dtype=torch.float32)
860 m = torch.nn.Conv2d(1, 1, (1, 3))
861 i, j = 41, 43
862 with tempfile.NamedTemporaryFile() as f:
863 pickle.dump(i, f)
864 torch.save(a, f)
865 pickle.dump(j, f)
866 torch.save(b, f)
867 torch.save(m, f)
868 self.assertTrue(f.tell() > 2 * 1024 * 1024 * 1024)
869 f.seek(0)
870 i_loaded = pickle.load(f)
871 a_loaded = torch.load(f)
872 j_loaded = pickle.load(f)
873 b_loaded = torch.load(f)
874 m_loaded = torch.load(f)
875 self.assertTrue(torch.equal(a, a_loaded))
876 self.assertTrue(torch.equal(b, b_loaded))
877 self.assertTrue(m.kernel_size == m_loaded.kernel_size)
878 self.assertEqual(i, i_loaded)
879 self.assertEqual(j, j_loaded)
880
881 @parametrize('weights_only', (True, False))
882 def test_serialization_offset_filelike(self, weights_only):

Callers

nothing calls this directly

Calls 7

tellMethod · 0.80
seekMethod · 0.80
randnMethod · 0.45
dumpMethod · 0.45
saveMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected