Strides are corrupted after to_dlpack / from_dlpack

Using PyTorch 2.0, I’m seeing weird behavior from to_dlpack / from_dlpack:

In [56]: from torch.utils.dlpack import to_dlpack, from_dlpack

In [57]:  a = torch.randint(0, 100, (1, 77), dtype=torch.int32)

In [58]:  b = from_dlpack(to_dlpack(a))

In [59]:  a.stride()
Out[59]: (77, 1)

In [60]: b.stride()
Out[60]: (1, 1)  # ???

According to A PyTorch and TVM version incompatibility problem while using from_dlpack and to_dlpack - Troubleshooting - Apache TVM Discuss, the problem can be fixed by downgrading to PT 1.12.

Is this a bug?

Could you create an issue on GitHub so that code owners could take a look at it, please?

Done [DLPACK] Strides are corrupted after `from_dlpack` / `to_dlpack` · Issue #99803 · pytorch/pytorch · GitHub

1 Like