# torch.utils.dlpack¶

torch.utils.dlpack.from_dlpack(ext_tensor)Tensor[source]

Convers a tensor from a external library into a torch.Tensor by means of the __dlpack__ protocol.

The tensor will share the memory with the object represented in the DLPack.

Warning

Only call from_dlpack once per capsule. Its behavior when used on the same capsule multiple times is undefined.

Parameters

ext_tensor (object with __dlpack__ attribute or DLPack capsule) – The tensor or DLPack capsule to convert.

torch.utils.dlpack.to_dlpack(tensor)PyCapsule

Returns a DLPack representing the tensor.

Parameters

tensor – a tensor to be exported

The DLPack shares the tensors memory. Note that each DLPack can only be consumed once.