Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Keep the shortcut perfectly clean
The original ResNet still applies a ReLU after adding the shortcut, so the “express lane” through the network is not quite empty. The follow-up paper moved the normalisation and ReLU inside the branch, before the convolutions. Now the shortcut is a pure copy, and the output of a block is its input plus a correction, exactly. Information and gradients can then travel through hundreds of blocks untouched, and networks of 1,000 layers trained better.
| stage | output C × H × W | parameters | multiply–adds |
|---|---|---|---|
| stem | 64 × 56 × 56 | 9.5 k | 118.01 M |
| stage2 | 64 × 56 × 56 | 148.0 k | 462.42 M |
| stage3 | 128 × 28 × 28 | 525.6 k | 411.04 M |
| stage4 | 256 × 14 × 14 | 2.10 M | 411.04 M |
| stage5 | 512 × 7 × 7 | 8.39 M | 411.04 M |
| head | 1000 × 1 × 1 | 513.0 k | 512.0 k |
| ResNet-18 | 11.69 M parameters | 1.81 G MACs |
| ResNet-50 | 25.56 M parameters | 4.09 G MACs |
The “pre-norm” ordering, normalise then transform then add, is the same choice that makes very deep transformers trainable. It is a design rule worth knowing for any deep model.
- 1. Pre-activation moves BN and ReLU…
- 2. The shortcut then is…
- 3. Transformers use the same idea as…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Original block: x_(l+1) = ReLU(x_l + F(x_l)), with F = conv → BN → ReLU → conv → BN.
- Pre-activation block: x_(l+1) = x_l + F(x_l), with F = BN → ReLU → conv → BN → ReLU → conv.
- Unrolled: x_L = x_l + F(x_l) + F(x_(l+1)) + … + F(x_(L−1)), so with residuals (1, 2) starting from x₀ = 1 the output is 4.
- Gradient: ∂L/∂x_l = ∂L/∂x_L·(1 + ∂/∂x_l Σ F), and the “1” term carries the gradient directly from any depth.
- Scaled shortcuts: x_(l+1) = λx_l + F gives a factor λ^L: 0.9¹⁰⁰ ≈ 2.7·10⁻⁵, while 1.1¹⁰⁰ ≈ 13,781.
- CIFAR depth: bottleneck networks with 3 stages of n blocks have 9n + 2 layers, so n = 18 gives 164 and n = 111 gives 1,001.
- 1. Unrolled x_L equals…
- 2. Gradient factor through 100 shortcuts scaled by 0.9:
- 3. Depth for n = 111 bottleneck blocks per stage:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Pre-activation in code
Exercise 1.
- With a zero residual branch, the pre-activation block returned its input exactly, while the original block clipped negative values.
- The unrolled sum matched.
- Gradients through scaled shortcuts shrank or grew exponentially.
Practice.
- In a pre-activation network the first convolution is not preceded by BN–ReLU.
- A final BN–ReLU is needed before global pooling, because the last block’s output has not been normalised.
- When a block changes the shape, apply the projection shortcut to the pre-activated input.
- The same recipe as ResNet works. The paper also trained 200-layer ImageNet networks, which overfitted less than the original form.
class PreAct(nn.Module):
def __init__(self, c):
super().__init__(); self.f = nn.Sequential(nn.BatchNorm2d(c), nn.ReLU(), nn.Conv2d(c, c, 3, 1, 1, bias=False),
nn.BatchNorm2d(c), nn.ReLU(), nn.Conv2d(c, c, 3, 1, 1, bias=False))
def forward(self, x): return x + self.f(x) # nothing on the shortcut, no ReLU after the addition- 1. Before global pooling, a pre-activation net needs…
- 2. The first convolution of the network is preceded by…
- 3. After the addition, pre-activation applies…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why identity matters. If x_(l+1) = h(x_l) + F(x_l), the gradient passes through Π ∂h. Any h other than the identity changes the gradient multiplicatively at every block. The authors tested several shortcut variants on a 110-layer CIFAR-10 ResNet, and all were worse than the identity:
- scaling by 0.5;
- exclusive and shortcut-only gating;
- 1 × 1 convolutions;
- dropout on the shortcut.
Why move the activation. The ReLU after the addition in the original block makes the shortcut path non-linear and blocks negative signals. Moving BN and ReLU into the branch, as “pre-activation”, gives a clean shortcut and also normalises every branch’s input. The second effect regularises: the 1,001-layer and 200-layer networks overfitted less.
When it matters. With BatchNorm, the original ordering already trained well up to about 100–150 layers. The gains of pre-activation showed at 164 and especially 1,001 layers (CIFAR-10 error 7.61% → 4.92%). In shallow networks the difference is small. Exercise 2 shows that without normalisation, at 20–50 layers, there is no consistent difference.
- 1. Shortcut variants such as scaling or gating were…
- 2. A second benefit of pre-activation is…
- 3. Pre-activation's gains were largest at…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does the block order matter at moderate depth?
History.
- K. He, X. Zhang, S. Ren and J. Sun (2016b) published “Identity mappings in deep residual networks” at ECCV, introducing pre-activation.
- Pre-norm transformers, with layer norm before attention and MLP (R. Xiong et al., 2020), use the same principle and train without learning-rate warm-up more easily than post-norm.
Exercise 2. The data are three-class spirals; the networks are 16 units wide with no BatchNorm. They have 10 or 25 residual blocks of two layers (20 or 50 layers), with the second layer of each block starting at zero, in the original or the pre-activation order. Each is trained with full-batch Adam (learning rate 0.003) for 150 steps. Final training loss:
| blocks | original order (seeds 0, 1) | pre-activation (seeds 0, 1) |
|---|---|---|
| 10 | 0.014, 0.019 | 0.010, 0.016 |
| 25 | 0.074, 0.016 | 0.036, 0.017 |
- Both orders trained well, and neither was consistently better. In seeds 2 to 4, pre-activation was ahead in four of six cases but much worse in one (0.33 against 0.06 at 25 blocks).
- In earlier trials with 50 and 100 layers, at learning rates 0.01 and 0.003, the original order was ahead on average. Without BatchNorm, the pre-activation residual stream x_l grows without bound as blocks are added.
- The paper’s gains needed BatchNorm and very deep networks. This exercise does not contradict them; it shows that the benefit of a design choice can depend on depth and normalisation, so claims should be tested at the scale where they will be used.
Pre-activation in AI, robotics and aerospace
- Very deep backbones: pre-activation blocks are used where depth is large, for example in some segmentation and generative models.
- Transformers: pre-norm ordering made deep language and vision transformers trainable, including those used for robot policies.
- Design reasoning: the unrolled sum, input plus corrections, is a useful mental model for any residual architecture.
References
- K. He, X. Zhang, S. Ren, J. Sun (2016). “Identity mappings in deep residual networks.” Proc. ECCV.
- K. He, X. Zhang, S. Ren, J. Sun (2016). “Deep residual learning for image recognition.” Proc. CVPR.
- R. Xiong et al. (2020). “On layer normalization in the transformer architecture.” Proc. ICML.