Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deepcopy for tensor with MTIA device key. #107427

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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