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
- requires_grad and the Computation Graph
- Call backward() to Get Gradients
- Reading and Zeroing .grad
- torch.no_grad() for Inference