Make hash_storage work with size 0/1 storage (#100467)

Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/100467
Approved by: https://github.com/Skylion007, https://github.com/voznesenskym
This commit is contained in:
Edward Z. Yang
2023-05-02 11:41:58 -07:00
committed by PyTorch MergeBot
parent 4b9ba3fad5
commit 409fc7a4c7
2 changed files with 9 additions and 2 deletions

View File

@ -6,7 +6,11 @@ import torch
from torch.multiprocessing.reductions import StorageWeakRef
from torch.testing._internal.common_device_type import instantiate_device_type_tests
from torch.testing._internal.common_utils import run_tests, TestCase
from torch.utils._content_store import ContentStoreReader, ContentStoreWriter
from torch.utils._content_store import (
ContentStoreReader,
ContentStoreWriter,
hash_storage,
)
class TestContentStore(TestCase):
@ -50,6 +54,10 @@ class TestContentStore(TestCase):
StorageWeakRef(n_y.untyped_storage()),
)
def test_scalar(self, device):
# Should not raise an error
hash_storage(torch.tensor(2, device=device).untyped_storage())
instantiate_device_type_tests(TestContentStore, globals())

View File

@ -120,7 +120,6 @@ def hash_storage(storage: torch.UntypedStorage, *, stable_hash: bool = False) ->
if pad > 0:
x = F.pad(x, (0, pad), "constant", 0)
x = x.view(torch.int32)
torch._dynamo.mark_dynamic(x, 0)
# We run the 32-bit hash five times with differing parameters to
# reduce chance of collision
ITER = 5