Jump to content

PyTorch: Difference between revisions

4 bytes added ,  22 February 2021
Line 72: Line 72:


==Optimizations==
==Optimizations==
===Reducing memory usage===
===Reducing GPU memory usage===
* Save loss using [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.item <code>.item()</code>] which returns a standard Python number
* Save loss using [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.item <code>.item()</code>] which returns a standard Python number
* For non-scalar items, use <code>my_var.detach().cpu().numpy()</code>
* For non-scalar items, use <code>my_var.detach().cpu().numpy()</code>