Walk me through what happens inside a single transformer decoder block.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
A decoder block takes hidden states of shape (n_tokens × d_model) and applies two sublayers, each wrapped in a residual connection with a normalization:
- Norm → masked self-attention → add. The input is normalized (RMSNorm in modern models), then projected into queries, keys, and values. Scaled dot-product attention with a causal mask mixes information across positions - each token gathers a weighted summary of earlier tokens. The result goes through an output projection and is added to the original input (residual).
- Norm → MLP → add. The updated stream is normalized again and passed through a position-wise feed-forward network - typically up-project to ~3-4× d_model, nonlinearity (SwiGLU in Llama-family models), down-project - applied identically and independently at every position. Added back to the residual stream.
Full worked answer with diagram
A decoder block takes hidden states of shape (n_tokens × d_model) and applies two sublayers, each wrapped in a residual connection with a normalization:
- Norm → masked self-attention → add. The input is normalized (RMSNorm in modern models), then projected into queries, keys, and values. Scaled dot-product attention with a causal mask mixes information across positions - each token gathers a weighted summary of earlier tokens. The result goes through an output projection and is added to the original input (residual).
- Norm → MLP → add. The updated stream is normalized again and passed through a position-wise feed-forward network - typically up-project to ~3-4× d_model, nonlinearity (SwiGLU in Llama-family models), down-project - applied identically and independently at every position. Added back to the residual stream.
So the division of labour is: attention moves information between tokens; the MLP transforms information at each token (it's where most parameters and, plausibly, most stored "knowledge" live). The residual stream acts as a shared workspace that each sublayer reads from and writes small updates into - a framing that explains why you can stack 100+ blocks: the identity path means each block only needs to make an incremental refinement.
Placement of the norm matters: modern models are pre-norm (norm inside the residual branch), which keeps the residual path clean and training stable at depth; the 2017 original was post-norm. In a real model each attention sublayer also applies RoPE to Q and K, and the block repeats N times (e.g. 32 blocks for a 7-8B model, 80 for a 70B), followed by a final norm and the LM head projecting to vocabulary logits.
Worth sketching. Draw the residual line straight across first, then hang the two sublayers off it: that ordering is the whole point of the block.
flowchart LR
X["residual stream in"] --> N1["RMSNorm"]
N1 --> A["masked self-attention<br/>moves info between tokens"]
A --> AD1["add"]
X --> AD1
AD1 --> N2["RMSNorm"]
N2 --> M["SwiGLU MLP<br/>transforms info at each token"]
M --> AD2["add"]
AD1 --> AD2
AD2 --> OUT["next block, x N"]
What a good answer covers
- Norm → masked self-attention → add
- Norm → MLP → add
- So the division of labour is
- The residual stream acts as a shared workspace that each sublayer reads from and writes small updates…
- Placement of the norm matters
Key terms: Norm → MLP → add · pre-norm
In the glossary: RMSNorm · Attention · Causal mask · Residual stream · Pre-norm · RoPE
Interviewer follow-ups to expect
Roughly what fraction of a block's parameters are in the MLP vs attention?
Why do residual connections matter more as depth grows?
What changes in this picture for an MoE model?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep