Foundations
Backpropagation, visualized
Backpropagation applies reverse-mode differentiation to a computational graph, reusing local derivatives to obtain every parameter gradient.
Updated
1
Concept
Backpropagation is an efficient application of the chain rule to a computational graph. It answers: for the scalar loss produced by this forward computation, how sensitive is the loss to every intermediate and parameter? It does not choose the loss, collect data, or update weights. Those are separate responsibilities.
Consider , , and . The forward pass evaluates these operations in order and saves values needed for derivatives. The graph has variables as nodes and operations as edges or operation nodes. For one input, it produces a numerical loss and a trace of how that loss was constructed.
The backward pass begins with . For the square, the local derivative is , producing . ReLU passes that gradient when and blocks it when . The affine operation then yields , , and .
The pattern is upstream gradient times local derivative. Each operation knows how its outputs change with its inputs. Reverse-mode automatic differentiation visits operations in reverse topological order, multiplying or applying vector-Jacobian products. It never needs to materialize an enormous full Jacobian for a scalar loss. This makes reverse mode especially efficient when there are many parameters and one objective.
Graphs can branch. If a value influences loss along two paths, its derivative is the sum of both contributions. This is why autodiff frameworks accumulate gradients. It is also why PyTorch parameter gradients accumulate across repeated backward calls unless cleared: summation is the mathematically correct default for multiple uses, while the training loop decides where batch boundaries lie.
Memory is a central trade-off. Backward often needs forward activations, so training stores them until their gradients are computed. Gradient checkpointing saves selected states and recomputes missing intermediates during backward, exchanging extra compute for lower activation memory. In-place mutation can destroy values the graph expects; frameworks detect some cases, but disciplined code avoids surprising aliasing.
Gradient checking validates a small implementation with finite differences: perturb one parameter by and , estimate the slope, and compare it with backprop. The check requires suitable precision and step size and can fail near nondifferentiable points. It is too expensive for training but excellent for testing a new custom operation.
In deep networks, products of many local derivatives can shrink or grow, producing vanishing or exploding gradients. Activation choice, initialization, normalization, residual connections, clipping, and architecture all influence the path. Backprop faithfully reports the derivative of the computation it is given; a useless gradient can reflect poor geometry rather than a bug in differentiation. The enduring picture is a reverse flow of responsibility through a recorded graph, with local rules combining into global sensitivity.
Autodiff also follows the graph actually executed, including branches and detached values. Accidentally converting a tensor to a plain number, mutating saved state, or running a region under no_grad can sever a path. Inspecting whether expected parameters have finite, nonzero gradients is therefore part of validating the program, not an optional optimization ritual.
2
Explain it like I am five
A bakery records every transformation from flour to finished loaves. When the final loaf is too dense, a reviewer walks the ledger backward. At each station, they combine the complaint arriving from downstream with that station’s local sensitivity: how kneading affected rise, how water affected dough, and how flour affected water absorption. Shared ingredients receive complaints from every path. The backward audit assigns responsibility efficiently without baking one new loaf per knob.
3
Teach it back
Explain forward pass, computational graph, upstream gradient, local derivative, accumulation, and why backprop is not itself an optimizer.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
The forward pass computes intermediates and scalar loss, forming a graph of operations. Reverse mode starts with dL/dL=1. Each node multiplies the upstream gradient by its local derivative and sends contributions to parents; contributions add when a value influences loss through multiple paths. This yields parameter gradients efficiently. Backprop only differentiates the current computation. An optimizer separately uses those gradients to update parameters.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- David E. Rumelhart, Geoffrey E. Hinton, and Ronald J. Williams (1986). Learning representations by back-propagating errors.