Skip to content

Commit

Permalink
Handle Tensor.__deepcopy__ via clone(), on IPU (#89129)
Browse files Browse the repository at this point in the history
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](#86557)) doesn't discuss whether this could be broadened.
Pull Request resolved: #89129
Approved by: https://github.com/albanD
  • Loading branch information
charlie-wt authored and pytorchmergebot committed Dec 6, 2022
1 parent 029ec16 commit 1e0e36c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion torch/_tensor.py
Expand Up @@ -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"
Expand Down

0 comments on commit 1e0e36c

Please sign in to comment.