Reverse-mode differentiation
Reverse-mode differentiation propagates output sensitivities backward through local derivative rules.
On this page 8 sections
- Overview
- Understand the idea
- If a downstream scalar L=L(y) supplies ∂ L/∂ y=4, start the backward pass with 4
- A backward pass reuses the forward values to evaluate local derivative rules
- A downstream loss can supply an initial sensitivity other than 1
- Key takeaway
- Sources & further reading
- Concept connections
01Understand the idea#
Reverse-mode differentiation computes how a final scalar responds to earlier values by working backward through a computational graph. Neural-network backpropagation is an application of this method. The backward numbers are sensitivities, not the original forward values run in reverse.
First evaluate the graph forward. Then initialize the final scalar’s sensitivity to itself as 1. At each preceding node, multiply the received sensitivity by the appropriate local derivative, evaluated using the saved forward inputs.
For a scalar output , write for its sensitivity to a node . Start at the output: .
Move backward through the graph, multiplying the received sensitivity by the operation’s local derivative.
Let and . At , first compute and . The square’s local rate is ; the scale’s local rate is .
For , at , save and . Backward from , begin with 1. The square contributes , so sensitivity to is 12. Multiplying by gives sensitivity to equal to 36. The two occurrences of 36 here have different meanings: output value and input sensitivity.
and . At , find the backward sensitivity .
Show answer and explanation
The forward value is . Backward multiplication gives .
02If a downstream scalar L=L(y) supplies ∂ L/∂ y=4, start the backward pass with 4#
If a downstream scalar supplies , start the backward pass with . Multiply by each local rate at the forward evaluation point.
and . At , a downstream scalar supplies . Find .
Show answer and explanation
The local rates are and . Multiply backward: .
03A backward pass reuses the forward values to evaluate local derivative rules#
A backward pass reuses the forward values to evaluate local derivative rules. It does not perturb each input. For , , keeping only gives the response to , not to .
Continue to the requested input and include every local factor along that chain.
and . At , a backward pass stops at . Repair the final sensitivity .
Show answer and explanation
The forward value is . Backward multiplication gives .
04A downstream loss can supply an initial sensitivity other than 1#
A downstream loss can supply an initial sensitivity other than 1. If for this same example, sensitivities become 48 at and 144 at . Use the supplied upstream sensitivity; resetting it to 1 would differentiate instead of the requested .
Start with the output sensitivity and multiply through every operation back to the requested input.
- Propagate a scalar-output sensitivity backward through a chain.
Sources & further reading
- [1]Stanford CS231n: Backpropagation ↗Stanford CS231n · Article