Skip to content
Glacius
CalculusConcept reference

Shared-path gradients

A shared graph node receives the sum of all backward sensitivity contributions from its consumers.

On this page 8 sections
  1. Overview
  2. A value can influence the final loss through more than one branch
  3. For u=2x and L=u^2+3u at x=1, the intermediate value is u=2
  4. Contributions carry signs
  5. Shared weights and reused activations are common in models
  6. Key takeaway
  7. Sources & further reading
  8. Concept connections

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 u=x2u=x^2, v=3xv=3x, and y=u+vy=u+v, both branches depend on xx.

At x=2x=2, the square branch contributes 2x=42x=4 and the scale branch contributes 33. The sum passes sensitivity 11 into each branch.

Backward computation for y=x²+3x at x=2. The output sum sends sensitivity 1 into each branch. The square branch contributes 4 to x and the scale branch contributes 3 to x. They add to dy/dx=7 at the shared input.Backward computation for y=x²+3x at x=2. The output sum sends sensitivity 1 into each branch. The square branch contributes 4 to x and the scale branch contributes 3 to x. They add to dy/dx=7 at the shared input.
Figure 1Backward computation for y=x²+3x at x=2. The output sum sends sensitivity 1 into each branch. The square branch contributes 4 to x and the scale branch contributes 3 to x. They add to dy/dx=7 at the shared input.
Link to this figure ↗Download SVGDownload PNG

Let a=x2a=x^2, b=3xb=3x, and L=a+bL=a+b. At x=2x=2, the square route contributes 1×2x=41\times2x=4 and the linear route contributes 1×3=31\times3=3. The total derivative is 7. Overwriting the first contribution with the second would incorrectly leave only 3.

Check your reasoning

u=x2u=x^2, v=5xv=5x, and y=u+vy=u+v. At x=4x=4, find dy/dxdy/dx.

Show answer and explanation
13

Add the two signed contributions: 8+(5)=138+(5)=13.

02For u=2x and L=u^2+3u at x=1, the intermediate value is u=2#

For u=2xu=2x and L=u2+3uL=u^2+3u at x=1x=1, the intermediate value is u=2u=2. Add its two branch rates: 4+3=74+3=7. Then apply the upstream rate du/dx=2du/dx=2.

dLdx=7×2=14\frac{dL}{dx}=7\times2=14
Check your reasoning

A score uses u=2xu=2x, v=u2v=u^2, w=3uw=-3u, and L=v+wL=v+w. At x=2x=2, find dL/dxdL/dx.

Show answer and explanation
10

At u=4u=4, add branch rates 8+(3)=58+(-3)=5, then multiply by du/dx=2du/dx=2 to get 1010.

03Contributions carry signs#

Contributions carry signs. For y=x24xy=x^2-4x at x=2x=2, they are 44 and 4-4, giving a total rate of 00. Two nonzero paths can cancel.

A backward implementation adds into a shared node’s sensitivity. Replacing its old value loses earlier paths.

Check your reasoning

u=x2u=x^2, v=7xv=7x, and y=u+vy=u+v. At x=2x=-2, a backward pass keeps only the scale branch. Repair dy/dxdy/dx.

Show answer and explanation
3

Add the two signed contributions: 4+(7)=3-4+(7)=3.

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.

Key takeaway

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. [1]
    Stanford CS231n: BackpropagationStanford CS231n · Article

Reference this concept

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

Glacius. “Shared-path gradients.” Math behind ML. /learn/c-reverse-branch