A single-channel 3×3 input X=[102210031] is cross-correlated (no padding, stride 1, no bias) with a 2×2 kernel W, giving output Y. Given upstream loss gradient ∂L∂Y=[1−120], what is ∂L∂W, and how is ∂L∂X computed in general?

Deep learning, Convolutional networks
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can derive convolution backward passes using the chain rule and evaluate the weight gradient numerically.

Key idea

In the forward pass Yi,j=∑a,bWa,bXi+a,j+b (zero-indexed). By the chain rule, ∂L∂Wa,b sums ∂L∂Yi,jXi+a,j+b over all output positions (i,j), which is simply the cross-correlation of X with ∂L∂Y.

Steps

  1. Write the forward relation (zero-indexed i,j∈{0,1}, a,b∈{0,1}): Yi,j=∑a=01∑b=01Wa,b Xi+a,j+b.
  2. Apply the chain rule for ∂L∂Wa,b=∑i=01∑j=01∂L∂Yi,j∂Yi,j∂Wa,b=∑i=01∑j=01Gi,jXi+a,j+b, where G=∂L∂Y. Notice this is the cross-correlation of X by G.
  3. Evaluate the four entries with G=[1−120]: (0,0): 1(1)+(−1)(0)+2(2)+0(1)=5; (0,1): 1(0)+(−1)(2)+2(1)+0(0)=0; (1,0): 1(2)+(−1)(1)+2(0)+0(3)=1; (1,1): 1(1)+(−1)(0)+2(3)+0(1)=7. Thus ∂L∂W=[5017].
  4. Derive ∂L∂Xu,v: each Xu,v contributes to Yi,j whenever u=i+a and v=j+b (so a=u−i,b=v−j with 0≤u−i<k and 0≤v−j<k, where k is the kernel width), giving ∂L∂Xu,v=∑i,jGi,j Wu−i,v−j — a full convolution (cross-correlation with a 180∘-flipped kernel W, padded by k−1).

Common mistakes

How long your answer should be

Half a page; 4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: What is a dilated (atrous) convolution with dilation factor d? For a 1-D input of length L, what are the output length and the receptive field after two stacked 3×1 convolutions with stride 1, no padding and dilations d1=1 and d2=2, and why does exponential dilation (d=1,2,4,…) avoid the gridding problem?
Next in Deep learning: How does a transposed convolution upsample a feature map (give its output size formula for input size n, kernel k, stride s and padding p), and why does it often create checkerboard artefacts when k is not divisible by s?