All courses

Explain what is known about LLM internals

Describe how information is represented and processed inside a model: the residual stream, linear features in superposition, MLPs as fact stores, and attention circuits. Describe the tools used to probe these: logit lens and sparse autoencoders.

Builds on: Sparse autoencoders for interpretable features, Logit lens: reading intermediate predictions, MLPs as key-value memories for facts, QK and OV circuits of a head

▶ Watch this lesson Start the whole course

What the animation says

Where does 'Paris' come from?

Give a model the prompt: The Eiffel Tower is in the city of. It answers: Paris. Each token has its own position, and each position carries a running vector up through the layers. The prediction is made at the last position, on the word 'of'. But 'of' says nothing about Paris. The fact must be retrieved somewhere, then moved here. So where is Eiffel Tower to Paris first looked up?

Stream, features, lookups, routing

The lookup happens in a middle-layer MLP, at the Tower position. MLPs work one position at a time. Keys detect a pattern, Eiffel Tower. Values write related features: Paris, France. A feature is a direction. Superposition packs more features than dimensions, as nearly perpendicular directions, with few active at once. Then a later head: its query-key part picks Tower to read from, its output-value part copies Paris to the last position. Each sublayer adds its output to the stream. Nothing is overwritten.

Everything is a sum of writes

Every write is added, so the final vector at the last position is a sum: embedding, plus every head and MLP output. Treat the final norm as a fixed scale, here one. Then a token's logit is that sum dotted with its unembedding column. For Paris versus London, use the difference of their columns. Call it u. Each write's push is its own dot product with u. The last-position MLP wrote zero, one, zero. How much does it push Paris over London?

Crediting each write

Zero. That write lies along a direction u ignores. Size alone tells you nothing. Embedding: one-point-five times zero-point-two is zero-point-three, minus zero-point-two from the last entry. Total: zero-point-one. The head: one-point-five times two is three, plus zero-point-five. Three-point-five. Add the shares: three-point-six. Paris is about thirty-seven times likelier than London. Signs matter. A positive share favors Paris; a negative share favors London. Another head writes minus one, two, zero. Which way does it push?

Who delivered vs who computed

Back to Paris. The head wrote three-point-five, almost the whole margin. But it didn't invent Paris. It copied Paris from the Tower position, where the mid-layer MLP had written it. Credit at the last position shows who delivered the answer, not who computed it. To find the source, ablate: switch a component off and watch the margin. Tap the component to switch off so the head has nothing to copy.

What the tools see, and don't

Two tools read this stream. The logit lens unembeds the partial sums, layer by layer, to watch the answer form. It's noisy in early layers. The tuned lens learns a small map per layer and reads them better. A sparse autoencoder learns feature directions, and how strongly each fires for an input. But it leaves reconstruction error: part of the vector it can't explain. So: a sum of additive writes, MLPs looking up facts, heads routing them. Much of the computation is still unexplained.

Where does 'Paris' actually get computed?

Prompt: *The Eiffel Tower is in the city of* → the model says *Paris*. Somewhere inside, the fact *Eiffel Tower → Paris* is retrieved and moved to the last position, where the prediction is made. Can we say **where** this happens and **in what form**? Partly, yes. The findings from earlier concepts fit into one picture, and two tools let us test that picture on a real model.

One picture: stream, features, lookups, routing

**Residual stream:** each position carries a running vector. Every sublayer reads it and *adds* its output. **Features:** meanings are directions. Superposition packs more features than $d$ as nearly orthogonal directions, with few active at once. **MLPs:** at each position, keys detect a pattern (*Eiffel Tower*) and values write related features (*Paris, France*). **Heads:** QK picks which position to read from. OV picks what to copy. Here, a mid-layer MLP enriches *Tower*, then a later head copies *Paris* to the last position.

Everything is a sum of writes

Every write is added, so $$r^{(L)}_t = r^{(0)}_t + \sum_{\ell=1}^{L}\big(\mathrm{attn}^{(\ell)}_t + \mathrm{mlp}^{(\ell)}_t\big)$$ Each term is roughly a sparse sum of feature directions $\sum_i a_i f_i$. Treat the final norm as a fixed scale $s$, with its learned gain folded into $W_U$. Then $z_t \approx s\, r^{(L)}_t W_U$, and a component's push on token $j$ is $s\cdot(\text{its output})\cdot W_U[:,j]$. The **logit lens** reads the partial sums $r^{(\ell)}$. An **SAE** learns the directions $f_i$ and how to compute each input's $a_i$.

Crediting each component for 'Paris'

Toy $d=3$, $s=1$. Let $u = W_U[:,\text{Paris}] - W_U[:,\text{London}] = [1.5, 0, 0.5]$. Dot each write at the last position with $u$: - embedding $[0.2, 1, -0.4]$: $0.3+0-0.2=0.1$ - last-position MLP $[0, 1, 0]$: $0$ - head $[2, 0, 1]$: $3+0.5=3.5$ Sum: $z_{\text{Paris}}-z_{\text{London}}=3.6$, so Paris is $e^{3.6}\approx 37\times$ likelier than London. The head writes the answer, but it only copies it. The MLP at *Tower* wrote it at that position. Ablate that MLP and the head has nothing to copy.

What to remember

The final residual stream is a sum of additive writes, built from nearly orthogonal feature directions. MLPs look up facts at each position. Attention heads route features between positions. The logit lens and SAEs read this stream, but only partly. The logit lens is noisy in early layers; the tuned lens, with a learned map per layer, helps. SAEs leave reconstruction error. Much of the computation is still unexplained.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.