5,323
edits
(→Usage) |
(→Memory) |
||
Line 75: | Line 75: | ||
* For non-scalar items, use <code>my_var.detach().cpu().numpy()</code> | * For non-scalar items, use <code>my_var.detach().cpu().numpy()</code> | ||
* [https://pytorch.org/docs/stable/autograd.html#torch.Tensor.detach <code>detach()</code> ] | * [https://pytorch.org/docs/stable/autograd.html#torch.Tensor.detach <code>detach()</code>] removes the item from the autograd edge. | ||
* [https://pytorch.org/docs/stable/tensors.html?highlight=cpu#torch.Tensor.cpu <code>cpu()</code>] moves the tensor to the CPU. | * [https://pytorch.org/docs/stable/tensors.html?highlight=cpu#torch.Tensor.cpu <code>cpu()</code>] moves the tensor to the CPU. | ||
* [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.numpy <code>numpy()</code>] returns a numpy view of the tensor. | * [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.numpy <code>numpy()</code>] returns a numpy view of the tensor. |