Models are functions of functions. A prediction is computed from the weights, a loss is computed from the prediction, and in a neural network there are dozens of layers in between. To get the derivative of the loss with respect to a weight deep inside, we need the chain rule.
Read it as a chain of exchange rates. If changes 3 times as fast as , and changes 2 times as fast as , then changes times as fast as . Example: . Let , so . Then and , so .
A computation graph
Take the squared error of a one-weight model: prediction , error , loss . Draw each operation as a node. The forward pass computes values left to right. The backward pass starts from and moves right to left, multiplying by each node's local derivative.
Notice that reuses the first two factors. Backward passes share work: the gradient arriving at a node is computed once and passed to everything that feeds into it. That reuse is why computing the gradient for all parameters costs only about as much as one or two forward passes, no matter how many parameters there are.
When a value is used twice
If one variable feeds into several places, its gradient is the sum of the gradients from each path. This is the multivariable chain rule: for , each of the two uses contributes , giving . Forgetting to accumulate (sum) gradients is one of the most common bugs in hand-written backprop.
Backpropagation is nothing but the chain rule applied to a computation graph, right to left, reusing work. Modern frameworks (PyTorch, JAX) record the graph as you compute and run this backward pass for you.