The single most important architecture trick of the last decade
A residual connection is y = x + f(x): the output of a block is the input plus the block's transformation. The "skip" lets gradients flow through depth without being multiplied by the block's local Jacobian. This is what makes 100-layer networks (ResNet) and 175-billion-parameter transformers (GPT-3 and beyond) actually trainable.
Before residuals, training got worse as you added layers past 20-30. After residuals, depth pays off all the way up. This isn't a regularization trick — it's a depth-enabler.
x + sublayer(x) in code, that's a residual connection. Spot-check that the shapes match (skip + transform must have the same shape). When they don't, you need a projection (nn.Linear or nn.Conv2d with stride) on the skip.Where residuals appear
Everywhere modern. ResNet (CNNs), Transformers (every block has two residuals — attention and FFN), DenseNet (concat instead of add), U-Net (encoder-to-decoder skip), Mamba/SSM blocks. The pattern transcends architecture family.
The math, briefly
If y = x + f(x), then dy/dx = 1 + f'(x). Even when f'(x) is tiny (vanishing gradient), the +1 keeps the gradient alive. The chain rule's product becomes a chain rule's sum-of-products, which is much more numerically forgiving.