To derive the gradient of a scalar loss L with respect to the input x in a residual block defined as:
y=x+F(x,W)
we apply the chain rule from calculus. The gradient ∂x∂L is obtained by propagating the gradient of L with respect to y, denoted as ∂y∂L, through the transformation y=x+F(x,W).
Derivation of the Gradient
Given:
y=x+F(x,W)
We differentiate y with respect to x:
∂x∂y=I+∂x
where I is the identity matrix (or 1 in the scalar case), and ∂x∂F is the Jacobian matrix of F with respect to .
Using the chain rule, the gradient of the loss L with respect to x is:
∂x∂L=∂y
Substituting the expression for ∂x∂y, we get:
∂x∂L=∂y
This can be expanded as:
∂x∂L=∂y
This result shows that the gradient of L with respect to x consists of two components:
- A direct gradient ∂y∂L, which is passed through the identity mapping x.
- A gradient through the function F , which depends on the Jacobian of .
Why Residual Connections Mitigate Vanishing Gradients
In deep neural networks, gradients often vanish or explode due to the multiplication of many small (or large) terms across layers. This is particularly problematic when the network is deep, as the gradient becomes a product of many Jacobians, each of which can shrink or amplify the signal.
Residual connections address this issue by introducing an identity path from the input x to the output y. This allows gradients to flow directly from later layers to earlier layers without being multiplied by potentially small Jacobians from the function F.
Even if ∂x∂F is small (e.g., due to activation saturation or poor initialization), the identity term ∂y ensures that the gradient does not vanish entirely. This is because the gradient is guaranteed to have at least a direct path through the identity mapping, which preserves the gradient magnitude.
In contrast, in a standard feedforward network without residual connections, the gradient would be a product of all Jacobians from the current layer to the output. If any of these Jacobians are small, the gradient can diminish exponentially as it propagates backward, leading to the vanishing gradient problem.
By allowing gradients to bypass layers through shortcut connections, residual networks enable stable gradient propagation through deep architectures. This makes it possible to train much deeper networks effectively.
Final Answer
∂x∂L=
Residual connections mitigate vanishing gradients because the identity term ∂y∂L ensures that gradients can propagate directly through shortcut connections, even when ∂x is small. This preserves gradient magnitude during backpropagation and enables stable training of deep networks.