PyTorch torch.from_dlpack Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.from_dlpackIt is a function in PyTorch used to create a PyTorch tensor from a dlpack tensor.

Function Definition

torch.from_dlpack(ext_tensor)

Usage Example

Example

import torch

# Create tensor
x = torch.randn(3, 4)

# Get dlpack capsule
dlpack = x.toDlpack()

# Create a new tensor from dlpack
y = torch.from_dlpack(dlpack)

print(y.shape)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions