From 80abad3e7460415efe480ab21c1d5c90fc345a27 Mon Sep 17 00:00:00 2001 From: charlie-wt Date: Wed, 7 Dec 2022 12:46:26 +0000 Subject: [PATCH] Handle Tensor.__deepcopy__ via clone(), on IPU (#89129) (#89999) Currently it falls through to a call to `storage()`, which the IPU doesn't support. I've made the minimal change here for ease of merging (this'd help us if it was in for 1.13.1), however... **QUESTION**: Is there any reason why `not torch._C._has_storage(self)` needs to *also* be guarded on `self.device.type == privateuseone`? in other words, could the condition for using `clone` not be this? ```python self.is_sparse or self.device.type in ["lazy", "xla", "mps", "ort", "meta", "hpu", "ipu"] or not torch._C._has_storage(self) or (type(self) is not Tensor and self.data_ptr() == 0) ``` If the condition fails, the very next thing is a call to `self._typed_storage()` which will fail, so it feels to me like *any* case without storage shouldn't fall through to the `storage()` call. The original PR for adding the 'no storage and device is `PrivateUse1`' condition ([86557](https://github.com/pytorch/pytorch/pull/86557)) doesn't discuss whether this could be broadened. Pull Request resolved: https://github.com/pytorch/pytorch/pull/89129 Approved by: https://github.com/albanD --- torch/_tensor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch/_tensor.py b/torch/_tensor.py index 8330fde58246cf6..fd3f338d514d0a7 100644 --- a/torch/_tensor.py +++ b/torch/_tensor.py @@ -113,7 +113,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", "hpu"] + or self.device.type + in ["lazy", "xla", "mps", "ort", "meta", "hpu", "ipu"] or ( not torch._C._has_storage(self) and self.device.type == "privateuseone"