03
When paths meet, add
Multiply along a path. Add across paths. Reusing a value creates another contribution to its sensitivity.
One value, two uses
Through , the contribution to the hidden value is . Changing affects both branches at once:
These arrows follow the backward calculation. The branch contributions add before propagating through the activation. BP-C02, BP-C11.
This is the multivariable chain rule. If a value feeds several direct consumers , accumulate every contribution before propagating farther upstream:
Conceptually, initialize a node’s sensitivity to zero and add contributions. Overwriting −0.5 with −0.25 discards a real dependence. Add first, then continue in reverse dependency order. BP-C02
Through the activation
Our is in ReLU’s positive region, whose local slope is one. Hence . For , the local derivatives are with respect to and one with respect to :
| Parameter | Calculation | Gradient |
|---|---|---|
| w | -1.5 | |
| b | -0.75 | |
| v | -0.5 | |
| u | -0.5 | |
| c | -0.5 |
The gradient collects all five partial derivatives in the declared order . A negative gradient for predicts that a small increase in lowers loss. Gradient descent subtracts that negative gradient. BP-C11, BP-C15
A zero needs a diagnosis
For , ReLU stays zero under sufficiently small perturbations. Its slope is zero, blocking the signal to and for this example. With , gradients of and are also zero. Output bias can still have a nonzero gradient. A blocked hidden route does not imply every parameter stopped learning.
At exactly , ReLU has no ordinary derivative. Our code uses a zero backward rule there, consistent with PyTorch’s minimum-norm subgradient convention for this convex operation. This is an implementation choice, not an ordinary derivative. Autograd’s nondifferentiable-function rules give the convention. BP-C04, BP-C14
Another cause of zero is cancellation. If while , contributions to cancel. The activation is positive. Inspect the routes before diagnosing an inactive activation.
Three kinds of accumulation
The path sum belongs to one graph. If a batch loss is a sum of example losses, its gradient is their sum; if it is a mean over a fixed batch of examples, the gradient includes the same factor. Reduction changes the objective you differentiate.
There is also framework storage behavior: PyTorch accumulates gradients into parameter .grad buffers across backward calls. A usual fresh training step clears them with optimizer.zero_grad() before computing new gradients. That housekeeping does not replace the chain rule’s path sum. The optimization tutorial shows the ordering. BP-C06