# One Attention Head, Taken Apart: the QK and OV Circuits

Author: Ishwar Jangid
Canonical URL: https://ishwarj.com/papers/transformer-circuits/part-2-one-attention-head/
Updated: 2026-10-17
Source: https://github.com/ishwar6/ishwar-books/blob/main/content/papers/transformer-circuits/part-2-one-attention-head.md


In Part 1 an attention head was a closed box. It read the residual stream, computed something, and added its result back. That was enough to show that the stream is a sum of pieces. Now we open the box.

Inside, a head has four weight matrices: $$W_{\mathrm{Q}}$$, $$W_{\mathrm{K}}$$, $$W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$. The usual way to explain them talks about queries, keys and values. The paper takes a different view. It shows that a head really does **two separate jobs**. The first job decides **which earlier tokens to read from**. The second job decides **what information to move**, and where to put it. Each job is controlled by one matrix that is the product of two of the four. The first is the **QK circuit**, and the second is the **OV circuit**. By the end of this part you will be able to read both of them straight from the weights of a real model.

This part follows the paper's attention-head sections in order. We start with a small fact: heads in the same layer never interact, they simply add. Then we see a head as a machine that moves information from one token to another. Next comes the paper's compact formula for a head, $$h(x)=(A\otimes W_{\mathrm{O}} W_{\mathrm{V}})\,x$$, built up with a two-token example you can check by hand. After that we go through the paper's list of observations about heads, and we finish with the two circuits.

The real model is `attn-only-1l` from Part 1, a one-layer model with eight heads. We look closely at one of them, **head 0.3** (layer 0, head 3), on a ten-token prompt: *"I like green tea, so I drink green"*. The model's guess for the next word is " tea". We will see exactly how head 0.3 helps it get there.

## What is inside one head

Before the paper's sections, we need the standard description of a head in the paper's notation. The paper assumes you know it, so here it is from the start.

A head looks at the residual stream at every position. In Part 1, $$x_i$$ was the stream vector at position $$i$$. It has $$d_\text{model}=512$$ numbers. The head first makes three short vectors from each position, each with $$d_\text{head}=64$$ numbers:

$$
\begin{aligned}
q_i&=W_{\mathrm{Q}}\,x_i\\
k_j&=W_{\mathrm{K}}\,x_j\\
v_j&=W_{\mathrm{V}}\,x_j
\end{aligned}
$$

Here $$W_{\mathrm{Q}}$$, $$W_{\mathrm{K}}$$ and $$W_{\mathrm{V}}$$ are each 64 × 512. So each of them reads the 512-number stream and makes a 64-number vector. The vector $$q_i$$ is the **query** of position $$i$$, $$k_j$$ is the **key** of position $$j$$, and $$v_j$$ is the **value** of position $$j$$.

> [!DEFINITION] Query, key and value
> These are three vectors a head makes from each token. The **query** says what the current token is looking for. The **key** says what each token offers. The **value** is the information a token hands over if someone reads it. All three are made by multiplying the stream by a 64 × 512 matrix.

Next the head scores every pair of positions. The score of position $$j$$, seen from position $$i$$, is the dot product of a query and a key:

$$
s_{ij}=q_i\cdot k_j
$$

A large score means "token $$i$$ wants to read token $$j$$". The softmax then turns each row of scores into weights that add up to 1:

$$
A_{ij}=\frac{e^{s_{ij}}}{\sum_{j'\le i}e^{s_{ij'}}}
$$

The sum only runs over $$j'\le i$$, and $$A_{ij}=0$$ when $$j>i$$. A token may only read itself and earlier tokens, never later ones, because the model must not see the word it is trying to predict. The table $$A$$ is the **attention pattern**. It has one row and one column per position.

> [!DEFINITION] Attention pattern and causal mask
> The attention pattern $$A$$ is a square table with one row per **destination** token (the token that reads) and one column per **source** token (the token being read). Entry $$A_{ij}$$ says how much token $$i$$ reads from token $$j$$. Each row adds up to 1. The **causal mask** sets every entry above the diagonal to 0, so no token reads a later token. The paper writes this masked softmax as $$\text{softmax}^*$$.

Finally the head mixes the values with these weights, and writes the mix back into the stream:

$$
r_i=\sum_{j\le i}A_{ij}\,v_j
$$

$$
h(x)_i=W_{\mathrm{O}}\,r_i
$$

The vector $$r_i$$ is the **result vector** of position $$i$$. It has 64 numbers. The matrix $$W_{\mathrm{O}}$$ is 512 × 64, so $$h(x)_i$$ has 512 numbers, the width of the stream. This is the vector the head adds to the stream at position $$i$$.

> [!DEFINITION] Result vector
> The weighted average of the value vectors that one token reads, $$r_i=\sum_j A_{ij}v_j$$. It is still a short 64-number vector. The output matrix $$W_{\mathrm{O}}$$ turns it into a 512-number vector that can be added to the stream.

One detail differs between the paper and the code. Real implementations, including TransformerLens, divide every score by $$\sqrt{d_\text{head}}=8$$ before the softmax. The paper leaves this out, because the division can be folded into $$W_{\mathrm{Q}}$$. Here are the four matrices of head 0.3 in the paper's shapes, as printed by our script:

```text
== 1. ONE HEAD, FOUR MATRICES (attn-only-1l, head 0.3, paper shapes = TransformerLens shapes transposed)
  W_Q: paper shape (64, 512)  (32,768 numbers)
  W_K: paper shape (64, 512)  (32,768 numbers)
  W_V: paper shape (64, 512)  (32,768 numbers)
  W_O: paper shape (512, 64)  (32,768 numbers)
  d_model=512 d_head=64 heads per layer=8  (8 x 64 = 512)
  scores are divided by sqrt(d_head) = 8 before the softmax (the paper folds this into W_Q)
```

## Heads are independent and additive {§Attention Heads are Independent and Additive}

In Part 1 we wrote a layer as "every head adds its output to the stream". But that is not how the original transformer paper describes a layer. The paper first shows that the two descriptions are the same.

