Answers · The mathematics underneath
What does a computation graph actually let you differentiate?
In shortIt lets you differentiate a final number with respect to any earlier value in the graph by multiplying local derivatives along each route and adding across routes.
A computation graph lets you differentiate a final scalar with respect to any earlier value that actually reaches it, provided every operation on the way has a derivative. The derivative is not stored on a node. Each operation supplies a local derivative, and the graph supplies the routes along which those local derivatives are multiplied and added.
The formula is the chain rule written for a graph. Along one route from to you multiply the local derivatives of the operations you pass through, because each small change is fed into the next. If there is more than one route, the changes happen at the same time and their effects add. The product along a route is the derivative of the loss with respect to the start of that route, holding the other route fixed; the sum removes that holding fixed. That is why the graph is recorded with edges rather than as a list of layers: an edge says this value was used here, and a second edge from the same value says it was used again somewhere else.
One unit, split into operations
Take the unit , , , with , , and loss . Then , , and . The local derivative of the squash is . The add has local derivative with respect to either input. The multiply has local derivative with respect to , and with respect to .
The derivative is accumulated, not read off
At the multiply node the local derivatives are and . It is tempting to read off that node. That is wrong by the factor that the loss sends back through the squash and the add. The node knows how changes when changes. It does not know how changes when changes, and that second fact arrives from the other side. The correct value is , not .
With , the two branches give and , so and . Changing changes through and through . The route contributes . The route contributes . Both happen at the same time, so the total is . If only one branch were present the derivative would be or ; the second branch is not a correction to the first, it is an additional term. In reverse mode the from reaches and , each sends its local derivative back to , and the two arrivals are added at .
The graph differentiates values, not names. A weight, a bias, an input, and an intermediate activation are all the same kind of object as far as the graph is concerned: each is a value with edges leaving it. A weight used in three places has three outgoing edges, so its derivative is the sum of three contributions, one per use. If a value is used once, its incoming derivative is simply what the next operation sends; if it is used many times, the incoming contributions are summed before the local derivative is applied. Reverse mode starts with and sweeps once in the reverse of the recorded order, so one backward pass gives the derivative of the same scalar with respect to every value in the graph. That is why the cost is proportional to the number of edges, not to the number of values squared.
Where the chain stops
The chain rule on a graph is only as good as the local derivatives. If an operation has no derivative at the value it actually received, for example an absolute value at zero or a hard threshold, no local derivative exists and the graph cannot supply one. A value with no path to the loss has derivative zero, not undefined, because the loss does not depend on it through the recorded graph. The graph is the record of the operations that ran, so a data-dependent branch contributes the paths it actually took. For a value used many times, enumerating paths is correct but exponential. One reverse sweep accumulates the same sum without listing them.
Worth keeping
- A node supplies only a local derivative; the derivative of the loss with respect to that node is the sum of contributions arriving from all paths to the loss.
- For a value used twice, the two route contributions add: with a=2, p=3a, q=5a and L=p+q, dL/da=3+5=8.
- If an operation is not differentiable at the value it received, the graph has no local derivative to multiply, so the chain rule cannot proceed through it.
Where this goes next
This question is one step of Backpropagation in Full, a course that works through its subject from the beginning. The page that teaches this part of it is Every Computation Is a Graph, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why does backpropagation never build the full Jacobian?Backpropagation only needs a vector multiplied by each layer's derivative matrix, so it computes that product directly and never builds the matrix.
- Why does softmax followed by cross entropy have gradient p minus y?Because the derivative of the loss through softmax simplifies to the predicted probability minus the target, one number per class, with the exponentials and fractions cancelling out.
- Why do derivatives multiply along a chain but add when the path splits?Along a chain each step scales the effect that arrived, so the scalings multiply; at a split each use contributes its own effect to the same change, so the contributions add.
- Why does adding a shortcut connection stop gradients from vanishing?A shortcut gives the gradient a route whose factor is one plus the layer's own factor, so many layers in series no longer multiply the signal down to nothing.
- What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
- How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.