Order the tail-end operations that turn the last residual stream into logits
- 1Output of the final transformer block (residual stream of shape (batch, seq_len, d_model))
- 2Apply softmax (during loss or during sampling) to convert logits into a probability distribution
- 3Apply the unembedding / output-head linear projection from d_model to vocab_size
- 4Apply the final RMSNorm (or LayerNorm) to the residual stream
- 5Resulting logits tensor of shape (batch, seq_len, vocab_size)
Tail-end recipe for a modern pre-norm LLM: residual stream out of the last block, final RMSNorm, then linear unembedding to vocab_size produces logits, then softmax (during loss or sampling) yields probabilities.
Imagine a long relay race where 80 runners pass a baton. The baton picks up extra paint smudges at every handoff, and by the time the last runner crosses the line the baton is a mess of colors. Before judges can use the baton's colors to declare a winner, someone has to wipe it down to a standard appearance. That cleanup is the final RMSNorm. Then a judge holds up a giant chart with one entry per possible winner and compares the baton's colors to the chart, producing one score per entry. That comparison is the output head. Finally a panel converts those raw scores into 'chance of winning' percentages that add to 100. Three steps in order: clean up, score against every option, convert scores to chances.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: walk the five-step tail, explain why pre-norm requires the final RMSNorm specifically, discuss weight tying vs untying tradeoffs, mention softmax+cross-entropy fusion and logit upcasting for numerical stability.
| Step | Operation | Input shape | Output shape |
|---|---|---|---|
| 1 | Final block output (residual stream) | (B, T, D) | (B, T, D) |
| 2 | Final RMSNorm | (B, T, D) | (B, T, D) |
| 3 | Unembedding linear projection | (B, T, D) | (B, T, V) |
| 4 | Logits tensor | (B, T, V) | (B, T, V) |
| 5 | Softmax (during sampling) or cross-entropy (during loss) | (B, T, V) | (B, T, V) probabilities or scalar loss |
Real products, models, and research that use this idea.
- Llama 3 config: 80 transformer blocks, then `model.norm` (RMSNorm), then `lm_head` (Linear from d_model to vocab_size). Tail recipe is exactly as described.
- Mistral 7B: 32 blocks, `model.norm` (RMSNorm), `lm_head` (Linear, untied). Same recipe.
- GPT-2: 12 blocks (or 48 for XL), `ln_f` (LayerNorm), `lm_head` tied to wte (the input embedding). Same structural recipe; only difference is LayerNorm vs RMSNorm and tied vs untied.
- DeepSeek V4: tail recipe identical, with the addition that the LM head has higher dimensionality for MoE-augmented vocab routing in some experimental configs.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat happens to training if you remove the final RMSNorm from a pre-norm Llama?
QWhy do most modern large LLMs untie the input embedding and the unembedding matrix?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Skipping the final RMSNorm because the per-block pre-norm felt sufficient. In a pre-norm stack the residual stream is not normalized after the last block, so a final norm is necessary before the unembedding projection.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.