PyTorch torch.from_dlpack function
PyTorch torch reference manual
torch.from_dlpack A function in PyTorch for creating a PyTorch tensor from a dlpack tensor.
Function definition
torch.from_dlpack(ext_tensor)
Usage examples
Example
import
torch
Creating tensors
x
=
torch.
randn
(
3
,
4
)
Get the dlpack capsule
dlpack
=
x.
toDlpack
(
)
Create a new tensor from dlpack
y
=
torch.
from_dlpack
(
dlpack
)
(
y.
shape
)