Skip to content

Commit

Permalink
Fix incorrect tensor storage check (#86845)
Browse files Browse the repository at this point in the history
Fix incorrect tensor storage check

This change contains an incorrect check for storage: #86557
**self.storage is not None**
should have been:
**not torch._C._has_storage(self)**

These fixes were run through the DirectML test suite, and confirm the check is now working correctly.
Pull Request resolved: #86845
Approved by: https://github.com/martinb35, https://github.com/bdhirsh
  • Loading branch information
smk2007 authored and pytorchmergebot committed Oct 13, 2022
1 parent afc9963 commit 4839f73
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions torch/_tensor.py
Expand Up @@ -112,11 +112,13 @@ def __deepcopy__(self, memo):
# doesn't work because of
# https://github.com/pytorch/pytorch/issues/47442
# Update the test in test_serialization if you remove 'meta' from here

if (
self.is_sparse
or self.device.type in ["lazy", "xla", "mps", "ort", "meta", "hpu"]
or (self.storage is None and self.device.type == "privateuseone")
or (
not torch._C._has_storage(self)
and self.device.type == "privateuseone"
)
or (type(self) is not Tensor and self.data_ptr() == 0)
):
new_tensor = self.clone()
Expand Down Expand Up @@ -273,7 +275,7 @@ def _reduce_ex_internal(self, proto):
# `tolist()` converts every single element in the tensor into python objects
# and serialize them one by one.
if self.device.type in ["xla", "ort", "hpu"] or (
self.storage is None and self.device.type == "privateuseone"
not torch._C._has_storage(self) and self.device.type == "privateuseone"
):
# Convert BFloat16 tesors to Float32 before conversion to numpy, as numpy doesn't
# support BFloat16. The rebuild tensor from numpy takes in the original self.dtype,
Expand Down

0 comments on commit 4839f73

Please sign in to comment.