mindspore.Tensor.to_

View Source On Gitee
Tensor.to_(device=None, non_blocking=False)[source]

In-place version of mindspore.Tensor.to(), converts the device of the original tensor to the specified device and returns the tensor.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • device (str, optional) – Specifies the hardware device where the output tensor is located. Default: None.

  • non_blocking (bool, optional) – Whether to perform asynchronous data conversion. If True, the data conversion is asynchronous; if False, the data conversion is synchronous. Default: False.

Returns

Tensor, the modified self itself, which is stored on the specified device.

Examples

>>> import mindspore as ms
>>> x = ms.Tensor([1, 2, 3, 4])
>>> x.to_(device="Ascend", non_blocking=True)
>>> print(x.device)
"Ascend:0"