Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.from_dlpack function

PyTorch torch.from_dlpack function


PyTorch torch reference manual 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

)

print

(

y.

shape

)


PyTorch torch reference manual PyTorch torch reference manual