What role do residual connections play around each sublayer of a Transformer block?

Last updated 22 November 2026

Each sublayer computes an update that is added to its input (x + Sublayer(x)). This gives gradients an identity path through the whole stack, so deep Transformers can be trained. It also means each layer only has to learn a refinement of the representation, not rebuild it.

  • Gradient flow: ∂(x + F(x))/∂x = I + ∂F/∂x. The identity term keeps gradients from vanishing as they pass through dozens of layers.

  • Easy-to-learn defaults: A layer can approximate the identity by outputting near zero, so adding depth rarely hurts. This is the same insight behind ResNets.

  • Information preservation: Token identity and positional information from the embeddings are carried forward. Attention cannot accidentally wipe them out by averaging.

  • The residual stream view: The sum acts as a shared communication channel: attention and FFN sublayers read from it and write additive updates back. This is a core idea in mechanistic interpretability.

  • Design constraints:

    • Every sublayer must output d_model dimensions so the addition works, which is why the width is constant through the stack.

    • Residuals are paired with LayerNorm. Where the norm is placed (pre-norm vs post-norm) decides whether the identity path stays clean, and therefore how stable training is.

  • https://www.mantramindai.in/courses/transformer-architecture-q-a/lessons/explain-role-of-residual-connections-in-a-transformer-block-and-what-fails
  • https://codingnowai.in/notes/dl/residual-connections
  • https://github.com/purepisces/Wenqing-Machine_Learning_Blog/blob/main/Machine-Learning-Interview-Questions/Transformer-Interview-Question.md
All Transformers interview questions