A residual (skip) connection adds the input of a layer to its output:
where is the layer's transformation (attention, feed-forward, etc.).
The residual stream view: the input flows through a "stream" and each layer reads from and writes to it. The stream carries the original signal forward; layers contribute incremental updates.
Why it works:
- Gradient flow: during Backpropagation, . The identity term provides a gradient highway — even if vanishes, the gradient passes through unimpeded
- Easier optimization: the network only needs to learn the residual (deviation from identity), which is often simpler
- Enables depth: ResNets (152 layers), transformers (96+ layers) would be untrainable without skip connections
In transformers: every sub-layer (attention, feed-forward) has a residual connection:
Pre-norm vs post-norm: modern transformers apply LayerNorm before the sub-layer (pre-norm) for more stable training.
See also: Backpropagation, Batch Normalization, Self-Attention