Summary
A residual block adds a learned change to a shortcut: . The identity branch supplies a direct gradient contribution, not a guarantee about the combined gradient.
Take , and . Find the output and the two contributions to .
The mechanism
A residual block:
y = x + f(x)
The input goes to both branches. Addition joins their values in the forward pass and splits the upstream gradient in backward.
One input, two contributions
Addition copies the upstream gradient; each branch then applies its own derivative
Derivation
Does the identity path receive only half of the upstream gradient?
References: Deep Residual Learning and Identity Mappings in Deep Residual Networks.
The loss is , giving upstream gradient . The shortcut contributes ; the residual branch contributes . Directly differentiating gives at too.
For vector inputs, the diagram’s row-gradient convention gives
One contribution crosses no residual operation. The sum still depends on .
Change the shortcut
1. Change output dimension
New task: map into three channels with .
Picture and change: replace the identity wire by , giving . The branches must produce matching shapes before addition.
Check: . Row upstream gradient returns , not the unchanged upstream vector.
Use when: channels or spatial resolution change across a block.
2. Move normalization outside the addition
New task: compare pre-norm and post-norm , with . LayerNorm has unit gain and zero offset.
Picture and change: add a common shift to . Pre-norm retains it through the shortcut; post-norm removes it by centering.
Check: the directional derivative along is for pre-norm and zero for post-norm.
Use when: reasoning about gradient paths across normalization boundaries.
The two contributions can cancel
Set . Then and . The total input gradient is zero even though the identity contribution exists. An identity branch does not prove a nonvanishing total gradient.
Try repeating the block
Does repeatedly applying prevent gradient explosion?
Check your answer
No. Each block has local gain . Across identical scalar blocks, the derivative is .
Why it works (intuitions)
The ResNet paper studied degradation in deeper plain networks, including worse training error. An additive block can represent identity by setting its residual function to zero. Veit et al. analyze paths of differing depths; this is not an ensemble of independently trained models.
Pre-norm vs. post-norm in transformers
Their Jacobians are for pre-norm and for post-norm. Matrix order matters. Neither expression guarantees bounded gradients through a whole network. See Xiong et al. for normalization placement under stated training and initialization assumptions.
Bottleneck blocks
A bottleneck reduces channels before the expensive spatial convolution, then expands them:
y = x + Conv1x1 ↓ → Conv3x3 → Conv1x1 ↑ (x)
Ignoring biases, its convolution parameters total . Savings depend on widths, spatial sizes and the comparison block, not a fixed factor or accuracy guarantee.
Where residuals show up
| Architecture | Where |
|---|---|
| ResNet, ResNeXt, Wide ResNet | Every block |
| U-Net | Long skips may concatenate; distinguish those from additive residual blocks |
| Transformer (encoder & decoder) | Around attention and FFN sub-blocks |
| Diffusion U-Nets | Both within blocks and across encoder-decoder |
| MLP-Mixer, ConvNeXt | Block residuals |
Common pitfalls
Some deep-network recipes scale residual contributions with depth; the scale must match their initialization and training assumptions. Addition, saved activations and projection shortcuts have memory or compute costs.