Skip to content

Commit

Permalink
Fix deepcopy for tensor with MTIA device key. (#107427)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #107427

Tensor with MTIA device type doesn't have storage and we need to treat it same as other tensors which don't have storage.

Test Plan: CI tests.

Differential Revision: D48456004

fbshipit-source-id: 941beb1ebd74ddcb338f109e9e030db9142d0ddb
  • Loading branch information
egienvalue authored and facebook-github-bot committed Aug 22, 2023
1 parent 2e05403 commit e5bb8bd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions torch/_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def __deepcopy__(self, memo):
# 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", "ipu"]
or self.device.type
in ["lazy", "xla", "mtia", "mps", "ort", "meta", "ipu"]
or (
not torch._C._has_storage(self)
and self.device.type == torch._C._get_privateuse1_backend_name()
Expand Down Expand Up @@ -248,7 +249,7 @@ def _reduce_ex_internal(self, proto):
# See Note [Don't serialize hooks]
torch.utils.hooks.warn_if_has_hooks(self)
backward_hooks: Dict[Any, Any] = OrderedDict()
# Note: Numpy array is chosen to be the rebuild component for XLA, ORT Tensors.
# Note: Numpy array is chosen to be the rebuild component for XLA, MTIA, ORT Tensors.
# We considered a few options:
# 1. CPU tensor can't be used here.
# Otherwise in torch.load CPU storage is reconstructed with randomly
Expand All @@ -258,7 +259,7 @@ def _reduce_ex_internal(self, proto):
# 2. Python list is not a good fit due to performance reason.
# `tolist()` converts every single element in the tensor into python objects
# and serialize them one by one.
if self.device.type in ["xla", "ort"] or (
if self.device.type in ["xla", "mtia", "ort"] or (
not torch._C._has_storage(self)
and self.device.type == torch._C._get_privateuse1_backend_name()
):
Expand Down

0 comments on commit e5bb8bd

Please sign in to comment.