Residual Connections & Skip Connections

Why identity shortcuts solve the degradation problem: formal analysis of gradient flow in deep networks, the unraveled view of ResNets as exponential ensembles, and the dynamical systems interpretation of residual blocks.

Intermediate

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. The Degradation Problem
  5. The Residual Learning Framework
  6. Gradient Flow Analysis
  7. The Unraveled View
  8. Dynamical Systems Interpretation
  9. Dense Connections (DenseNet)
  10. Common Pitfalls
  11. Summary
  12. Exercises

Learning Objectives

  1. Explain the degradation problem and why adding layers can increase training error.
  2. Derive how skip connections create direct gradient pathways.
  3. Prove that a ResNet with LL blocks can be viewed as an ensemble of 2L2^L paths.
  4. Interpret residual blocks as Euler discretization of an ODE.
  5. Analyze the effect of residual connections on the loss landscape.

Notation

  • h(l)\mathbf{h}^{(l)} — hidden state at layer ll
  • F(l)()F^{(l)}(\cdot) — residual function (nonlinear transformation at block ll)
  • LL — total number of residual blocks

Core Intuition

A plain network of depth LL requires gradients to traverse LL nonlinear layers. Each layer's Jacobian can shrink or amplify gradients. A residual connection adds the identity: h(l+1)=h(l)+F(l)(h(l))\mathbf{h}^{(l+1)} = \mathbf{h}^{(l)} + F^{(l)}(\mathbf{h}^{(l)}). This creates a "gradient highway" — the identity path carries gradients directly, regardless of what happens in FF.

Residual / Skip Connections

12345678|∂L/∂x|Gradient magnitude by layerskip pathPlain: final grad = 0.8% · Residual: 51.3%y = F(x) + x∂y/∂x = ∂F/∂x + 1 (identity path always flows)
L8 plain: 0.8%L8 residual: 51.3%
Depth
8
Plain networkWith skip (y = F(x)+x)
Insight: Skip connections add a gradient highway: ∂L/∂x flows directly through the identity path. Deep plain networks suffer vanishing gradients; ResNets train 100+ layers reliably.

The Degradation Problem

Observation (He et al., 2015). Training error of a 56-layer plain network is higher than a 20-layer network — not due to overfitting (training error, not just test error, degrades).

Why? The deeper network has strictly more representational capacity. It could learn the identity for the extra layers. But optimization fails: the gradient signal is too weak or chaotic to find good solutions when traversing many composed nonlinearities.


The Residual Learning Framework

Instead of learning H(x)H(\mathbf{x}) directly, learn the residual F(x)=H(x)xF(\mathbf{x}) = H(\mathbf{x}) - \mathbf{x}:

h(l+1)=h(l)+F(l)(h(l)).(1)\mathbf{h}^{(l+1)} = \mathbf{h}^{(l)} + F^{(l)}(\mathbf{h}^{(l)}). \tag{1}

Key insight: If the optimal function is close to identity, learning a small F0F \approx 0 is easier than learning HIH \approx \mathbf{I} from scratch. The skip connection provides the "default" identity mapping.


Gradient Flow Analysis

For a ResNet with LL blocks, the output is:

h(L)=h(0)+l=0L1F(l)(h(l)).(2)\mathbf{h}^{(L)} = \mathbf{h}^{(0)} + \sum_{l=0}^{L-1} F^{(l)}(\mathbf{h}^{(l)}). \tag{2}

The gradient of the loss with respect to an intermediate layer:

Lh(l)=Lh(L)h(L)h(l).(3)\frac{\partial \mathcal{L}}{\partial \mathbf{h}^{(l)}} = \frac{\partial \mathcal{L}}{\partial \mathbf{h}^{(L)}} \cdot \frac{\partial \mathbf{h}^{(L)}}{\partial \mathbf{h}^{(l)}}. \tag{3}

Using the chain rule through residual blocks:

h(L)h(l)=k=lL1(I+F(k)h(k)).(4)\frac{\partial \mathbf{h}^{(L)}}{\partial \mathbf{h}^{(l)}} = \prod_{k=l}^{L-1}\left(\mathbf{I} + \frac{\partial F^{(k)}}{\partial \mathbf{h}^{(k)}}\right). \tag{4}

Expanding the product:

h(L)h(l)=I+k=lL1F(k)h(k)+higher-order terms.(5)\frac{\partial \mathbf{h}^{(L)}}{\partial \mathbf{h}^{(l)}} = \mathbf{I} + \sum_{k=l}^{L-1}\frac{\partial F^{(k)}}{\partial \mathbf{h}^{(k)}} + \text{higher-order terms}. \tag{5}

