Vector–Jacobian products
A vector–Jacobian product propagates output sensitivity backward through the derivative of a vector operation.
On this page 9 sections
01Start with a scalar objective downstream#
Suppose a layer maps two inputs to two outputs: and . Its output-row Jacobian is
Now a later computation assigns the scalar score . We want the rates of this score with respect to the layer's original inputs.
The score's output sensitivities are and . Collect them into a column .
These are rates, not the output values . The incoming sensitivity says how a small change in each output would affect the scalar objective, after accounting for the computation downstream.
02Add the paths back to each input#
Input affects with rate and with rate . Its total effect on is therefore .
Input affects both outputs, with rates and . Its total effect is . The two paths partly cancel.
The resulting input gradient is . The diagram places the incoming sensitivity at the top and the resulting input sensitivity below. The transposed Jacobian sits beside the arrow; we will unpack that matrix operation next.
There is a direct check: substitute the layer's outputs into the score.
Its gradient with respect to the original inputs is , matching the sum of path contributions. The local backward calculation recovered the derivative of the full composition.
; output sensitivity . Find input sensitivity.
Show answer and explanation
Use .
03Read the vector–Jacobian product#
Using column gradients, the operation we just performed is
Each column of contains the effects of one input on all outputs. Transposing puts that column into a row, so its dot product with sums the contributions for that input.
The name “vector–Jacobian product,” or VJP, is often written using a row sensitivity: . Its transpose is , our column result.
The two forms contain the same derivatives. State the row or column convention before multiplying; the word “vector” by itself does not specify an orientation.
For a map with inputs and outputs, has shape . The incoming sensitivity has entries. Multiplying , of shape , by returns input sensitivities.
This differs from , which sends an input perturbation forward to an output perturbation. A VJP sends sensitivities to a scalar objective backward.
04Apply a local backward rule#
For an elementwise square, , each output depends only on the matching input. Its local derivative is , so the backward rule is
At with incoming sensitivity , the result is . The negative input produces a negative local derivative in the second coordinate.
The square map's Jacobian at this point is diagonal, with entries and . Multiplying its transpose by gives exactly the entrywise calculation above.
We do not need to allocate that full matrix to compute the result. A local rule can apply its effect directly, which is useful when a layer has many inputs and outputs.
For , , output sensitivity . Find input sensitivity.
Show answer and explanation
Use : .
05Check the orientation and accumulation#
In the first example, using instead of gives . Both products happen to fit because is square, but only one collects all output paths for each input.
Check the meaning, not only the dimensions: the derivative for must include its influence on both and . Those rates live in column two of .
; output sensitivity . Used backward. Repair it.
Show answer and explanation
Use .
Across several layers, start from the final scalar objective and apply each local VJP in reverse order. Each local Jacobian is evaluated at the corresponding forward input.
When an intermediate value is used in more than one branch, add the incoming contributions from those branches before continuing backward. Replacing one contribution with another would discard a dependency path.
For matrix-shaped parameters, the resulting scalar-loss gradient can be arranged in the same shape as the parameter array. That arrangement preserves which derivative belongs to which parameter.
Computing these derivatives leaves the parameters unchanged. An optimizer then uses the gradients, together with its update rule and learning rate, to choose new parameter values.
With column sensitivities, multiply by the Jacobian transpose; local rules can compute the product directly.
- Propagate a supplied output sensitivity through a vector operation.
Sources & further reading
- [1]JAX authors: The Autodiff Cookbook with JVP and VJP ↗JAX authors · Article