← PyTorch learning pathPyTorch · Module 3 of 10
Autograd
Compute gradients automatically for training.
📖 Key ideas
- requires_grad=True tracks operations on a tensor.
- loss.backward() computes gradients.
- Gradients are stored in .grad.
- Use torch.no_grad() during inference to save memory.
- Zero gradients each step: optimizer.zero_grad().
💡 Real-life example: Autograd is a diary recording every calculation, so it can retrace steps to find blame (gradients).
AutogradAutomatic differentiation engine
backward()Computes gradients
.gradStored gradient
no_grad()Disables gradient tracking