mindspore.Tensor.delete_
- mindspore.Tensor.delete_(non_blocking=False)[源代码]
主动释放tensor在 device 或 host 侧的内存。
警告
这是一个实验性API,后续可能修改或删除。
- 参数:
non_blocking (bool, 可选) - 内存异步释放。如果是
True,内存异步释放。如果是False,内存同步释放。默认值:False。
- 返回:
Tensor,返回被修改后的 self 自身,其数据内存已被释放。
样例:
>>> import mindspore as ms >>> x = ms.Tensor([1, 2, 3, 4]) >>> y = x.to(device="Ascend", non_blocking=True) >>> x.delete_(non_blocking=True) Tensor(shape=[4], dtype=Int64, value= [0, 0, 0, 0]) >>> x.data = y >>> print(x.device) "Ascend:0"