Chapter 7
Computation Graphs and Automatic Differentiation
Computation graphs, forward values, local derivatives, gradient accumulation, finite-difference checks, and autodiff modes.
- Subject
- Deep Learning
- Lessons
- 8 lessons
- Practice
- 22 checks
- Review
- 3 pages
Introduction
Training needs gradients. A gradient tells how a small change in a value would change the loss.
Automatic differentiation, or autodiff, is the machinery that computes those gradients from the computation the model actually performed.
It is not symbolic algebra. It is not numerical guessing. It is organized chain rule applied to a recorded computation.
A computation graph records how forward values were produced, so derivatives can follow the same dependencies backward.
This chapter explains what must be recorded before gradients can be computed:
- the operations;
- the forward values;
- the local derivatives;
- how gradients accumulate;
- where gradient flow can be stopped;
- how finite differences can check a gradient;
- why reverse mode is useful for neural networks.
No framework is needed yet. The examples are scalar and hand-computable.
You are ready when
- Trace a small computation graph.
- Compute local derivatives and chain-rule products.
- Explain gradient accumulation and stop-gradient.
- Distinguish autodiff from symbolic differentiation and finite differences.
Where this leads
- Backpropagation Through Networks
- Training Loops and Optimizers
- PyTorch as Compression