Zenaique

After W_O projects the multi-head output back to d_model, what happens before the next sub-layer runs?

MCQ·Easy·4.0 · 0·~1 min·Asked atLinkedinPineconeTencent·Relevant atAi4bharatCerebrasDeepseekMeta
Attempt it
TL;DR

The attention block adds its W_O output back into the residual stream: x_out = x_in + W_O(concat(heads)). The skip connection keeps deep training stable.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a long whiteboard where every meeting in a building adds a few notes without erasing what was already there. Each meeting reads the current state, decides what to contribute, and writes those new notes alongside the old ones. The whiteboard never gets wiped. By the end of the day, the bottom of the board shows the original meeting and the top shows the latest, with everything in between visible. A transformer block is a meeting. The residual stream is the whiteboard. Attention writes its conclusions onto the stream by addition, never by overwrite, so signal from the first layer is still readable at the last layer.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The residual addition at the end of every transformer sub-block is one of the smallest pieces of arithmetic in the whole architecture and one of the most consequential. Remove it and deep transformers stop training. Misunderstand it and you cannot explain how features compose across layers.

This deep dive walks through the exact write-back operation, contrasts it with the wrong alternatives, explains why the addition is what makes deep transformers trainable, and connects the design choice to modern interpretability work.

Mental model: attention produces a delta that is added to the residual stream. The stream never gets overwritten. Every layer reads the cumulative state and contributes a new term.

The exact write-back operation

The formula

In a pre-norm transformer block, the attention sub-block performs:

xout=xin+WOConcat(head1,,headh)x_\text{out} = x_\text{in} + W_O \cdot \text{Concat}(\text{head}_1, \ldots, \text{head}_h)

The order of operations is:

  1. Apply LayerNorm to x_in (in pre-norm).
  2. Project to Q, K, V through W_Q, W_K, W_V.
  3. Run scaled dot-product attention per head.
  4. Concatenate per-head outputs.
  5. Project through W_O.
  6. Add the result to the original unnormalized x_in.

Shape check

After concatenation the per-token tensor is (seq_len, d_model). W_O is (d_model, d_model), so the post-projection output is also (seq_len, d_model). The residual x_in is (seq_len, d_model). The addition is element-wise and shape-preserving.

Why the addition uses unnormalized x_in

In pre-norm, LayerNorm normalizes only the input to the sub-layer, not the residual itself. The residual stream stays unnormalized through the whole stack, and each layer's LN happens locally. This is what gives pre-norm its stable depth-scaling behavior.

Why addition makes deep training work
Why the wrong answers fail
The residual stream as a feature bus and connection to interpretability
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Every modern frontier transformer (Llama 4 Maverick, GPT-5.5, Claude Opus 4.7, Gemini 3.1 Pro, Mistral, DeepSeek V4) uses pre-norm with residual additions inherited from the original 2017 transformer block.
  • ResNet (2015) introduced the residual connection in vision and is the direct architectural ancestor.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhat changes if you switch from post-norm to pre-norm?
A

Post-norm normalizes after the residual add (LN(x + attn(x))); pre-norm normalizes before the sub-layer (x + attn(LN(x))). Pre-norm trains stably at much greater depths because the residual stream remains unnormalized and identity gradients pass cleanly. Modern stacks use pre-norm.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Thinking attention replaces the residual stream. It does not. The output is added to the residual, that addition is what makes deep transformers trainable.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The formula for the attention sub-block output

  • Why residual addition prevents gradient vanishing

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium