Elena' s AI Blog

Attention Mechanisms Meet Residual Connections: How Transformers Use Skip Connections

30 Oct 2026 (updated: 02 Nov 2026) / 9 minutes to read

Elena Daehnhardt

Generated by Midjourney. Prompt: Abstract glowing neural network representing superintelligent AI.


TL;DR:
  • Residual paths are the core stability mechanism in transformers. Pre-LN is usually safer at scale, while residual scaling and careful optimization become critical in deeper stacks.

πŸ“š This post is part of the "Neural Network Architecture" series

Series: Neural Network Architecture (Part 4 of 9)

Previous: Part 2 β€” Understanding Neural Network Architecture: From Basics to Residual Connections

Next: Part 5 β€” DeepSeek's mHC: Making Neural Networks Learn Better by Preserving Identity

Where this fits:Transformers Explore the AI Landscape →

This is Part 4 of the Neural Network Architecture series.

What Are Residual Connections in Transformers?

A residual connection is a skip path that adds a layer’s input to its output (x + F(x)), so gradients and signal can flow through depth unchanged. Transformers look like a new paradigm, but they still depend on the same core trick that made deep CNNs practical: skip connections. Residual learning was the breakthrough that made depth trainable in vision (He et al., 2015), and transformers inherit that same stability logic (Vaswani et al., 2017). If the identity-mapping intuition behind x + F(x) is new to you, my earlier post on neural network architecture covers it from first principles β€” here I assume that foundation and focus on what changes once attention enters the picture.

Without residual paths around attention and feed-forward layers, deep transformer stacks become fragile: gradients degrade, optimization becomes sensitive, and training can collapse.

Residual Connections in a Pre-LN Transformer Block

In a modern Pre-LN transformer block, the core pattern is:

\(x' = x + \text{Attention}(\text{LN}(x))\) \(y = x' + \text{MLP}(\text{LN}(x'))\)

A Pre-LN transformer block does not replace the old representation; it adds a learned update to it. Preserving signal while learning refinement is the entire point of residual design.

Pre-LN Transformer Block (single block)

           +---------------- Attention(LN(x)) ----------------+
           |                                                  v
x ---------+----------------------------------------------> (+) ----> x'

           +------------------ MLP(LN(x')) ------------------+
           |                                                  v
x' --------+----------------------------------------------> (+) ----> y

Why Residual Connections Keep Gradients Alive in Deep Transformers

If a block is $f(x) = x + g(x)$, then:

\[\frac{\partial f}{\partial x} = I + \frac{\partial g}{\partial x}\]

Even if $\frac{\partial g}{\partial x}$ is poorly conditioned, the identity term $I$ gives gradients a direct path through depth. This is why very deep residual stacks are trainable in practice (He et al., 2015), and why transformers rely on the same mechanism (Vaswani et al., 2017).

Gradient intuition through one residual block

Forward:  x ---> [ g(x) ] ---+
           \                 |
            \----------------+----> y = x + g(x)

Backward: dL/dy splits into:
          1) identity path  --------> direct gradient
          2) residual branch -------> transformed gradient

Pre-LN versus Post-LN, residual scaling, the PyTorch block and failure modes follow below.

References

πŸ”’ Subscribe to keep reading.

You've hit a Deep Dive tutorial.

I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):

Already a subscriber? Use the magic link from your last newsletter, or reset your password.

New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in β€” use the same email afterwards.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2026) 'Attention Mechanisms Meet Residual Connections: How Transformers Use Skip Connections', daehnhardt.com, 30 October 2026. Available at: https://daehnhardt.com/blog/2026/10/30/transformers-residual-connections/
All Posts