← PyTorch learning path
PyTorch · Module 3 of 10

Autograd

Compute gradients automatically for training.

📖 Key ideas

  1. requires_grad=True tracks operations on a tensor.
  2. loss.backward() computes gradients.
  3. Gradients are stored in .grad.
  4. Use torch.no_grad() during inference to save memory.
  5. 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