Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Passing the blame backwards
A factory has a line of machines. Each one takes the previous machine’s output and changes it. At the end, the product is wrong by some amount. Who should adjust, and by how much? Start at the end and walk backwards. Each machine knows how its output depends on its input, so it can pass back a share of the blame to the machine before it.
This backward blame-passing is backpropagation. It’s how every neural network learns.
A robot’s control policy might be a network with millions of adjustable numbers. Backpropagation computes how every one of them affects the robot’s mistake, in about the time it takes to run the network twice. Without it, modern AI training would be impossible.
- 1. Backpropagation passes blame…
- 2. Three machines in a row each double their input. The overall effect of the first input?
- 3. If one machine feeds two others, its blame is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.A computation graph
Every formula is a graph of simple operations. For : , then .
Forward pass (, , ): , .
Backward pass (start with ):
- : and .
- : addition passes the gradient through unchanged, so .
Each node only needs its local derivative and the gradient arriving from its output.
- 1. f = (x + y)z with x = 2, y = 3, z = 4. ∂f/∂z = ?
- 2. An addition node passes the gradient…
- 3. A multiplication node u = a·b sends ∂L/∂u times ___ to a.
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.The algorithm
- Forward: evaluate the nodes in topological order and store every intermediate value.
- Backward: set . In reverse topological order, for each node and each input , accumulate .
Here is called the adjoint. The matters: gradients add where a value is used more than once (the multivariable chain rule, A3.2-4).
| Node | Local rule for |
|---|---|
| , | |
| , | |
| , | |
| softmax-CE | (A3.3-4) |
Costs: the backward pass takes about 1–3× the forward cost, and memory grows with the number of stored activations.
- 1. f = x·x + 3x at x = 4: ∂f/∂x = ?
- 2. Backward order is…
- 3. The ReLU gradient for a negative input is…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Why it’s correct
Claim: after processing node ’s consumers, .
Proof by induction in reverse topological order. It holds for , since . For any , the variable depends on only through its consumers . By the multivariable chain rule, , which is exactly what the accumulations compute. ∎
Why reverse order is the efficient one
For , forward accumulation needs passes, one per input direction. Reverse accumulation gets all partials in one backward pass. Its cost is a constant multiple of evaluating , independent of (the “cheap gradient principle”; Griewank and Walther, 2008). With one scalar loss and millions of parameters, that’s the difference between feasible and impossible (Practice Code 4).
Vanishing and exploding gradients, again
Backprop multiplies local Jacobians along each path: . If their norms are typically , early adjoints vanish exponentially. If , they explode (A3.1-3). Recurrent networks suffer this over time steps (Practice Code 5). LSTMs, residual connections, normalization and careful initialization are the cures.
Exercise 3.1: For L = (ab + c)² + 2c, compute ∂L/∂c at a = 2, b = −1, c = 3
. Path 1, through : . Path 2, through : . Total: . This is the demo’s default setting.
- 1. Backprop's correctness rests on…
- 2. Forward-mode passes needed for the full gradient of f: ℝ¹⁰⁰⁰ → ℝ?
- 3. Reverse-mode passes needed for the same?
Level 4: Expert
★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.Memory: gradient checkpointing
Storing every activation of a 100-layer network, or a long robot trajectory, can exhaust GPU memory. Checkpointing stores only every -th activation and recomputes each segment during the backward pass. With , memory falls from to for one extra forward pass (Griewank, 1992; Chen et al., 2016). It’s standard in large-model training (torch.utils.checkpoint).
Backprop beyond neural networks
- Backpropagation through time (Werbos, 1990) unrolls recurrent networks and sequence models. Truncated BPTT limits the horizon to control memory and exploding gradients.
- Differentiable simulation and control. Backprop through physics simulators (Brax, Warp, MuJoCo MJX) gives exact policy and trajectory gradients for robots (Degrave et al., 2019; Hu et al., 2020, DiffTaichi). The adjoint method does the same through ODE solvers with constant memory (Chen et al., 2018, Neural ODEs). Long horizons bring chaotic, exploding gradients, an active research topic (Suh et al., 2022).
- The adjoint method in engineering. Aerodynamic shape optimization of wings and rocket nozzles has used reverse-mode “adjoint” sensitivities since the 1980s (Jameson, 1988). It is the same mathematics as backprop, discovered independently.
- Frameworks. PyTorch builds the graph dynamically during the forward pass (“define-by-run”). JAX traces functions into graphs and offers
grad,vjpandjvpas composable transformations (A3.3-6).
References
- S. Linnainmaa (1970). MSc thesis, University of Helsinki. (Reverse-mode automatic differentiation.)
- D. Rumelhart, G. Hinton, R. Williams (1986). “Learning representations by back-propagating errors.” Nature, 323.
- P. Werbos (1990). “Backpropagation through time: what it does and how to do it.” Proceedings of the IEEE, 78(10).
- A. Griewank (1992). “Achieving logarithmic growth of temporal and spatial complexity in reverse automatic differentiation.” Optimization Methods and Software, 1.
- T. Chen, B. Xu, C. Zhang, C. Guestrin (2016). “Training deep nets with sublinear memory cost.” arXiv:1604.06174.
- A. Griewank, A. Walther (2008). Evaluating Derivatives, 2nd ed. SIAM.
- R. T. Q. Chen, Y. Rubanova, J. Bettencourt, D. Duvenaud (2018). “Neural ordinary differential equations.” NeurIPS.
- H. J. T. Suh, M. Simchowitz, K. Zhang, R. Tedrake (2022). “Do differentiable simulators give better policy gradients?” ICML.
- A. Paszke et al. (2019). “PyTorch: An imperative style, high-performance deep learning library.” NeurIPS.