Skip to content
Glacius
CalculusConcept reference

Vector–Jacobian products

A vector–Jacobian product propagates output sensitivity backward through the derivative of a vector operation.

On this page 9 sections
  1. Overview
  2. Start with a scalar objective downstream
  3. Add the paths back to each input
  4. Read the vector–Jacobian product
  5. Apply a local backward rule
  6. Check the orientation and accumulation
  7. Key takeaway
  8. Sources & further reading
  9. Concept connections

01Start with a scalar objective downstream#

Suppose a layer maps two inputs to two outputs: y1=2x1+x2y_1=2x_1+x_2 and y2=3x2y_2=3x_2. Its output-row Jacobian is

J=(2103).J=\begin{pmatrix}2&1\\0&3\end{pmatrix}.

Now a later computation assigns the scalar score L=4y1−y2L=4y_1-y_2. We want the rates of this score with respect to the layer's original inputs.

The score's output sensitivities are ∂L/∂y1=4\partial L/\partial y_1=4 and ∂L/∂y2=−1\partial L/\partial y_2=-1. Collect them into a column s=(4,−1)Ts=(4,-1)^T.

These are rates, not the output values (y1,y2)(y_1,y_2). 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 x1x_1 affects y1y_1 with rate 22 and y2y_2 with rate 00. Its total effect on LL is therefore 4(2)+(−1)(0)=84(2)+(-1)(0)=8.

Input x2x_2 affects both outputs, with rates 11 and 33. Its total effect is 4(1)+(−1)(3)=14(1)+(-1)(3)=1. The two paths partly cancel.

The resulting input gradient is g=(8,1)Tg=(8,1)^T. 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.

Column-vector sensitivity convention. A Jacobian with rows [2,1] and [0,3] maps input changes to output changes. For output sensitivity [4,-1], its transpose sends sensitivity [8,1] back to the inputs: 2×4+0×(-1)=8 and 1×4+3×(-1)=1. Layout is schematic.Column-vector sensitivity convention. A Jacobian with rows [2,1] and [0,3] maps input changes to output changes. For output sensitivity [4,-1], its transpose sends sensitivity [8,1] back to the inputs: 2×4+0×(-1)=8 and 1×4+3×(-1)=1. Layout is schematic.
Figure 1Column-vector sensitivity convention. A Jacobian with rows [2,1] and [0,3] maps input changes to output changes. For output sensitivity [4,-1], its transpose sends sensitivity [8,1] back to the inputs: 2×4+0×(-1)=8 and 1×4+3×(-1)=1. Layout is schematic.
Link to this figure ↗Download SVGDownload PNG

There is a direct check: substitute the layer's outputs into the score.

L=4(2x1+x2)−3x2=8x1+x2.\begin{gathered}L=4(2x_1+x_2)-3x_2\\=8x_1+x_2.\end{gathered}

Its gradient with respect to the original inputs is (8,1)T(8,1)^T, matching the sum of path contributions. The local backward calculation recovered the derivative of the full composition.

Check your reasoning

J=[1230]J=\begin{bmatrix}1&2\\3&0\end{bmatrix}; output sensitivity s=(2,−1)Ts=(2, -1)^T. Find input sensitivity.

  1. A(0,6)T(0, 6)^T
  2. B(−1,4)T(-1, 4)^T
  3. C(0,3)T(0, 3)^T
Show answer and explanation
(−1,4)T(-1, 4)^T

Use JTsJ^Ts.

03Read the vector–Jacobian product#

Using column gradients, the operation we just performed is

g=JTs.g=J^Ts.

Each column of JJ contains the effects of one input on all outputs. Transposing puts that column into a row, so its dot product with ss sums the contributions for that input.

The name “vector–Jacobian product,” or VJP, is often written using a row sensitivity: sTJs^TJ. Its transpose is JTsJ^Ts, 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 nn inputs and mm outputs, JJ has shape m×nm\times n. The incoming sensitivity ss has mm entries. Multiplying JTJ^T, of shape n×mn\times m, by ss returns nn input sensitivities.

This differs from JΔxJ\Delta x, 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, yi=xi2y_i=x_i^2, each output depends only on the matching input. Its local derivative is 2xi2x_i, so the backward rule is

gi=2xisi.g_i=2x_i s_i.

At x=(2,−3)Tx=(2,-3)^T with incoming sensitivity s=(5,2)Ts=(5,2)^T, the result is g=(20,−12)Tg=(20,-12)^T. The negative input produces a negative local derivative in the second coordinate.

The square map's Jacobian at this point is diagonal, with entries 44 and −6-6. Multiplying its transpose by ss 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.

Check your reasoning

For yi=xi2y_i=x_i^2, x=(3,2)Tx=(3, 2)^T, output sensitivity s=(−1,4)Ts=(-1, 4)^T. Find input sensitivity.

  1. A(6,4)T(6, 4)^T
  2. B(24,−4)T(24, -4)^T
  3. C(−6,16)T(-6, 16)^T
Show answer and explanation
(−6,16)T(-6, 16)^T

Use 2xisi2x_i s_i: (−6,16)T(-6, 16)^T.

05Check the orientation and accumulation#

In the first example, using JsJs instead of JTsJ^Ts gives (7,−3)T(7,-3)^T. Both products happen to fit because JJ is square, but only one collects all output paths for each input.

Check the meaning, not only the dimensions: the derivative for x2x_2 must include its influence on both y1y_1 and y2y_2. Those rates live in column two of JJ.

Check your reasoning

J=[321−1]J=\begin{bmatrix}3&2\\1&-1\end{bmatrix}; output sensitivity s=(2,3)Ts=(2, 3)^T. Used JsJs backward. Repair it.

  1. A(9,1)T(9, 1)^T
  2. B(12,−1)T(12, -1)^T
  3. C(10,0)T(10, 0)^T
Show answer and explanation
(9,1)T(9, 1)^T

Use JTsJ^Ts.

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.

Key takeaway

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. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Vector–Jacobian products.” Math behind ML. /learn/c-vjp