Frontier Lab Notes

Transformer Block Anatomy

Transformer Block Anatomy
Pre-Norm Transformer Block h = h + Attn(Norm(h)); h = h + MLP(Norm(h)) residual stream [batch, seq, d_model] Token stream in RMSNorm Multi-Head Attention Q heads K heads V heads softmax(QKᵀ/√d)·V, causal mask, RoPE + residual add RMSNorm MLP · SwiGLU SiLU(W_gate·x) W_up·x W_out( gate * up ) — expands to d_ff, per-token + residual add To next block (×N) Sublayers write updates into the residual stream; they never overwrite it. Pre-norm keeps deep stacks stable to optimize.

One pre-norm decoder block: the residual stream flows through RMSNorm, multi-head attention (QKV heads), a residual add, another RMSNorm, a SwiGLU MLP, and a second residual add.

The transformer block is the core unit of modern frontier LLMs. Most frontier models are still recognizably stacks of decoder-only transformer blocks, with many engineering changes around normalization, positional encoding, attention variants, MLP design, routing, and systems.

Primary source: Attention Is All You Need.

The Decoder-Only Shape

A causal LLM takes a sequence of token ids:

x_1, x_2, ..., x_T

It maps them to embeddings, processes them through many transformer blocks, and predicts the next-token distribution at each position:

P(x_{t+1} | x_1, ..., x_t)

A modern pre-norm decoder block usually looks like:

h = h + Attention(Norm(h))
h = h + MLP(Norm(h))

This means each block adds updates into the residual stream.

The Residual Stream

The residual stream is the model's working memory at each token position. Attention and MLP sublayers do not replace the representation; they write updates into it.

Why this matters:

Attention Sublayer

Self-attention is the token-mixing part.

At each position, the model computes:

Core equation:

Attention(Q, K, V) = softmax(QK^T / sqrt(d_k)) V

Causal masking prevents a token from attending to future tokens.

Related note: Attention Mechanics and KV Cache.

MLP Sublayer

The MLP is applied independently at each token position. It does not directly move information across positions. Its job is feature transformation and nonlinear computation.

Modern LLM MLPs often use gated activations such as SwiGLU:

MLP(x) = W_out( SiLU(W_gate x) * W_up x )

Why MLPs matter:

Normalization

Modern LLMs often use RMSNorm instead of LayerNorm.

Why normalization matters:

Pre-norm is common:

x + Sublayer(Norm(x))

Post-norm was used in the original Transformer:

Norm(x + Sublayer(x))

Positional Information

Attention itself is permutation-invariant unless position is added. LLMs use schemes such as:

RoPE is especially common in modern decoder LLMs because it injects relative position structure into query/key space.

Primary source: RoFormer: Enhanced Transformer with Rotary Position Embedding.

Modern Frontier Block Ingredients

Common ingredients in contemporary LLM blocks:

What To Be Able To Derive

You should be able to write shapes for:

Research Questions

Related