Where do the parameters and FLOPs actually live in a transformer? Walk me through the budget.
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
Per decoder block, for a Llama-2-7B-shaped model (d_model = 4096, 32 heads, head_dim 128, SwiGLU d_ff = 11008, full MHA):
- Attention: four projections W_q, W_k, W_v, W_o, each d×d → 4d² ≈ 67M params. With GQA (e.g. 8 of 32 KV heads), K and V shrink 4× → ~2.5d² ≈ 42M.
- MLP (SwiGLU): three matrices (gate, up, down), each d × d_ff → 3 · 4096 · 11008 ≈ 135M params - roughly 2/3 of the block. (SwiGLU uses d_ff ≈ 2.7d with three matrices instead of the classic 4d with two - roughly parameter-neutral by design.)
- Norms: negligible (~2d each).
Full worked answer with diagram
Per decoder block, for a Llama-2-7B-shaped model (d_model = 4096, 32 heads, head_dim 128, SwiGLU d_ff = 11008, full MHA):
- Attention: four projections W_q, W_k, W_v, W_o, each d×d → 4d² ≈ 67M params. With GQA (e.g. 8 of 32 KV heads), K and V shrink 4× → ~2.5d² ≈ 42M.
- MLP (SwiGLU): three matrices (gate, up, down), each d × d_ff → 3 · 4096 · 11008 ≈ 135M params - roughly 2/3 of the block. (SwiGLU uses d_ff ≈ 2.7d with three matrices instead of the classic 4d with two - roughly parameter-neutral by design.)
- Norms: negligible (~2d each).
Times 32 blocks: ~6.5B. Plus embeddings/LM head: vocab × d = 32000 × 4096 ≈ 131M each (262M untied). The scaling insight: embedding params are linear in d while block params are quadratic, so vocab matters enormously for small models (a 1B model with a 128k vocab can spend >30% of params on embeddings - why small models tie weights and historically kept vocabs small) and is noise at 70B+.
FLOPs: training ≈ 6·N·D (forward 2ND + backward 4ND); inference forward pass ≈ 2·N per token - matrix-multiply params dominate. The critical caveat: attention's QKᵀ and weights·V FLOPs scale with sequence length (~per-token cost ∝ n·d per layer) and aren't in N. At short contexts (≤4k), MLPs dominate compute and 2N is accurate; at 100k+, attention score computation overtakes the parameter FLOPs - the crossover is why long-context prefill is expensive and why attention-efficiency work matters even though attention holds a minority of parameters.
Why this budget matters practically: (1) it explains why MoE targets the MLP - that's where the parameters are, so that's where conditional compute pays; (2) LoRA placement discussions and quantization sensitivity analyses are really conversations about this map; (3) interpretability's working hypothesis that MLPs store knowledge while attention routes it aligns with where the capacity sits; (4) at decode time the whole budget becomes a bandwidth budget - every parameter is read per token, so params ≈ bytes moved, which is why small-batch decode speed tracks model size in GB, not FLOPs.
Worth sketching. A budget drawn as a tree is far easier to defend than a recited list of numbers.
flowchart TD
B["one decoder block, d_model 4096"] --> AT["attention: 4 d^2 ~ 67M params<br/>(~2.5 d^2 with GQA)"]
B --> MLP["SwiGLU MLP: 3 x d x d_ff ~ 135M<br/>roughly two thirds of the block"]
B --> NM["norms: ~2d each, negligible"]
AT --> X32["x 32 blocks = ~6.5B"]
MLP --> X32
X32 --> EMB["plus vocab x d for embedding and head:<br/>linear in d, so it dominates small models"]
EMB --> FL["FLOPs: 2N per token, until attention's<br/>n x d term overtakes at long context"]
What a good answer covers
- Attention: four projections W_q, W_k, W_v, W_o, each d×d → 4d² ≈ 67M params
- MLP (SwiGLU): three matrices (gate, up, down), each d × d_ff → 3 · 4096 · 11008 ≈ 135M params - roughly…
- Plus embeddings/LM head: vocab × d = 32000 × 4096 ≈ 131M each (262M untied)
- The scaling insight: embedding params are linear in d while block params are quadratic, so vocab matters…
- FLOPs: training ≈ 6·N·D (forward 2ND + backward 4ND); inference forward pass ≈ 2·N per token -…
Key terms: Attention · MLP (SwiGLU) · Norms · embeddings/LM head · FLOPs · MoE targets the MLP
In the glossary: MHA · Attention · GQA · MoE · LoRA · Quantization
Interviewer follow-ups to expect
Derive the 6ND training-FLOP estimate. At what context length does attention compute overtake MLP compute for this architecture?
- Attention: four projections W_q, W_k, W_v, W_o, each d×d → 4d² ≈ 67M params. With GQA (e.g. 8 of 32 KV heads), K and V shrink 4× → ~2.5d² ≈ 42M.
- MLP (SwiGLU): three matrices (gate, up, down), each d × d_ff → 3 · 4096 · 11008 ≈ 135M params - roughly 2/3 of the block. (SwiGLU uses d_ff ≈ 2.7d with three matrices instead of the classic 4d with two - roughly parameter-neutral by design.)
- Norms: negligible (~2d each).
How does GQA change the parameter and bandwidth budgets differently?
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