Why does a deep transformer stack stop training if you remove the residual connections?
A 32-layer transformer trains fine with residual connections. A teammate removes them as a 'simplification'. Explain what specifically breaks during training and why.
Without residuals, the gradient through 32 stacked sublayers is a product of 64 Jacobians; that product vanishes or explodes long before it reaches the early layers.
Think about telling a message down a line of 64 people, where each person is allowed to change the message a little before passing it on. After 64 retellings, the original message is unrecognizable. Now imagine each person is also given a copy of the ORIGINAL message and is only asked to write a small correction next to it. After 64 people, you still have the original plus a stack of small corrections. That second setup is what a residual connection does. During training, the model has to send a correction signal BACK through the line so each person can learn how to do better next time. Without the original-message copy (the residual), that signal gets garbled and the people at the front of the line never hear what they did wrong. With residuals, the signal travels straight back to them.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: chain rule gives a product of 64 Jacobians + product vanishes or explodes + residuals make each Jacobian `I + J` + product behavior switches from exponential to linear + ResNet origin + pre-norm versus post-norm + empirical training collapse without residuals.
| Aspect | Without residuals | With residuals |
|---|---|---|
| Effective Jacobian per layer | `J_i` (arbitrary spectrum) | `I + J_i` (anchored near identity) |
| Gradient norm at depth 32 | Exponential in depth (vanish or explode) | Linear in depth |
| Max trainable depth | ~10-15 layers | 80+ layers in practice |
| Sensitivity to initialization | Extreme; needs orthogonal init + LR warmup | Robust; standard init works |
| What the early layers learn | Stays near random init | Fits the task normally |
Real products, models, and research that use this idea.
- He et al., 'Deep Residual Learning for Image Recognition' (2015), showed a 56-layer plain CNN trained WORSE than a 20-layer one; adding residuals reversed the ordering and was the unlock for very deep convnets.
- Vaswani et al. (2017) imported residual connections from ResNet into the transformer block recipe; every transformer block in production today still uses them.
- Llama 3.1 70B stacks 80 transformer blocks (160 residual connections) and trains stably to convergence on 15T tokens; without residuals this depth would not be reachable.
- Xiong et al. (2020), 'On Layer Normalization in the Transformer Architecture', empirically demonstrated that pre-norm placement (which preserves a clean residual path) is required for stable training past about 20 layers.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does pre-norm specifically help relative to post-norm, given both use residual connections?
QWhat does the gradient look like at layer 1 of an 80-layer pre-norm transformer at the start of training?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Calling this 'just' a vanishing-gradient issue. The exploding-gradient case is equally real, and it is the geometric mean of the Jacobian singular values that controls which direction it fails in.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.