> [!PAPER] · Attention Heads are Independent and Additive
> [![The paragraph showing that stacking result vectors and multiplying by W_O^H equals the sum of each head's W_O times its result](https://ishwarj.com/img/papers/circuits/p2-independent.png/p2-independent.png)](/img/papers/circuits/p2-independent.png)
>
> **What it says:** the original transformer paper stacks the result vectors of all heads and multiplies them by one big output matrix $$W_{\mathrm{O}}^H$$. Split $$W_{\mathrm{O}}^H$$ into one block per head, and the big product turns into a sum. Each head multiplies its own result by its own block, and the results are added.
>
> **What it means:**
>
> Think of eight cooks who each add one ingredient to the same pot. They can hand all eight ingredients to one helper, who tips them in together. Or each cook can tip in their own. The soup is the same.
>
> The two ways give exactly the same numbers. The stacked way is faster on a GPU, because one big multiplication is cheaper than eight small ones. The sum way is easier to think about, because each head becomes a separate term that we can study alone.
>
> Code uses the first way, and the paper reasons with the second. The derivation below shows why they agree.

### The derivation

Take a layer with eight heads. Each head $$h$$ has a result vector $$r^h$$ of 64 numbers. The usual description stacks the eight result vectors into one long vector of $$8\times64=512$$ numbers. It then multiplies this long vector by one output matrix $$W_{\mathrm{O}}^H$$, which is 512 × 512.

To see why this equals a sum, we need one fact about any matrix-vector product. Multiplying a matrix $$W$$ by a vector $$v$$ is the same as adding up the columns of $$W$$, each one scaled by the matching number in $$v$$:

$$
W v=\sum_k v_k\,W_{:,k}
$$

Here $$W_{:,k}$$ means column $$k$$ of $$W$$. You can check this on any small example: row $$i$$ of the answer is $$\sum_k W_{ik}v_k$$, which is exactly row $$i$$ of the sum of scaled columns.

Now apply this to $$W_{\mathrm{O}}^H$$ and the stacked vector. The first 64 numbers of the stacked vector belong to head 1, and they only ever multiply the first 64 columns of $$W_{\mathrm{O}}^H$$. The next 64 numbers belong to head 2, and they only multiply the next 64 columns, and so on. So we can group the sum of columns by head. The first 64 columns of $$W_{\mathrm{O}}^H$$ form a 512 × 64 block, which we call $$W_{\mathrm{O}}^{1}$$. The next 64 columns form $$W_{\mathrm{O}}^{2}$$, and so on. With two heads, the product reads:

$$
\begin{aligned}
W_{\mathrm{O}}^H r&=\big[W_{\mathrm{O}}^{1}\;\;W_{\mathrm{O}}^{2}\big]\begin{bmatrix}r^{1}\\r^{2}\end{bmatrix}\\
&=W_{\mathrm{O}}^{1}r^{1}+W_{\mathrm{O}}^{2}r^{2}
\end{aligned}
$$

With eight heads the sum simply has eight terms. In words, the big output matrix is just the eight small output matrices placed side by side. Multiplying by it is the same as letting every head write on its own and adding the results.

**A toy example.** Our toy script uses a 3-number stream and two heads with 2-number results. Head 1 has $$r^1=(1,2)$$ and head 2 has $$r^2=(3,-1)$$. The figure works it out both ways.

<figure class="fig"><svg viewBox="0 0 760 340" role="img" aria-label="Two heads writing into a 3-number stream. Top: the stacked result vector (1, 2, 3, -1) times the 3 by 4 matrix W_O^H gives (7, 2, 2). Bottom: head 1 alone gives W_O^1 r^1 = (1, 2, 3), head 2 alone gives W_O^2 r^2 = (6, 0, -1), and their sum is (7, 2, 2), the same."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">1. The usual way: stack the result vectors, then one big multiply</text><rect class="s1" x="40.0" y="50.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="58.0" y="66.0" text-anchor="middle">1</text><rect class="s1" x="80.0" y="50.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="98.0" y="66.0" text-anchor="middle">0</text><rect class="s2" x="120.0" y="50.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="138.0" y="66.0" text-anchor="middle">2</text><rect class="s2" x="160.0" y="50.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="178.0" y="66.0" text-anchor="middle">0</text><rect class="s1" x="40.0" y="78.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="58.0" y="94.0" text-anchor="middle">0</text><rect class="s1" x="80.0" y="78.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="98.0" y="94.0" text-anchor="middle">1</text><rect class="s2" x="120.0" y="78.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="138.0" y="94.0" text-anchor="middle">0</text><rect class="s2" x="160.0" y="78.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="178.0" y="94.0" text-anchor="middle">0</text><rect class="s1" x="40.0" y="106.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="58.0" y="122.0" text-anchor="middle">1</text><rect class="s1" x="80.0" y="106.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="98.0" y="122.0" text-anchor="middle">1</text><rect class="s2" x="120.0" y="106.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="138.0" y="122.0" text-anchor="middle">0</text><rect class="s2" x="160.0" y="106.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="178.0" y="122.0" text-anchor="middle">1</text><text class="t-tick" x="118.0" y="150.0" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">O</tspan>ᴴ (3 × 4)</text><text class="t-title" x="214.0" y="95.0" text-anchor="middle">×</text><rect class="s1" x="232.0" y="36.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="250.0" y="52.0" text-anchor="middle">1</text><rect class="s1" x="232.0" y="64.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="250.0" y="80.0" text-anchor="middle">2</text><rect class="s2" x="232.0" y="92.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="250.0" y="108.0" text-anchor="middle">3</text><rect class="s2" x="232.0" y="120.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="250.0" y="136.0" text-anchor="middle">-1</text><text class="t-tick" x="250.0" y="164.0" text-anchor="middle">[r¹; r²]</text><text class="t-title" x="300.0" y="95.0" text-anchor="middle">=</text><rect class="s3" x="324.0" y="50.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="342.0" y="66.0" text-anchor="middle">7</text><rect class="s3" x="324.0" y="78.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="342.0" y="94.0" text-anchor="middle">2</text><rect class="s3" x="324.0" y="106.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="342.0" y="122.0" text-anchor="middle">2</text><text class="t-tick" x="342.0" y="150.0" text-anchor="middle">result</text><text class="t-muted" x="420.0" y="70.0" text-anchor="start">columns 1-2 of W<tspan baseline-shift="sub" style="font-size:72%">O</tspan>ᴴ belong to head 1,</text><text class="t-muted" x="420.0" y="88.0" text-anchor="start">columns 3-4 to head 2</text><text class="t-muted" x="420.0" y="114.0" text-anchor="start">1×1 + 0×2 + 2×3 + 0×(-1) = 7</text><text class="t-title" x="24.0" y="190.0" text-anchor="start">2. The paper's way: each head uses its own slice of W<tspan baseline-shift="sub" style="font-size:72%">O</tspan> and the results are added</text><rect class="s1" x="40.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="58.0" y="230.0" text-anchor="middle">1</text><rect class="s1" x="80.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="98.0" y="230.0" text-anchor="middle">0</text><rect class="s1" x="40.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="58.0" y="258.0" text-anchor="middle">0</text><rect class="s1" x="80.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="98.0" y="258.0" text-anchor="middle">1</text><rect class="s1" x="40.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="58.0" y="286.0" text-anchor="middle">1</text><rect class="s1" x="80.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="98.0" y="286.0" text-anchor="middle">1</text><text class="t-tick" x="78.0" y="314.0" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">O</tspan>¹</text><text class="t-title" x="130.0" y="259.0" text-anchor="middle">×</text><rect class="s1" x="144.0" y="228.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="162.0" y="244.0" text-anchor="middle">1</text><rect class="s1" x="144.0" y="256.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="162.0" y="272.0" text-anchor="middle">2</text><text class="t-tick" x="162.0" y="314.0" text-anchor="middle">r¹</text><text class="t-title" x="198.0" y="259.0" text-anchor="middle">=</text><rect class="s1" x="214.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="232.0" y="230.0" text-anchor="middle">1</text><rect class="s1" x="214.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="232.0" y="258.0" text-anchor="middle">2</text><rect class="s1" x="214.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="232.0" y="286.0" text-anchor="middle">3</text><text class="t-title" x="276.0" y="259.0" text-anchor="middle">+</text><rect class="s2" x="340.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="358.0" y="230.0" text-anchor="middle">2</text><rect class="s2" x="380.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="398.0" y="230.0" text-anchor="middle">0</text><rect class="s2" x="340.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="358.0" y="258.0" text-anchor="middle">0</text><rect class="s2" x="380.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="398.0" y="258.0" text-anchor="middle">0</text><rect class="s2" x="340.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="358.0" y="286.0" text-anchor="middle">0</text><rect class="s2" x="380.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="398.0" y="286.0" text-anchor="middle">1</text><text class="t-tick" x="378.0" y="314.0" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">O</tspan>²</text><text class="t-title" x="430.0" y="259.0" text-anchor="middle">×</text><rect class="s2" x="444.0" y="228.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="462.0" y="244.0" text-anchor="middle">3</text><rect class="s2" x="444.0" y="256.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="462.0" y="272.0" text-anchor="middle">-1</text><text class="t-tick" x="462.0" y="314.0" text-anchor="middle">r²</text><text class="t-title" x="498.0" y="259.0" text-anchor="middle">=</text><rect class="s2" x="514.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="532.0" y="230.0" text-anchor="middle">6</text><rect class="s2" x="514.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="532.0" y="258.0" text-anchor="middle">0</text><rect class="s2" x="514.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="532.0" y="286.0" text-anchor="middle">-1</text><text class="t-title" x="590.0" y="251.0" text-anchor="middle">=</text><rect class="s3" x="610.0" y="214.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="628.0" y="230.0" text-anchor="middle">7</text><rect class="s3" x="610.0" y="242.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="628.0" y="258.0" text-anchor="middle">2</text><rect class="s3" x="610.0" y="270.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="628.0" y="286.0" text-anchor="middle">2</text><text class="t-tick" x="628.0" y="318.0" text-anchor="middle">same result</text></svg><figcaption>Two ways to compute the same layer output. At the top, the two result vectors are stacked into (1, 2, 3, -1) and multiplied by the 3 by 4 matrix W_O^H, whose first two columns belong to head 1 and last two to head 2. At the bottom, each head multiplies its own result by its own 3 by 2 block, giving (1, 2, 3) and (6, 0, -1), and the two are added. Both ways give (7, 2, 2).</figcaption></figure>

**On the real model.** Our script takes the eight result vectors that TransformerLens stores (`hook_z`), stacks them, and multiplies by the big matrix. It also multiplies each head by its own slice of $$W_{\mathrm{O}}$$ and adds the eight answers. Finally it compares both with what the model really added to the stream:

```python
z = cache['blocks.0.attn.hook_z'][0]                 # [10 positions, 8 heads, 64]: every r^h
big = z.reshape(10, 512) @ model.W_O[0].reshape(512, 512)          # stack, then one multiply
summed = sum(z[:, h] @ model.W_O[0, h] for h in range(8))          # each head alone, then add
```

```text
== 2. CONCATENATE-THEN-MULTIPLY EQUALS THE SUM OF EACH HEAD THROUGH ITS OWN SLICE OF W_O
  attn-only-1l layer 0: W_O^H is (512, 512) (paper shape); |concat - sum| max = 1.2e-06; |sum - model| max = 3.5e-06
  attn-only-2l layer 0: W_O^H is (512, 512) (paper shape); |concat - sum| max = 3.3e-06; |sum - model| max = 3.8e-06
  attn-only-2l layer 1: W_O^H is (512, 512) (paper shape); |concat - sum| max = 5.7e-06; |sum - model| max = 4.8e-06
```

In all three layers the largest difference is a few millionths, which is rounding noise. So the paper's picture is exact: a layer is eight heads that each write on their own.

**Why this is useful.** A head in a layer never sees what the other heads in the same layer write. They all read the same stream, and their outputs are only added afterwards. So we can study one head at a time, which is what the rest of this part does. This is also why, in Part 1, the final stream split cleanly into one piece per head.

## A head moves information {§Attention Heads as Information Movement}

If heads work alone, what does each one do? The paper's answer is short.

> [!PAPER] · Attention Heads as Information Movement
> [![The paragraph stating that the fundamental action of attention heads is moving information, and that where to move from is separable from what is moved](https://ishwarj.com/img/papers/circuits/p2-moving.pngcuits/p2-moving.png)](/img/papers/circuits/p2-moving.png)
>
> **What it says:** "The fundamental action of attention heads is moving information." A head reads from the stream of one token and writes into the stream of another. **Which tokens** the information comes from is "completely separable" from **what information** is read and how it is written.
>
> **What it means:**
>
> Think of a librarian who carries a page from one book to another. Two questions describe each trip: which book did the page come from, and what was written on it? The paper says that inside a head, these two questions have separate answers.
>
> This is the idea behind the whole part. A head has a "where" part and a "what" part, and the two can be studied apart. The rest of the section turns this sentence into an equation.

Remember from Part 1 that every position has its own residual stream. Before attention, the stream at position 9 only knows about token 9. A head is the only part of this model that can carry information **across** positions. The paper draws it like this:

> [!PAPER] · Attention Heads as Information Movement
> [![The paper's figure: a band of information leaves the residual stream of token A and enters the residual stream of token B, in a different place](https://ishwarj.com/img/papers/circuits/p2-moving-fig.pngs/p2-moving-fig.png)](/img/papers/circuits/p2-moving-fig.png)
>
> **What it says:** attention heads copy information from the residual stream of one token to the residual stream of another. "They typically write to a different subspace than they read from."
>
> **What it means:**
>
> Follow the band in the drawing. It leaves token A's stream from one lane and enters token B's stream in another lane. So a head does not only copy numbers between tokens. It can also move them to a new place in the stream.
>
> Token B's stream already holds information about token B. When the copied message goes into a different subspace, it does not get mixed up with what was there. We measure this on the real model later in this part.

### The three steps

The paper then writes a head as three steps. These are the same equations as in our first section, but now each step is labelled by what it does.

> [!PAPER] · Attention Heads as Information Movement
> [![The three steps of an attention head: compute value vectors, mix them with the attention pattern, project out with W_O; and the remark that x is multiplied on different sides](https://ishwarj.com/img/papers/circuits/p2-three-steps.png/p2-three-steps.png)](/img/papers/circuits/p2-three-steps.png)
>
> **What it says:** given an attention pattern, a head works in three steps. (1) It computes a value vector for each token, $$v_i=W_{\mathrm{V}} x_i$$. (2) It mixes the value vectors with the pattern, $$r_i=\sum_j A_{ij}v_j$$. (3) It computes the output for each token, $$h(x)_i=W_{\mathrm{O}} r_i$$. Treat $$x$$ as a table with one vector per token: $$W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$ multiply it on one side, and $$A$$ on the other.
>
> **What it means:**
>
> Picture three machines in a row in a post office. The first stamps each parcel on its own. The second is the only one that moves parcels between addresses. The third stamps each parcel again, on its own.
>
> Step 1 and step 3 act on each token separately. Step 2 is the only step that moves anything between tokens. That is the separation the paper promised: $$A$$ handles "where", and $$W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$ handle "what".
>
> The last sentence, about multiplying $$x$$ on different sides, is the key to the tensor notation later in this part.

Let us run the three steps by hand on a tiny head. The stream has 3 numbers per token, and there are 3 tokens. The head has $$d_\text{head}=1$$, so every value is a single number. Its matrices are $$W_{\mathrm{V}}=(1,1,0)$$, which adds up dimensions 1 and 2, and $$W_{\mathrm{O}}=(0,0,1)^\top$$, which writes into dimension 3. The attention pattern is given.

<figure class="fig"><svg viewBox="0 0 760 320" role="img" aria-label="One toy head in three steps. Read: each token's value is W_V x, giving 2, 1 and 0. Mix: the attention pattern averages the values, so token 3 gets 0.8 times 2 plus 0.2 times 1, which is 1.8; the results are 2, 1.5 and 1.8. Write: W_O puts each result into dimension 3 of that token's stream, giving (0, 0, 2), (0, 0, 1.5) and (0, 0, 1.8)."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><rect class="box" x="10.0" y="10.0" width="240.0" height="300.0" rx="12"/><circle class="node on" cx="28.0" cy="28.0" r="11"/><text class="t-note" x="28.0" y="32.5" text-anchor="middle">1</text><text class="t-title" x="46.0" y="33.0" text-anchor="start">Read: v = W<tspan baseline-shift="sub" style="font-size:72%">V</tspan> x</text><text class="t-tick" x="26.0" y="90.0" text-anchor="start">token 1</text><rect class="s1" x="80.0" y="72.0" width="26" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="93.0" y="88.0" text-anchor="middle">2</text><rect class="s1" x="110.0" y="72.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="123.0" y="88.0" text-anchor="middle">0</text><rect class="s1" x="140.0" y="72.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="153.0" y="88.0" text-anchor="middle">0</text><line class="edge" x1="172.0" y1="84.0" x2="196.0" y2="84.0" marker-end="url(#ah)"/><rect class="s2" x="202.0" y="72.0" width="30" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="217.0" y="88.0" text-anchor="middle">2</text><text class="t-tick" x="26.0" y="152.0" text-anchor="start">token 2</text><rect class="s1" x="80.0" y="134.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="93.0" y="150.0" text-anchor="middle">0</text><rect class="s1" x="110.0" y="134.0" width="26" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="123.0" y="150.0" text-anchor="middle">1</text><rect class="s1" x="140.0" y="134.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="153.0" y="150.0" text-anchor="middle">0</text><line class="edge" x1="172.0" y1="146.0" x2="196.0" y2="146.0" marker-end="url(#ah)"/><rect class="s2" x="202.0" y="134.0" width="30" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="217.0" y="150.0" text-anchor="middle">1</text><text class="t-tick" x="26.0" y="214.0" text-anchor="start">token 3</text><rect class="s1" x="80.0" y="196.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="93.0" y="212.0" text-anchor="middle">0</text><rect class="s1" x="110.0" y="196.0" width="26" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="123.0" y="212.0" text-anchor="middle">0</text><rect class="s1" x="140.0" y="196.0" width="26" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="153.0" y="212.0" text-anchor="middle">1</text><line class="edge" x1="172.0" y1="208.0" x2="196.0" y2="208.0" marker-end="url(#ah)"/><rect class="s2" x="202.0" y="196.0" width="30" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="217.0" y="212.0" text-anchor="middle">0</text><text class="t-muted" x="80.0" y="64.0" text-anchor="start">x (3 numbers)</text><text class="t-muted" x="202.0" y="64.0" text-anchor="start">v</text><text class="t-muted" x="26.0" y="276.0" text-anchor="start">W<tspan baseline-shift="sub" style="font-size:72%">V</tspan> = (1, 1, 0) adds</text><text class="t-muted" x="26.0" y="294.0" text-anchor="start">dimensions 1 and 2</text><rect class="box" x="260.0" y="10.0" width="240.0" height="300.0" rx="12"/><circle class="node on" cx="278.0" cy="28.0" r="11"/><text class="t-note" x="278.0" y="32.5" text-anchor="middle">2</text><text class="t-title" x="296.0" y="33.0" text-anchor="start">Mix: r = A v</text><text class="t-tick" x="340.0" y="84.0" text-anchor="middle">v=2</text><text class="t-tick" x="380.0" y="84.0" text-anchor="middle">v=1</text><text class="t-tick" x="420.0" y="84.0" text-anchor="middle">v=0</text><text class="t-tick" x="312.0" y="116.0" text-anchor="end">to 1</text><rect class="cell" x="322" y="94" width="36" height="36" rx="3" style="fill-opacity:0.80"/><text class="t-val" x="340.0" y="116.0" text-anchor="middle">1</text><rect class="cell-masked" x="362" y="94" width="36" height="36" rx="3"/><rect class="cell-masked" x="402" y="94" width="36" height="36" rx="3"/><rect class="s2" x="454.0" y="98.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="472.0" y="114.0" text-anchor="middle">2</text><text class="t-tick" x="312.0" y="156.0" text-anchor="end">to 2</text><rect class="cell" x="322" y="134" width="36" height="36" rx="3" style="fill-opacity:0.40"/><text class="t-val" x="340.0" y="156.0" text-anchor="middle">0.5</text><rect class="cell" x="362" y="134" width="36" height="36" rx="3" style="fill-opacity:0.40"/><text class="t-val" x="380.0" y="156.0" text-anchor="middle">0.5</text><rect class="cell-masked" x="402" y="134" width="36" height="36" rx="3"/><rect class="s2" x="454.0" y="138.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="472.0" y="154.0" text-anchor="middle">1.5</text><text class="t-tick" x="312.0" y="196.0" text-anchor="end">to 3</text><rect class="cell" x="322" y="174" width="36" height="36" rx="3" style="fill-opacity:0.64"/><text class="t-val" x="340.0" y="196.0" text-anchor="middle">0.8</text><rect class="cell" x="362" y="174" width="36" height="36" rx="3" style="fill-opacity:0.16"/><text class="t-val" x="380.0" y="196.0" text-anchor="middle">0.2</text><rect class="cell" x="402" y="174" width="36" height="36" rx="3" style="fill-opacity:0.08"/><text class="t-val" x="420.0" y="196.0" text-anchor="middle">0</text><rect class="s2" x="454.0" y="178.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="472.0" y="194.0" text-anchor="middle">1.8</text><text class="t-muted" x="472.0" y="84.0" text-anchor="middle">r</text><text class="t-muted" x="380.0" y="66.0" text-anchor="middle">A: from token (column)</text><text class="t-muted" x="276.0" y="236.0" text-anchor="start">row 3: 0.8 × 2 + 0.2 × 1 = 1.8</text><text class="t-muted" x="276.0" y="258.0" text-anchor="start">each row adds up to 1, and</text><text class="t-muted" x="276.0" y="276.0" text-anchor="start">no token looks at a later one</text><rect class="box" x="510.0" y="10.0" width="240.0" height="300.0" rx="12"/><circle class="node on" cx="528.0" cy="28.0" r="11"/><text class="t-note" x="528.0" y="32.5" text-anchor="middle">3</text><text class="t-title" x="546.0" y="33.0" text-anchor="start">Write: h(x) = W<tspan baseline-shift="sub" style="font-size:72%">O</tspan> r</text><text class="t-tick" x="526.0" y="90.0" text-anchor="start">token 1</text><rect class="s3" x="590.0" y="72.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="608.0" y="88.0" text-anchor="middle">0</text><rect class="s3" x="630.0" y="72.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="648.0" y="88.0" text-anchor="middle">0</text><rect class="s3" x="670.0" y="72.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="688.0" y="88.0" text-anchor="middle">2</text><text class="t-tick" x="526.0" y="152.0" text-anchor="start">token 2</text><rect class="s3" x="590.0" y="134.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="608.0" y="150.0" text-anchor="middle">0</text><rect class="s3" x="630.0" y="134.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="648.0" y="150.0" text-anchor="middle">0</text><rect class="s3" x="670.0" y="134.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="688.0" y="150.0" text-anchor="middle">1.5</text><text class="t-tick" x="526.0" y="214.0" text-anchor="start">token 3</text><rect class="s3" x="590.0" y="196.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="608.0" y="212.0" text-anchor="middle">0</text><rect class="s3" x="630.0" y="196.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="648.0" y="212.0" text-anchor="middle">0</text><rect class="s3" x="670.0" y="196.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="688.0" y="212.0" text-anchor="middle">1.8</text><text class="t-muted" x="590.0" y="64.0" text-anchor="start">added to the stream</text><text class="t-muted" x="526.0" y="276.0" text-anchor="start">W<tspan baseline-shift="sub" style="font-size:72%">O</tspan> = (0, 0, 1)ᵀ writes</text><text class="t-muted" x="526.0" y="294.0" text-anchor="start">into dimension 3 only</text></svg><figcaption>One toy head in three steps. In step 1, each token's value is W_V x: the three tokens give 2, 1 and 0. In step 2, the pattern A mixes the values: token 2 takes half of tokens 1 and 2 and gets 1.5, and token 3 takes 0.8 of token 1 and 0.2 of token 2 and gets 1.8. In step 3, W_O writes each result into dimension 3 of that token's own stream.</figcaption></figure>

Look at token 3. Its own stream is $$(0,0,1)$$, and its own value is 0. Yet after the head, dimension 3 of its stream has received 1.8. That number came almost entirely from token 1, which had a 2 in its first dimension. The information "token 1 has something in dimension 1" has moved to token 3, and it has landed in dimension 3. This is the paper's picture in three small tables.

### A real attention pattern

Now the real head. We run `attn-only-1l` on our prompt and keep the pattern of head 0.3:

```python
logits, cache = model.run_with_cache('I like green tea, so I drink green')
A = cache['blocks.0.attn.hook_pattern'][0, 3]       # [10, 10]: head 0.3, row = destination, column = source
```

```text
== 3. ONE HEAD ON A REAL PROMPT (attn-only-1l, head 0.3)
  prompt: ['<|BOS|>', 'I', ' like', ' green', ' tea', ',', ' so', ' I', ' drink', ' green']  (10 tokens); the model predicts ' tea' next
  row of A for the last token ' green': ' tea' 0.37, '<|BOS|>' 0.37, ' drink' 0.15
  every row adds up to 1: max |row sum - 1| = 1.2e-07; entries above the diagonal (the future) are 0
```

<figure class="fig"><svg viewBox="0 0 760 620" role="img" aria-label="The 10 by 10 attention pattern of head 0.3 on the prompt "I like green tea, so I drink green". Each row adds up to 1 and the upper triangle is empty. In the last row, the final "green" puts 0.37 on "tea", 0.37 on the first token BOS and 0.15 on "drink"."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="415.0" y="36.0" text-anchor="middle">attn-only-1l, head 0.3: the attention pattern A</text><text class="t-muted" x="415.0" y="54.0" text-anchor="middle">source (the token read from)</text><text class="t-tick" x="190.0" y="72.0" text-anchor="middle">BOS</text><text class="t-tick" x="240.0" y="72.0" text-anchor="middle">I</text><text class="t-tick" x="290.0" y="72.0" text-anchor="middle">like</text><text class="t-tick" x="340.0" y="72.0" text-anchor="middle">green</text><text class="t-tick" x="390.0" y="72.0" text-anchor="middle">tea</text><text class="t-tick" x="440.0" y="72.0" text-anchor="middle">,</text><text class="t-tick" x="490.0" y="72.0" text-anchor="middle">so</text><text class="t-tick" x="540.0" y="72.0" text-anchor="middle">I</text><text class="t-tick" x="590.0" y="72.0" text-anchor="middle">drink</text><text class="t-tick" x="640.0" y="72.0" text-anchor="middle">green</text><text class="t-tick" x="157.0" y="109.0" text-anchor="end">BOS</text><g class="mark"><title>BOS attends to BOS: 1.00</title><rect class="cell" x="166.5" y="81.5" width="47.0" height="47.0" rx="3" style="fill-opacity:1.00"/></g><text class="t-cell on" x="190.0" y="109.0" text-anchor="middle">1.00</text><rect class="cell-masked" x="216.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="231.0" y1="96.0" x2="249.0" y2="114.0"/><line class="edge" x1="249.0" y1="96.0" x2="231.0" y2="114.0"/><rect class="cell-masked" x="266.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="281.0" y1="96.0" x2="299.0" y2="114.0"/><line class="edge" x1="299.0" y1="96.0" x2="281.0" y2="114.0"/><rect class="cell-masked" x="316.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="331.0" y1="96.0" x2="349.0" y2="114.0"/><line class="edge" x1="349.0" y1="96.0" x2="331.0" y2="114.0"/><rect class="cell-masked" x="366.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="381.0" y1="96.0" x2="399.0" y2="114.0"/><line class="edge" x1="399.0" y1="96.0" x2="381.0" y2="114.0"/><rect class="cell-masked" x="416.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="431.0" y1="96.0" x2="449.0" y2="114.0"/><line class="edge" x1="449.0" y1="96.0" x2="431.0" y2="114.0"/><rect class="cell-masked" x="466.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="96.0" x2="499.0" y2="114.0"/><line class="edge" x1="499.0" y1="96.0" x2="481.0" y2="114.0"/><rect class="cell-masked" x="516.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="96.0" x2="549.0" y2="114.0"/><line class="edge" x1="549.0" y1="96.0" x2="531.0" y2="114.0"/><rect class="cell-masked" x="566.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="96.0" x2="599.0" y2="114.0"/><line class="edge" x1="599.0" y1="96.0" x2="581.0" y2="114.0"/><rect class="cell-masked" x="616.5" y="81.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="96.0" x2="649.0" y2="114.0"/><line class="edge" x1="649.0" y1="96.0" x2="631.0" y2="114.0"/><text class="t-tick" x="157.0" y="159.0" text-anchor="end">I</text><g class="mark"><title>I attends to BOS: 0.99</title><rect class="cell" x="166.5" y="131.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.99"/></g><text class="t-cell on" x="190.0" y="159.0" text-anchor="middle">0.99</text><g class="mark"><title>I attends to I: 0.01</title><rect class="cell" x="216.5" y="131.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="159.0" text-anchor="middle">0.01</text><rect class="cell-masked" x="266.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="281.0" y1="146.0" x2="299.0" y2="164.0"/><line class="edge" x1="299.0" y1="146.0" x2="281.0" y2="164.0"/><rect class="cell-masked" x="316.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="331.0" y1="146.0" x2="349.0" y2="164.0"/><line class="edge" x1="349.0" y1="146.0" x2="331.0" y2="164.0"/><rect class="cell-masked" x="366.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="381.0" y1="146.0" x2="399.0" y2="164.0"/><line class="edge" x1="399.0" y1="146.0" x2="381.0" y2="164.0"/><rect class="cell-masked" x="416.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="431.0" y1="146.0" x2="449.0" y2="164.0"/><line class="edge" x1="449.0" y1="146.0" x2="431.0" y2="164.0"/><rect class="cell-masked" x="466.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="146.0" x2="499.0" y2="164.0"/><line class="edge" x1="499.0" y1="146.0" x2="481.0" y2="164.0"/><rect class="cell-masked" x="516.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="146.0" x2="549.0" y2="164.0"/><line class="edge" x1="549.0" y1="146.0" x2="531.0" y2="164.0"/><rect class="cell-masked" x="566.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="146.0" x2="599.0" y2="164.0"/><line class="edge" x1="599.0" y1="146.0" x2="581.0" y2="164.0"/><rect class="cell-masked" x="616.5" y="131.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="146.0" x2="649.0" y2="164.0"/><line class="edge" x1="649.0" y1="146.0" x2="631.0" y2="164.0"/><text class="t-tick" x="157.0" y="209.0" text-anchor="end">like</text><g class="mark"><title>like attends to BOS: 0.99</title><rect class="cell" x="166.5" y="181.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.99"/></g><text class="t-cell on" x="190.0" y="209.0" text-anchor="middle">0.99</text><g class="mark"><title>like attends to I: 0.01</title><rect class="cell" x="216.5" y="181.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="209.0" text-anchor="middle">0.01</text><g class="mark"><title>like attends to like: 0.00</title><rect class="cell" x="266.5" y="181.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="209.0" text-anchor="middle">0.00</text><rect class="cell-masked" x="316.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="331.0" y1="196.0" x2="349.0" y2="214.0"/><line class="edge" x1="349.0" y1="196.0" x2="331.0" y2="214.0"/><rect class="cell-masked" x="366.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="381.0" y1="196.0" x2="399.0" y2="214.0"/><line class="edge" x1="399.0" y1="196.0" x2="381.0" y2="214.0"/><rect class="cell-masked" x="416.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="431.0" y1="196.0" x2="449.0" y2="214.0"/><line class="edge" x1="449.0" y1="196.0" x2="431.0" y2="214.0"/><rect class="cell-masked" x="466.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="196.0" x2="499.0" y2="214.0"/><line class="edge" x1="499.0" y1="196.0" x2="481.0" y2="214.0"/><rect class="cell-masked" x="516.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="196.0" x2="549.0" y2="214.0"/><line class="edge" x1="549.0" y1="196.0" x2="531.0" y2="214.0"/><rect class="cell-masked" x="566.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="196.0" x2="599.0" y2="214.0"/><line class="edge" x1="599.0" y1="196.0" x2="581.0" y2="214.0"/><rect class="cell-masked" x="616.5" y="181.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="196.0" x2="649.0" y2="214.0"/><line class="edge" x1="649.0" y1="196.0" x2="631.0" y2="214.0"/><text class="t-tick" x="157.0" y="259.0" text-anchor="end">green</text><g class="mark"><title>green attends to BOS: 0.96</title><rect class="cell" x="166.5" y="231.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.96"/></g><text class="t-cell on" x="190.0" y="259.0" text-anchor="middle">0.96</text><g class="mark"><title>green attends to I: 0.01</title><rect class="cell" x="216.5" y="231.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="259.0" text-anchor="middle">0.01</text><g class="mark"><title>green attends to like: 0.00</title><rect class="cell" x="266.5" y="231.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="259.0" text-anchor="middle">0.00</text><g class="mark"><title>green attends to green: 0.03</title><rect class="cell" x="316.5" y="231.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="259.0" text-anchor="middle">0.03</text><rect class="cell-masked" x="366.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="381.0" y1="246.0" x2="399.0" y2="264.0"/><line class="edge" x1="399.0" y1="246.0" x2="381.0" y2="264.0"/><rect class="cell-masked" x="416.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="431.0" y1="246.0" x2="449.0" y2="264.0"/><line class="edge" x1="449.0" y1="246.0" x2="431.0" y2="264.0"/><rect class="cell-masked" x="466.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="246.0" x2="499.0" y2="264.0"/><line class="edge" x1="499.0" y1="246.0" x2="481.0" y2="264.0"/><rect class="cell-masked" x="516.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="246.0" x2="549.0" y2="264.0"/><line class="edge" x1="549.0" y1="246.0" x2="531.0" y2="264.0"/><rect class="cell-masked" x="566.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="246.0" x2="599.0" y2="264.0"/><line class="edge" x1="599.0" y1="246.0" x2="581.0" y2="264.0"/><rect class="cell-masked" x="616.5" y="231.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="246.0" x2="649.0" y2="264.0"/><line class="edge" x1="649.0" y1="246.0" x2="631.0" y2="264.0"/><text class="t-tick" x="157.0" y="309.0" text-anchor="end">tea</text><g class="mark"><title>tea attends to BOS: 0.77</title><rect class="cell" x="166.5" y="281.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.77"/></g><text class="t-cell on" x="190.0" y="309.0" text-anchor="middle">0.77</text><g class="mark"><title>tea attends to I: 0.01</title><rect class="cell" x="216.5" y="281.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="309.0" text-anchor="middle">0.01</text><g class="mark"><title>tea attends to like: 0.01</title><rect class="cell" x="266.5" y="281.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="309.0" text-anchor="middle">0.01</text><g class="mark"><title>tea attends to green: 0.04</title><rect class="cell" x="316.5" y="281.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="309.0" text-anchor="middle">0.04</text><g class="mark"><title>tea attends to tea: 0.18</title><rect class="cell" x="366.5" y="281.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.18"/></g><text class="t-cell" x="390.0" y="309.0" text-anchor="middle">0.18</text><rect class="cell-masked" x="416.5" y="281.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="431.0" y1="296.0" x2="449.0" y2="314.0"/><line class="edge" x1="449.0" y1="296.0" x2="431.0" y2="314.0"/><rect class="cell-masked" x="466.5" y="281.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="296.0" x2="499.0" y2="314.0"/><line class="edge" x1="499.0" y1="296.0" x2="481.0" y2="314.0"/><rect class="cell-masked" x="516.5" y="281.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="296.0" x2="549.0" y2="314.0"/><line class="edge" x1="549.0" y1="296.0" x2="531.0" y2="314.0"/><rect class="cell-masked" x="566.5" y="281.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="296.0" x2="599.0" y2="314.0"/><line class="edge" x1="599.0" y1="296.0" x2="581.0" y2="314.0"/><rect class="cell-masked" x="616.5" y="281.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="296.0" x2="649.0" y2="314.0"/><line class="edge" x1="649.0" y1="296.0" x2="631.0" y2="314.0"/><text class="t-tick" x="157.0" y="359.0" text-anchor="end">,</text><g class="mark"><title>, attends to BOS: 0.64</title><rect class="cell" x="166.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.64"/></g><text class="t-cell on" x="190.0" y="359.0" text-anchor="middle">0.64</text><g class="mark"><title>, attends to I: 0.01</title><rect class="cell" x="216.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="359.0" text-anchor="middle">0.01</text><g class="mark"><title>, attends to like: 0.00</title><rect class="cell" x="266.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="359.0" text-anchor="middle">0.00</text><g class="mark"><title>, attends to green: 0.07</title><rect class="cell" x="316.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="359.0" text-anchor="middle">0.07</text><g class="mark"><title>, attends to tea: 0.25</title><rect class="cell" x="366.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.25"/></g><text class="t-cell" x="390.0" y="359.0" text-anchor="middle">0.25</text><g class="mark"><title>, attends to ,: 0.02</title><rect class="cell" x="416.5" y="331.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="440.0" y="359.0" text-anchor="middle">0.02</text><rect class="cell-masked" x="466.5" y="331.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="481.0" y1="346.0" x2="499.0" y2="364.0"/><line class="edge" x1="499.0" y1="346.0" x2="481.0" y2="364.0"/><rect class="cell-masked" x="516.5" y="331.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="346.0" x2="549.0" y2="364.0"/><line class="edge" x1="549.0" y1="346.0" x2="531.0" y2="364.0"/><rect class="cell-masked" x="566.5" y="331.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="346.0" x2="599.0" y2="364.0"/><line class="edge" x1="599.0" y1="346.0" x2="581.0" y2="364.0"/><rect class="cell-masked" x="616.5" y="331.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="346.0" x2="649.0" y2="364.0"/><line class="edge" x1="649.0" y1="346.0" x2="631.0" y2="364.0"/><text class="t-tick" x="157.0" y="409.0" text-anchor="end">so</text><g class="mark"><title>so attends to BOS: 0.48</title><rect class="cell" x="166.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.48"/></g><text class="t-cell" x="190.0" y="409.0" text-anchor="middle">0.48</text><g class="mark"><title>so attends to I: 0.04</title><rect class="cell" x="216.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="409.0" text-anchor="middle">0.04</text><g class="mark"><title>so attends to like: 0.01</title><rect class="cell" x="266.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="409.0" text-anchor="middle">0.01</text><g class="mark"><title>so attends to green: 0.07</title><rect class="cell" x="316.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="409.0" text-anchor="middle">0.07</text><g class="mark"><title>so attends to tea: 0.21</title><rect class="cell" x="366.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.21"/></g><text class="t-cell" x="390.0" y="409.0" text-anchor="middle">0.21</text><g class="mark"><title>so attends to ,: 0.18</title><rect class="cell" x="416.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.18"/></g><text class="t-cell" x="440.0" y="409.0" text-anchor="middle">0.18</text><g class="mark"><title>so attends to so: 0.00</title><rect class="cell" x="466.5" y="381.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="490.0" y="409.0" text-anchor="middle">0.00</text><rect class="cell-masked" x="516.5" y="381.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="531.0" y1="396.0" x2="549.0" y2="414.0"/><line class="edge" x1="549.0" y1="396.0" x2="531.0" y2="414.0"/><rect class="cell-masked" x="566.5" y="381.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="396.0" x2="599.0" y2="414.0"/><line class="edge" x1="599.0" y1="396.0" x2="581.0" y2="414.0"/><rect class="cell-masked" x="616.5" y="381.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="396.0" x2="649.0" y2="414.0"/><line class="edge" x1="649.0" y1="396.0" x2="631.0" y2="414.0"/><text class="t-tick" x="157.0" y="459.0" text-anchor="end">I</text><g class="mark"><title>I attends to BOS: 0.69</title><rect class="cell" x="166.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.69"/></g><text class="t-cell on" x="190.0" y="459.0" text-anchor="middle">0.69</text><g class="mark"><title>I attends to I: 0.01</title><rect class="cell" x="216.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="459.0" text-anchor="middle">0.01</text><g class="mark"><title>I attends to like: 0.02</title><rect class="cell" x="266.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="459.0" text-anchor="middle">0.02</text><g class="mark"><title>I attends to green: 0.04</title><rect class="cell" x="316.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="459.0" text-anchor="middle">0.04</text><g class="mark"><title>I attends to tea: 0.17</title><rect class="cell" x="366.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.17"/></g><text class="t-cell" x="390.0" y="459.0" text-anchor="middle">0.17</text><g class="mark"><title>I attends to ,: 0.06</title><rect class="cell" x="416.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="440.0" y="459.0" text-anchor="middle">0.06</text><g class="mark"><title>I attends to so: 0.01</title><rect class="cell" x="466.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="490.0" y="459.0" text-anchor="middle">0.01</text><g class="mark"><title>I attends to I: 0.01</title><rect class="cell" x="516.5" y="431.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="540.0" y="459.0" text-anchor="middle">0.01</text><rect class="cell-masked" x="566.5" y="431.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="581.0" y1="446.0" x2="599.0" y2="464.0"/><line class="edge" x1="599.0" y1="446.0" x2="581.0" y2="464.0"/><rect class="cell-masked" x="616.5" y="431.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="446.0" x2="649.0" y2="464.0"/><line class="edge" x1="649.0" y1="446.0" x2="631.0" y2="464.0"/><text class="t-tick" x="157.0" y="509.0" text-anchor="end">drink</text><g class="mark"><title>drink attends to BOS: 0.48</title><rect class="cell" x="166.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.48"/></g><text class="t-cell" x="190.0" y="509.0" text-anchor="middle">0.48</text><g class="mark"><title>drink attends to I: 0.02</title><rect class="cell" x="216.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="509.0" text-anchor="middle">0.02</text><g class="mark"><title>drink attends to like: 0.00</title><rect class="cell" x="266.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="509.0" text-anchor="middle">0.00</text><g class="mark"><title>drink attends to green: 0.04</title><rect class="cell" x="316.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="509.0" text-anchor="middle">0.04</text><g class="mark"><title>drink attends to tea: 0.20</title><rect class="cell" x="366.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.20"/></g><text class="t-cell" x="390.0" y="509.0" text-anchor="middle">0.20</text><g class="mark"><title>drink attends to ,: 0.14</title><rect class="cell" x="416.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.14"/></g><text class="t-cell" x="440.0" y="509.0" text-anchor="middle">0.14</text><g class="mark"><title>drink attends to so: 0.00</title><rect class="cell" x="466.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="490.0" y="509.0" text-anchor="middle">0.00</text><g class="mark"><title>drink attends to I: 0.03</title><rect class="cell" x="516.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="540.0" y="509.0" text-anchor="middle">0.03</text><g class="mark"><title>drink attends to drink: 0.08</title><rect class="cell" x="566.5" y="481.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="590.0" y="509.0" text-anchor="middle">0.08</text><rect class="cell-masked" x="616.5" y="481.5" width="47.0" height="47.0" rx="3"/><line class="edge" x1="631.0" y1="496.0" x2="649.0" y2="514.0"/><line class="edge" x1="649.0" y1="496.0" x2="631.0" y2="514.0"/><text class="t-tick t-strong" x="157.0" y="559.0" text-anchor="end">green</text><g class="mark"><title>green attends to BOS: 0.37</title><rect class="cell" x="166.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.37"/></g><text class="t-cell" x="190.0" y="559.0" text-anchor="middle">0.37</text><g class="mark"><title>green attends to I: 0.00</title><rect class="cell" x="216.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="240.0" y="559.0" text-anchor="middle">0.00</text><g class="mark"><title>green attends to like: 0.00</title><rect class="cell" x="266.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="290.0" y="559.0" text-anchor="middle">0.00</text><g class="mark"><title>green attends to green: 0.01</title><rect class="cell" x="316.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="340.0" y="559.0" text-anchor="middle">0.01</text><g class="mark"><title>green attends to tea: 0.37</title><rect class="cell" x="366.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.37"/></g><text class="t-cell" x="390.0" y="559.0" text-anchor="middle">0.37</text><g class="mark"><title>green attends to ,: 0.09</title><rect class="cell" x="416.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="440.0" y="559.0" text-anchor="middle">0.09</text><g class="mark"><title>green attends to so: 0.00</title><rect class="cell" x="466.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="490.0" y="559.0" text-anchor="middle">0.00</text><g class="mark"><title>green attends to I: 0.00</title><rect class="cell" x="516.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="540.0" y="559.0" text-anchor="middle">0.00</text><g class="mark"><title>green attends to drink: 0.15</title><rect class="cell" x="566.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.15"/></g><text class="t-cell" x="590.0" y="559.0" text-anchor="middle">0.15</text><g class="mark"><title>green attends to green: 0.01</title><rect class="cell" x="616.5" y="531.5" width="47.0" height="47.0" rx="3" style="fill-opacity:0.12"/></g><text class="t-cell" x="640.0" y="559.0" text-anchor="middle">0.01</text><text class="t-muted" x="95.0" y="600.0" text-anchor="start">destination (the token that reads), one row each</text></svg><figcaption>The attention pattern of head 0.3 on the ten-token prompt. Rows are destinations and columns are sources. Crossed cells are masked: no token reads a later one. In the last row, the final "green" reads "tea" with weight 0.37, the start token BOS with 0.37, and "drink" with 0.15.</figcaption></figure>

The first token, `<|BOS|>`, is a special "beginning of text" token that TransformerLens adds in front of every prompt. Many rows put a lot of weight on it. A head must spend its weights somewhere, because each row adds up to 1, and the first token is a common place to park weight that has nothing better to do.

The interesting row is the last one. Standing on the second " green", head 0.3 reads " tea" with weight 0.37. That is the token the model predicts next. So the head looks back at the word that followed "green" last time. What does it carry over? We can check by reading the head's output at the last position through the unembedding $$W_{\mathrm{U}}$$, as in Part 1:

```text
  head 0.3 output at ' green', read with W_U: top tokens [(' tea', 2.62), (' teac', 2.44), (' Tea', 2.3), (' cups', 2.25), (' brew', 2.16)]
  rank of " tea" among 48,262 tokens: 1
```

<figure class="fig"><svg viewBox="0 0 760 230" role="img" aria-label="Head 0.3's output at the last position, multiplied by the unembedding, raises tea by 2.62, teac by 2.44, Tea by 2.30, cups by 2.25 and brew by 2.16."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">What head 0.3 writes at the last token "green", read through W<tspan baseline-shift="sub" style="font-size:72%">U</tspan></text><text class="t-tick" x="24.0" y="46.0" text-anchor="start">the five tokens whose logits it raises most (out of 48,262)</text><text class="t-tick" x="126.0" y="85.0" text-anchor="end">tea</text><g class="mark"><title>tea: +2.62</title><rect class="s2" x="134.0" y="69.0" width="420.0" height="22.0" rx="3"/></g><text class="t-val" x="560.0" y="85.0" text-anchor="start">+2.62</text><text class="t-tick" x="126.0" y="115.0" text-anchor="end">teac</text><g class="mark"><title>teac: +2.44</title><rect class="s2" x="134.0" y="99.0" width="391.1" height="22.0" rx="3"/></g><text class="t-val" x="531.1" y="115.0" text-anchor="start">+2.44</text><text class="t-tick" x="126.0" y="145.0" text-anchor="end">Tea</text><g class="mark"><title>Tea: +2.30</title><rect class="s2" x="134.0" y="129.0" width="368.7" height="22.0" rx="3"/></g><text class="t-val" x="508.7" y="145.0" text-anchor="start">+2.30</text><text class="t-tick" x="126.0" y="175.0" text-anchor="end">cups</text><g class="mark"><title>cups: +2.25</title><rect class="s2" x="134.0" y="159.0" width="360.7" height="22.0" rx="3"/></g><text class="t-val" x="500.7" y="175.0" text-anchor="start">+2.25</text><text class="t-tick" x="126.0" y="205.0" text-anchor="end">brew</text><g class="mark"><title>brew: +2.16</title><rect class="s2" x="134.0" y="189.0" width="346.3" height="22.0" rx="3"/></g><text class="t-val" x="486.3" y="205.0" text-anchor="start">+2.16</text></svg><figcaption>What head 0.3 adds to the stream at the last "green", multiplied by the unembedding. Of all 48,262 tokens, the five it pushes up most are all about tea: tea (+2.62), teac (+2.44), Tea (+2.30), cups (+2.25) and brew (+2.16).</figcaption></figure>

Out of 48,262 tokens, the one this head pushes up most is " tea". The head moved "tea" from position 4 to position 9. In the paper's words, it moved information from one residual stream to another.

## The two sides of x, and the tensor product {§Attention Heads as Information Movement}

The paper now asks a natural question. Each of the three steps is a matrix multiplication, so why not collapse them into one step? The answer needs one new piece of notation, the tensor product.

### x is a table, and it has two sides

So far $$x_i$$ was one token's vector. Now put all the tokens together. Stack the vectors as the rows of one table $$x$$. For our prompt, $$x$$ has 10 rows (one per token) and 512 columns (one per dimension of the stream).

A matrix can multiply this table from two sides.

- Multiplying from the **left**, as in $$A\,x$$, mixes the **rows**. Row $$i$$ of $$A\,x$$ is $$\sum_j A_{ij}\,x_j$$, a weighted mix of the tokens. This is what the attention pattern does.
- Multiplying from the **right**, as in $$x\,W^\top$$, changes **each row on its own**. Row $$i$$ of $$x\,W^\top$$ is $$W x_i$$. This is what $$W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$ do.

<figure class="fig"><svg viewBox="0 0 760 390" role="img" aria-label="The stream x drawn as a table with 10 rows (tokens) and 512 columns (dimensions). On its left, the 10 by 10 attention pattern A of head 0.3 multiplies across rows: which token reads from which. On its right, the 512 by 512 matrix W_OV transposed multiplies inside each row: what information is read and where it is written."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">x is a table (tokens × dimensions). A and W<tspan baseline-shift="sub" style="font-size:72%">OV</tspan> act on different sides.</text><rect class="box-ghost" x="36.0" y="106.0" width="166.0" height="166.0" rx="5"/><rect class="s2" x="40.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.93"/><rect class="s2" x="56.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="72.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="104.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="120.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="136.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="110.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.92"/><rect class="s2" x="56.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="104.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="120.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="136.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="126.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.92"/><rect class="s2" x="56.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="104.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="120.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="136.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="142.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.90"/><rect class="s2" x="56.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.20"/><rect class="s2" x="104.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="120.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="136.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="158.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.76"/><rect class="s2" x="56.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="88.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.21"/><rect class="s2" x="104.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.31"/><rect class="s2" x="120.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="136.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="174.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.66"/><rect class="s2" x="56.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.23"/><rect class="s2" x="104.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.37"/><rect class="s2" x="120.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.20"/><rect class="s2" x="136.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="190.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.54"/><rect class="s2" x="56.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.21"/><rect class="s2" x="72.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="88.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.23"/><rect class="s2" x="104.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.34"/><rect class="s2" x="120.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.32"/><rect class="s2" x="136.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="206.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.69"/><rect class="s2" x="56.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="72.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.20"/><rect class="s2" x="88.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.21"/><rect class="s2" x="104.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.31"/><rect class="s2" x="120.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.23"/><rect class="s2" x="136.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="184.0" y="222.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.54"/><rect class="s2" x="56.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.20"/><rect class="s2" x="72.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.21"/><rect class="s2" x="104.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.33"/><rect class="s2" x="120.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.28"/><rect class="s2" x="136.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.20"/><rect class="s2" x="168.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.24"/><rect class="s2" x="184.0" y="238.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="40.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.45"/><rect class="s2" x="56.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="72.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="88.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><rect class="s2" x="104.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.46"/><rect class="s2" x="120.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.25"/><rect class="s2" x="136.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="152.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.18"/><rect class="s2" x="168.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.29"/><rect class="s2" x="184.0" y="254.0" width="14" height="14" rx="2" style="fill-opacity:0.19"/><text class="t-math" x="119.0" y="98.0" text-anchor="middle">A</text><text class="t-tick" x="119.0" y="288.0" text-anchor="middle">10 × 10</text><text class="t-big" x="220.0" y="194.0" text-anchor="middle">·</text><rect class="box-ghost" x="238.0" y="106.0" width="230.0" height="146.0" rx="5"/><rect class="s1" x="242.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="256.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="270.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="284.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="298.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="312.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="326.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="340.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="354.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="368.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="382.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="396.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="410.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="424.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="438.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="452.0" y="110.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="242.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="256.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="270.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="284.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="298.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="312.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="326.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="340.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="354.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="368.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="382.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="396.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="410.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="424.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="438.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="452.0" y="124.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="242.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="256.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="270.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="284.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="298.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="312.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="326.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="340.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="354.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="368.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="382.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="396.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="410.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="424.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="438.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="452.0" y="138.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="242.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="256.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="270.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="284.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="298.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="312.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="326.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="340.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="354.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="368.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="382.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="396.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="410.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="424.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="438.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="452.0" y="152.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="242.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="256.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="270.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="284.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="298.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="312.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="326.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="340.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="354.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="368.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="382.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="396.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="410.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="424.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="438.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="452.0" y="166.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="242.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="256.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="270.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="284.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="298.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="312.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="326.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="340.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="354.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="368.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="382.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="396.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="410.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="424.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="438.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="452.0" y="180.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="242.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="256.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="270.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="284.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="298.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="312.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="326.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="340.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="354.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="368.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="382.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="396.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="410.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="424.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="438.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="452.0" y="194.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="242.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="256.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="270.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="284.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="298.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="312.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="326.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="340.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="354.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="368.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="382.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="396.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="410.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="424.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="438.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="452.0" y="208.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="242.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="256.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="270.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="284.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="298.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="312.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="326.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="340.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="354.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="368.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="382.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="396.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="410.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="424.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="438.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="452.0" y="222.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="242.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="256.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="270.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="284.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="298.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="312.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="326.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="340.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="354.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="368.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="382.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s1" x="396.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s1" x="410.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s1" x="424.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s1" x="438.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s1" x="452.0" y="236.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><text class="t-math" x="353.0" y="98.0" text-anchor="middle">x</text><text class="t-tick" x="353.0" y="268.0" text-anchor="middle">10 tokens × 512 dims</text><text class="t-big" x="486.0" y="194.0" text-anchor="middle">·</text><rect class="box-ghost" x="504.0" y="58.0" width="230.0" height="230.0" rx="5"/><rect class="s3" x="508.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="522.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="536.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="550.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="564.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="578.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="592.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="606.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="620.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="634.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="648.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="662.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="676.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="690.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="704.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="718.0" y="62.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="508.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="522.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="536.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="550.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="564.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="578.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="592.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="606.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="620.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="634.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="648.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="662.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="676.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="690.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="704.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="718.0" y="76.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="508.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="522.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="536.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="550.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="564.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="578.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="592.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="606.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="620.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="634.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="648.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="662.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="676.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="690.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="704.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="718.0" y="90.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="508.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="522.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="536.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="550.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="564.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="578.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="592.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="606.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="620.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="634.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="648.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="662.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="676.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="690.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="704.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="718.0" y="104.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="508.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="522.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="536.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="550.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="564.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="578.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="592.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="606.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="620.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="634.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="648.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="662.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="676.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="690.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="704.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="718.0" y="118.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="508.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="522.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="536.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="550.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="564.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="578.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="592.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="606.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="620.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="634.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="648.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="662.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="676.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="690.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="704.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="718.0" y="132.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="508.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="522.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="536.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="550.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="564.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="578.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="592.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="606.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="620.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="634.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="648.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="662.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="676.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="690.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="704.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="718.0" y="146.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="508.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="522.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="536.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="550.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="564.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="578.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="592.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="606.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="620.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="634.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="648.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="662.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="676.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="690.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="704.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="718.0" y="160.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="508.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="522.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="536.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="550.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="564.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="578.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="592.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="606.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="620.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="634.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="648.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="662.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="676.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="690.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="704.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="718.0" y="174.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="508.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="522.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="536.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="550.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="564.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="578.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="592.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="606.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="620.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="634.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="648.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="662.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="676.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="690.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="704.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="718.0" y="188.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="508.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="522.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="536.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="550.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="564.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="578.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="592.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="606.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="620.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="634.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="648.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="662.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="676.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="690.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="704.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="718.0" y="202.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="508.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="522.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="536.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="550.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="564.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="578.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="592.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="606.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="620.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="634.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="648.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="662.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="676.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="690.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="704.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="718.0" y="216.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="508.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="522.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="536.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="550.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="564.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="578.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="592.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="606.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="620.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="634.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="648.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="662.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="676.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="690.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="704.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="718.0" y="230.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="508.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="522.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="536.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="550.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="564.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="578.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="592.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="606.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="620.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="634.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="648.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="662.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="676.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="690.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="704.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="718.0" y="244.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="508.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="522.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="536.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="550.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="564.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="578.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="592.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="606.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="620.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="634.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="648.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="662.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="676.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="690.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="704.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="718.0" y="258.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="508.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="522.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="536.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="550.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="564.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="578.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="592.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="606.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="620.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="634.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="648.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><rect class="s3" x="662.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.62"/><rect class="s3" x="676.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.49"/><rect class="s3" x="690.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.69"/><rect class="s3" x="704.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.55"/><rect class="s3" x="718.0" y="272.0" width="12" height="12" rx="2" style="fill-opacity:0.42"/><text class="t-tick" x="619.0" y="304.0" text-anchor="middle">512 × 512</text><text class="t-math" x="619.0" y="46.0" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">OV</tspan>ᵀ</text><text class="t-tick t-strong" x="119.0" y="314.0" text-anchor="middle">mixes rows:</text><text class="t-tick" x="119.0" y="332.0" text-anchor="middle">which token reads</text><text class="t-tick" x="119.0" y="350.0" text-anchor="middle">from which</text><text class="t-tick t-strong" x="619.0" y="330.0" text-anchor="middle">acts inside each row:</text><text class="t-tick" x="619.0" y="348.0" text-anchor="middle">what is read and</text><text class="t-tick" x="619.0" y="366.0" text-anchor="middle">where it is written</text></svg><figcaption>The stream of the whole prompt as one table x, with 10 rows (tokens) and 512 columns (dimensions). The attention pattern A of head 0.3 (10 by 10, shaded by its real weights) multiplies from the left and mixes rows. W_OV transposed (512 by 512) multiplies from the right and acts inside every row.</figcaption></figure>

### One formula for the whole head

Now collapse the three steps. Start from step 3 and substitute steps 2 and 1 into it:

$$
\begin{aligned}
h(x)_i&=W_{\mathrm{O}}\,r_i\\
&=W_{\mathrm{O}}\sum_j A_{ij}\,v_j\\
&=W_{\mathrm{O}}\sum_j A_{ij}\,W_{\mathrm{V}} x_j
\end{aligned}
$$

The number $$A_{ij}$$ is just a scalar, so it can move past the matrices. And $$W_{\mathrm{O}}$$ can move inside the sum, because matrix multiplication spreads over a sum. This gives:

$$
h(x)_i=\sum_j A_{ij}\,(W_{\mathrm{O}} W_{\mathrm{V}})\,x_j
$$

Read this slowly. For each source token $$j$$, the matrix $$W_{\mathrm{O}} W_{\mathrm{V}}$$ turns $$x_j$$ into "what token $$j$$ sends". Then $$A_{ij}$$ decides how much of it token $$i$$ receives. The two parts never mix: $$A$$ only has position indices, and $$W_{\mathrm{O}} W_{\mathrm{V}}$$ only acts inside a vector.

In table form, using the two sides from above, the whole head is:

$$
h(x)=A\,x\,(W_{\mathrm{O}} W_{\mathrm{V}})^\top
$$

The paper gives the product $$W_{\mathrm{O}} W_{\mathrm{V}}$$ its own name, $$W_{\mathrm{OV}}$$. It is 512 × 512.

### The tensor product, made plain

The paper writes the same thing with a new symbol, $$\otimes$$. For any position-mixing matrix $$A$$ and any per-token matrix $$W$$, it defines

$$
(A\otimes W)\,x=A\,x\,W^\top
$$

That is all the symbol means here: "mix the rows with $$A$$, and change each row with $$W$$". With this notation, the whole head is

$$
h(x)=(A\otimes W_{\mathrm{O}} W_{\mathrm{V}})\,x
$$

> [!DEFINITION] Tensor product (as used here)
> $$A\otimes W$$ is a map that takes a table $$x$$ (tokens × dimensions) and returns $$A\,x\,W^\top$$. The left factor $$A$$ works across tokens, and the right factor $$W$$ works inside each token. Mathematicians call it a tensor product or a Kronecker product; the paper calls a map from tables to tables a "(2,2)-tensor".

The appendix of the paper lists the practical rules:

> [!PAPER] · Tensor Product / Kronecker Product Notation
> [![The notation appendix: Id ⊗ W multiplies each position, A ⊗ Id multiplies across positions, A ⊗ W does both and the order does not matter, and the mixed-product property](https://ishwarj.com/img/papers/circuits/p2-tensor-notation.pngtensor-notation.png)](/img/papers/circuits/p2-tensor-notation.png)
>
> **What it says:** $$\text{Id}\otimes W$$ multiplies every position by $$W$$, and $$A\otimes\text{Id}$$ multiplies across positions. $$A\otimes W$$ does both, and "it doesn't matter which order you do this in". Tensor products also obey the mixed-product property.
>
> **What it means:**
>
> Think of a spreadsheet with one row per token and one column per dimension. $$\text{Id}\otimes W$$ edits every row in the same way and leaves the rows where they are. $$A\otimes\text{Id}$$ mixes whole rows and leaves the meaning of each column alone.
>
> The two act on different sides of the table, so they do not get in each other's way. That is why the order does not matter. The order rule is the formal version of "the where part and the what part are independent".
>
> These rules, with the mixed-product property, are all the tensor algebra the paper needs.

In symbols, the order does not matter because matrix multiplication is associative: $$(A\,x)\,W^\top$$ and $$A\,(x\,W^\top)$$ are the same table. So you can mix first and transform second, or the other way round. Here is a toy with two tokens and two dimensions. $$A$$ lets token 2 take half of each token, and $$W$$ swaps the two numbers of a token.

<figure class="fig"><svg viewBox="0 0 760 352" role="img" aria-label="A toy x with two tokens, (1, 2) and (3, 4). Top: swap the two numbers of each token first, giving (2, 1) and (4, 3), then let token 2 take half of each token, giving (2, 1) and (3, 2). Bottom: mix first, giving (1, 2) and (2, 3), then swap, giving (2, 1) and (3, 2). Both orders give the same result."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">(A ⊗ W) x: W changes each token, A mixes tokens. Either order works.</text><rect class="s1" x="60.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.24"/><text class="t-val" x="80.0" y="91.0" text-anchor="middle">1</text><rect class="s1" x="104.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="124.0" y="91.0" text-anchor="middle">2</text><rect class="s1" x="60.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.51"/><text class="t-val" x="80.0" y="121.0" text-anchor="middle">3</text><rect class="s1" x="104.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="124.0" y="121.0" text-anchor="middle">4</text><text class="t-tick" x="52.0" y="93.0" text-anchor="end">t1</text><text class="t-tick" x="52.0" y="123.0" text-anchor="end">t2</text><text class="t-tick" x="102.0" y="150.0" text-anchor="middle">x</text><line class="edge" x1="156.0" y1="102.0" x2="276.0" y2="102.0" marker-end="url(#ah)"/><text class="t-muted" x="216.0" y="66.0" text-anchor="middle">W: swap the 2 numbers</text><rect class="s2" x="300.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="320.0" y="91.0" text-anchor="middle">2</text><rect class="s2" x="344.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.24"/><text class="t-val" x="364.0" y="91.0" text-anchor="middle">1</text><rect class="s2" x="300.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="320.0" y="121.0" text-anchor="middle">4</text><rect class="s2" x="344.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.51"/><text class="t-val" x="364.0" y="121.0" text-anchor="middle">3</text><text class="t-tick" x="292.0" y="93.0" text-anchor="end">t1</text><text class="t-tick" x="292.0" y="123.0" text-anchor="end">t2</text><text class="t-tick" x="342.0" y="150.0" text-anchor="middle">x Wᵀ</text><line class="edge" x1="396.0" y1="102.0" x2="536.0" y2="102.0" marker-end="url(#ah)"/><text class="t-muted" x="466.0" y="66.0" text-anchor="middle">A: token 2 takes half of each</text><rect class="s3" x="560.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="580.0" y="91.0" text-anchor="middle">2</text><rect class="s3" x="604.0" y="74.0" width="40" height="26" rx="4" style="fill-opacity:0.28"/><text class="t-val" x="624.0" y="91.0" text-anchor="middle">1</text><rect class="s3" x="560.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="580.0" y="121.0" text-anchor="middle">3</text><rect class="s3" x="604.0" y="104.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="624.0" y="121.0" text-anchor="middle">2</text><text class="t-tick" x="552.0" y="93.0" text-anchor="end">t1</text><text class="t-tick" x="552.0" y="123.0" text-anchor="end">t2</text><text class="t-tick" x="602.0" y="150.0" text-anchor="middle">result</text><rect class="s1" x="60.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.24"/><text class="t-val" x="80.0" y="241.0" text-anchor="middle">1</text><rect class="s1" x="104.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.38"/><text class="t-val" x="124.0" y="241.0" text-anchor="middle">2</text><rect class="s1" x="60.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.51"/><text class="t-val" x="80.0" y="271.0" text-anchor="middle">3</text><rect class="s1" x="104.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="124.0" y="271.0" text-anchor="middle">4</text><text class="t-tick" x="52.0" y="243.0" text-anchor="end">t1</text><text class="t-tick" x="52.0" y="273.0" text-anchor="end">t2</text><text class="t-tick" x="102.0" y="300.0" text-anchor="middle">x</text><line class="edge" x1="156.0" y1="252.0" x2="276.0" y2="252.0" marker-end="url(#ah)"/><text class="t-muted" x="216.0" y="216.0" text-anchor="middle">A: token 2 takes half of each</text><rect class="s2" x="300.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.28"/><text class="t-val" x="320.0" y="241.0" text-anchor="middle">1</text><rect class="s2" x="344.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="364.0" y="241.0" text-anchor="middle">2</text><rect class="s2" x="300.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="320.0" y="271.0" text-anchor="middle">2</text><rect class="s2" x="344.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="364.0" y="271.0" text-anchor="middle">3</text><text class="t-tick" x="292.0" y="243.0" text-anchor="end">t1</text><text class="t-tick" x="292.0" y="273.0" text-anchor="end">t2</text><text class="t-tick" x="342.0" y="300.0" text-anchor="middle">A x</text><line class="edge" x1="396.0" y1="252.0" x2="536.0" y2="252.0" marker-end="url(#ah)"/><text class="t-muted" x="466.0" y="216.0" text-anchor="middle">W: swap the 2 numbers</text><rect class="s3" x="560.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="580.0" y="241.0" text-anchor="middle">2</text><rect class="s3" x="604.0" y="224.0" width="40" height="26" rx="4" style="fill-opacity:0.28"/><text class="t-val" x="624.0" y="241.0" text-anchor="middle">1</text><rect class="s3" x="560.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="580.0" y="271.0" text-anchor="middle">3</text><rect class="s3" x="604.0" y="254.0" width="40" height="26" rx="4" style="fill-opacity:0.47"/><text class="t-val" x="624.0" y="271.0" text-anchor="middle">2</text><text class="t-tick" x="552.0" y="243.0" text-anchor="end">t1</text><text class="t-tick" x="552.0" y="273.0" text-anchor="end">t2</text><text class="t-tick" x="602.0" y="300.0" text-anchor="middle">result</text><text class="t-tick" x="60.0" y="338.0" text-anchor="start">A = [[1, 0], [0.5, 0.5]] and W = [[0, 1], [1, 0]]. Both orders give the same result.</text></svg><figcaption>The tensor product on a two-token toy. Top: first W swaps each token's two numbers, giving (2, 1) and (4, 3), then A lets token 2 take half of each token, giving (2, 1) and (3, 2). Bottom: first A mixes, giving (1, 2) and (2, 3), then W swaps, giving the same (2, 1) and (3, 2).</figcaption></figure>

You can also flatten the table into one long vector of 4 numbers. Then $$A\otimes W$$ becomes one ordinary 4 × 4 matrix, the **Kronecker product**. Our toy script builds it and gets the same answer:

```text
  as one 4 x 4 matrix A (x) W = [[0.0, 1.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0], [0.0, 0.5, 0.0, 0.5], [0.5, 0.0, 0.5, 0.0]], times x flattened [1.0, 2.0, 3.0, 4.0] = [2.0, 1.0, 3.0, 2.0]
```

The flat view is correct, but it hides the structure, so the paper (and this series) uses the two-sided view.

### The paper's derivation, step by step

> [!PAPER] · Attention Heads as Information Movement
> [![The head written as a product of three tensor products, then collapsed by the mixed product property into A ⊗ W_O W_V](https://ishwarj.com/img/papers/circuits/p2-tensor.pngcuits/p2-tensor.png)](/img/papers/circuits/p2-tensor.png)
>
> **What it says:** a head is three tensor products in a row. It computes the values ($$\text{Id}\otimes W_{\mathrm{V}}$$), mixes them across tokens ($$A\otimes\text{Id}$$) and projects the results out ($$\text{Id}\otimes W_{\mathrm{O}}$$). "Applying the mixed product property and collapsing identities" gives $$h(x)=(A\otimes W_{\mathrm{O}} W_{\mathrm{V}})\,x$$.
>
> **What it means:**
>
> Think of two currency changes in a row: dollars to euros, then euros to yen. A bank can replace them with one direct rate from dollars to yen. Here $$W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$ are the two changes, and $$W_{\mathrm{O}} W_{\mathrm{V}}$$ is the direct rate.
>
> The pattern $$A$$ sits between them, but it works on the other side of the table. So it can step out of the way, and the two per-token matrices meet. The final line shows the whole head as one pair: a pattern $$A$$ and a matrix $$W_{\mathrm{O}} W_{\mathrm{V}}$$.
>
> This is the paper's main way of writing a head from now on. The paper skips the algebra, so we fill it in below.

The three steps, read from right to left, are:

$$
\begin{aligned}
h(x)={}&(\text{Id}\otimes W_{\mathrm{O}})\\
&\cdot(A\otimes\text{Id})\\
&\cdot(\text{Id}\otimes W_{\mathrm{V}})\,x
\end{aligned}
$$

Here $$\text{Id}$$ is the identity matrix, which changes nothing. So $$\text{Id}\otimes W_{\mathrm{V}}$$ means "do not mix tokens; multiply each token by $$W_{\mathrm{V}}$$". The **mixed-product property** says how two tensor products combine:

$$
\begin{aligned}
&(A\otimes B)(C\otimes D)\\
&=(AC)\otimes(BD)
\end{aligned}
$$

It follows from our definition in two lines. Apply $$C\otimes D$$ first, then $$A\otimes B$$:

$$
\begin{aligned}
(A\otimes B)(C\,x\,D^\top)&=A\,C\,x\,D^\top B^\top\\
&=(AC)\,x\,(BD)^\top
\end{aligned}
$$

The last step uses $$D^\top B^\top=(BD)^\top$$, a standard rule for transposes. The right side is exactly $$\big((AC)\otimes(BD)\big)\,x$$. Now combine the first two factors of the head:

$$
\begin{aligned}
&(\text{Id}\otimes W_{\mathrm{O}})(A\otimes\text{Id})\\
&=(\text{Id}\,A)\otimes(W_{\mathrm{O}}\,\text{Id})\\
&=A\otimes W_{\mathrm{O}}
\end{aligned}
$$

Then combine the result with the last factor:

$$
\begin{aligned}
&(A\otimes W_{\mathrm{O}})(\text{Id}\otimes W_{\mathrm{V}})\\
&=(A\,\text{Id})\otimes(W_{\mathrm{O}} W_{\mathrm{V}})\\
&=A\otimes W_{\mathrm{O}} W_{\mathrm{V}}
\end{aligned}
$$

That is the paper's result. The identities "collapse" because multiplying by $$\text{Id}$$ changes nothing.

**On the real model.** We computed head 0.3's output on our prompt in three ways: the three steps, the formula with $$A$$ applied first, and the formula with $$W_{\mathrm{OV}}$$ applied first.

```python
W_OV_row = model.W_V[0, 3] @ model.W_O[0, 3]     # TransformerLens stores the transpose: this is W_OV^T
first_A = (A @ X) @ W_OV_row                      # mix tokens first, then change each token
first_W = A @ (X @ W_OV_row)                      # change each token first, then mix
```

```text
  three steps by hand: |r - model r| max = 0.0e+00
  (A (x) W_OV) x, A first vs W_OV first: max diff 1.7e-06; vs the three steps: 1.4e-06
```

All three agree up to rounding noise. Here `X` is the stream as the head sees it, after the leftover part of layer norm from Part 1.

## The pattern in one step: the QK matrix {§Attention Heads as Information Movement}

We have collapsed the "what" part. The paper does the same for the "where" part, the attention pattern.

> [!PAPER] · Attention Heads as Information Movement
> [![The paragraph computing the attention pattern in one step as softmax of x^T W_Q^T W_K x, and the note that this would be horribly inefficient](https://ishwarj.com/img/papers/circuits/p2-qk-one-step.png/p2-qk-one-step.png)](/img/papers/circuits/p2-qk-one-step.png)
>
> **What it says:** normally one computes keys and queries and then their dot products. "But we can do it all in one step without referring to keys and queries": $$A=\text{softmax}(x^\top {W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}\,x)$$. The paper adds that actually computing a head this way would be "horribly inefficient".
>
> **What it means:**
>
> Think of a matchmaker who scores every pair of people. One way is to give each person a wish list (the query) and a profile (the key), then compare the two. Another way is one big chart that gives the score of every pair directly. Both ways give the same scores.
>
> So the pattern depends on $$W_{\mathrm{Q}}$$ and $$W_{\mathrm{K}}$$ only through one product. Queries and keys are a way to compute it, not something the head needs.
>
> The big chart is slow to use, which is why the paper calls it "horribly inefficient". But for reading a head, the chart is the natural object. We come back to the cost after the derivation.

### The derivation

Write the score of one pair as a product of matrices. A dot product $$a\cdot b$$ is the same as $$a^\top b$$, so:

$$
\begin{aligned}
s_{ij}&=q_i\cdot k_j\\
&=(W_{\mathrm{Q}} x_i)^\top(W_{\mathrm{K}} x_j)\\
&=x_i^\top {W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}\,x_j
\end{aligned}
$$

The last step uses the transpose rule again: $$(W_{\mathrm{Q}} x_i)^\top=x_i^\top {W_{\mathrm{Q}}}^{\top}$$. The paper names the middle product:

$$
W_{\mathrm{QK}}={W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}
$$

Its shape is $$(512\times64)(64\times512)=512\times512$$. With it, every score is $$s_{ij}=x_i^\top W_{\mathrm{QK}}\,x_j$$. The paper writes the whole table of scores at once as $$x^\top W_{\mathrm{QK}}\,x$$ (with the tokens as the columns of $$x$$), and then applies the masked softmax.

> [!DEFINITION] Bilinear form
> A function of two vectors of the form $$a^\top M\,b$$. It is linear in $$a$$ when $$b$$ is fixed, and linear in $$b$$ when $$a$$ is fixed. An attention score is a bilinear form of the destination's stream and the source's stream, with the matrix $$W_{\mathrm{QK}}$$.

**A toy example.** Let the stream have 2 numbers and the head 1 number. The query reads dimension 1, $$W_{\mathrm{Q}}=(1,0)$$, and the key reads dimension 2, $$W_{\mathrm{K}}=(0,1)$$. The destination token is $$(2,0)$$ and the source token is $$(0,3)$$.

<figure class="fig"><svg viewBox="0 0 760 300" role="img" aria-label="Top: the query of the destination token (2, 0) is W_Q x = 2, the key of the source token (0, 3) is W_K x = 3, and the score is their product, 6. Bottom: the single matrix W_QK = W_Q transposed times W_K is [[0, 1], [0, 0]], and x_dst transposed times W_QK times x_src is also 6."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">Two ways to get the same attention score</text><text class="t-note" x="24.0" y="60.0" text-anchor="start">1. With a query and a key</text><rect class="box-1" x="24.0" y="76.0" width="150.0" height="30.0" rx="6"/><text class="t-tick" x="99.0" y="95.5" text-anchor="middle">x<tspan baseline-shift="sub" style="font-size:72%">dst</tspan> = (2, 0)</text><line class="edge" x1="180.0" y1="91.0" x2="214.0" y2="91.0" marker-end="url(#ah)"/><rect class="box" x="220.0" y="76.0" width="140.0" height="30.0" rx="6"/><text class="t-tick" x="290.0" y="95.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">Q</tspan> = (1, 0)</text><line class="edge" x1="366.0" y1="91.0" x2="400.0" y2="91.0" marker-end="url(#ah)"/><rect class="box-1" x="406.0" y="76.0" width="80.0" height="30.0" rx="6"/><text class="t-tick" x="446.0" y="95.5" text-anchor="middle">q = 2</text><rect class="box-2" x="24.0" y="122.0" width="150.0" height="30.0" rx="6"/><text class="t-tick" x="99.0" y="141.5" text-anchor="middle">x<tspan baseline-shift="sub" style="font-size:72%">src</tspan> = (0, 3)</text><line class="edge" x1="180.0" y1="137.0" x2="214.0" y2="137.0" marker-end="url(#ah)"/><rect class="box" x="220.0" y="122.0" width="140.0" height="30.0" rx="6"/><text class="t-tick" x="290.0" y="141.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">K</tspan> = (0, 1)</text><line class="edge" x1="366.0" y1="137.0" x2="400.0" y2="137.0" marker-end="url(#ah)"/><rect class="box-2" x="406.0" y="122.0" width="80.0" height="30.0" rx="6"/><text class="t-tick" x="446.0" y="141.5" text-anchor="middle">k = 3</text><line class="edge" x1="490.0" y1="91.0" x2="530.0" y2="112.0"/><line class="edge" x1="490.0" y1="137.0" x2="530.0" y2="116.0"/><rect class="box-3" x="536.0" y="99.0" width="190.0" height="30.0" rx="6"/><text class="t-tick" x="631.0" y="118.5" text-anchor="middle">q · k = 2 × 3 = 6</text><text class="t-note" x="24.0" y="200.0" text-anchor="start">2. With one matrix, W<tspan baseline-shift="sub" style="font-size:72%">QK</tspan> = W<tspan baseline-shift="sub" style="font-size:72%">Q</tspan>ᵀ W<tspan baseline-shift="sub" style="font-size:72%">K</tspan></text><rect class="s1" x="60.0" y="216.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="78.0" y="232.0" text-anchor="middle">0</text><rect class="s1" x="100.0" y="216.0" width="36" height="24" rx="4" style="fill-opacity:0.65"/><text class="t-val" x="118.0" y="232.0" text-anchor="middle">1</text><rect class="s1" x="60.0" y="244.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="78.0" y="260.0" text-anchor="middle">0</text><rect class="s1" x="100.0" y="244.0" width="36" height="24" rx="4" style="fill-opacity:0.10"/><text class="t-val" x="118.0" y="260.0" text-anchor="middle">0</text><text class="t-tick" x="98.0" y="286.0" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">QK</tspan> (2 × 2)</text><text class="t-note" x="170.0" y="245.0" text-anchor="start">x<tspan baseline-shift="sub" style="font-size:72%">dst</tspan>ᵀ W<tspan baseline-shift="sub" style="font-size:72%">QK</tspan> x<tspan baseline-shift="sub" style="font-size:72%">src</tspan> = 2 × 1 × 3</text><text class="t-muted" x="170.0" y="268.0" text-anchor="start">no query or key vector is ever made</text><rect class="box-3" x="536.0" y="228.0" width="190.0" height="30.0" rx="6"/><text class="t-tick" x="631.0" y="247.5" text-anchor="middle">score = 6</text></svg><figcaption>The same attention score computed two ways. With a query and a key: the destination's query is 2, the source's key is 3, and the score is 6. With one matrix: W_QK = W_Q transposed times W_K is the 2 by 2 matrix [[0, 1], [0, 0]], and x_dst transposed times W_QK times x_src is also 6.</figcaption></figure>

The single entry 1 in $$W_{\mathrm{QK}}$$ sits in row 1, column 2. It means "dimension 1 of the destination meets dimension 2 of the source". Every entry of a real $$W_{\mathrm{QK}}$$ has this meaning: how much one direction at the destination wants to meet another direction at the source.

**On the real model.** The real head also has biases on its queries and keys. Part 1 showed that a bias is just one more column for an always-1 input. So we add a 513th dimension that is always 1, put the biases there, and compute the whole pattern from a single 513 × 513 matrix:

```python
Xt  = torch.cat([X, ones], 1)                                  # [10, 513]: an always-1 column for the biases
WQt = torch.cat([W_Q, b_Q[None]], 0); WKt = torch.cat([W_K, b_K[None]], 0)
scores = Xt @ (WQt @ WKt.T) @ Xt.T / 8                         # every query-key score in one product
```

```text
== 4. THE PATTERN IN ONE STEP: A = softmax(x^T W_QK x), WITHOUT KEYS OR QUERIES
  W_QK with the biases folded in: (513, 513); |A from W_QK - model A| max = 6.0e-07
  raw scores of the last row (before softmax): [2.92, -1.89, -2.8, -0.45, 2.93, 1.48, -3.64, -2.5, 2.01, -0.58]
```

The pattern from one matrix matches the model's pattern to within 0.0000006. Look at the raw scores of the last row. " tea" (position 4) scores 2.93 and BOS scores 2.92. Nearly equal scores give nearly equal weights, which is why both got 0.37.

**Why "horribly inefficient"?** $$W_{\mathrm{QK}}$$ has $$512\times512=262{,}144$$ numbers, while $$W_{\mathrm{Q}}$$ and $$W_{\mathrm{K}}$$ together have $$65{,}536$$. Multiplying a token by the big matrix costs about four times as much as going through the two thin ones. So code keeps the factors. But for **reading** a head, the product is the natural object.

## What the new form shows {§Observations about Attention Heads}

The paper then lists what this way of writing a head reveals. We take its observations one at a time.

### Heads move information, so the stream holds copied information

The first observation repeats the main idea: heads move information from one token's stream to another's. The paper draws a consequence. The residual stream is often called a "contextual word embedding", as if it only described the current token. But after a head has run, the stream at a token **also contains information copied from other tokens**, in its own subspace. We saw exactly this: after head 0.3, the stream at the last " green" contains a direction that means "tea".

### Two linear operations, and only one is non-linear

> [!PAPER] · Observations about Attention Heads
> [![The observations: an attention head applies two linear operations A and W_O W_V, A governs which tokens, W_O W_V governs which information; A is the only non-linear part](https://ishwarj.com/img/papers/circuits/p2-two-operations.png-two-operations.png)](/img/papers/circuits/p2-two-operations.png)
>
> **What it says:** a head applies two linear operations, $$A$$ and $$W_{\mathrm{O}} W_{\mathrm{V}}$$, which act on different dimensions. $$A$$ "governs which token's information is moved from and to". $$W_{\mathrm{O}} W_{\mathrm{V}}$$ "governs which information is read from the source token and how it is written to the destination token". $$A$$ is "the only non-linear part", because it comes from a softmax. So if the pattern is held fixed, the head is linear, and the paper calls heads "half-linear".
>
> **What it means:**
>
> Think of a sound mixer. The sliders decide how loud each channel is, and the channels are added. If someone sets the sliders and walks away, the output is a sum of the inputs, each scaled. The sliders are $$A$$.
>
> Why is the head non-linear at all? Because the pattern is computed from the input. If you double $$x$$, the scores grow four times, because both $$x_i$$ and $$x_j$$ double. The softmax of the new scores is a different pattern. But once $$A$$ is fixed, $$h(x)=A\,x\,{W_{\mathrm{OV}}}^{\top}$$ is linear in $$x$$: doubling $$x$$ doubles the output.
>
> This gives the two circuits their jobs, and it gives a tool. Record a head's pattern and hold it fixed, and everything else is matrix multiplication. Part 4 uses this "freezing" trick on the one-layer model.

### W_OV and W_QK are low-rank

The paper's footnote on this observation explains how $$W_{\mathrm{OV}}$$ chooses what to read and where to write. It uses the singular value decomposition $$W_{\mathrm{OV}}=USV$$. "Since $$d_\text{head}<d_\text{model}$$, $$W_{\mathrm{OV}}$$ is low-rank and only a subset of the diagonal entries in $$S$$ are non-zero." The right singular vectors "describe which subspace of the residual stream being attended to is read in", and the left singular vectors "describe what subspace of the destination residual stream they are written to".

> [!DEFINITION] Singular value decomposition (SVD)
> A way to write any matrix as $$M=U S V^\top$$. The columns of $$V$$ are **input directions**, the columns of $$U$$ are **output directions**, and $$S$$ is a diagonal list of **singular values**, one per pair. The matrix takes the size of the input along input direction $$k$$, multiplies it by singular value $$k$$, and writes the result along output direction $$k$$. The number of singular values that are not zero is the rank of $$M$$. (The paper writes $$USV$$ and leaves the transpose implicit.)

First, why can the rank of $$W_{\mathrm{OV}}$$ be at most 64? Apply it to any vector $$x$$:

$$
W_{\mathrm{OV}}\,x=W_{\mathrm{O}}\,(W_{\mathrm{V}}\,x)
$$

The bracket $$W_{\mathrm{V}} x$$ has only 64 numbers. So the output is $$W_{\mathrm{O}}$$ times some 64-number vector. That is always a mix of the 64 columns of $$W_{\mathrm{O}}$$. Every possible output lies in a space of at most 64 dimensions, out of 512. The same argument works for $$W_{\mathrm{QK}}={W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}$$.

**A toy example.** In our three-step toy, $$W_{\mathrm{OV}}=W_{\mathrm{O}} W_{\mathrm{V}}$$ is a 3 × 3 matrix whose last row is $$(1,1,0)$$ and whose other rows are zero. Its rank is 1. The SVD from the toy script finds one singular value, 1.414. Its input direction is $$(0.707,0.707,0)$$, which is "dimensions 1 and 2 together". Its output direction is $$(0,0,1)$$, which is "dimension 3". In words: this head reads dimensions 1 and 2, and writes into dimension 3. Those are two different subspaces, just like the paper's drawing.

**On the real model.** Our script computes the SVD of both matrices of head 0.3:

```text
== 5. W_OV = W_O W_V AND W_QK = W_Q^T W_K (paper shapes)
  W_OV: shape (512, 512) = 262,144 numbers, rank 64; stored as two factors: 65,536 numbers
    singular values: 1st 2.866, 2nd 2.761, 64th 1.0605, 65th 8.8e-07, 512th 4.2e-11
  W_QK: shape (512, 512) = 262,144 numbers, rank 64; stored as two factors: 65,536 numbers
    singular values: 1st 1.312, 2nd 1.196, 64th 0.1876, 65th 2.7e-07, 512th 2.3e-11
```

<figure class="fig"><svg viewBox="0 0 760 270" role="img" aria-label="Bar charts of the first 80 singular values of head 0.3's W_OV and W_QK. In both, the first 64 bars are clearly above zero (W_OV from 2.87 down to 1.06, W_QK from 1.31 down to 0.19) and bars 65 to 80 are zero, so both 512 by 512 matrices have rank 64."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">Head 0.3: the first 80 of 512 singular values. Only 64 are not zero.</text><text class="t-note" x="40.0" y="52.0" text-anchor="start">W<tspan baseline-shift="sub" style="font-size:72%">OV</tspan>: 512 × 512, rank 64</text><line class="axis" x1="40" y1="210" x2="360" y2="210"/><g class="mark"><title>W_OV singular value 1: 2.87</title><rect class="s2" x="40.0" y="60.0" width="3" height="150.0"/></g><g class="mark"><title>W_OV singular value 2: 2.76</title><rect class="s2" x="44.0" y="65.5" width="3" height="144.5"/></g><g class="mark"><title>W_OV singular value 3: 2.75</title><rect class="s2" x="48.0" y="65.9" width="3" height="144.1"/></g><g class="mark"><title>W_OV singular value 4: 2.63</title><rect class="s2" x="52.0" y="72.6" width="3" height="137.4"/></g><g class="mark"><title>W_OV singular value 5: 2.5</title><rect class="s2" x="56.0" y="79.0" width="3" height="131.0"/></g><g class="mark"><title>W_OV singular value 6: 2.4</title><rect class="s2" x="60.0" y="84.5" width="3" height="125.5"/></g><g class="mark"><title>W_OV singular value 7: 2.38</title><rect class="s2" x="64.0" y="85.3" width="3" height="124.7"/></g><g class="mark"><title>W_OV singular value 8: 2.38</title><rect class="s2" x="68.0" y="85.5" width="3" height="124.5"/></g><g class="mark"><title>W_OV singular value 9: 2.32</title><rect class="s2" x="72.0" y="88.6" width="3" height="121.4"/></g><g class="mark"><title>W_OV singular value 10: 2.28</title><rect class="s2" x="76.0" y="90.7" width="3" height="119.3"/></g><g class="mark"><title>W_OV singular value 11: 2.26</title><rect class="s2" x="80.0" y="91.7" width="3" height="118.3"/></g><g class="mark"><title>W_OV singular value 12: 2.21</title><rect class="s2" x="84.0" y="94.5" width="3" height="115.5"/></g><g class="mark"><title>W_OV singular value 13: 2.2</title><rect class="s2" x="88.0" y="95.0" width="3" height="115.0"/></g><g class="mark"><title>W_OV singular value 14: 2.19</title><rect class="s2" x="92.0" y="95.4" width="3" height="114.6"/></g><g class="mark"><title>W_OV singular value 15: 2.16</title><rect class="s2" x="96.0" y="96.9" width="3" height="113.1"/></g><g class="mark"><title>W_OV singular value 16: 2.13</title><rect class="s2" x="100.0" y="98.3" width="3" height="111.7"/></g><g class="mark"><title>W_OV singular value 17: 2.12</title><rect class="s2" x="104.0" y="98.8" width="3" height="111.2"/></g><g class="mark"><title>W_OV singular value 18: 2.1</title><rect class="s2" x="108.0" y="100.4" width="3" height="109.6"/></g><g class="mark"><title>W_OV singular value 19: 2.08</title><rect class="s2" x="112.0" y="101.1" width="3" height="108.9"/></g><g class="mark"><title>W_OV singular value 20: 2.07</title><rect class="s2" x="116.0" y="101.7" width="3" height="108.3"/></g><g class="mark"><title>W_OV singular value 21: 2.04</title><rect class="s2" x="120.0" y="103.2" width="3" height="106.8"/></g><g class="mark"><title>W_OV singular value 22: 2.03</title><rect class="s2" x="124.0" y="103.5" width="3" height="106.5"/></g><g class="mark"><title>W_OV singular value 23: 2.01</title><rect class="s2" x="128.0" y="104.6" width="3" height="105.4"/></g><g class="mark"><title>W_OV singular value 24: 1.98</title><rect class="s2" x="132.0" y="106.5" width="3" height="103.5"/></g><g class="mark"><title>W_OV singular value 25: 1.97</title><rect class="s2" x="136.0" y="106.9" width="3" height="103.1"/></g><g class="mark"><title>W_OV singular value 26: 1.96</title><rect class="s2" x="140.0" y="107.5" width="3" height="102.5"/></g><g class="mark"><title>W_OV singular value 27: 1.95</title><rect class="s2" x="144.0" y="108.2" width="3" height="101.8"/></g><g class="mark"><title>W_OV singular value 28: 1.94</title><rect class="s2" x="148.0" y="108.7" width="3" height="101.3"/></g><g class="mark"><title>W_OV singular value 29: 1.92</title><rect class="s2" x="152.0" y="109.6" width="3" height="100.4"/></g><g class="mark"><title>W_OV singular value 30: 1.92</title><rect class="s2" x="156.0" y="109.8" width="3" height="100.2"/></g><g class="mark"><title>W_OV singular value 31: 1.91</title><rect class="s2" x="160.0" y="110.1" width="3" height="99.9"/></g><g class="mark"><title>W_OV singular value 32: 1.88</title><rect class="s2" x="164.0" y="111.8" width="3" height="98.2"/></g><g class="mark"><title>W_OV singular value 33: 1.85</title><rect class="s2" x="168.0" y="113.3" width="3" height="96.7"/></g><g class="mark"><title>W_OV singular value 34: 1.84</title><rect class="s2" x="172.0" y="113.8" width="3" height="96.2"/></g><g class="mark"><title>W_OV singular value 35: 1.82</title><rect class="s2" x="176.0" y="114.7" width="3" height="95.3"/></g><g class="mark"><title>W_OV singular value 36: 1.81</title><rect class="s2" x="180.0" y="115.3" width="3" height="94.7"/></g><g class="mark"><title>W_OV singular value 37: 1.8</title><rect class="s2" x="184.0" y="116.0" width="3" height="94.0"/></g><g class="mark"><title>W_OV singular value 38: 1.79</title><rect class="s2" x="188.0" y="116.3" width="3" height="93.7"/></g><g class="mark"><title>W_OV singular value 39: 1.77</title><rect class="s2" x="192.0" y="117.5" width="3" height="92.5"/></g><g class="mark"><title>W_OV singular value 40: 1.76</title><rect class="s2" x="196.0" y="117.9" width="3" height="92.1"/></g><g class="mark"><title>W_OV singular value 41: 1.75</title><rect class="s2" x="200.0" y="118.6" width="3" height="91.4"/></g><g class="mark"><title>W_OV singular value 42: 1.73</title><rect class="s2" x="204.0" y="119.2" width="3" height="90.8"/></g><g class="mark"><title>W_OV singular value 43: 1.73</title><rect class="s2" x="208.0" y="119.5" width="3" height="90.5"/></g><g class="mark"><title>W_OV singular value 44: 1.71</title><rect class="s2" x="212.0" y="120.3" width="3" height="89.7"/></g><g class="mark"><title>W_OV singular value 45: 1.7</title><rect class="s2" x="216.0" y="121.0" width="3" height="89.0"/></g><g class="mark"><title>W_OV singular value 46: 1.67</title><rect class="s2" x="220.0" y="122.6" width="3" height="87.4"/></g><g class="mark"><title>W_OV singular value 47: 1.66</title><rect class="s2" x="224.0" y="123.1" width="3" height="86.9"/></g><g class="mark"><title>W_OV singular value 48: 1.65</title><rect class="s2" x="228.0" y="123.9" width="3" height="86.1"/></g><g class="mark"><title>W_OV singular value 49: 1.64</title><rect class="s2" x="232.0" y="124.0" width="3" height="86.0"/></g><g class="mark"><title>W_OV singular value 50: 1.63</title><rect class="s2" x="236.0" y="124.7" width="3" height="85.3"/></g><g class="mark"><title>W_OV singular value 51: 1.61</title><rect class="s2" x="240.0" y="125.7" width="3" height="84.3"/></g><g class="mark"><title>W_OV singular value 52: 1.58</title><rect class="s2" x="244.0" y="127.4" width="3" height="82.6"/></g><g class="mark"><title>W_OV singular value 53: 1.55</title><rect class="s2" x="248.0" y="128.7" width="3" height="81.3"/></g><g class="mark"><title>W_OV singular value 54: 1.55</title><rect class="s2" x="252.0" y="128.8" width="3" height="81.2"/></g><g class="mark"><title>W_OV singular value 55: 1.52</title><rect class="s2" x="256.0" y="130.2" width="3" height="79.8"/></g><g class="mark"><title>W_OV singular value 56: 1.51</title><rect class="s2" x="260.0" y="130.9" width="3" height="79.1"/></g><g class="mark"><title>W_OV singular value 57: 1.5</title><rect class="s2" x="264.0" y="131.5" width="3" height="78.5"/></g><g class="mark"><title>W_OV singular value 58: 1.47</title><rect class="s2" x="268.0" y="132.9" width="3" height="77.1"/></g><g class="mark"><title>W_OV singular value 59: 1.46</title><rect class="s2" x="272.0" y="133.8" width="3" height="76.2"/></g><g class="mark"><title>W_OV singular value 60: 1.41</title><rect class="s2" x="276.0" y="136.3" width="3" height="73.7"/></g><g class="mark"><title>W_OV singular value 61: 1.38</title><rect class="s2" x="280.0" y="137.9" width="3" height="72.1"/></g><g class="mark"><title>W_OV singular value 62: 1.36</title><rect class="s2" x="284.0" y="138.9" width="3" height="71.1"/></g><g class="mark"><title>W_OV singular value 63: 1.21</title><rect class="s2" x="288.0" y="146.5" width="3" height="63.5"/></g><g class="mark"><title>W_OV singular value 64: 1.06</title><rect class="s2" x="292.0" y="154.5" width="3" height="55.5"/></g><g class="mark"><title>W_OV singular value 65: 8.78e-07</title><rect class="s2" x="296.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 66: 8.2e-07</title><rect class="s2" x="300.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 67: 7.41e-07</title><rect class="s2" x="304.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 68: 7.19e-07</title><rect class="s2" x="308.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 69: 7.04e-07</title><rect class="s2" x="312.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 70: 6.79e-07</title><rect class="s2" x="316.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 71: 6.69e-07</title><rect class="s2" x="320.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 72: 6.5e-07</title><rect class="s2" x="324.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 73: 6.33e-07</title><rect class="s2" x="328.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 74: 6.21e-07</title><rect class="s2" x="332.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 75: 6.04e-07</title><rect class="s2" x="336.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 76: 5.89e-07</title><rect class="s2" x="340.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 77: 5.78e-07</title><rect class="s2" x="344.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 78: 5.74e-07</title><rect class="s2" x="348.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 79: 5.68e-07</title><rect class="s2" x="352.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_OV singular value 80: 5.49e-07</title><rect class="s2" x="356.0" y="209.5" width="3" height="0.5"/></g><line class="base-line" x1="296" y1="58" x2="296" y2="216"/><text class="t-tick" x="296.0" y="232.0" text-anchor="middle">64</text><text class="t-tick" x="40.0" y="232.0" text-anchor="middle">1</text><text class="t-tick" x="360.0" y="232.0" text-anchor="middle">80</text><text class="t-muted" x="40.0" y="254.0" text-anchor="start">1st 2.87, 64th 1.06, 65th 8.8e-07</text><text class="t-note" x="400.0" y="52.0" text-anchor="start">W<tspan baseline-shift="sub" style="font-size:72%">QK</tspan>: 512 × 512, rank 64</text><line class="axis" x1="400" y1="210" x2="720" y2="210"/><g class="mark"><title>W_QK singular value 1: 1.31</title><rect class="s1" x="400.0" y="60.0" width="3" height="150.0"/></g><g class="mark"><title>W_QK singular value 2: 1.2</title><rect class="s1" x="404.0" y="73.3" width="3" height="136.7"/></g><g class="mark"><title>W_QK singular value 3: 1.05</title><rect class="s1" x="408.0" y="89.6" width="3" height="120.4"/></g><g class="mark"><title>W_QK singular value 4: 1.01</title><rect class="s1" x="412.0" y="94.2" width="3" height="115.8"/></g><g class="mark"><title>W_QK singular value 5: 0.914</title><rect class="s1" x="416.0" y="105.5" width="3" height="104.5"/></g><g class="mark"><title>W_QK singular value 6: 0.895</title><rect class="s1" x="420.0" y="107.7" width="3" height="102.3"/></g><g class="mark"><title>W_QK singular value 7: 0.833</title><rect class="s1" x="424.0" y="114.8" width="3" height="95.2"/></g><g class="mark"><title>W_QK singular value 8: 0.822</title><rect class="s1" x="428.0" y="116.0" width="3" height="94.0"/></g><g class="mark"><title>W_QK singular value 9: 0.795</title><rect class="s1" x="432.0" y="119.2" width="3" height="90.8"/></g><g class="mark"><title>W_QK singular value 10: 0.78</title><rect class="s1" x="436.0" y="120.9" width="3" height="89.1"/></g><g class="mark"><title>W_QK singular value 11: 0.769</title><rect class="s1" x="440.0" y="122.1" width="3" height="87.9"/></g><g class="mark"><title>W_QK singular value 12: 0.756</title><rect class="s1" x="444.0" y="123.6" width="3" height="86.4"/></g><g class="mark"><title>W_QK singular value 13: 0.744</title><rect class="s1" x="448.0" y="124.9" width="3" height="85.1"/></g><g class="mark"><title>W_QK singular value 14: 0.732</title><rect class="s1" x="452.0" y="126.3" width="3" height="83.7"/></g><g class="mark"><title>W_QK singular value 15: 0.726</title><rect class="s1" x="456.0" y="127.0" width="3" height="83.0"/></g><g class="mark"><title>W_QK singular value 16: 0.714</title><rect class="s1" x="460.0" y="128.4" width="3" height="81.6"/></g><g class="mark"><title>W_QK singular value 17: 0.705</title><rect class="s1" x="464.0" y="129.4" width="3" height="80.6"/></g><g class="mark"><title>W_QK singular value 18: 0.694</title><rect class="s1" x="468.0" y="130.7" width="3" height="79.3"/></g><g class="mark"><title>W_QK singular value 19: 0.691</title><rect class="s1" x="472.0" y="131.0" width="3" height="79.0"/></g><g class="mark"><title>W_QK singular value 20: 0.68</title><rect class="s1" x="476.0" y="132.3" width="3" height="77.7"/></g><g class="mark"><title>W_QK singular value 21: 0.672</title><rect class="s1" x="480.0" y="133.2" width="3" height="76.8"/></g><g class="mark"><title>W_QK singular value 22: 0.664</title><rect class="s1" x="484.0" y="134.0" width="3" height="76.0"/></g><g class="mark"><title>W_QK singular value 23: 0.648</title><rect class="s1" x="488.0" y="136.0" width="3" height="74.0"/></g><g class="mark"><title>W_QK singular value 24: 0.642</title><rect class="s1" x="492.0" y="136.6" width="3" height="73.4"/></g><g class="mark"><title>W_QK singular value 25: 0.633</title><rect class="s1" x="496.0" y="137.6" width="3" height="72.4"/></g><g class="mark"><title>W_QK singular value 26: 0.621</title><rect class="s1" x="500.0" y="139.0" width="3" height="71.0"/></g><g class="mark"><title>W_QK singular value 27: 0.615</title><rect class="s1" x="504.0" y="139.7" width="3" height="70.3"/></g><g class="mark"><title>W_QK singular value 28: 0.611</title><rect class="s1" x="508.0" y="140.2" width="3" height="69.8"/></g><g class="mark"><title>W_QK singular value 29: 0.604</title><rect class="s1" x="512.0" y="140.9" width="3" height="69.1"/></g><g class="mark"><title>W_QK singular value 30: 0.593</title><rect class="s1" x="516.0" y="142.3" width="3" height="67.7"/></g><g class="mark"><title>W_QK singular value 31: 0.592</title><rect class="s1" x="520.0" y="142.4" width="3" height="67.6"/></g><g class="mark"><title>W_QK singular value 32: 0.581</title><rect class="s1" x="524.0" y="143.6" width="3" height="66.4"/></g><g class="mark"><title>W_QK singular value 33: 0.575</title><rect class="s1" x="528.0" y="144.3" width="3" height="65.7"/></g><g class="mark"><title>W_QK singular value 34: 0.57</title><rect class="s1" x="532.0" y="144.9" width="3" height="65.1"/></g><g class="mark"><title>W_QK singular value 35: 0.562</title><rect class="s1" x="536.0" y="145.7" width="3" height="64.3"/></g><g class="mark"><title>W_QK singular value 36: 0.557</title><rect class="s1" x="540.0" y="146.4" width="3" height="63.6"/></g><g class="mark"><title>W_QK singular value 37: 0.549</title><rect class="s1" x="544.0" y="147.2" width="3" height="62.8"/></g><g class="mark"><title>W_QK singular value 38: 0.547</title><rect class="s1" x="548.0" y="147.5" width="3" height="62.5"/></g><g class="mark"><title>W_QK singular value 39: 0.531</title><rect class="s1" x="552.0" y="149.3" width="3" height="60.7"/></g><g class="mark"><title>W_QK singular value 40: 0.529</title><rect class="s1" x="556.0" y="149.5" width="3" height="60.5"/></g><g class="mark"><title>W_QK singular value 41: 0.514</title><rect class="s1" x="560.0" y="151.2" width="3" height="58.8"/></g><g class="mark"><title>W_QK singular value 42: 0.506</title><rect class="s1" x="564.0" y="152.1" width="3" height="57.9"/></g><g class="mark"><title>W_QK singular value 43: 0.505</title><rect class="s1" x="568.0" y="152.3" width="3" height="57.7"/></g><g class="mark"><title>W_QK singular value 44: 0.493</title><rect class="s1" x="572.0" y="153.6" width="3" height="56.4"/></g><g class="mark"><title>W_QK singular value 45: 0.488</title><rect class="s1" x="576.0" y="154.2" width="3" height="55.8"/></g><g class="mark"><title>W_QK singular value 46: 0.48</title><rect class="s1" x="580.0" y="155.1" width="3" height="54.9"/></g><g class="mark"><title>W_QK singular value 47: 0.466</title><rect class="s1" x="584.0" y="156.7" width="3" height="53.3"/></g><g class="mark"><title>W_QK singular value 48: 0.465</title><rect class="s1" x="588.0" y="156.8" width="3" height="53.2"/></g><g class="mark"><title>W_QK singular value 49: 0.453</title><rect class="s1" x="592.0" y="158.2" width="3" height="51.8"/></g><g class="mark"><title>W_QK singular value 50: 0.437</title><rect class="s1" x="596.0" y="160.1" width="3" height="49.9"/></g><g class="mark"><title>W_QK singular value 51: 0.428</title><rect class="s1" x="600.0" y="161.0" width="3" height="49.0"/></g><g class="mark"><title>W_QK singular value 52: 0.413</title><rect class="s1" x="604.0" y="162.8" width="3" height="47.2"/></g><g class="mark"><title>W_QK singular value 53: 0.403</title><rect class="s1" x="608.0" y="163.9" width="3" height="46.1"/></g><g class="mark"><title>W_QK singular value 54: 0.39</title><rect class="s1" x="612.0" y="165.4" width="3" height="44.6"/></g><g class="mark"><title>W_QK singular value 55: 0.385</title><rect class="s1" x="616.0" y="166.0" width="3" height="44.0"/></g><g class="mark"><title>W_QK singular value 56: 0.372</title><rect class="s1" x="620.0" y="167.4" width="3" height="42.6"/></g><g class="mark"><title>W_QK singular value 57: 0.342</title><rect class="s1" x="624.0" y="170.9" width="3" height="39.1"/></g><g class="mark"><title>W_QK singular value 58: 0.307</title><rect class="s1" x="628.0" y="174.9" width="3" height="35.1"/></g><g class="mark"><title>W_QK singular value 59: 0.275</title><rect class="s1" x="632.0" y="178.6" width="3" height="31.4"/></g><g class="mark"><title>W_QK singular value 60: 0.264</title><rect class="s1" x="636.0" y="179.8" width="3" height="30.2"/></g><g class="mark"><title>W_QK singular value 61: 0.258</title><rect class="s1" x="640.0" y="180.5" width="3" height="29.5"/></g><g class="mark"><title>W_QK singular value 62: 0.227</title><rect class="s1" x="644.0" y="184.0" width="3" height="26.0"/></g><g class="mark"><title>W_QK singular value 63: 0.201</title><rect class="s1" x="648.0" y="187.0" width="3" height="23.0"/></g><g class="mark"><title>W_QK singular value 64: 0.188</title><rect class="s1" x="652.0" y="188.6" width="3" height="21.4"/></g><g class="mark"><title>W_QK singular value 65: 2.7e-07</title><rect class="s1" x="656.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 66: 2.51e-07</title><rect class="s1" x="660.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 67: 2.39e-07</title><rect class="s1" x="664.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 68: 2.19e-07</title><rect class="s1" x="668.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 69: 2.18e-07</title><rect class="s1" x="672.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 70: 2.1e-07</title><rect class="s1" x="676.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 71: 2.07e-07</title><rect class="s1" x="680.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 72: 2.02e-07</title><rect class="s1" x="684.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 73: 1.96e-07</title><rect class="s1" x="688.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 74: 1.91e-07</title><rect class="s1" x="692.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 75: 1.89e-07</title><rect class="s1" x="696.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 76: 1.84e-07</title><rect class="s1" x="700.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 77: 1.82e-07</title><rect class="s1" x="704.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 78: 1.79e-07</title><rect class="s1" x="708.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 79: 1.78e-07</title><rect class="s1" x="712.0" y="209.5" width="3" height="0.5"/></g><g class="mark"><title>W_QK singular value 80: 1.76e-07</title><rect class="s1" x="716.0" y="209.5" width="3" height="0.5"/></g><line class="base-line" x1="656" y1="58" x2="656" y2="216"/><text class="t-tick" x="656.0" y="232.0" text-anchor="middle">64</text><text class="t-tick" x="400.0" y="232.0" text-anchor="middle">1</text><text class="t-tick" x="720.0" y="232.0" text-anchor="middle">80</text><text class="t-muted" x="400.0" y="254.0" text-anchor="start">1st 1.31, 64th 0.19, 65th 2.7e-07</text></svg><figcaption>The first 80 of the 512 singular values of head 0.3's two matrices. In W_OV the first 64 run from 2.87 down to 1.06; in W_QK from 1.31 down to 0.19. From number 65 on, both are zero up to rounding (below 0.000001). Both 512 by 512 matrices have rank exactly 64.</figcaption></figure>

There is a sharp cliff after value 64. The 65th singular value is about a million times smaller than the 64th, which means it is zero up to rounding. So each 512 × 512 matrix really lives in 64 dimensions.

Does the head read and write in different places, as the paper's drawing says? We measured the overlap between the 64-dimensional read subspace and the 64-dimensional write subspace of each head's $$W_{\mathrm{OV}}$$. The score is 1 if they are the same subspace and 0 if they are at right angles. Two random 64-dimensional subspaces of a 512-dimensional space score about $$64/512=0.125$$.

```text
  overlap of the 64-dim read and write subspaces of W_OV (1 = the same subspace, 0 = at right angles, random 64-dim subspaces of 512 dims: 0.125)
    head 0.0: 0.153, head 0.1: 0.176, head 0.2: 0.134, head 0.3: 0.155, head 0.4: 0.130, head 0.5: 0.120, head 0.6: 0.130, head 0.7: 0.155
```

Every head scores between 0.120 and 0.176, close to the random 0.125. So the heads read from one part of the stream and write to a mostly different part. For head 0.3 this makes sense. It reads "which token is this" (an embedding direction) and writes "which token should come next" (an unembedding direction). Part 1 showed that these are different, because $$W_{\mathrm{U}}$$ is not the inverse of $$W_{\mathrm{E}}$$.

### Queries, keys and values are superficial

> [!PAPER] · Observations about Attention Heads
> [![The observations that W_Q and W_K always operate together, that keys, queries and values are superficial, and the definitions of W_OV and W_QK](https://ishwarj.com/img/papers/circuits/p2-always-together.pngalways-together.png)](/img/papers/circuits/p2-always-together.png)
>
> **What it says:** $$W_{\mathrm{Q}}$$ and $$W_{\mathrm{K}}$$ "always operate together", and so do $$W_{\mathrm{O}}$$ and $$W_{\mathrm{V}}$$. So "keys, queries and value vectors are, in some sense, superficial", and "one could easily reparametrize" them. The paper names the products $$W_{\mathrm{OV}}=W_{\mathrm{O}} W_{\mathrm{V}}$$ and $$W_{\mathrm{QK}}={W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}$$.
>
> **What it means:**
>
> Think of the number 12. You can write it as 3 × 4, as 2 × 6 or as 24 × 0.5. The factors are a choice; only the product is fixed. $$W_{\mathrm{O}} W_{\mathrm{V}}$$ works the same way: many pairs of factors give the same product.
>
> Queries, keys and values are by-products of one such choice. The familiar story about them describes one of infinitely many equal ways to split the same two low-rank matrices. Swap the factors for another pair with the same product, and you get different vectors that work identically.
>
> Only the products are fixed by what the head does, so only the products deserve to be interpreted. Below, "reparametrize" becomes exact, and then we test it on the real head.

What does "reparametrize" mean? Take any invertible 64 × 64 matrix $$M$$. Replace $$W_{\mathrm{V}}$$ by $$M\,W_{\mathrm{V}}$$ and $$W_{\mathrm{O}}$$ by $$W_{\mathrm{O}} M^{-1}$$. The value vectors are now completely different. But their product is unchanged:

$$
\begin{aligned}
W_{\mathrm{O}}'W_{\mathrm{V}}'&=(W_{\mathrm{O}} M^{-1})(M\,W_{\mathrm{V}})\\
&=W_{\mathrm{O}}\,(M^{-1}M)\,W_{\mathrm{V}}\\
&=W_{\mathrm{O}} W_{\mathrm{V}}
\end{aligned}
$$

> [!DEFINITION] Invertible matrix
> A square matrix $$M$$ that can be undone: there is a matrix $$M^{-1}$$ with $$M^{-1}M=I$$, the identity. Multiplying by $$M$$ and then by $$M^{-1}$$ gets you back where you started.

The same trick works for queries and keys, with $$M$$ on one side and the transpose of $$M^{-1}$$ on the other. In our toy, scaling every value by $$M=2$$ and $$W_{\mathrm{O}}$$ by one half gives new values $$(4,2,0)$$ but exactly the same outputs.

On the real head we used a random 64 × 64 matrix. The value vectors and queries change completely, and the head does not change at all:

```text
== 6. CHANGE THE VALUES WITH ANY INVERTIBLE 64 x 64 MATRIX M: THE HEAD DOES NOT CHANGE
  value vectors: mean |change| 4.62 (their mean size is 0.58); head output: max |change| 3.9e-14
  queries: mean |change| 5.28 (mean size 0.72); every query-key score: max |change| 2.0e-12 (mean size 22.83)
```

The values moved by 4.62 on average, eight times their usual size. The head's output moved by less than $$10^{-13}$$. So "dimension 17 of the value vector" means nothing on its own, just as "dimension 7 of the stream" meant nothing in Part 1. The meaningful objects are $$W_{\mathrm{OV}}$$ and $$W_{\mathrm{QK}}$$.

### Products of heads behave like heads

The last observation looks ahead. By the mixed-product property, two heads applied one after the other combine like this:

$$
\begin{aligned}
&(A^{2}\otimes W_{\mathrm{OV}}^{2})(A^{1}\otimes W_{\mathrm{OV}}^{1})\\
&=(A^{2}A^{1})\otimes(W_{\mathrm{OV}}^{2}W_{\mathrm{OV}}^{1})
\end{aligned}
$$

The result has the same shape as one head: a pattern $$A^2A^1$$ and an OV matrix $$W_{\mathrm{OV}}^2W_{\mathrm{OV}}^1$$. The paper calls it a **virtual attention head**. It only appears when there are two layers, so Part 5 comes back to it. Our toy script checked the property itself on 2 × 2 matrices, with a difference of exactly 0.

## From weights to tokens: the QK and OV circuits {§Splitting Attention Head terms into Query-Key and Output-Value Circuits}

The paper's last step for a single head turns both matrices into tables of tokens.

> [!PAPER] · Splitting Attention Head terms into Query-Key and Output-Value Circuits
> [![The paper's figure of the OV circuit W_U W_O W_V W_E from a source token to the output, and the QK circuit W_E^T W_Q^T W_K W_E from the source and destination tokens to an attention score](https://ishwarj.com/img/papers/circuits/p2-circuits-fig.pngp2-circuits-fig.png)](/img/papers/circuits/p2-circuits-fig.png)
>
> **What it says:** the **OV ("output-value") circuit**, $$W_{\mathrm{U}} W_{\mathrm{O}} W_{\mathrm{V}} W_{\mathrm{E}}$$, "determines how attending to a given token affects the logits". The **QK ("query-key") circuit**, $${W_{\mathrm{E}}}^{\top} {W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}} W_{\mathrm{E}}$$, "controls which tokens the head prefers to attend to". Each one is a path through the model that starts and ends at tokens.
>
> **What it means:**
>
> So far $$W_{\mathrm{QK}}$$ and $$W_{\mathrm{OV}}$$ act on the 512-number stream, and a stream vector is hard to read. A token is easy to read. Attach the embedding at the start and the unembedding at the end, and both matrices become tables with a token on each side.
>
> The OV circuit answers one question: "if the head reads this token, which next tokens go up?" The QK circuit answers another: "standing on this token, which earlier tokens does the head want to read?"
>
> The paper defines them inside its study of the one-layer model. Here we only build them and read one head. Part 4 reads them as skip-trigrams.

### The derivation

Take a one-layer model and ignore the position embedding for now, as the paper does. Then the stream that the head reads at position $$j$$ is just the token's embedding, $$x_j=W_{\mathrm{E}}\,t_j$$, where $$t_j$$ is the one-hot vector of the token (Part 1).

**The QK circuit.** Put $$x_i=W_{\mathrm{E}} t_i$$ and $$x_j=W_{\mathrm{E}} t_j$$ into the score:

$$
\begin{aligned}
s_{ij}&=x_i^\top W_{\mathrm{QK}}\,x_j\\
&=(W_{\mathrm{E}} t_i)^\top W_{\mathrm{QK}}\,(W_{\mathrm{E}} t_j)\\
&=t_i^\top\big({W_{\mathrm{E}}}^{\top} W_{\mathrm{QK}} W_{\mathrm{E}}\big)\,t_j
\end{aligned}
$$

The matrix in the bracket is the QK circuit. It multiplies a 48,262 × 512 matrix, a 512 × 512 matrix and a 512 × 48,262 matrix, so its shape is 48,262 × 48,262. Multiplying by two one-hot vectors just picks one entry. So the entry in row $$a$$, column $$b$$ is the score that a destination token $$a$$ gives to a source token $$b$$. It is a table of "how much does token $$a$$ want to read token $$b$$".

**The OV circuit.** The head adds $$h(x)_i$$ to the stream, and in a one-layer model the stream goes straight to the unembedding. So the head's effect on the logits at position $$i$$ is $$W_{\mathrm{U}}\,h(x)_i$$. Using our one-line formula for the head:

$$
\begin{aligned}
W_{\mathrm{U}} h(x)_i&=\sum_j A_{ij}\,W_{\mathrm{U}} W_{\mathrm{OV}}\,x_j\\
&=\sum_j A_{ij}\,\big(W_{\mathrm{U}} W_{\mathrm{OV}} W_{\mathrm{E}}\big)\,t_j
\end{aligned}
$$

The matrix in the bracket is the OV circuit, also $$48{,}262\times48{,}262$$. Column $$b$$ of it is a list of 48,262 logit changes. It answers: "if this head reads token $$b$$ with full weight, which next tokens does it push up?"

> [!DEFINITION] QK circuit and OV circuit
> The **QK circuit** $${W_{\mathrm{E}}}^{\top} W_{\mathrm{QK}} W_{\mathrm{E}}$$ is a table of attention scores, with one row per destination token and one column per source token. The **OV circuit** $$W_{\mathrm{U}} W_{\mathrm{OV}} W_{\mathrm{E}}$$ is a table of logit effects, with one column per source token and one row per output token. Together they describe one head of a one-layer model completely, apart from positions.

<figure class="fig"><svg viewBox="0 0 760 350" role="img" aria-label="Two path diagrams. QK circuit: a destination token goes through W_E and W_Q to a 64-number query, a source token goes through W_E and W_K to a 64-number key, and their dot product is one attention score. OV circuit: a source token goes through W_E, W_V, W_O and W_U to 48,262 logits. Each circuit is a 48,262 by 48,262 table."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="26.0" text-anchor="start">The two circuits of one head, as paths from tokens to tokens</text><text class="t-note" x="24.0" y="58.0" text-anchor="start">QK circuit  W<tspan baseline-shift="sub" style="font-size:72%">E</tspan>ᵀ W<tspan baseline-shift="sub" style="font-size:72%">Q</tspan>ᵀ W<tspan baseline-shift="sub" style="font-size:72%">K</tspan> W<tspan baseline-shift="sub" style="font-size:72%">E</tspan>: how much a destination token wants to read a source token</text><rect class="box-1" x="24.0" y="72.0" width="116.0" height="32.0" rx="6"/><text class="t-tick" x="82.0" y="92.5" text-anchor="middle">destination</text><line class="edge" x1="144.0" y1="88.0" x2="164.0" y2="88.0" marker-end="url(#ah)"/><rect class="box" x="168.0" y="72.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="214.0" y="92.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">E</tspan></text><text class="t-muted" x="214.0" y="122.0" text-anchor="middle">512 × 48,262</text><line class="edge" x1="264.0" y1="88.0" x2="284.0" y2="88.0" marker-end="url(#ah)"/><rect class="box" x="288.0" y="72.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="334.0" y="92.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">Q</tspan></text><text class="t-muted" x="334.0" y="122.0" text-anchor="middle">64 × 512</text><line class="edge" x1="384.0" y1="88.0" x2="404.0" y2="88.0" marker-end="url(#ah)"/><rect class="box-1" x="408.0" y="72.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="454.0" y="92.5" text-anchor="middle">query q</text><text class="t-muted" x="454.0" y="122.0" text-anchor="middle">64</text><rect class="box-1" x="24.0" y="140.0" width="116.0" height="32.0" rx="6"/><text class="t-tick" x="82.0" y="160.5" text-anchor="middle">source</text><line class="edge" x1="144.0" y1="156.0" x2="164.0" y2="156.0" marker-end="url(#ah)"/><rect class="box" x="168.0" y="140.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="214.0" y="160.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">E</tspan></text><text class="t-muted" x="214.0" y="190.0" text-anchor="middle">512 × 48,262</text><line class="edge" x1="264.0" y1="156.0" x2="284.0" y2="156.0" marker-end="url(#ah)"/><rect class="box" x="288.0" y="140.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="334.0" y="160.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">K</tspan></text><text class="t-muted" x="334.0" y="190.0" text-anchor="middle">64 × 512</text><line class="edge" x1="384.0" y1="156.0" x2="404.0" y2="156.0" marker-end="url(#ah)"/><rect class="box-1" x="408.0" y="140.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="454.0" y="160.5" text-anchor="middle">key k</text><text class="t-muted" x="454.0" y="190.0" text-anchor="middle">64</text><line class="edge" x1="504.0" y1="88.0" x2="530.0" y2="118.0"/><line class="edge" x1="504.0" y1="156.0" x2="530.0" y2="126.0"/><rect class="box-3" x="536.0" y="106.0" width="200.0" height="32.0" rx="6"/><text class="t-tick" x="636.0" y="126.5" text-anchor="middle">score q · k (one number)</text><text class="t-note" x="24.0" y="232.0" text-anchor="start">OV circuit  W<tspan baseline-shift="sub" style="font-size:72%">U</tspan> W<tspan baseline-shift="sub" style="font-size:72%">O</tspan> W<tspan baseline-shift="sub" style="font-size:72%">V</tspan> W<tspan baseline-shift="sub" style="font-size:72%">E</tspan>: what reading a source token does to the output logits</text><rect class="box-2" x="24.0" y="248.0" width="116.0" height="32.0" rx="6"/><text class="t-tick" x="82.0" y="268.5" text-anchor="middle">source</text><line class="edge" x1="144.0" y1="264.0" x2="164.0" y2="264.0" marker-end="url(#ah)"/><rect class="box" x="168.0" y="248.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="214.0" y="268.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">E</tspan></text><text class="t-muted" x="214.0" y="298.0" text-anchor="middle">512 × 48,262</text><line class="edge" x1="264.0" y1="264.0" x2="284.0" y2="264.0" marker-end="url(#ah)"/><rect class="box" x="288.0" y="248.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="334.0" y="268.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">V</tspan></text><text class="t-muted" x="334.0" y="298.0" text-anchor="middle">64 × 512</text><line class="edge" x1="384.0" y1="264.0" x2="404.0" y2="264.0" marker-end="url(#ah)"/><rect class="box" x="408.0" y="248.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="454.0" y="268.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">O</tspan></text><text class="t-muted" x="454.0" y="298.0" text-anchor="middle">512 × 64</text><line class="edge" x1="504.0" y1="264.0" x2="524.0" y2="264.0" marker-end="url(#ah)"/><rect class="box" x="528.0" y="248.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="574.0" y="268.5" text-anchor="middle">W<tspan baseline-shift="sub" style="font-size:72%">U</tspan></text><text class="t-muted" x="574.0" y="298.0" text-anchor="middle">48,262 × 512</text><line class="edge" x1="624.0" y1="264.0" x2="644.0" y2="264.0" marker-end="url(#ah)"/><rect class="box-2" x="648.0" y="248.0" width="92.0" height="32.0" rx="6"/><text class="t-tick" x="694.0" y="268.5" text-anchor="middle">logits</text><text class="t-muted" x="694.0" y="298.0" text-anchor="middle">48,262</text><text class="t-tick" x="24.0" y="336.0" text-anchor="start">Each circuit is one 48,262 × 48,262 table: one row or column per token.</text></svg><figcaption>The two circuits as paths. QK: the destination token goes through W_E and W_Q to a 64-number query, a source token goes through W_E and W_K to a 64-number key, and their dot product is one score. OV: the source token goes through W_E, W_V, W_O and W_U to 48,262 logits. Each circuit is a 48,262 by 48,262 table.</figcaption></figure>

Look at the formula for $$W_{\mathrm{U}} h(x)_i$$ once more. It is the sum over source tokens of **(weight from QK) × (effect from OV)**. The QK circuit only affects the weights $$A_{ij}$$. The OV circuit only affects what each source contributes. That is the "completely separable" of the paper, now written in tokens.

**Why splitting is useful.** Each circuit is a fixed table that can be read from the weights alone, without any input text. The QK circuit is bilinear (a score between two tokens), and the OV circuit is linear (an effect of one token). Both are easy kinds of function. The only hard part, the softmax, sits between them and does not change what either table says.

### Reading the OV circuit of head 0.3

A full circuit has $$48{,}262^2\approx2.33$$ billion entries, which is too many to store comfortably. So we compute one column at a time. There is one practical step. The leftover layer norm (Part 1) divides each token's vector by its size before the head reads it. So we scale every embedding to that same size first. A scale does not change which outputs come top in a column, but it keeps different tokens comparable.

```python
WE = model.W_E - model.W_E.mean(1, keepdim=True)
WE = WE / WE.std(1, keepdim=True)                                 # what layer norm does to each token
t = model.to_single_token(' tea')
col = (WE[t] @ model.W_V[0, 3] @ model.W_O[0, 3]) @ model.W_U     # column ' tea' of W_U W_OV W_E
print(model.to_str_tokens(col.topk(6).indices))
```

```text
== 7. THE OV CIRCUIT W_U W_OV W_E AND THE QK CIRCUIT W_E^T W_QK W_E (head 0.3, read from the weights only)
  each full circuit is 48,262 x 48,262 = 2.33 billion numbers, so we compute one column or row at a time
  OV  attend to ' tea'     -> raises [' tea', ' Tea', ' teac', ' brew', ' brewing', ' flavon']
  OV  attend to ' green'   -> raises [' green', 'Green', ' greens', 'green', ' Green', ' cyan']
  OV  attend to ' Paris'   -> raises ['Paris', ' Paris', 'France', ' rue', 'French', 'rès']
  OV  attend to ' Obama'   -> raises ['Obama', ' Obama', ' McCain', ' Romney', ' Barack', ' Palin']
  OV  attend to ' coffee'  -> raises [' Coffee', ' coffee', ' caffeine', ' Starbucks', ' roast', ' caffe']
  OV  attend to ' cat'     -> raises [' cats', ' cat', 'Cat', ' Cat', 'cats', ' euthan']
  OV  attend to ' London'  -> raises ['London', ' London', 'inburgh', ' Thames', 'Brit', 'Oxford']
  OV  attend to ' Potter'  -> raises [' Potter', ' Hog', 'Harry', ' wand', ' teac', 'Ep']
```

<figure class="fig"><svg viewBox="0 0 760 310" role="img" aria-label="For six source tokens, the four output tokens whose logits head 0.3 raises most when it attends to them: tea to tea, Tea, teac, brew; green to green, -Green, greens, -green; Paris to -Paris, Paris, -France, rue; Obama to -Obama, Obama, McCain, Romney; coffee to Coffee, coffee, caffeine, Starbucks; London to -London, London, -inburgh, Thames."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="24.0" text-anchor="start">OV circuit of head 0.3: "if I read this token, I raise these logits"</text><text class="t-tick" x="24.0" y="44.0" text-anchor="start">top 4 entries of a column of W<tspan baseline-shift="sub" style="font-size:72%">U</tspan> W<tspan baseline-shift="sub" style="font-size:72%">OV</tspan> W<tspan baseline-shift="sub" style="font-size:72%">E</tspan>, computed from the weights only (no text is run)</text><rect class="box-2" x="24.0" y="64.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="83.5" text-anchor="middle">tea</text><line class="edge" x1="140.0" y1="79.0" x2="176.0" y2="79.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="64.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="83.5" text-anchor="middle">tea</text><rect class="box" x="324.0" y="64.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="83.5" text-anchor="middle">Tea</text><rect class="box" x="464.0" y="64.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="83.5" text-anchor="middle">teac</text><rect class="box" x="604.0" y="64.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="83.5" text-anchor="middle">brew</text><rect class="box-2" x="24.0" y="104.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="123.5" text-anchor="middle">green</text><line class="edge" x1="140.0" y1="119.0" x2="176.0" y2="119.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="104.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="123.5" text-anchor="middle">green</text><rect class="box" x="324.0" y="104.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="123.5" text-anchor="middle">-Green</text><rect class="box" x="464.0" y="104.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="123.5" text-anchor="middle">greens</text><rect class="box" x="604.0" y="104.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="123.5" text-anchor="middle">-green</text><rect class="box-2" x="24.0" y="144.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="163.5" text-anchor="middle">Paris</text><line class="edge" x1="140.0" y1="159.0" x2="176.0" y2="159.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="144.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="163.5" text-anchor="middle">-Paris</text><rect class="box" x="324.0" y="144.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="163.5" text-anchor="middle">Paris</text><rect class="box" x="464.0" y="144.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="163.5" text-anchor="middle">-France</text><rect class="box" x="604.0" y="144.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="163.5" text-anchor="middle">rue</text><rect class="box-2" x="24.0" y="184.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="203.5" text-anchor="middle">Obama</text><line class="edge" x1="140.0" y1="199.0" x2="176.0" y2="199.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="184.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="203.5" text-anchor="middle">-Obama</text><rect class="box" x="324.0" y="184.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="203.5" text-anchor="middle">Obama</text><rect class="box" x="464.0" y="184.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="203.5" text-anchor="middle">McCain</text><rect class="box" x="604.0" y="184.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="203.5" text-anchor="middle">Romney</text><rect class="box-2" x="24.0" y="224.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="243.5" text-anchor="middle">coffee</text><line class="edge" x1="140.0" y1="239.0" x2="176.0" y2="239.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="224.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="243.5" text-anchor="middle">Coffee</text><rect class="box" x="324.0" y="224.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="243.5" text-anchor="middle">coffee</text><rect class="box" x="464.0" y="224.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="243.5" text-anchor="middle">caffeine</text><rect class="box" x="604.0" y="224.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="243.5" text-anchor="middle">Starbucks</text><rect class="box-2" x="24.0" y="264.0" width="110.0" height="30.0" rx="6"/><text class="t-tick" x="79.0" y="283.5" text-anchor="middle">London</text><line class="edge" x1="140.0" y1="279.0" x2="176.0" y2="279.0" marker-end="url(#ah)"/><rect class="box-3" x="184.0" y="264.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="249.0" y="283.5" text-anchor="middle">-London</text><rect class="box" x="324.0" y="264.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="389.0" y="283.5" text-anchor="middle">London</text><rect class="box" x="464.0" y="264.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="529.0" y="283.5" text-anchor="middle">-inburgh</text><rect class="box" x="604.0" y="264.0" width="130.0" height="30.0" rx="6"/><text class="t-tick" x="669.0" y="283.5" text-anchor="middle">Thames</text></svg><figcaption>The OV circuit of head 0.3, read from the weights with no text at all. When the head reads "tea", it raises tea, Tea, teac and brew. When it reads "Paris", it raises Paris and France. When it reads "Obama", it raises Obama, McCain and Romney. A leading dash marks a piece glued to the word before.</figcaption></figure>

The pattern is clear. Whatever token head 0.3 reads, it pushes up **that same token** and close relatives: other spellings, plurals, related words ("Paris" brings "France", "Obama" brings "McCain"). This is a **copying** head. We can count it over 2,000 ordinary tokens (numbers 1,000 to 2,999):

```text
  share of tokens 1000..2999 whose top OV output is the token itself: 0.0: 0.37, 0.1: 0.00, 0.2: 0.00, 0.3: 0.34, 0.4: 0.26, 0.5: 0.00, 0.6: 0.12, 0.7: 0.00
```

For head 0.3, the top output is the token itself for 34% of tokens. Heads 0.0 and 0.4 copy too; heads 0.1, 0.2, 0.5 and 0.7 almost never do. So the eight heads of one layer really do different jobs, and the OV circuit tells them apart from the weights alone.

This explains our prompt. On the last " green", the QK side made the head read " tea", and the OV side turned "I read tea" into "push up tea". The output we read earlier (tea +2.62) is built the same way: this column of the OV circuit, weighted by 0.37, plus the columns of the other tokens the head read, each weighted by its own attention. In the real model the values also carry a position part, so the match is not exact, but the mechanism is the same.

### Reading the QK circuit of head 0.3

For the QK circuit we fix a destination token and compute its row: the score it gives to every one of the 48,262 possible source tokens. This leaves out positions and biases, so it shows only the token part of the score.

```python
K = WE @ model.W_K[0, 3]                                  # the key of every token: [48262, 64]
q = WE[model.to_single_token(' in')] @ model.W_Q[0, 3]    # the query of ' in'
row = K @ q / 8                                           # row ' in' of W_E^T W_QK W_E
```

```text
  QK  query ' in'    -> attends most to ['imbabwe', ' Bulgaria', ' Cambodia', 'agua', 'htra', ' vivo', ' Aires', 'alore']  (scores 4.6 .. 3.9; median 0.5)
  QK  query ' see'   -> attends most to [' Derek', ' Trudeau', ' Shawn', ' Stephanie', ' Laden', ' Elaine', ' Bess', ' Cassie']  (scores 2.8 .. 2.7; median 0.2)
  QK  query ' of'    -> attends most to [' HBV', ' schizophrenia', ' cirrhosis', ' hepatocellular', ' sepsis', 'aucoma', ' ovarian', ' psori']  (scores 2.7 .. 2.4; median 0.4)
  QK  query ' the'   -> attends most to [' cytosol', 'arynx', ' myocardium', ' landlord', 'aucoma', ' cerebellum', ' cytoplasm', ' debtor']  (scores 2.8 .. 2.5; median 0.5)
  QK  query ' drink' -> attends most to ['()))', "']))", 'ength', '())', ',)', 'ayout', ' and', 'er']  (scores 3.0 .. 2.6; median -0.1)
```

<figure class="fig"><svg viewBox="0 0 760 270" role="img" aria-label="For five destination tokens, the four source tokens head 0.3 scores highest: in to -imbabwe (from Zimbabwe), Bulgaria, Cambodia, -agua; see to Derek, Trudeau, Shawn, Stephanie; of to HBV, schizophrenia, cirrhosis, hepatocellular; the to cytosol, -arynx, myocardium, landlord; drink to code punctuation with no clear pattern."><defs><marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="arrow" d="M0,0L10,5L0,10z"/></marker><marker id="ah-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-on" d="M0,0L10,5L0,10z"/></marker><marker id="ah-2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path class="arrow-2" d="M0,0L10,5L0,10z"/></marker></defs><text class="t-title" x="24.0" y="24.0" text-anchor="start">QK circuit of head 0.3: "standing on this token, which earlier tokens do I read?"</text><text class="t-tick" x="24.0" y="44.0" text-anchor="start">top 4 entries of a row of W<tspan baseline-shift="sub" style="font-size:72%">E</tspan>ᵀ W<tspan baseline-shift="sub" style="font-size:72%">QK</tspan> W<tspan baseline-shift="sub" style="font-size:72%">E</tspan> (no positions, no biases), from the weights only</text><rect class="box-1" x="24.0" y="64.0" width="90.0" height="30.0" rx="6"/><text class="t-tick" x="69.0" y="83.5" text-anchor="middle">in</text><line class="edge" x1="120.0" y1="79.0" x2="152.0" y2="79.0" marker-end="url(#ah)"/><rect class="box-3" x="160.0" y="64.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="220.0" y="83.5" text-anchor="middle">-imbabwe</text><rect class="box" x="288.0" y="64.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="348.0" y="83.5" text-anchor="middle">Bulgaria</text><rect class="box" x="416.0" y="64.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="476.0" y="83.5" text-anchor="middle">Cambodia</text><rect class="box" x="544.0" y="64.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="604.0" y="83.5" text-anchor="middle">-agua</text><rect class="box-1" x="24.0" y="104.0" width="90.0" height="30.0" rx="6"/><text class="t-tick" x="69.0" y="123.5" text-anchor="middle">see</text><line class="edge" x1="120.0" y1="119.0" x2="152.0" y2="119.0" marker-end="url(#ah)"/><rect class="box-3" x="160.0" y="104.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="220.0" y="123.5" text-anchor="middle">Derek</text><rect class="box" x="288.0" y="104.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="348.0" y="123.5" text-anchor="middle">Trudeau</text><rect class="box" x="416.0" y="104.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="476.0" y="123.5" text-anchor="middle">Shawn</text><rect class="box" x="544.0" y="104.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="604.0" y="123.5" text-anchor="middle">Stephanie</text><rect class="box-1" x="24.0" y="144.0" width="90.0" height="30.0" rx="6"/><text class="t-tick" x="69.0" y="163.5" text-anchor="middle">of</text><line class="edge" x1="120.0" y1="159.0" x2="152.0" y2="159.0" marker-end="url(#ah)"/><rect class="box-3" x="160.0" y="144.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="220.0" y="163.5" text-anchor="middle">HBV</text><rect class="box" x="288.0" y="144.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="348.0" y="163.5" text-anchor="middle">schizophrenia</text><rect class="box" x="416.0" y="144.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="476.0" y="163.5" text-anchor="middle">cirrhosis</text><rect class="box" x="544.0" y="144.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="604.0" y="163.5" text-anchor="middle">hepatocellular</text><rect class="box-1" x="24.0" y="184.0" width="90.0" height="30.0" rx="6"/><text class="t-tick" x="69.0" y="203.5" text-anchor="middle">the</text><line class="edge" x1="120.0" y1="199.0" x2="152.0" y2="199.0" marker-end="url(#ah)"/><rect class="box-3" x="160.0" y="184.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="220.0" y="203.5" text-anchor="middle">cytosol</text><rect class="box" x="288.0" y="184.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="348.0" y="203.5" text-anchor="middle">-arynx</text><rect class="box" x="416.0" y="184.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="476.0" y="203.5" text-anchor="middle">myocardium</text><rect class="box" x="544.0" y="184.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="604.0" y="203.5" text-anchor="middle">landlord</text><rect class="box-1" x="24.0" y="224.0" width="90.0" height="30.0" rx="6"/><text class="t-tick" x="69.0" y="243.5" text-anchor="middle">drink</text><line class="edge" x1="120.0" y1="239.0" x2="152.0" y2="239.0" marker-end="url(#ah)"/><rect class="box" x="160.0" y="224.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="220.0" y="243.5" text-anchor="middle">-()))</text><rect class="box" x="288.0" y="224.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="348.0" y="243.5" text-anchor="middle">-']))</text><rect class="box" x="416.0" y="224.0" width="120.0" height="30.0" rx="6"/><text class="t-tick" x="476.0" y="243.5" text-anchor="middle">-ength</text><text class="t-muted" x="604.0" y="244.0" text-anchor="middle">(no clear pattern)</text></svg><figcaption>The QK circuit of head 0.3, read from the weights. Standing on "in", the head most wants to read place names (-imbabwe from Zimbabwe, Bulgaria, Cambodia). On "see", it wants first names (Derek, Shawn, Stephanie). On "of", it wants diseases (HBV, schizophrenia, cirrhosis). On "the", it wants nouns such as cytosol and landlord. The row for "drink" shows no clear pattern.</figcaption></figure>

Most rows make sense once you pair them with the OV circuit. Standing on " in", the head looks for an earlier place name, and its OV circuit then copies that place: "... Bulgaria ... in" → "Bulgaria". Standing on " see", it looks for an earlier first name and copies it. The top scores (2.7 to 4.6) sit far above the typical score of each row, which is between 0.2 and 0.5, so these choices are strong.

Not every row is this clean. The row for " drink" is topped by pieces of code punctuation. This is honest data: a single head has 64 dimensions to serve 48,262 tokens, and the token-only view leaves out positions and biases. Part 4 shows how the paper summarises whole circuits rather than picking rows, and where the simple reading breaks down.

> [!TAKEAWAYS] Key takeaways
> - **Heads are independent and additive.** Stacking the result vectors and multiplying by the big $$W_{\mathrm{O}}^H$$ equals each head times its own slice of $$W_{\mathrm{O}}$$, added up. On `attn-only-1l` and `attn-only-2l` the two ways differed by at most 0.000006.
> - **A head moves information between tokens.** Its value step and output step act on each token alone. Only the attention pattern $$A$$ mixes tokens. On our prompt, head 0.3 read " tea" with weight 0.37 and wrote a direction whose top token is " tea".
> - **The whole head is one formula:** $$h(x)=(A\otimes W_{\mathrm{O}} W_{\mathrm{V}})\,x=A\,x\,{W_{\mathrm{OV}}}^{\top}$$. The left factor says where information comes from, and the right factor says what is moved. The order of the two does not matter.
> - **The pattern needs only one matrix:** $$s_{ij}=x_i^\top W_{\mathrm{QK}}\,x_j$$ with $$W_{\mathrm{QK}}={W_{\mathrm{Q}}}^{\top} W_{\mathrm{K}}$$. On the real head it reproduced the pattern to within 0.0000006.
> - **Both matrices are low-rank.** $$W_{\mathrm{OV}}$$ and $$W_{\mathrm{QK}}$$ are 512 × 512 but have rank exactly 64. The heads read and write in mostly different subspaces (overlap 0.12 to 0.18, close to the random 0.125).
> - **Queries, keys and values are superficial.** A random invertible 64 × 64 change moved the values by 4.62 on average and the output by less than $$10^{-13}$$. Only $$W_{\mathrm{OV}}$$ and $$W_{\mathrm{QK}}$$ are meaningful.
> - **The QK circuit** $${W_{\mathrm{E}}}^{\top} W_{\mathrm{QK}} W_{\mathrm{E}}$$ says which tokens a head wants to read, and **the OV circuit** $$W_{\mathrm{U}} W_{\mathrm{OV}} W_{\mathrm{E}}$$ says what reading them does to the logits. Head 0.3 is a copying head: reading " tea" raises " tea", and reading " Paris" raises " Paris" and "France".

**Next, in Part 3:** we put the pieces together. The paper's **path expansion trick** multiplies out the whole model, embedding, heads and unembedding, and turns it into a sum of end-to-end paths: the direct path from Part 1, plus one term per head built from exactly the QK and OV circuits of this part. **Part 4** then reads those terms for the one-layer model as **skip-trigrams**, with the paper's results on copying and its "bugs".

<details>
<summary>Run it yourself</summary>

The two scripts behind this part are [`circuits_part2.py`](https://github.com/ishwar6/ishwar-books/blob/main/code/papers/circuits/circuits_part2.py) (every real-model number: the shapes, the head-sum check on both models, the attention pattern, the tensor form, the one-step pattern, the ranks and singular values, the reparametrisation test, and the OV and QK circuits) and [`circuits_part2_toy.py`](https://github.com/ishwar6/ishwar-books/blob/main/code/papers/circuits/circuits_part2_toy.py) (the hand-sized examples). The first one downloads `attn-only-1l` and `attn-only-2l` from Hugging Face the first time, then runs on the CPU in under 10 seconds.

TransformerLens 4 replaced the `HookedTransformer` class used here, so install a 3.x version:

```bash
pip install torch "transformer_lens<4"
python circuits_part2.py        # writes results/part2.json and results/part2_stdout.txt
python circuits_part2_toy.py    # writes results/part2_toy.json
```

<figure><img src="/img/papers/circuits/part2-run.png" alt="Terminal output of circuits_part2.py: the head's four matrix shapes, the concatenate-versus-sum check for three layers, the attention pattern of head 0.3 and what it moved, the one-step pattern from W_QK, the ranks and singular values of W_OV and W_QK, the reparametrisation test, and the OV and QK circuits of head 0.3" loading="lazy" /><figcaption>The real output of circuits_part2.py.</figcaption></figure>

<figure><img src="/img/papers/circuits/part2_toy-run.png" alt="Terminal output of circuits_part2_toy.py: two heads added both ways, one head moving information in three steps, the tensor product in both orders and as a 4 by 4 matrix, one attention score computed two ways, and rescaled values" loading="lazy" /><figcaption>The real output of circuits_part2_toy.py.</figcaption></figure>

</details>

## References

**The paper**

1. N. Elhage, N. Nanda, C. Olsson, T. Henighan, N. Joseph, B. Mann, A. Askell, Y. Bai, A. Chen, T. Conerly, N. DasSarma, D. Drain, D. Ganguli, Z. Hatfield-Dodds, D. Hernandez, A. Jones, J. Kernion, L. Lovitt, K. Ndousse, D. Amodei, T. Brown, J. Clark, J. Kaplan, S. McCandlish, C. Olah. [*A Mathematical Framework for Transformer Circuits*](https://transformer-circuits.pub/2021/framework/index.html). Transformer Circuits Thread, Anthropic, 22 December 2021. The screenshots in this part come from this page.
2. [Transformer Circuits Thread](https://transformer-circuits.pub/), the series of articles this paper opened.

**Related papers**

3. A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, I. Polosukhin. [*Attention Is All You Need*](https://arxiv.org/abs/1706.03762). NeurIPS 2017. The original description of multi-head attention, with the stacked output matrix.
4. C. Olsson, N. Elhage, N. Nanda, et al. [*In-context Learning and Induction Heads*](https://arxiv.org/abs/2209.11895). 2022 ([web version](https://transformer-circuits.pub/2022/in-context-learning-and-induction-heads/index.html)). The follow-up that reads QK and OV circuits in larger models.
5. C. Olah, N. Cammarata, L. Schubert, G. Goh, M. Petrov, S. Carter. [*Zoom In: An Introduction to Circuits*](https://distill.pub/2020/circuits/zoom-in/). Distill, 2020. The earlier work on image models that gave "circuits" its meaning.

**Tools and models**

6. N. Nanda, J. Bloom, and contributors. [TransformerLens](https://github.com/TransformerLensOrg/TransformerLens), the library used for every experiment; version [3.9.0](https://pypi.org/project/transformer-lens/3.9.0/).
7. Model cards: [`NeelNanda/Attn_Only_1L512W_C4_Code`](https://huggingface.co/NeelNanda/Attn_Only_1L512W_C4_Code) (`attn-only-1l`) and [`NeelNanda/Attn_Only_2L512W_C4_Code`](https://huggingface.co/NeelNanda/Attn_Only_2L512W_C4_Code) (`attn-only-2l`).
8. Code for this part: [`circuits_part2.py`](https://github.com/ishwar6/ishwar-books/blob/main/code/papers/circuits/circuits_part2.py) and [`circuits_part2_toy.py`](https://github.com/ishwar6/ishwar-books/blob/main/code/papers/circuits/circuits_part2_toy.py).

