Usually you don’t care about the gradients in the input tensor or the target, so for most use cases you don’t need to set requires_grad=True for these tensors.


nn.Module.__call__ is called, registers some hooks and calls forward as seen here 1.


Don’t use the .data attribute, as it might yield unwanted side effects. The item() call returns a Python literal, e.g. which can be used easily for logging purposes.