Visual explainer
Backpropagation
Trace cached values, local derivatives and branch sums to compute weight gradients, then separate backpropagation from the optimizer update.
Backpropagation computes how a loss changes with each parameter. An optimizer then uses those gradients to change the parameters. The picture starts with a prediction of 1 and target of 3: the residual is −2 and squared loss is 4. The square's area represents squared error; it uses its own area scale, rather than the prediction axis scale.
Our synthetic scalar model is , with input , weight and bias . Unless explicitly changed below, the target stays 3 and . A gradient measures local sensitivity, rather than assigning a causal share of the loss to each weight.
Reverse Through Multiplication
For the product , the local derivatives are and . White routes show the product's dependencies; mint arrows carry sensitivities backward. An incoming produces and . The gradient on the fixed input helps explain the rule, even though training usually updates parameters.
Evaluate Before Differentiating
Follow multiplication, subtraction and squaring from left to right: , , and . The dashed ring selects the cached residual. Backward computation needs that value to differentiate the square, and the cached input to differentiate multiplication. Bias zero is omitted here to keep this single route visible. Retaining intermediate values costs memory; checkpointing can trade recomputation for storage.
Differentiate The Loss
The curve plots squared loss against prediction, with the target at its minimum. The dashed tangent touches the current point . Its data-space slope is : increasing the prediction slightly reduces loss. Combining that derivative with the product's local slope 2 gives the weight gradient −8. Loss 4 and gradient −4 are different quantities.
Add Contributions From Branches
This separate fan-out example uses at , so . Read the reverse-only graph from the unit seed at the right. The addition sends sensitivity 1 down each branch; the square branch multiplies its sensitivity by . At the shared input, contributions add: . The left plus circle represents gradient accumulation, while the right plus circle is the original forward addition. Multiplication applies along a path; addition combines different paths. See the Stanford computational-graph notes.
Let The Optimizer Step
Return to the original scalar model and hold bias at zero. Gradient descent with learning rate gives . The mint displacement is +0.8; its length uses the weight axis. The upper arrow shows only the gradient's direction. Re-evaluation gives and . The cross at weight 1.5 marks the zero-loss solution for this one example, not a guarantee about unseen data. Step size still matters even when derivatives are correct.
Small Factors Compound
The three bars share a linear length scale and show sensitivities 1, .25 and .0625 after zero, one and two backward factors. Ten factors of .25 give . These are deliberately chosen complete local derivatives. A sigmoid activation's slope bound alone does not bound a full layer derivative, which also includes weights. This small finite value is not automatically numerical zero. The vanishing-gradient visual develops that distinction.
Check A Gradient Numerically
This is an explicit local zoom of . Perturbing the current weight by gives and . The central difference is , agreeing with backpropagation. The secant nearly overlays the curve at this zoom. Central differences are approximate in general; this quadratic happens to give the exact slope in exact arithmetic. Floating-point cancellation and nondifferentiable points complicate checks. Perturbing every parameter is useful for debugging small models but expensive for training large ones.
Reuse The Reverse Sweep
Restoring bias to the graph, addition passes the incoming −4 to both bias and product. Multiplication then gives the weight gradient −8. One forward evaluation and a reverse traversal of this scalar-loss graph supply both derivatives, sharing intermediate work. Runtime still grows with graph size, and floating-point derivatives are not infinitely precise. If we now train both parameters at learning rate .1, their simultaneous updates are , giving prediction 3 and zero loss for this sample. That differs from the earlier weight-only update.
Where It Breaks
Change the model to while keeping and target 3. Preactivation is −1, output is zero and loss is 9. The loss sends gradient −6 toward the output, but ReLU's local slope at −1 is zero, so this weight receives zero data-loss gradient. The stop bar makes that blocked route visible. Backpropagation can be correct while this sample provides no useful update through the inactive route. Other samples, paths or parameter changes may reactivate the unit; regularization can also contribute a separate gradient.
The Quick Version
- Forward evaluation retains values needed for local derivatives.
- Chain-rule products transport sensitivities along paths.
- Different uses of a shared value contribute summed gradients.
- Optimizers apply updates after gradients are computed.
- Numerical differences help check small differentiable graphs.
- Correct gradients do not guarantee useful training progress.