from_dlpack¶
- paddle.utils.dlpack. from_dlpack ( dlpack ) [source]
-
Decodes a DLPack to a tensor.
- Parameters
-
dlpack (PyCapsule) – a PyCapsule object with the dltensor.
- Returns
-
- out (Tensor), a tensor decoded from DLPack. One thing to be noted, if we get
-
an input dltensor with data type as bool, we return the decoded tensor as uint8.
Examples
import paddle # x is a tensor with shape [2, 4] x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9], [0.1, 0.2, 0.6, 0.7]]) dlpack = paddle.utils.dlpack.to_dlpack(x) x = paddle.utils.dlpack.from_dlpack(dlpack) print(x) # Tensor(shape=[2, 4], dtype=float32, place=CUDAPlace(0), stop_gradient=True, # [[0.20000000, 0.30000001, 0.50000000, 0.89999998], # [0.10000000, 0.20000000, 0.60000002, 0.69999999]])