Preserve coalesce state in sparse COO tensor serialization (#102647)

Fixes #101186

Also, resolves the "serialization to preserve coalesced-ness" part in https://github.com/pytorch/pytorch/issues/73479

Pull Request resolved: https://github.com/pytorch/pytorch/pull/102647
Approved by: https://github.com/mikaylagawarecki
This commit is contained in:
Pearu Peterson
2023-06-02 23:31:01 +03:00
committed by PyTorch MergeBot
parent ec4a107f87
commit 39b04370db
3 changed files with 10 additions and 3 deletions

View File

@ -316,7 +316,7 @@ class SerializationMixin:
torch.save({"tensor": x}, f)
f.seek(0)
y = torch.load(f, weights_only=weights_only)
self.assertEqual(x, y["tensor"])
self.assertEqual(x, y["tensor"], exact_is_coalesced=True)
_test_serialization(lambda x: x.to_sparse())
_test_serialization(lambda x: x.to_sparse_csr())
_test_serialization(lambda x: x.to_sparse_csc())