0Pricing
Deep Learning Academy · Lesson

Call backward() to Get Gradients

Fill .grad with one line.

One Line to Differentiate

Once your graph is built, a single call does all the calculus. Run backward() on your output and gradients flow back to every input.

Start From a Scalar

You call backward on the final number you want to minimize, usually the loss. It must be a single scalar so autograd knows where to start.

y = x ** 2
y.backward()

All lessons in this course

  1. requires_grad and the Computation Graph
  2. Call backward() to Get Gradients
  3. Reading and Zeroing .grad
  4. torch.no_grad() for Inference
← Back to Deep Learning Academy