In a small computation graph, input x=2 feeds two branches that share the same weight w=3: a=wx and b=(w−1)2, and the loss is L=12(ab−20)2. How do you compute ∂L∂w by backpropagation, and what happens if an implementation overwrites instead of accumulating branch gradients?

Deep learning, Backpropagation
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you apply the multivariable chain rule (summing upstream contributions at fan-out nodes) when one parameter appears in multiple paths.

Key idea

When a node w fans out into two branches a(w) and b(w), backpropagation sums the gradients arriving along all paths: ∂L∂w=∂L∂a∂a∂w+∂L∂b∂b∂w. Here that gives 16(2)+24(4)=128.

Steps

  1. Forward pass at w=3,x=2: a=3(2)=6, b=(3−1)2=4, product p=ab=24, and L=12(24−20)2=8.
  2. Upstream gradients to a and b: ∂L∂p=p−20=4, so ∂L∂a=4b=16 and ∂L∂b=4a=24.
  3. Local derivatives with respect to w: ∂a∂w=x=2 and ∂b∂w=2(w−1)=4.
  4. Accumulate both paths: ∂L∂w=16(2)+24(4)=32+96=128. If code overwrites the stored gradient instead of adding to it, one branch’s gradient is silently lost (returning 32 or 96 instead of 128).

Common mistakes

How long your answer should be

4–5 lines with the forward values and summed chain rule.

Read this

Previous in Deep learning: How can a two-layer MLP with two ReLU hidden units and a linear output unit compute the XOR function on (x1,x2)∈{0,1}2, and what values do its hidden units and output take on all four inputs?
Next in Deep learning: A hidden layer with nin=256 independent inputs (each of mean 0 and variance 1) computes z=w⊤x with zero bias, which gives Var⁡(z)=nin σW2 when weights are drawn independently with mean 0 and variance σW2. What is the standard deviation of z under N(0,1) (σW2=1) versus Xavier-style normal N(0,1/nin) (σW2=1/256), and why does N(0,1) stall training under a tanh⁡ activation?