-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Description
🐛 Describe the bug
When converting a tensor to dlpack, the strides of single-value tensors (t.shape==(1,)) should be normalized to (1,). This is the fallout conclusion from #82610.
Here is a demo of what is wrong:
>>> from torch.utils import dlpack
>>> a = torch.rand(16)
>>> b = a[::3]
>>> c = b[:1]
>>> c.shape
torch.Size([1])
>>> c.stride()
(3,) # <- shape is (1,), strides is not (1,)
>>> capsule = dlpack.to_dlpack(c)
>>> d = dlpack.from_dlpack(capsule)
>>> d.shape
torch.Size([1])
>>> d.stride()
(3,) # <- the weird strides is still here. It should be (1,)
Versions
Collecting environment information...
PyTorch version: 1.10.0a0+git2aa19f3
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (GCC) 9.4.0
Clang version: 12.0.1 (https://github.com/conda-forge/clangdev-feedstock 83cefdc6bfd937aa14138cf601945c6d9fc9a490)
CMake version: version 3.21.1
Libc version: glibc-2.31
Python version: 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:39:48) [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-122-generic-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: 11.2.152
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1660 SUPER
Nvidia driver version: 470.141.03
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: False
Versions of relevant libraries:
[pip3] mypy==0.812
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.2
[pip3] torch==1.10.0a0+git2aa19f3
[pip3] torchaudio==0.10.0a0+8a347b6
[conda] magma-cuda112 2.5.2 1 pytorch
[conda] mkl 2021.3.0 h726a3e6_557 conda-forge
[conda] mkl-include 2021.3.0 h726a3e6_557 conda-forge
[conda] numpy 1.21.2 py39hdbf815f_0 conda-forge
[conda] torch 1.12.0a0+git1f29b31 dev_0
[conda] torchaudio 0.10.0a0+8a347b6 pypi_0 pypi