The leading I\mathbf{I} term ensures the gradient never vanishes — even if all F(k)/h(k)0\partial F^{(k)}/\partial \mathbf{h}^{(k)} \to 0, the gradient flows directly through the identity.


The Unraveled View

Theorem (Veit et al., 2016). A ResNet with LL blocks is equivalent to an ensemble of 2L2^L paths of different lengths.

Proof. Expanding (2) recursively:

h(L)=h(0)+lF(l)=S{0,,L1}(path through blocks in S).(6)\mathbf{h}^{(L)} = \mathbf{h}^{(0)} + \sum_{l} F^{(l)} = \sum_{S \subseteq \{0,\ldots,L-1\}} \text{(path through blocks in } S). \tag{6}

Each subset SS defines a path that passes through blocks in SS and skips the rest. There are 2L2^L such paths. Most effective paths have length L/2\sim L/2 (binomial distribution peaks).

Implication: ResNets exhibit graceful degradation — removing individual blocks has small effect because most paths remain intact.


Dynamical Systems Interpretation

The update h(l+1)=h(l)+F(l)(h(l))\mathbf{h}^{(l+1)} = \mathbf{h}^{(l)} + F^{(l)}(\mathbf{h}^{(l)}) is an Euler discretization of the ODE:

dhdt=F(h(t),t),(7)\frac{d\mathbf{h}}{dt} = F(\mathbf{h}(t), t), \tag{7}

with step size Δt=1\Delta t = 1. This perspective leads to:

  • Neural ODEs (Chen et al., 2018): use adaptive ODE solvers instead of fixed layers.
  • Depth as continuous time: deeper networks = longer integration time.
  • Stability analysis: if F/h<1\lVert\partial F/\partial\mathbf{h}\rVert < 1, the system is contractive and stable.

Dense Connections (DenseNet)

DenseNet concatenates all previous features:

h(l)=[h(0),h(1),,h(l1)]Rld0.(8)\mathbf{h}^{(l)} = [\mathbf{h}^{(0)}, \mathbf{h}^{(1)}, \ldots, \mathbf{h}^{(l-1)}] \in \mathbb{R}^{ld_0}. \tag{8}

Every layer has direct access to all earlier features. This maximizes information flow but increases memory (O(L2d)O(L^2d) features at the final layer).


Common Pitfalls

Pitfall 1. Expecting skip connections to help shallow networks. The benefit is primarily for deep networks (L>10L > 10) where gradient degradation is significant.

Pitfall 2. Adding skip connections with dimension mismatch. When dim(h(l))dim(F(l))\dim(\mathbf{h}^{(l)}) \neq \dim(F^{(l)}), use a linear projection: h(l+1)=Wsh(l)+F(l)(h(l))\mathbf{h}^{(l+1)} = \mathbf{W}_s\mathbf{h}^{(l)} + F^{(l)}(\mathbf{h}^{(l)}).

Pitfall 3. Not initializing residual blocks near zero. For very deep networks, if F(l)F^{(l)} outputs are large at initialization, the sum in (2) grows as O(L)O(L) causing instability.


Summary

  • Skip connections solve the degradation problem by providing identity shortcuts.
  • The gradient contains a direct I\mathbf{I} term — it never vanishes regardless of depth.
  • ResNets can be viewed as ensembles of 2L2^L paths — inherently robust.
  • The ODE interpretation dh/dt=F(h)d\mathbf{h}/dt = F(\mathbf{h}) connects depth to continuous dynamics.
  • Residual connections smooth the loss landscape, making optimization easier.

Exercises

Exercise 1. For a plain network h(L)=fLf1(h(0))\mathbf{h}^{(L)} = f_L \circ \cdots \circ f_1(\mathbf{h}^{(0)}), show that the gradient is lJl\prod_l \mathbf{J}_l. How does this differ from equation (4)?

Exercise 2. Prove that a ResNet with LL blocks has 2L2^L unique paths from input to output.

Exercise 3. For the ODE dh/dt=Ahd\mathbf{h}/dt = -\mathbf{A}\mathbf{h} with positive definite A\mathbf{A}, show the solution is contractive: h(t)h(0)\lVert\mathbf{h}(t)\rVert \leq \lVert\mathbf{h}(0)\rVert.

Exercise 4. Show that Pre-Norm ResNets have gradient norm L/h(l)L/h(L)\lVert\partial\mathcal{L}/\partial\mathbf{h}^{(l)}\rVert \geq \lVert\partial\mathcal{L}/\partial\mathbf{h}^{(L)}\rVert for all ll.

Exercise 5. Compute the memory cost of DenseNet vs ResNet with LL blocks and hidden dimension dd.