Shared-path gradients
A shared graph node receives the sum of all backward sensitivity contributions from its consumers.
On this page 8 sections
01A value can influence the final loss through more than one branch#
A value can influence the final loss through more than one branch. Its backward sensitivity must add every branch’s contribution. This is the multivariable chain rule applied to a computational graph: multiply along each route, then add where the routes meet.
A shared input can affect an output along several paths. Multiply rates along each path, then add the contributions where they meet.
For , , and , both branches depend on .
At , the square branch contributes and the scale branch contributes . The sum passes sensitivity into each branch.
Let , , and . At , the square route contributes and the linear route contributes . The total derivative is 7. Overwriting the first contribution with the second would incorrectly leave only 3.
, , and . At , find .
Show answer and explanation
Add the two signed contributions: .
02For u=2x and L=u^2+3u at x=1, the intermediate value is u=2#
For and at , the intermediate value is . Add its two branch rates: . Then apply the upstream rate .
A score uses , , , and . At , find .
Show answer and explanation
At , add branch rates , then multiply by to get .
03Contributions carry signs#
Contributions carry signs. For at , they are and , giving a total rate of . Two nonzero paths can cancel.
A backward implementation adds into a shared node’s sensitivity. Replacing its old value loses earlier paths.
, , and . At , a backward pass keeps only the scale branch. Repair .
Show answer and explanation
Add the two signed contributions: .
04Shared weights and reused activations are common in models#
Shared weights and reused activations are common in models. Their gradients accumulate contributions from each use. A node’s number of outgoing edges alone is not the gradient; each route has its own derivative, evaluated at the saved forward values.
Multiply along each path, then add every signed contribution at the shared node.
- Accumulate sensitivities at an input used by multiple graph branches.
Sources & further reading
- [1]Stanford CS231n: Backpropagation ↗Stanford CS231n · Article