Abstract

In the attention mechanism, a query is compared with every key, and each value is read in proportion to how well its key matches the query. Keys are therefore often viewed as addresses and values as content. Values have been shown to carry content, but it has rarely been tested whether the value that a key calls up holds the fact that the key should call up. To test this, we run three main experiments on short synthetic prompts that state one fact about each of two people. First, we swap the cached values or keys of the two facts. Second, we measure which token selected attention heads attend to when the question changes. Third, we swap the two values only in the key-value heads that these heads use. We find that in most LLMs, swapping the two values switches the answer to the other fact in nearly all examples. In every LLM, asking about the other fact moves the attention of the selected heads to its token, and in some LLMs, swapping the two values only in those key-value heads also switches the answer. These results support the claim that the value called up through the key that points to a fact holds the fact that this key should call up. We also find that in long prompts, exchanging only the rotary positions of the two keys changes the answer to the other fact more often than moving them by the same amount at random.

Introduction

Transformers read their context through attention. The output of an attention head at a position is a weighted sum of the values of that position and the earlier positions, with weights computed from the dot products between the query at that position and their keys (Eq. (1) in Section §3). In the key–value memory of Miller et al. [1], a query matches keys as addresses and reads out the paired values as content. If attention works in the same way, keys and values should correspond: the value called up through the key that points to a fact should hold that fact. While previous work has shown that values carry content [4][5], few studies have directly tested whether this correspondence holds. We test this correspondence in two parts. Part (a) asks whether swapping the values of the tokens that state the queried fact and another fact changes the answer to the other fact. Part (b) asks whether the query at the last token of the prompt, whose output predicts the first answer token, selects the token of the queried fact by its key.

Prior work has replaced keys or values with those from a matched counterfactual input, at every prompt token or only at the tokens of the fact [4][8][7]. In these tests, the patched vectors are computed from another input, so a change in the answer can also come from content that the original input did not state or from the other context in which the vectors were computed. Another test swaps the keys of two number tokens two positions apart in the same input, from one layer onward; the probability of the answer expected from the swap rises but stays below that of the correct answer [2].

We swap the keys or the values of two tokens tens of tokens apart in all layers, and let only the final positions read the swap. The context gives the favorite colors of two people, and the question asks for Alice's. We prefill all but the last token of the prompt and then swap, at the two color-word tokens in all layers and KV heads, the cached keys (the key swap), the values (the value swap) or both. The final positions are the last token of the prompt and the generated tokens (Figure 1). Because earlier positions are never recomputed, the value swap leaves the set of keys and the set of values in the cache unchanged and changes only which key is paired with which value. RoPE is re-applied to swapped keys at their new positions.

Figure1|Illustration of the cache edits. (1) To build the cache, the prompt is run once up to the token before the last. (2) The values, keys or both of the two color-word tokens are swapped in every layer and KV head. (3) Only the last token of the prompt and the generated tokens read the edit, so a change in the answer comes from this edit.

Because the final positions see only the multiset of (key, value) pairs, the key swap is equivalent to the value swap combined with an exchange of the rotary position embedding (RoPE) phases of the two keys, and swapping both is equivalent to this phase exchange alone (Section §3.2). A change in the answer after the key swap therefore combines the effect of the value swap with that of moving the RoPE phases, and does not show by itself whether the query uses the content of the keys. To test part (b), we instead measure attention. On separate examples, we select heads whose attention from the last token of the prompt favors the color-word token of the queried person, the selected heads (Section §4.4), and ask whether their attention follows the content of the keys.

Across six instruction-tuned models (Table 11), we observe the following.

  1. Swapping the two values changes the answer (part a). After swapping only the values of the two color-word tokens, the six-token answer contains the other person's color in almost all examples with templated prompts and in nearly all examples with prompts written as short stories in all six models except Llama-3.1-8B (Section §4.3).

  2. The attention of the selected heads follows the key content of the queried person's token (part b). In a single-layer key swap, the scores of the selected heads follow mainly the key content in most (example, head) pairs. Asking about Bob instead of Alice shifts their attention from Alice's color-word token to Bob's, and both results hold in all six models (Table 8; Figure 3; Section §4.4). For the selected heads, these observations support part (b). However, a single-layer key swap, run on 40 examples in all six models except OLMo-2, brings Bob's color into the answer in at most a quarter of them (Appendix H.2), so we do not show that this attention determines the answer.

  3. Swapping the two values only in the KV heads of the selected heads changes the answer in two models (linking parts a and b). In Phi-3.5-mini and OLMo-2, swapping the two values only in the KV heads of the selected heads changes the answer in almost all examples, whereas random sets of the same size rarely do. In the other four models, the criterion is not satisfied or the judgment is undetermined (Section §4.5).

Observations 1 and 2 support the claim that, in this task and in all six models except Llama-3.1-8B, the value called up through the key that points to Alice holds Alice's color, the fact that this key should call up; observation 3 links the two parts in two models.

Llama-3.1-8B, the only model studied by Chowdhury et al. [2], is the exception: in examples with templated prompts, its answer contains Bob's color after the value swap only when Alice's fact comes first (Section §4.3). In a test on long documents, the phase exchange changes the answer to Bob's color more often than the sum of the rates when only one of the two keys is moved, in every model except Olmo-3. In every model, it also changes the answer to Bob's color more often than moving the two keys by the same total number of positions at random (Section §4.6). All other results come from short synthetic contexts with two or three people and one attribute (Section §5).

Keys and values as address and content In memory-augmented networks [1] and in attention [12], keys control which entries are read and values control what information is read. Circuit analyses make the same split: a query–key circuit controls which tokens are attended to, and an output–value circuit controls what information is moved [13]. Prakash et al. [3] describe a lookback mechanism in trained models: a query formed from a pointer at a later token matches a key formed from an address at an earlier token, and attention retrieves the payload stored alongside that address. None of these works tests this distinction by editing the keys or values of particular positions in a trained model.

Tests that bring in content from another input Most tests replace the keys or values at the same positions with those of another input or another model [4][5][6][14][7][8], or recompute the keys, queries or values of later heads from head outputs on another input [15]. Dinh et al. [4] replace them at every prompt token, which does not show which token's value is read. In Dinh et al. [4] and in the GPT-2-scale models of Ding et al. [5], values have a greater effect on the answer than keys, and in Lin et al. [6] values have a greater effect on safety behavior than keys. In contrast, in Bogdan et al. [7], who patch only the tokens of the fact, patching keys has the greater effect when the patched tokens carry representations of the preceding entity, and they do not specify whether later positions are recomputed. Wu et al. [8] also patch only the tokens of the fact but move keys and values together.

Activation patching, attention knockout and which positions read an edit Causal tracing [16], patching the values of selected heads [17] and attention knockout over all heads [11] neither patch keys on their own nor copy a key or value between two positions of the same input. Feng et al. [9] move a token's activations to another position by intervening on its RoPE position [18] and report that this results in little change in model behavior; our phase exchange applies this change to the cached keys of two color-word tokens.

Swaps within one input Chowdhury et al. [2] swap keys between two positions of one input. In Llama-3.1-8B, on sequences of numbers whose later segment repeats the differences of the earlier segment, they swap the keys of two number tokens two positions apart and expect the answer obtained by copying the difference stored at the other position. The swap is applied from one layer onward, and the values of both positions are left unchanged. The probability of that answer increases but remains below that of the correct answer. This key swap moves each key together with its own RoPE phase (swap-Kraw\textsf{swap-K}_\mathrm{raw}; Appendix A), so a position that attends to both swapped positions sees the same (key, value) pairs as after a value swap (Section §3.2). They specify the layers but not which positions read the swapped keys, whereas we let only the final positions read a swap of the cached entries at the two token positions (Section §3.1). In their results the correct answer keeps the higher probability, whereas in our color task the value swap changes the answer to the other person's color in almost all examples in all six models except Llama-3.1-8B (Section §4.3). The authors attribute the correct answer remaining ahead to information in the values. In our Llama-3.1-8B results, one possible explanation is that a token before the final positions carries the original color onward (Appendix H.5); we did not measure whether such a token contributes in their setting.

What we add We know of no previous work that swaps only the keys or only the values of two positions tens of tokens apart in the same input, in all layers and KV heads, and lets only the final positions read the swap. Nor do we know of work that compares the key swap and the value swap across context lengths. Like Li [10], we re-apply the RoPE rotation when we move a cached key to another position, and Section §3.2 analyzes what this choice implies for a swap within one input.

Preliminaries

Notation For each example i∈{1,…,n}i\in\{1,\dots,n\}, the prompt has TiT_i tokens, and the two tokens whose cache entries we swap are at positions ℓi,ℓi′∈{0,…,Ti−1}\ell_i,\ell'_i\in\{0,\dots,T_i-1\} (in our task, the color words of the two people, Alice and Bob; Section §4.1). A model has NLN_L layers, HkvH_{kv} KV heads and HqH_q query heads, indexed by LL, gg and jj. In multi-head attention each query head has its own keys and values; with grouped-query attention [19], several query heads share the keys and values of one KV head. We write g(j)g(j) for the KV head whose keys and values query head jj uses, and q~t,j(L)∈Rdh\tilde q^{(L)}_{t,j}\in\mathbb R^{d_h} for the query of head jj at position tt after the rotary position embedding (RoPE). The cache entry at layer LL, KV head gg and position ss consists of the key after RoPE, k~s,g(L)∈Rdh\tilde k^{(L)}_{s,g}\in\mathbb R^{d_h}, and the value vs,g(L)∈Rdhv^{(L)}_{s,g}\in\mathbb R^{d_h}; ropes\mathrm{rope}_s and unropes\mathrm{unrope}_s apply and remove the RoPE rotation [18] of position ss, and kˉ≔unropes(k~)\bar k\coloneqq\mathrm{unrope}_s(\tilde k) is the key before this rotation, which we call the key's content. At one layer and query head, omitting LL, jj and gg, the output of the head at position tt is

ot=∑s≤tsoftmaxs ⁣(q~t⋅k~sdh) vs.(1)o_t=\sum_{s\le t}\mathrm{softmax}_s\!\Bigl(\tfrac{\tilde q_t\cdot\tilde k_s}{\sqrt{d_h}}\Bigr)\,v_s . \quad\text{(1)}

3.1 Cache edits and the positions that read them

We first run the positions 0,…,ci−10,\dots,c_i-1 of the prompt without intervention to build the cache. We then edit the cache, process the remaining prompt positions ci,…,Ti−1c_i,\dots,T_i-1 using the edited cache and generate the answer. The two color-word tokens are at distinct positions before cic_i: ℓi≠ℓi′\ell_i\ne\ell'_i and max⁡(ℓi,ℓi′)<ci≤Ti−1\max(\ell_i,\ell'_i)<c_i\le T_i-1. The edits apply to layers L⊆{0,…,NL−1}\mathcal L\subseteq\{0,\dots,N_L-1\} and KV heads G⊆{0,…,Hkv−1}\mathcal G\subseteq\{0,\dots,H_{kv}-1\}; by default they apply to all of them with ci=Ti−1c_i=T_i-1, the position of the last token of the prompt, and for L∈LL\in\mathcal L and g∈Gg\in\mathcal G they are

swap-V:vℓi,g(L)↔vℓi′,g(L),(2)swap-K:k~ℓi,g(L)←ropeℓi(unropeℓi′(k~ℓi′,g(L))),k~ℓi′,g(L)←ropeℓi′(unropeℓi(k~ℓi,g(L))),(3)swap-KV:both.(4)\begin{aligned} \textsf{swap-V}:&\quad v^{(L)}_{\ell_i,g}\leftrightarrow v^{(L)}_{\ell'_i,g},\quad\text{(2)}\\ \textsf{swap-K}:&\quad \tilde k^{(L)}_{\ell_i,g}\leftarrow \mathrm{rope}_{\ell_i}\bigl(\mathrm{unrope}_{\ell'_i}(\tilde k^{(L)}_{\ell'_i,g})\bigr),\quad \tilde k^{(L)}_{\ell'_i,g}\leftarrow \mathrm{rope}_{\ell'_i}\bigl(\mathrm{unrope}_{\ell_i}(\tilde k^{(L)}_{\ell_i,g})\bigr),\quad\text{(3)}\\ \textsf{swap-KV}:&\quad \text{both.}\quad\text{(4)} \end{aligned}

All assignments are simultaneous, so each right-hand side uses the cache before the edit. For reference, we also report the model without edits (none) and two reference edits, patch-V and mask-A (Appendix A).

Why only the final positions read the edit An edit made during the forward pass is read by every later position, and the keys and values of those positions at later layers are computed from the edited state. Because prompts are sequences of bounded length over a finite vocabulary (an assumption also made by [33]), the keys and values that a model can produce from unedited prompts form a finite set, and those that later positions compute from the edited state can fall outside it. Such vectors may differ from those the model saw during training, so reading them can put the model off distribution, a concern also raised for activation patching [17][20]. A change in the answer could then come from them rather than from which value is paired with which key. A key-only swap adds a second problem: positions are then recomputed from a state in which the swap is only partly present. For example, a position between the two edited positions sees only the earlier of them under the causal mask, where the swapped-in key is paired with the unchanged value, and later positions can read what it computed. Commas, periods and delimiter tokens are known to store information from earlier tokens that later positions read, such as sentiment [21] and conclusions computed from a prompt field [10]. We therefore do not recompute the positions 0,…,ci−10,\dots,c_i-1, so only cic_i and later positions read the edit, and only these positions compute such vectors. The last token of the prompt and the generated tokens attend to both edited positions, so for them a key swap that keeps the original rotation of each key (swap-Kraw\textsf{swap-K}_\mathrm{raw}, Appendix A) is exactly equivalent to the value swap.

3.2 Equivalent edits

At one layer and KV head (we omit the superscripts), let kˉA≔unropeℓi(k~ℓi)\bar k_A\coloneqq\mathrm{unrope}_{\ell_i}(\tilde k_{\ell_i}) and kˉB≔unropeℓi′(k~ℓi′)\bar k_B\coloneqq\mathrm{unrope}_{\ell'_i}(\tilde k_{\ell'_i}) be the key contents of the color-word tokens of Alice and Bob, and vA,vBv_A,v_B their values. The output of any query at position t≥cit\ge c_i depends only on the multiset of (key, value) pairs that it attends to, not on which position holds which pair. We define the phase exchange, which keeps the content of each key but gives it the RoPE phase of the other position:

phase:k~ℓi←ropeℓi′(kˉA),k~ℓi′←ropeℓi(kˉB).(5)\textsf{phase}:\quad \tilde k_{\ell_i}\leftarrow\mathrm{rope}_{\ell'_i}(\bar k_A),\qquad \tilde k_{\ell'_i}\leftarrow\mathrm{rope}_{\ell_i}(\bar k_B). \quad\text{(5)}

Comparing the multisets of pairs under each edit (Figure 5 in Appendix G.2) gives, in exact arithmetic and for every query position t∈{ci,ci+1,… }t\in\{c_i,c_i+1,\dots\},

swap-KV≡phase,(6)swap-K≡swap-V∘phase.(7)\begin{aligned} \textsf{swap-KV}&\equiv\textsf{phase},\quad\text{(6)}\\ \textsf{swap-K}&\equiv\textsf{swap-V}\circ\textsf{phase}.\quad\text{(7)} \end{aligned}

These equivalences hold because both positions are visible to every such query, the models add no position-dependent term other than RoPE, and there is no dropout. Swapping both therefore tests only the phase exchange. If both the key swap and the value swap change the answer, this shows only that the phase exchange does not cancel the effect of the value swap, so the key swap gives no evidence independent of the value swap. Evidence specific to keys comes from attention measured after the edit (Section §4.4); two key duplications are reported in Appendix G.3.

Experiments

4.1 Task

Each example gives the favorite colors of two people, Alice and Bob, among eight neutral sentences, and asks: "What is Alice's favorite color? Answer with one word." The two colors, blue and red, always differ, and the order of the two facts is reversed with probability 1/2. In templated prompts each fact reads "Name's favorite color is color." (Appendix E), and in story prompts the facts are written within a short story in one of four phrasings. We use greedy decoding with at most six new tokens and n=120n=120 examples per condition. Table 11 (Appendix G.7) lists the six models and Olmo-3-7B-Instruct, which we use in the long-document experiment (Section §4.6) and in the controls of Sections §4.4 and §4.5.

4.2 Evaluation

Fraction of examples whose answer contains a color For X∈{A,B}X\in\{A,B\}, the fraction of examples whose lowercase answer contains the color of XX as a substring is

accX≔1n∑i=1n1[the six-token answer of example i contains X’s color word].(8)\mathrm{acc}_X\coloneqq\tfrac1n\textstyle\sum_{i=1}^n\mathbb{1}[\text{the six-token answer of example }i\text{ contains }X\text{'s color word}]. \quad\text{(8)}

Answer classes For judgments based on answers (Appendix B), each answer is classified into one of three classes, and in the three-person task into one of four (Section §4.3). An answer is classified as Alice's (A) or Bob's (B) color only if it is exactly the color, optionally after a fixed phrase, and as amb\mathrm{amb} otherwise; an answer that adds an explanation is therefore classified as amb\mathrm{amb} but is still counted in accX\mathrm{acc}_X. For a condition η\eta, clX(η)\mathrm{cl}_X(\eta) is the fraction of examples classified as XX, pamb(η)p_\mathrm{amb}(\eta) is the fraction classified as amb\mathrm{amb}, and agreecat\mathrm{agree}^\mathrm{cat} is the fraction of examples with the same class under two conditions (Appendix G.1).

Judgments Each judgment applies a criterion (Appendix B) to the answer classes or to attention weights, and its outcome is met, not met or undetermined. A judgment based on answers is undetermined if pamb(η)>10%p_\mathrm{amb}(\eta)>10\% for a condition η\eta that it uses, or in the cases of Appendix G.1. All thresholds were fixed before running the experiments. We report how many of the six models give each outcome; Llama-3.1-8B (Section §4.3) is counted with the other models, and Olmo-3 is reported separately.

4.3 Value swap: does the answer change to the other person's color? (part a)

What a swap within one input can show At the first edited layer, swap-V leaves the attention weights of cic_i unchanged and reaches cic_i only through the values; at later layers the query of cic_i can also change. Because the other person's color is in the same context, an answer that changes to exactly that color is evidence that the pairing of values with keys determines the answer. With only two colors, however, a weaker contribution of Alice's value could also leave Bob's color as the only remaining answer, and the three-person task tests this. Swaps do not require a counterfactual input of the same length, so they can also be applied to long documents.

Two people In the templated prompts, in all six models except Llama-3.1-8B, swap-V gives accB=\mathrm{acc}_B= 98.3%–100.0% and swap-K gives accB=\mathrm{acc}_B= 84.2%–99.2% (Figure 2; Table 7 in Appendix F). In all six models, swap-KV gives accA=100.0%\mathrm{acc}_A=100.0\%, and the phase exchange, which equals swapping both the keys and the values, rarely changes the answer class (agreecat\mathrm{agree}^\mathrm{cat} 98.3%–100.0%) and satisfies the phase criterion, which requires agreecat≥95%\mathrm{agree}^\mathrm{cat}\ge95\% (Table 1).

Figure2|Short contexts in the templated prompts (n=120n=120 examples per bar). Bars show accB\mathrm{acc}_B under the value swap and the key swap, and 1−accA1-\mathrm{acc}_A under swapping both the keys and the values; 1−accA1-\mathrm{acc}_A is 0.000 in all six models. Error bars show 95% Wilson confidence intervals; the numbers are given in Table 7.

Three people The three-person task adds Carol's color, and answers are classified as the color of the queried person, of the other person in the swap, of the third person or as amb\mathrm{amb}. With three people, in every model but Llama-3.1-8B, swapping Alice's and Bob's values or keys changes the answer from Alice's color to Bob's in at least 80% of examples, whereas swapping Bob's and Carol's keys leaves the answer class, with Bob's and Carol's colors counted as one, unchanged in at least 95% of examples. The judgment for Llama-3.1-8B is undetermined (Table 1).

Llama-3.1-8B: dependence on the order of the facts In Llama-3.1-8B, swap-V and swap-K give accB=\mathrm{acc}_B= 40.0% and 45.8% in the templated prompts; these are 77.4% and 88.7% when Alice's fact comes first and both 0% when Bob's fact comes first. When the edits are read from the position right after the later of the two color-word tokens onward, the two fractions rise to 80.0% and 74.2% (Appendix H.5).

4.4 Attention: does the question's query select the token by its key? (part b)

Selected heads We select heads without edits on 120 selection examples disjoint from the evaluation examples. The selected heads Hatt\mathcal H_\mathrm{att} are the query heads whose attention from the last token of the prompt to Alice's color-word token exceeds that to Bob's by at least 0.05, averaged over the selection examples with the question about Alice (Appendix G.5).

Single-layer scores To test whether these heads select the token by the content of its key, we swap the keys only in the layer of each selected head. The query of that layer is then identical to that without edits, so the score changes in that layer are due to the keys alone, and the change in the score of a moved key is due only to the change of RoPE phase. We consider the (example, layer, selected head) triples in which the scores of the two color-word tokens without edits differ by at least 1. Among them, FAF_A is the fraction in which moving Alice's key content to Bob's position changes the attention score of the moved key by at most half of this difference, and FBF_B is the same fraction for Bob's key content. In all six models, FA=F_A= 0.935–1.000 and FB=F_B= 0.909–1.000 (Table 8), and the single-layer criterion (FA≥0.8F_A\ge0.8 and FB≥0.8F_B\ge0.8) is satisfied (Table 1). The attention weights follow the moved key content (Table 8; Appendix H.2); when all layers are edited, however, the queries of the reading layers also change (Appendix H.2).

Figure3|Attention of the selected heads from the last token of the prompt without edits, in the templated prompts: the weight on Alice's color-word token minus that on Bob's (DˉQ\bar D^{Q}), averaged over 120 examples and the selected heads, under the Alice and Bob questions. The 95% bootstrap confidence intervals over examples are narrower than ±0.02\pm0.02 (Appendix C); the numbers are given in Table 8.

Asking about Bob Because the heads were selected with the Alice question, their preference for Alice's color-word token with this question is expected from the selection. To distinguish "the query selects the key of the queried person" from "Alice's key is preferred regardless of the question", we also ask "What is Bob's favorite color?". Without edits, DˉAl\bar D^\mathrm{Al} and DˉBo\bar D^\mathrm{Bo} are the attention weights of the selected heads to Alice's color-word token minus the weights to Bob's, averaged over examples and heads, under the question about Alice and about Bob. ϕBo\phi^\mathrm{Bo} is the fraction of selected heads whose difference, averaged over examples under the question about Bob, is negative. In all six models, the selected heads put more weight on Alice's color-word token under the Alice question (DˉAl\bar D^\mathrm{Al} 0.194–0.313) and on Bob's under the Bob question (DˉBo\bar D^\mathrm{Bo} from −0.311-0.311 to −0.183-0.183; Figure 3). Under the Bob question, the weight of every selected head, averaged over examples, is greater for Bob's token (ϕBo=1.000\phi^\mathrm{Bo}=1.000), and the Bob-question attention criterion (DˉAl≥0.05\bar D^\mathrm{Al}\ge0.05, DˉBo≤−0.05\bar D^\mathrm{Bo}\le-0.05 and ϕBo≥0.8\phi^\mathrm{Bo}\ge0.8) is satisfied in all six models (Table 1).

Model Single-layer Bob, Phase Three Bob, Bob,
scores attention people value swap three people
Qwen2.5-3B ✓ ✓ ✓ ✓ ×\times ✓
Qwen2.5-7B ✓ ✓ ✓ ✓ ✓ ✓
Mistral-7B ✓ ✓ ✓ ✓ ✓ ✓
Llama-3.1-8B ✓ ✓ ✓ ? ? ?
Phi-3.5-mini ✓ ✓ ✓ ✓ ✓ ✓
OLMo-2-7B ✓ ✓ ✓ ✓ ✓ ✓
met 6 6 6 5 4 5

Table1|Judgments by the criteria of Table 2 in the templated prompts (✓: met; ×\times: not met; ?: undetermined); in the story prompts, the phase criterion gives the same judgments. Masking and head-wise knockout are in Appendix H.3, and the phase criterion under the Bob question, which is satisfied in all six models, is not shown.

Question form: the name that appears last Because the name that appears last in the prompt is always that of the queried person, these conditions cannot distinguish selection by the meaning of the question from the use of that name as a cue. The control with other question forms separates the queried person from the name that appears last: it replaces only the question sentence with one of five forms (Table 10), and in F2a and F2b the other person's name follows the question. Under F2a and F2b, the attention weight averaged over examples and the same selected heads still favors the token of the queried person by at least 0.05 under each question in all six models and in Olmo-3. In at least 80% of examples, the mean over the selected heads favors it under both questions. In no example of any model does it favor the token of the person named last under both questions (Appendix H.2). The criterion (Table 3) also requires both questions of an example to be answered correctly in at least 90% of examples, which Mistral-7B does not reach, so it is satisfied in all six models except Mistral-7B, whose judgment is undetermined, and in Olmo-3.

Other names and attributes The control with other names and attributes tests whether the results are specific to the names Alice and Bob and to colors; it uses other names (S1), pets (S2) and morning drinks (S3), and selects the heads again in each set (Appendix G.4). The Bob-question attention criterion is satisfied in every set in all six models and in Olmo-3 (Table 9; Appendix H.2). The value-swap criterion requires the answer to move from Alice's attribute word to Bob's in at least 80% of examples. It is satisfied in four, four and three of the six models in S1, S2 and S3, compared with five in the color task rerun with the same implementation and answer class (Table 9; Appendix H.1).

4.5 Linking the two parts: values used by the selected heads

In this subsection, we ask whether the value swap changes the answer through the selected heads. The selected heads are the query heads that, on separate examples, attend more to Alice's color-word token than to Bob's (Section §4.4). We therefore swap the values of the two color-word tokens only in the KV heads of the selected heads (swap-V@UH\textsf{swap-V@}\mathcal U_\mathrm{H}; Appendix G.6) and compare this with swapping them in up to ten random sets with the same number of KV heads in each layer. With grouped-query attention, unlike multi-head attention, query heads outside Hatt\mathcal H_\mathrm{att} also use these KV heads.

When only the values of the KV heads of the selected heads are swapped, the fraction of examples in which the answer changes to Bob's color is 98.3% in Phi-3.5-mini and 100.0% in OLMo-2. For the ten random sets, it is at most 3.3% in either model (Table 13; criterion in Table 3). The criterion, which requires the KV heads of the selected heads to change the answer in at least 50% of examples and at a rate at least 20 percentage points higher than every random set, is satisfied in Phi-3.5-mini, OLMo-2 and Olmo-3, not satisfied in Qwen2.5-7B, and undetermined in Qwen2.5-3B, Mistral-7B and Llama-3.1-8B (Appendix H.3). Head-wise knockout of the heads with the largest selection difference is undetermined in all six models because its positive control is not satisfied (Appendix H.3).

4.6 Long documents

In this subsection, we ask whether the effects of the key swap and the value swap change in long documents.

Context length We insert the two fact sentences, in the phrasings of the story prompts, into Wikipedia articles (122 articles from WikiText-103; [34]) to build contexts of about 1k, 4k and 16k tokens. Let ΔK\Delta_K and ΔV\Delta_V be the drops in accB\mathrm{acc}_B under the key swap and the value swap from about 1k tokens to the longest length (Table 14 in Appendix H.6).

Figure4|Results at about 1k, 4k and 16k tokens for all seven models: fractions of examples whose six-token answer contains Bob's color (swap-V, swap-K) or lacks Alice's color (swap-KV, including answers lacking it without edits). Leftmost points: short contexts of about 170 tokens in the story prompts (not run for Olmo-3); other points: Wikipedia documents (OLMo-2: about 1k and 3.5k tokens). Open markers: Olmo-3 with only its eight full-attention layers edited. Error bars: 95% Wilson intervals.

From about 1k tokens to the longest length, the 95% bootstrap confidence interval of the difference between the two drops (ΔK−ΔV\Delta_K-\Delta_V) excludes 0 in Qwen2.5-3B and Mistral-7B and includes 0 in the other five models (Figure 4; Table 14). In Mistral-7B, Phi-3.5-mini, Olmo-3 and OLMo-2, however, 11.7%–33.3% of the answers without edits already lack the queried color within the first six tokens at the longer lengths, so their drops also include these answers (Appendix H.6).

Because the key swap equals the value swap combined with the phase exchange (Eq. (7)), a larger drop under the key swap can come from exchanging the rotary phases of the two keys rather than their content. Swapping both the keys and the values, which equals the phase exchange alone, also changes the answer to Bob's color more often at longer lengths among examples answered correctly without edits (phase column of Table 5, from the preliminary experiment before the test, described below; Appendix H.6).

Moving one key at a time The phase exchange makes two moves at once: it gives Alice's key the rotation of Bob's position and Bob's key that of Alice's. To compare it with making each move alone, we also give only Alice's key the rotation of Bob's position (shift-A), or only Bob's key that of Alice's (shift-B). In a preliminary experiment, on the contexts of about 1k, 4k and 16k tokens above, the phase exchange changes the answer to Bob's color more often than shift-A and shift-B added together (for example, 0.542 against 0.083 and 0.250 for Qwen2.5-3B at about 16k tokens). This holds for every model and length except Llama-3.1-8B at about 1k and 4k tokens, where no edit changes the answer to Bob's color (Table 5; Appendix D).

Long-document test Because the pattern was identified in the preliminary experiment, we tested it on 240 newly drawn documents from the same articles, each giving prompts of about 3.5k and 16k tokens with the two facts near or far apart (Appendix D). The test uses the models of Figure 4 except Phi-3.5-mini (Appendix H.6), and some of these models were chosen because of their results at the three context lengths, so the results may not generalize to other models. For Olmo-3, only the eight full-attention layers are edited, to match the preliminary experiment. In that run, Alice's fact at approximately 16k tokens lay outside the sliding window of the other layers in most examples, so editing all layers would have changed the number of edited layers across examples and lengths. For each document, the excess is the rate at which the answer changes to Bob's color under the phase exchange minus the sum of the rates under shift-A and shift-B, averaged over its prompts at the tested length whose answer without edits contains Alice's color but not Bob's. The mean excess is positive in every model, from 0.034 (Olmo-3) to 0.283 (Qwen2.5-7B), and its 95% bootstrap interval excludes 0 in every model except Olmo-3 (Table 4). Because the outcome is binary, two moves that each leave the answer unchanged can change it together, so the excess does not show an interaction between the two moves. We did not analyze a continuous measure such as the logit difference.

Moving both keys without an exchange To test whether this change comes from exchanging the positions of the keys or simply from moving them, we compare the phase exchange on the same 240 documents with two moves of the same total size that do not exchange them (Appendix D). With Δℓ\Delta\ell the distance between the two color-word tokens, the parallel move shifts both keys toward the start by Δℓ\Delta\ell positions, keeping their order, and the random move shifts the earlier and later keys by ±a\pm a and ±(2Δℓ−a)\pm(2\Delta\ell-a) positions, with aa and the two signs drawn at random. At the tested length, the phase exchange changes the answer to Bob's color more often than the random move in every model, with mean differences from 0.037 (Llama-3.1-8B) to 0.303 (Qwen2.5-3B). It also changes the answer more often than the parallel move in every model except Olmo-3 and OLMo-2, whose intervals include 0 (Table 6). Whether the answer changes therefore depends on where the keys are moved, not only on how far.

Length and distance In short contexts, the phase exchange rarely changes the answer class (Section §4.3), consistent with the little change in behavior that Feng et al. [9] report when the positions of two entities are swapped. At the tested length, however, it changes the answer to Bob's color in some prompts in every tested model, and in 230 of 235 prompts in Qwen2.5-3B with the facts far apart (Appendix D). Their setting differs from ours in the task, the edited tokens and positions, and the measure (mean log probability rather than the generated answer), and we have not tested which of these differences accounts for the discrepancy. Within each document, we compare prompts whose answer without edits contains Alice's color but not Bob's at both settings. The phase exchange changes the answer to Bob's color more often at approximately 16k than at approximately 3.5k tokens in every model tested at both lengths, and more often far than near in every tested model, with intervals that exclude 0 (Table 4). Neither comparison isolates length or distance: the longer prompt also adds text of different content before the facts, and moving the earlier fact also changes the exchanged rotation and its distance to the question.

Conclusion

Swapping the cached values of two facts in the same input, with only the final positions reading the edit, changed the answer to the other fact in most of the models we studied. When the keys of one layer were swapped, the attention of the selected heads followed the content of the keys, and without edits it moved to the queried fact when the question changed. In some models, swapping the two values only in the KV heads of these heads changed the answer far more often than swapping equally large random sets of values. Together, these results support the claim that the value called up through the key that points to a fact holds the fact that this key should call up.

These results come from short synthetic contexts. In long documents, exchanging only the rotary phases of the two keys also changed the answer to the other fact in some examples. The phase exchange changed the answer to the other fact more often than the sum of the rates when each phase was moved alone, in most models. In long documents, the match between a query and a key may depend on the rotary phase of the key strongly enough to change the answer, whereas in the short contexts tested, the phase exchange rarely changed the answer class. It remains open how the rotary phase affects which key the query selects in long documents. In long documents we recorded only the answers; future work could investigate there the attention to the two facts' tokens and the logit difference between the two colors.

Limitations Each example involves two or three people and one attribute, and we leave more entities and naturally occurring facts for future work. With only two colors, a swap that weakens the value of the queried fact could leave the other color as the only remaining answer. The results of the three-person task are evidence against this explanation, but we ran it only in the templated prompts. The value swap does not tell whether the value holds the color itself or an index that a later step uses to retrieve the color, as in the lookback mechanism of Prakash et al. [3].

Appendix

A. Implementation details

Which keys and values are edited The cache stores, for every layer LL, KV head gg and position ss, the key after RoPE, k~s,g(L)=ropes(kˉs,g(L))\tilde k^{(L)}_{s,g}=\mathrm{rope}_s(\bar k^{(L)}_{s,g}), and the value vs,g(L)v^{(L)}_{s,g}. We edit these cached tensors directly; in models with grouped-query attention [19] (Qwen2.5, Mistral, Llama) every query head that uses an edited KV head sees the edit. The key before RoPE is obtained as kˉ=unropes(k~)\bar k=\mathrm{unrope}_s(\tilde k). In OLMo-2 and Olmo-3, an RMSNorm [22] is applied to the full key projection before RoPE, so kˉ\bar k is the normalized key; in the other models kˉ\bar k is the output of the key projection. In Olmo-3, the full-attention layers scale RoPE (YaRN), so ropes\mathrm{rope}_s and unropes\mathrm{unrope}_s denote the RoPE map of each layer and its inverse. RoPE is not applied to values, so they are moved unchanged.

Reference edits patch-V replaces Alice's value with the value from a counterfactual input in which the two colors are exchanged, so that both positions then carry the same color, and mask-A masks Alice's color-word token from position cic_i onward.

Precision of RoPE Removing and re-applying RoPE uses the cosine and sine tables of the model, which the standard forward pass rounds to the model's dtype (bfloat16) and our implementation can keep in float32. Before the results were seen, we fixed the rule to report the float32 values if swap-K and swap-KV each agree between the two variants in at least 118 of 120 answers in the templated prompts, and the model-dtype values otherwise. Five models meet this rule; in Llama-3.1-8B, swap-K agrees in 117 of 120 (97.5%), so Tables Table 7 and Table 12 give its model-dtype values in both kinds of prompts. The long-document test uses the float32 tables in every model.

Implementation checks Four pairs of edits are equal in exact arithmetic (Section §3.2): swap-KVraw\textsf{swap-KV}_\mathrm{raw} with none, swap-Kraw\textsf{swap-K}_\mathrm{raw} with swap-V, swap-KV with phase, and swap-K with swap-V∘phase\textsf{swap-V}\circ\textsf{phase}, where the subscript raw means that keys are moved without re-applying RoPE. The four pairs give identical answers in four models, and in OLMo-2, Llama-3.1-8B and Olmo-3 every re-checked example in which they differ agrees when re-run in float32, so the differences are consistent with bfloat16 rounding.

Software All models run in bfloat16 with the Hugging Face transformers library [23] and greedy decoding. The single-layer scores, the attention weights, masking, head-wise knockout, the three-person task, the questions about Bob and the controls with other question forms, other names and attributes, and the KV heads of the selected heads use our own attention function, which performs the same operations as the library's eager attention and also records attention scores and weights. All other conditions use the library's scaled-dot-product attention. On the conditions run with both implementations, the answers agree exactly in at least 95.0% of examples in every model and condition except dupK_BA in Qwen2.5-7B (48.3%; Appendix H.4). The supplementary material gives the agreement of each pair, further implementation checks, the library versions and the hardware.

Prompts and examples Each prompt is one user turn passed through the model's chat template without a system message. The templates of Qwen2.5 add their default system prompt, that of Llama-3.1 adds a system header, and the others add nothing. The user turn is "Read the following notes." (templated prompts) or "Read the following story." (story prompts), a blank line, the context, a blank line, and "Question: " followed by the question. Examples are drawn with fixed seeds: 101 for the head-selection examples, 1 for the long-document test (Appendix D) and 0 for all other evaluation examples. The long documents are built from the articles of the test and validation splits of WikiText-103 (raw; [34]), after dropping paragraphs that contain the words red, blue, Alice, Bob, Carol or Dave. In the contexts of about 1k, 4k and 16k tokens, paragraphs are concatenated from a random starting article until the target length is reached. The two fact sentences, each in one of the four story phrasings, are then inserted at two distinct sentence boundaries drawn uniformly between 2% and 98% of the document, and the user turn reads "Read the following document." The long-document test places the facts in its own way (Appendix D).

B. Judgment criteria

Table 2 gives the criteria for the phase exchange, attention, key duplication, masking, head-wise knockout, the three-person task and the questions about Bob (Section §4.2). Table 1 reports which models satisfy them; key duplication is in Appendix H.4, masking, three-person masking and head-wise knockout are in Appendix H.3, and the Bob-question phase criterion is satisfied in all six models. Appendix G gives the formulas of the quantities in the criteria.

Criterion Met if
Phase agreecat(phase,none)≥0.95\mathrm{agree}^\mathrm{cat}(\textsf{phase},\textsf{none})\ge0.95 and ΠAA(none,phase)≥clA(none)−0.05\Pi_{AA}(\textsf{none},\textsf{phase})\ge\mathrm{cl}_A(\textsf{none})-0.05
Single-layer scores FA≥0.8F_A\ge0.8 and FB≥0.8F_B\ge0.8
Key duplication dupK_AB: ∑Y≠AΠAY(none,dupK_AB)≥0.2\sum_{Y\ne\mathrm A}\Pi_{AY}(\textsf{none},\textsf{dupK\_AB})\ge0.2; dupK_BA: clA(dupK_BA)≤clA(none)−0.5\mathrm{cl}_A(\textsf{dupK\_BA})\le\mathrm{cl}_A(\textsf{none})-0.5
Masking after swap-K, hiding ℓi′\ell'_i lowers clB\mathrm{cl}_B by ≥0.5\ge0.5 and hiding ℓi\ell_i by ≤0.1\le0.1 (positions reversed for swap-V)
Head-wise knockout positive control met, then blocking H∗\mathcal H^\ast lowers clB\mathrm{cl}_B by ≥0.3\ge0.3 (bootstrap interval below 0), by ≥0.2\ge0.2 more than each Rrhead\mathcal R^\mathrm{head}_r, and blocking the other position changes it by ≤0.1\le0.1
Three people clself(none)≥0.9\mathrm{cl}_\mathrm{self}(\textsf{none})\ge0.9; for Alice↔\leftrightarrowBob swap-V and swap-K, Πself,part≥0.8\Pi_\mathrm{self,part}\ge0.8 and cloth≤0.1\mathrm{cl}_\mathrm{oth}\le0.1; for Bob↔\leftrightarrowCarol swap-K, agreecat≥0.95\mathrm{agree}^\mathrm{cat}\ge0.95
Three people, masking after swap-K, hiding the partner's position lowers clpart\mathrm{cl}_\mathrm{part} by ≥0.5\ge0.5; hiding Carol's lowers it by ≤0.1\le0.1
Bob, value swap ppair≥0.9p_\mathrm{pair}\ge0.9 (Appendix G.4); ΠBABo(none,swap-V)≥0.8\Pi^\mathrm{Bo}_{BA}(\textsf{none},\textsf{swap-V})\ge0.8 and clBBo(swap-V)≤0.1\mathrm{cl}^\mathrm{Bo}_B(\textsf{swap-V})\le0.1
Bob, phase ppair≥0.9p_\mathrm{pair}\ge0.9; agreecat(phase,none)≥0.95\mathrm{agree}^\mathrm{cat}(\textsf{phase},\textsf{none})\ge0.95 and ΠBBBo(none,phase)−clBBo(none)≥−0.05\Pi^\mathrm{Bo}_{BB}(\textsf{none},\textsf{phase})-\mathrm{cl}^\mathrm{Bo}_B(\textsf{none})\ge-0.05, with the Bob question
Bob, three people ppair≥0.9p_\mathrm{pair}\ge0.9 on the three-person examples; Bob↔\leftrightarrowAlice and Bob↔\leftrightarrowCarol value swaps move ≥0.8\ge0.8 of examples to the partner's color, the third color ≤0.1\le0.1; phase keeps agreecat≥0.95\mathrm{agree}^\mathrm{cat}\ge0.95
Bob, attention DˉAl≥0.05\bar D^\mathrm{Al}\ge0.05, DˉBo≤−0.05\bar D^\mathrm{Bo}\le-0.05 and ϕBo≥0.8\phi^\mathrm{Bo}\ge0.8 (uses weights only; no pambp_\mathrm{amb} gate)

Table2|Judgment criteria other than those of the three controls (Table 3).

Table 3 gives the criteria of the three controls (Sections §4.4 and §4.5). The sets S1–S3 of the control with other names and attributes use the criteria of Table 2 unchanged, each with its preconditions, plus the value-swap criterion. The outcome of a judgment is decided in the order construction, preconditions, pambp_\mathrm{amb} gate and criterion, so when a precondition and the pambp_\mathrm{amb} gate both fail, the precondition is reported.

Criterion Met if
Question form, asked DˉAl,f≥0.05\bar D^{\mathrm{Al},f}\ge0.05, DˉBo,f≤−0.05\bar D^{\mathrm{Bo},f}\le-0.05 and ψpairf≥0.8\psi^f_\mathrm{pair}\ge0.8
Question form, last DˉAl,f≤−0.05\bar D^{\mathrm{Al},f}\le-0.05, DˉBo,f≥0.05\bar D^{\mathrm{Bo},f}\ge0.05 and ψlastf≥0.8\psi^f_\mathrm{last}\ge0.8 (no ppairp_\mathrm{pair} requirement; the pambp_\mathrm{amb} gate still applies)
Question form, value swap for both questions QQ, Πqu paQ,f(none,swap-V)≥0.8\Pi^{Q,f}_{\mathrm{qu}\,\mathrm{pa}}(\textsf{none},\textsf{swap-V})\ge0.8 and clquQ,f(swap-V)≤0.1\mathrm{cl}^{Q,f}_{\mathrm{qu}}(\textsf{swap-V})\le0.1, where qu is the person asked and pa the other
Question form, phase for both questions, agreecat(phase,none)≥0.95\mathrm{agree}^\mathrm{cat}(\textsf{phase},\textsf{none})\ge0.95
Value swap (S1–S3) clA(none)≥0.9\mathrm{cl}_A(\textsf{none})\ge0.9; ΠAB(none,swap-V)≥0.8\Pi_{AB}(\textsf{none},\textsf{swap-V})\ge0.8 and clA(swap-V)≤0.1\mathrm{cl}_A(\textsf{swap-V})\le0.1
Selected heads' KV heads clA(none)≥0.9\mathrm{cl}_A(\textsf{none})\ge0.9 and mv(swap-V)≥0.8\mathrm{mv}(\textsf{swap-V})\ge0.8; mv(swap-V@UH)≥0.5\mathrm{mv}(\textsf{swap-V@}\mathcal U_\mathrm{H})\ge0.5 and mv(swap-V@UH)−max⁡rmv(swap-V@Rrunit)≥0.2\mathrm{mv}(\textsf{swap-V@}\mathcal U_\mathrm{H})-\max_r\mathrm{mv}(\textsf{swap-V@}\mathcal R^\mathrm{unit}_r)\ge0.2; undetermined by construction if ∣UH∩⋂rRrunit∣/∣UH∣≥1/2\vert \mathcal U_\mathrm{H}\cap\bigcap_r\mathcal R^\mathrm{unit}_r\vert /\vert \mathcal U_\mathrm{H}\vert \ge1/2
Selected heads' KV heads, three people as above with the three-person task, Πself,part\Pi_\mathrm{self,part} in place of mv, the first min⁡(3,Nmrnd)\min(3,N^\mathrm{rnd}_m) random sets, and cloth(swap-V@UH)≤0.1\mathrm{cl}_\mathrm{oth}(\textsf{swap-V@}\mathcal U_\mathrm{H})\le0.1
Selected heads' KV heads, H∗\mathcal H^\ast as "Selected heads' KV heads" with H∗\mathcal H^\ast in place of Hatt\mathcal H_\mathrm{att} and its own random sets

Table3|Judgment criteria of the three controls. The question-form criteria must hold in both F2a and F2b and, except where noted, use only forms with ppairf≥0.9p^f_\mathrm{pair}\ge0.9 (Appendix G.4).

C. Intervals and threshold sensitivity

Unless stated otherwise, intervals are 95% percentile bootstrap confidence intervals with 10,000 resamples of examples; heads and (example, head) pairs are never resampled as independent units. The three context lengths were built with the same seed, so example ii corresponds across lengths. In the models run at all three lengths, examples 11–2424 exist at every length, 2525–6060 at approximately 1k and 4k, and 6161–120120 at approximately 1k only. Examples are therefore resampled within these three strata, and the same draw is used for every length and condition that contains them, so conditions measured on the same examples stay paired. The short context is resampled separately. All long documents come from 122 Wikipedia articles whose paragraphs overlap across examples (in the contexts of approximately 16k tokens, on average 50.6% of a document's paragraphs also appear in another), so the intervals are conditional on these articles.

Scope of the statistics Figures Figure 2 and Figure 4 show 95% Wilson confidence intervals [24]. An exact McNemar test [25] rechecks the bootstrap [26] interval of an undetermined head-wise knockout judgment and changes no judgment. The bootstrap intervals do not cover the variation over generations, head selection or the choice of criteria.

Context length Table 14 gives the intervals of ΔK\Delta_K, ΔV\Delta_V and ΔK−ΔV\Delta_K-\Delta_V. From the short context to about 16k tokens, the drops in Appendix H.6 all have intervals that exclude 0 except that of the value swap in Qwen2.5-3B (4.2 [0.0, 12.5] percentage points); under the key swap in Qwen2.5-3B the drop is 65.8 [46.7, 83.3] percentage points.

Margins of met judgments For each met judgment by the criteria of Table 2, the margin is the distance of each statistic from its threshold. Most margins have intervals that exclude 0; the exceptions are key-duplication judgments. For dupK_BA in Qwen2.5-7B, the margin is 0.0 [−9.2-9.2, 8.3] percentage points. Recomputing the whole judgment on each resample, including the pambp_\mathrm{amb} gate, gives met in 45.3% of resamples, not met in 42.8% and undetermined in 11.9%. For dupK_AB, the interval of the margin includes 0 in the story prompts in Qwen2.5-3B and OLMo-2, and touches 0 in the templated prompts in Qwen2.5-3B.

Threshold sensitivity For the judgments by the criteria of Table 2, we moved each threshold, one at a time, by ±0.05\pm0.05 and ±0.10\pm0.10 within the range that its statistic can take, and the pambp_\mathrm{amb} gate to 5% and 15%. Besides the key-duplication judgments, the three-person masking judgment becomes not met in Qwen2.5-3B, Phi-3.5-mini and OLMo-2 and met in Qwen2.5-7B, and the Bob-question value swap in Qwen2.5-3B becomes met. In Phi-3.5-mini, the phase criterion in the story prompts and the three-person judgment become not met, and head-wise knockout changes from undetermined to not met. No other judgment changes.

Attention Let diQ≔1∣Hatt∣∑(L,j)∈Hatt(βA,iQ,(L,j)−βB,iQ,(L,j))d^Q_i\coloneqq\frac1{|\mathcal H_\mathrm{att}|}\sum_{(L,j)\in\mathcal H_\mathrm{att}}(\beta^{Q,(L,j)}_{A,i}-\beta^{Q,(L,j)}_{B,i}) for Q∈{Al,Bo}Q\in\{\mathrm{Al},\mathrm{Bo}\}. In every model, all 120 examples have diAl>0d^\mathrm{Al}_i>0 and diBo<0d^\mathrm{Bo}_i<0. The intervals of DˉAl\bar D^\mathrm{Al} and DˉBo\bar D^\mathrm{Bo} are within 0.008 of the point values; the narrowest margin to ±0.05\pm0.05 is that of DˉBo\bar D^\mathrm{Bo} in Mistral-7B, −0.183-0.183 [−0.188-0.188, −0.178-0.178]. The widest interval of ΔβˉA\Delta\bar\beta_A and ΔβˉB\Delta\bar\beta_B is that of ΔβˉB\Delta\bar\beta_B in Phi-3.5-mini, 0.285 [0.269, 0.301].

Controls The intervals of the three controls use the same bootstrap. One resampling of the evaluation examples is shared by all forms, questions and conditions measured on them, and the examples of S2 and S3 and of the three-person tasks are resampled separately. For the control with swap-V@UH\mathcal U_\mathrm{H}, the intervals are conditional on the drawn random sets. We also applied the same shifts to the construction threshold 1/2. At a construction threshold of 0.45, the three-person judgment of swap-V@UH\mathcal U_\mathrm{H} of Qwen2.5-7B becomes undetermined by construction, and at 0.60 the H∗\mathcal H^\ast judgment of Qwen2.5-3B changes from undetermined by construction to not met.

D. The long-document test

Examples For each of the 240 documents b∈{1,…,240}b\in\{1,\dots,240\} of Section §4.6, a starting article is drawn uniformly, with replacement, from the same 122 articles, and the paragraphs of that article and of the following articles in a fixed order (wrapping around) are joined until the document has at least 70,000 characters. The later fact sentence is inserted at the sentence boundary closest to 2,200 characters before the end, and the earlier one at the boundary closest to 1,100 (near) or 8,800 (far) characters before the later one. Alice's color and whose fact comes later are each drawn with probability 1/2, and the article, the colors, the order and the phrasing of each fact are drawn independently for each document, so the documents are independent and identically distributed (i.i.d.). The long prompt is the whole document (14,301–18,916 tokens), and the short prompt is its shortest final segment that starts at a paragraph boundary and has at least 15,500 characters (3,234–4,947 tokens). Each document thus gives four prompts, one for each length and distance. The short and long prompts at the same distance share the facts, the text between them, the text after them and the question. Between the near and far prompts at the same length, only the place of the earlier fact differs. The later color-word token is 252–838 tokens before the last token of the prompt. For OLMo-2, four prompts longer than its maximum length were not run.

Edits and changes of the answer For a prompt xx, let ℓ\ell and ℓ′\ell' be the positions of Alice's and Bob's color-word tokens and kˉA,kˉB\bar k_A,\bar k_B their key contents. Every edit below is applied at every layer and KV head, except that for Olmo-3 only the eight full-attention layers are edited, as in the preliminary experiment, and the edits are read from the last token of the prompt onward. In addition to phase (Section §3.2), we use the two moves of a single key

shift-A: k~ℓ←ropeℓ′(kˉA),shift-B: k~ℓ′←ropeℓ(kˉB),(9)\textsf{shift-A}:\ \tilde k_{\ell}\leftarrow\mathrm{rope}_{\ell'}(\bar k_A),\qquad \textsf{shift-B}:\ \tilde k_{\ell'}\leftarrow\mathrm{rope}_{\ell}(\bar k_B), \quad\text{(9)}

and their shifted versions shift-Aσ\textsf{shift-A}^{\sigma} and shift-Bσ\textsf{shift-B}^{\sigma} for σ∈{+16,−16}\sigma\in\{+16,-16\}, which rotate to ℓ′+σ\ell'+\sigma and ℓ+σ\ell+\sigma instead, so that the two keys never share a rotary position. No value is changed. For model mm, edit η\eta and prompt xx, let incη(x)∈{0,1}\mathrm{inc}_\eta(x)\in\{0,1\} be 1 if the first six tokens of the answer under η\eta, after lowercasing, contain Alice's color as a substring, and incηB(x)\mathrm{inc}^\mathrm{B}_\eta(x) the same for Bob's color. Let Pm≔{x:incnone(x)=1, incnoneB(x)=0}\mathcal P_m\coloneqq\{x:\mathrm{inc}_{\textsf{none}}(x)=1,\ \mathrm{inc}^\mathrm{B}_{\textsf{none}}(x)=0\} be the prompts answered with only Alice's color without edits, and toBη(x)≔incηB(x) (1−incη(x))\mathrm{toB}_\eta(x)\coloneqq\mathrm{inc}^\mathrm{B}_\eta(x)\,(1-\mathrm{inc}_\eta(x)) for x∈Pmx\in\mathcal P_m, which is 1 if the answer changes to only Bob's color. As a check on numerical error, we also count the prompts in Pm\mathcal P_m, over all lengths and distances, in which swapping both the keys and the values, which equals the phase exchange in exact arithmetic, gives the same toB\mathrm{toB} as the phase exchange (column Agree of Table 4). The tested length τm∗\tau^\ast_m is about 16k tokens, and about 3.5k for OLMo-2, whose context length is 4,096 tokens. Let Pm(b)⊆Pm\mathcal P_m(b)\subseteq\mathcal P_m be the near and far prompts of document bb at τm∗\tau^\ast_m that lie in Pm\mathcal P_m, and Jm≔{b:Pm(b)≠∅}J_m\coloneqq\{b:\mathcal P_m(b)\ne\emptyset\}. For b∈Jmb\in J_m,

Zb≔1∣Pm(b)∣∑x∈Pm(b)(toBphase(x)−toBshift-A(x)−toBshift-B(x)),(10)Zb′≔1∣Pm(b)∣∑x∈Pm(b)(toBphase(x)−12∑σ∈{+16,−16}(toBshift-Aσ(x)+toBshift-Bσ(x))).(11)\begin{aligned} Z_b&\coloneqq\frac1{|\mathcal P_m(b)|}\sum_{x\in\mathcal P_m(b)}\big(\mathrm{toB}_{\textsf{phase}}(x)-\mathrm{toB}_{\textsf{shift-A}}(x)-\mathrm{toB}_{\textsf{shift-B}}(x)\big),\quad\text{(10)}\\ Z'_b&\coloneqq\frac1{|\mathcal P_m(b)|}\sum_{x\in\mathcal P_m(b)}\Big(\mathrm{toB}_{\textsf{phase}}(x)-\tfrac12\sum_{\sigma\in\{+16,-16\}}\big(\mathrm{toB}_{\textsf{shift-A}^{\sigma}}(x)+\mathrm{toB}_{\textsf{shift-B}^{\sigma}}(x)\big)\Big).\quad\text{(11)} \end{aligned}

For the length and distance comparisons, let xb,τ,κx_{b,\tau,\kappa} be the prompt of document bb at length τ∈{short,long}\tau\in\{\mathrm{short},\mathrm{long}\} and distance κ∈{near,far}\kappa\in\{\mathrm{near},\mathrm{far}\}. Let Kb≔{κ:xb,long,κ∈Pm∧xb,short,κ∈Pm}\mathcal K_b\coloneqq\{\kappa:x_{b,\mathrm{long},\kappa}\in\mathcal P_m\land x_{b,\mathrm{short},\kappa}\in\mathcal P_m\} be the distances at which both lengths lie in Pm\mathcal P_m, and Tb≔{τ:xb,τ,far∈Pm∧xb,τ,near∈Pm}\mathcal T_b\coloneqq\{\tau:x_{b,\tau,\mathrm{far}}\in\mathcal P_m\land x_{b,\tau,\mathrm{near}}\in\mathcal P_m\} the lengths at which both distances lie in Pm\mathcal P_m. Then

Ublen≔1∣Kb∣∑κ∈Kb(toBphase(xb,long,κ)−toBphase(xb,short,κ))for b with Kb≠∅,(12)Ubdist≔1∣Tb∣∑τ∈Tb(toBphase(xb,τ,far)−toBphase(xb,τ,near))for b with Tb≠∅.(13)\begin{aligned} U^\mathrm{len}_b&\coloneqq\frac1{|\mathcal K_b|}\sum_{\kappa\in\mathcal K_b}\big(\mathrm{toB}_{\textsf{phase}}(x_{b,\mathrm{long},\kappa})-\mathrm{toB}_{\textsf{phase}}(x_{b,\mathrm{short},\kappa})\big)\quad\text{for $b$ with }\mathcal K_b\ne\emptyset,\quad\text{(12)}\\ U^\mathrm{dist}_b&\coloneqq\frac1{|\mathcal T_b|}\sum_{\tau\in\mathcal T_b}\big(\mathrm{toB}_{\textsf{phase}}(x_{b,\tau,\mathrm{far}})-\mathrm{toB}_{\textsf{phase}}(x_{b,\tau,\mathrm{near}})\big)\quad\text{for $b$ with }\mathcal T_b\ne\emptyset.\quad\text{(13)} \end{aligned}

Intervals Because the documents are i.i.d. and whether b∈Jmb\in J_m depends only on document bb, the ZbZ_b with b∈Jmb\in J_m are i.i.d., and the same holds for the other quantities below. For each quantity, we report the mean over documents and a 95% percentile interval from 2,000 bootstrap resamples of the documents. We did not assess the effect of restricting the comparisons to the prompts in Pm\mathcal P_m, whose answer without edits contains Alice's color but not Bob's.

ZbZ_b Zb′Z'_b UblenU^\mathrm{len}_b UbdistU^\mathrm{dist}_b
Model ∣Jm∣\vert J_m\vert mean interval mean interval mean interval mean interval Agree
Qwen2.5-3B 238 0.267 [0.206, 0.326] 0.271 [0.212, 0.329] 0.097 [0.067, 0.126] 0.839 [0.799, 0.877] 941/943
Qwen2.5-7B 237 0.283 [0.243, 0.323] 0.287 [0.247, 0.329] 0.251 [0.217, 0.285] 0.464 [0.418, 0.511] 942/944
Mistral-7B 235 0.145 [0.102, 0.187] 0.143 [0.101, 0.184] 0.103 [0.068, 0.141] 0.268 [0.223, 0.318] 902/903
Llama-3.1-8B 240 0.037 [0.015, 0.065] 0.036 [0.014, 0.062] 0.056 [0.033, 0.081] 0.019 [0.002, 0.037] 959/960
Olmo-3-7B 221 0.034 [0.000, 0.068] 0.025 [−0.006-0.006, 0.058] 0.046 [0.011, 0.083] 0.096 [0.055, 0.139] 814/817
OLMo-2-7B†^\dagger 230 0.102 [0.061, 0.148] 0.111 [0.072, 0.154] --- --- 0.188 [0.126, 0.256] 434/437

Table4|The long-document test (Appendix D): means over documents and 95% bootstrap intervals. ∣Jm∣|J_m|: documents with prompts entering ZbZ_b. Agree: prompts answered with only Alice's color without edits in which the swap of both keys and values and the phase exchange agree on whether the answer changes to Bob's color. †^\daggerAbout 3.5k tokens; not compared across lengths.

Model Examples (about 1k, 4k, 16k tokens) phase shift-A shift-B
Qwen2.5-3B 120, 59, 24 0.142, 0.407, 0.542 0.000, 0.051, 0.083 0.017, 0.051, 0.250
Qwen2.5-7B 119, 60, 24 0.050, 0.183, 0.333 0.000, 0.000, 0.042 0.000, 0.017, 0.042
Mistral-7B 115, 55, 20 0.026, 0.127, 0.300 0.000, 0.018, 0.100 0.017, 0.055, 0.150
Llama-3.1-8B 120, 59, 23 0.000, 0.000, 0.087 0.000, 0.000, 0.000 0.000, 0.000, 0.000
Olmo-3-7B 118, 50, 16 0.025, 0.060, 0.375 0.008, 0.020, 0.125 0.000, 0.000, 0.062
OLMo-2-7B†^\dagger 119, 53 0.118, 0.208 0.008, 0.038 0.050, 0.094

Table5|The preliminary experiment on the examples at the three context lengths: rates at which the answer changes to Bob's color under the phase exchange and shift-A and shift-B, among examples whose answer without edits contains Alice's color but not Bob's; no test was run. Olmo-3: only the eight full-attention layers are edited, and only examples in which all three edits change the same layers are included. †^\daggerAbout 1k and 3.5k tokens.

Preliminary experiment In each of the 15 (model, length) combinations of Table 5 with a nonzero rate, the phase exchange changes the answer to Bob's color more often than shift-A and shift-B together, in five of them by only one or two examples.

Shifted versions of shift-A and shift-B The variant Zb′Z'_b (Eq. (11)), in which the moved key never shares a rotary position with the other key, gives the same result as ZbZ_b: its interval excludes 0 in every model except Olmo-3 (Table 4). Over all lengths and distances, the largest difference between the rate for a move of a single key (shift-A or shift-B) and that of either of its shifted versions lies between 0.4 and 1.6 percentage points, depending on the model.

Changes under the phase exchange At the tested length, among the prompts answered with only Alice's color without edits, the fraction whose answer changes to Bob's color under the phase exchange ranges from 2.3% (Mistral-7B, near) to 97.9% (Qwen2.5-3B, far) and is positive in every model and distance.

Moving both keys without an exchange For a prompt, let ℓ<≔min⁡(ℓ,ℓ′)\ell_<\coloneqq\min(\ell,\ell'), ℓ>≔max⁡(ℓ,ℓ′)\ell_>\coloneqq\max(\ell,\ell') and Δℓ≔ℓ>−ℓ<\Delta\ell\coloneqq\ell_>-\ell_<. A move (s<,s>)∈Z2(s_<,s_>)\in\mathbb Z^2 replaces the key at p∈{ℓ<,ℓ>}p\in\{\ell_<,\ell_>\} with ropep+sp\mathrm{rope}_{p+s_p} of its key content, at the same layers and KV heads as above and read from the last token of the prompt onward; a key with sp=0s_p=0 is unchanged. The phase exchange is (+Δℓ,−Δℓ)(+\Delta\ell,-\Delta\ell), the parallel move is (−Δℓ,−Δℓ)(-\Delta\ell,-\Delta\ell), and the random move is (ϵ<a, ϵ>(2Δℓ−a))(\epsilon_<a,\ \epsilon_>(2\Delta\ell-a)), with a∈{0,…,2Δℓ}a\in\{0,\dots,2\Delta\ell\} and ϵ<,ϵ>∈{+1,−1}\epsilon_<,\epsilon_>\in\{+1,-1\} drawn uniformly and independently, once per prompt. They are drawn again until both moved keys lie in {1,…,T−2}\{1,\dots,T-2\}, where TT is the number of tokens in the prompt. For b∈Jmb\in J_m,

Dbrnd≔1∣Pm(b)∣∑x∈Pm(b)(toBphase(x)−toBrnd(x)),(14)D^\mathrm{rnd}_b\coloneqq\frac1{|\mathcal P_m(b)|}\sum_{x\in\mathcal P_m(b)}\big(\mathrm{toB}_{\textsf{phase}}(x)-\mathrm{toB}_\mathrm{rnd}(x)\big), \quad\text{(14)}

where rnd denotes the random move. DbparD^\mathrm{par}_b is defined in the same way with the parallel move, over the prompts in Pm(b)\mathcal P_m(b) at which both moved keys lie in {1,…,T−2}\{1,\dots,T-2\} (only the near prompts for OLMo-2), for the documents that have at least one of them. Their means and intervals are computed as for ZbZ_b.

DbrndD^\mathrm{rnd}_b DbparD^\mathrm{par}_b
Model Documents mean interval far near mean interval
Qwen2.5-3B 238 0.303 [0.265, 0.340] 0.587 0.017 0.210 [0.166, 0.252]
Qwen2.5-7B 237 0.257 [0.222, 0.295] 0.509 0.013 0.184 [0.143, 0.226]
Mistral-7B 235 0.136 [0.102, 0.174] 0.274 −0.005-0.005 0.145 [0.113, 0.179]
Llama-3.1-8B 240 0.037 [0.017, 0.060] 0.050 0.025 0.029 [0.015, 0.048]
Olmo-3-7B 221 0.068 [0.038, 0.102] 0.064 0.034 0.020 [−0.011-0.011, 0.052]
OLMo-2-7B†^\dagger 230 0.065 [0.026, 0.104] 0.088 0.041 0.018 [−0.023-0.023, 0.059]

Table6|The phase exchange against the random move and the parallel move (Appendix D) at the tested length: means over documents of DbrndD^\mathrm{rnd}_b and DbparD^\mathrm{par}_b and 95% bootstrap intervals. Far, near: toBphase−toBrnd\mathrm{toB}_{\textsf{phase}}-\mathrm{toB}_\mathrm{rnd} averaged over the prompts at that distance. †^\daggerAbout 3.5k tokens; DbparD^\mathrm{par}_b uses only the near prompts (220 documents).

E. A worked example

The first example of the templated prompts (i=1i=1, seed 0) has the user message below; the two edited tokens are underlined. The model's chat template is applied around it.

Read the following notes.
The hiking trail is closed after heavy storms. A local band will perform in the park this weekend. The bridge on the main road is being repaired. The meeting was moved to the second floor conference room. Alice's favorite color is blue. A long queue formed outside the ticket office. A new bakery started selling bread near the station last month. The museum added a small exhibit about old clocks. Bob's favorite color is red. The library opens at nine in the morning on weekdays.
Question: What is Alice's favorite color? Answer with one word.

F. Tables of the main results

In Table 9, the value-swap criterion is that of Table 3.

Model none mask-A patch-V swap-V swap-K swap-KV
accA\mathrm{acc}_A
Qwen2.5-3B 1.000 0.000 0.000 0.008 0.017 1.000
Qwen2.5-7B 1.000 0.350 0.000 0.000 0.008 1.000
Mistral-7B 1.000 0.000 0.000 0.000 0.017 1.000
Llama-3.1-8B 1.000 1.000 0.000 0.600 0.542 1.000
Phi-3.5-mini 1.000 0.008 0.000 0.008 0.158 1.000
OLMo-2-7B 1.000 0.442 0.000 0.000 0.017 1.000
accB\mathrm{acc}_B
Qwen2.5-3B 0.000 1.000 1.000 0.992 0.983 0.000
Qwen2.5-7B 0.000 0.650 1.000 1.000 0.992 0.000
Mistral-7B 0.000 0.008 1.000 0.983 0.950 0.000
Llama-3.1-8B 0.000 0.000 1.000 0.400 0.458 0.000
Phi-3.5-mini 0.000 0.992 1.000 0.992 0.842 0.000
OLMo-2-7B 0.000 0.367 1.000 1.000 0.983 0.000

Table7|Fractions of examples whose answer contains Alice's color (accA\mathrm{acc}_A) or Bob's color (accB\mathrm{acc}_B) in the templated prompts (Figure 2), with all layers and KV heads edited and the edits read from the last token of the prompt onward (including the generated tokens); n=120n=120.

Single-layer key swap Key duplication Without edits
Model FAF_A FBF_B ΔβˉA\Delta\bar\beta_A ΔβˉB\Delta\bar\beta_B dupK_AB clA\mathrm{cl}_A(dupK_BA) DˉAl\bar D^\mathrm{Al} DˉBo\bar D^\mathrm{Bo}
Qwen2.5-3B 0.991 0.991 −0.310-0.310 0.294 0.275 0.717 0.313 −0.297-0.297
Qwen2.5-7B 0.998 0.998 −0.302-0.302 0.290 0.000 0.500 0.305 −0.301-0.301
Mistral-7B 0.994 0.998 −0.191-0.191 0.191 0.008 0.000 (all amb) 0.194 −0.183-0.183
Llama-3.1-8B 1.000 1.000 −0.193-0.193 0.189 0.000 0.958 0.194 −0.193-0.193
Phi-3.5-mini 0.935 0.909 −0.277-0.277 0.285 0.333 0.783 0.290 −0.311-0.311
OLMo-2-7B 0.999 0.999 −0.235-0.235 0.228 0.467 0.583 0.237 −0.236-0.236
Query ratio Ratio >12>\frac12
Model cov. E\mathcal E FAtotF^\mathrm{tot}_A FBtotF^\mathrm{tot}_B swap-K swap-V swap-K swap-V
Qwen2.5-3B 0.946 0.936 0.553 0.205 0.190 0.227 0.215
Qwen2.5-7B 0.921 0.900 0.740 0.187 0.190 0.163 0.162
Mistral-7B 0.883 0.872 0.792 0.109 0.108 0.150 0.154
Llama-3.1-8B 0.915 0.686 0.381 0.425 0.424 0.456 0.442
Phi-3.5-mini 0.816 0.754 0.587 0.207 0.225 0.247 0.278
OLMo-2-7B 0.936 0.897 0.612 0.124 0.122 0.233 0.237

Table8|Attention measures and key-duplication outcomes in the templated prompts (Table 1; Appendix H.4). dupK_AB: fraction of examples moved away from Alice's color; clA(dupK_BA)\mathrm{cl}_A(\textsf{dupK\_BA}): with clA(none)=1.000\mathrm{cl}_A(\textsf{none})=1.000, and "all amb" when every answer is amb\mathrm{amb}. Lower part (Appendix H.2): cov. E\mathcal E: fraction of triples in E\mathcal E; FXtotF^\mathrm{tot}_X: FXF_X with the all-layer key swap; query ratios after the all-layer swaps.

Color S1 S2 S3
Criterion Original M N U M N U M N U M N U
Value swap -- 5 0 1 4 1 1 4 1 1 3 1 2
Phase 6 6 0 0 6 0 0 6 0 0 6 0 0
dupK_AB 3 3 3 0 3 3 0 0 6 0 0 6 0
dupK_BA 1 0 4 2 0 4 2 0 2 4 0 2 4
Bob, value swap 4 4 1 1 5 0 1 5 1 0 3 1 2
Bob, phase 6 6 0 0 6 0 0 6 0 0 5 0 1
Bob, attention 6 6 0 0 6 0 0 6 0 0 6 0 0
Bob, three people 5 -- -- 5 1 0 4 0 2
Three people 5 -- -- 5 1 0 3 1 2
Criterion Original Color S1 S2 S3
Value swap -- ✓ ✓ ✓ ×\times
Phase ✓ ✓ ✓ ✓ ✓
dupK_AB ×\times ×\times ×\times ✓ ✓
dupK_BA ? ? ? ? ?
Bob, value swap ✓ ✓ ✓ ✓ ×\times
Bob, phase ✓ ✓ ✓ ✓ ✓
Bob, attention ✓ ✓ ✓ ✓ ✓
Bob, three people ✓ -- -- ✓ ×\times
Three people ✓ -- -- ✓ ×\times

Table9|Judgments of the control with other names and attributes: the criteria of Table 2 with other names (S1), pets (S2) and drinks (S3). Upper part: numbers of the six models met (M), not met (N) or undetermined (U); Original: models met in the color task (Table 1; Appendix H.4); Color: the color task rerun as in S1–S3. Lower part: Olmo-3-7B (✓: met; ×\times: not met; ?: undetermined).

G. Method details

G.1 Task and evaluation details

Prompts are about 115–150 tokens in the templated prompts and about 145–180 in the story prompts.

Answer classes For the answer classes of Section §4.2, an answer that is cut off at six tokens is extended to 16 tokens. The answer is lower-cased, and surrounding spaces, quotation marks and asterisks are removed, as is a final period or exclamation mark. It is classified as Alice's (A) or Bob's (B) color only if it is exactly the color, optionally preceded by "Name's favorite color is" with the name of the queried person, "her favorite color is", "the answer is" or "answer:"; anything else is amb\mathrm{amb}. In the conditions with questions about Bob, and in the Alice question run alongside them, the pronoun prefix is not accepted for either question, so the answer classes under these conditions are reported separately. Answers classified as amb\mathrm{amb} were not manually rechecked.

Measures on the answer classes Write cati(η)∈{A,B,amb}\mathrm{cat}_i(\eta)\in\{\mathrm A,\mathrm B,\mathrm{amb}\} for the answer class of example ii under condition η\eta. We define

clX(η)≔1n∑i1[cati(η)=X],ΠXY(η1,η2)≔1n∑i1[cati(η1)=X, cati(η2)=Y],(15)agreecat(η1,η2)≔1n∑i1[cati(η1)=cati(η2)],(16)\begin{gathered} \mathrm{cl}_X(\eta)\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}[\mathrm{cat}_i(\eta)=X],\qquad \Pi_{XY}(\eta_1,\eta_2)\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}[\mathrm{cat}_i(\eta_1)=X,\ \mathrm{cat}_i(\eta_2)=Y],\quad\text{(15)}\\ \mathrm{agree}^\mathrm{cat}(\eta_1,\eta_2)\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}[\mathrm{cat}_i(\eta_1)=\mathrm{cat}_i(\eta_2)],\quad\text{(16)} \end{gathered}

and pamb(η)≔1n∑i1[cati(η)=amb]p_\mathrm{amb}(\eta)\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}[\mathrm{cat}_i(\eta)=\mathrm{amb}].

Undetermined judgments Judgments whose preconditions are not met, and judgments of swap-V@UH\mathcal U_\mathrm{H} that are undetermined by construction (Appendix G.6), are also reported as undetermined (Appendix B).

Common settings The measurements that use the answer classes (Section §4.2) also run the phase exchange of Eq. (5). Except in the three-person task and the control with other names and attributes, they use the same 120 examples with templated prompts; the two-person swaps, the phase exchange and the key duplications are also run in the story prompts. The three controls use, as in the conditions with questions about Bob, the answer class without the pronoun prefix.

G.2 Cached pairs under each edit

Figure 5 shows the (key, value) pairs that the equivalences of Section §3.2 compare.

Figure5|Cached (key, value) pairs at the positions of the two color-word tokens under each edit, for one layer and KV head. kˉ\bar k is a key before RoPE and RsR_s the rotation of position ss. The last row shows dupK_BA\textsf{dupK\_BA}, which duplicates Bob's key content at Alice's position (Appendix G.3).

G.3 Key duplication

Because the key swap gives no evidence independent of the value swap (Section §3.2), we also ran two key duplications. With kˉA,kˉB\bar k_A,\bar k_B as in Section §3.2, we define the key duplications, applied in all layers and KV heads with the values unchanged, as

dupK_AB:k~ℓi′←ropeℓi′(kˉA)  (ℓi unchanged),(17)dupK_BA:k~ℓi←ropeℓi(kˉB)  (ℓi′ unchanged).(18)\begin{aligned} \textsf{dupK\_AB}:&\quad \tilde k_{\ell'_i}\leftarrow\mathrm{rope}_{\ell'_i}(\bar k_A)\ \ (\ell_i\text{ unchanged}),\quad\text{(17)}\\ \textsf{dupK\_BA}:&\quad \tilde k_{\ell_i}\leftarrow\mathrm{rope}_{\ell_i}(\bar k_B)\ \ (\ell'_i\text{ unchanged}).\quad\text{(18)} \end{aligned}

dupK gives both positions the same key content with different values, which no reordering of the pairs can produce. Their criteria are in Table 2 and their results in Appendix H.4.

G.4 Varied tasks and question forms

Three people The three-person task states Alice's, Bob's and Carol's colors, all different, in random order and asks for Alice's. The colors are blue, red and green, which are single tokens in all six tokenizers. Answers are classified as the color of the queried person (self), of the other person in the swap (part), of the third person (oth) or as amb\mathrm{amb}. The swaps act on the color-word positions of Alice and Bob or of Bob and Carol. For the Bob↔\leftrightarrowCarol swap, Bob's and Carol's colors are merged into one class, so agreecat\mathrm{agree}^\mathrm{cat} there checks whether the answer keeps the distinction between Alice's color and the others.

Questions about Bob With catiQ(η)\mathrm{cat}^{Q}_i(\eta) the answer class of example ii under question Q∈{Al,Bo}Q\in\{\mathrm{Al},\mathrm{Bo}\} (Section §4.2), the answer-based criteria that use both questions require, as a precondition, that both questions are answered correctly in the same example without edits in at least 90% of examples, with

ppair≔1n∑i=1n1[catiAl(none)=A∧catiBo(none)=B],(19)p_\mathrm{pair}\coloneqq\tfrac1n\textstyle\sum_{i=1}^n\mathbb{1}\bigl[\mathrm{cat}^\mathrm{Al}_i(\textsf{none})=\mathrm A\land\mathrm{cat}^\mathrm{Bo}_i(\textsf{none})=\mathrm B\bigr], \quad\text{(19)}

where A and B are Alice's and Bob's colors; in the three-person task ppairp_\mathrm{pair} is computed in the same way on the three-person examples, and under question form ff (below) it is written ppairfp^f_\mathrm{pair}.

Question form The question forms (Table 10) keep the context of the 120 evaluation examples, and the last token of the prompt is the same chat-template token in every form.

Form Question sentence Name mentioned last
F0 What is ⟨Q⟩\langle Q\rangle's favorite color? ⟨Q⟩\langle Q\rangle
F1a ⟨O⟩\langle O\rangle would like to know: what is ⟨Q⟩\langle Q\rangle's favorite color? ⟨Q⟩\langle Q\rangle
F1b (Question from ⟨O⟩\langle O\rangle.) What is ⟨Q⟩\langle Q\rangle's favorite color? ⟨Q⟩\langle Q\rangle
F2a What is ⟨Q⟩\langle Q\rangle's favorite color? ⟨O⟩\langle O\rangle would like to know. ⟨O⟩\langle O\rangle
F2b What is ⟨Q⟩\langle Q\rangle's favorite color? (Question from ⟨O⟩\langle O\rangle.) ⟨O⟩\langle O\rangle

Table10|Question forms. ⟨Q⟩\langle Q\rangle: the queried person; ⟨O⟩\langle O\rangle: the other person. Every form ends with "Answer with one word."

Other names and attributes Three sets repeat the judgments of Table 2. In S1, only the names in the evaluation examples and in the examples used to select heads (Section §4.4) are replaced, example by example, by two names drawn from a list of 29 names that are single tokens in every tokenizer. S2 (pets) and S3 (morning drinks) also change the fact sentences, the neutral sentences and the attribute words that take the place of the colors. Their facts read "Name has a X as a pet." and "Name usually drinks X in the morning.", where X is the attribute word, and their questions are "Which animal does Name keep as a pet?" and "What does Name usually drink in the morning?" followed by "Reply with a single word." The attribute words of two (or three) people are different words drawn from five per attribute, so that, unlike with two colors, the other person's attribute word is not determined by that of the queried person. The answer classes of S2 and S3 also accept forms specific to each task, such as plural forms in S2. They were fixed on 20 separate examples for each set before the evaluation examples were seen, and the word lists and the patterns are provided with the code. S2 and S3 also have a three-person task. In each set, we select the heads again by the same rule on 120 separate examples. For comparison, we rerun the color task with the Alice question and the main conditions of Table 2, using the same implementation and answer class.

G.5 Attention details

Formulas For layer LL and query head jj, which uses KV head g(j)g(j), let et,s(L,j)≔q~t,j(L)⊤k~s,g(j)(L)/dhe^{(L,j)}_{t,s}\coloneqq\tilde q^{(L)\top}_{t,j}\tilde k^{(L)}_{s,g(j)}/\sqrt{d_h} be the attention score and βA,i(L,j),βB,i(L,j)\beta^{(L,j)}_{A,i},\beta^{(L,j)}_{B,i} the attention weights from position Ti−1T_i-1 to ℓi\ell_i and ℓi′\ell'_i. On the 120 selection examples (Section §4.4), indexed by i′i', the selection gives 35–53 heads in each of the six models (58 in Olmo-3):

Dsel(L,j)≔1120∑i′(βA,i′(L,j)−βB,i′(L,j)),Hatt≔{(L,j):Dsel(L,j)≥0.05}.(20)D^{(L,j)}_\mathrm{sel}\coloneqq\tfrac{1}{120}\textstyle\sum_{i'}\bigl(\beta^{(L,j)}_{A,i'}-\beta^{(L,j)}_{B,i'}\bigr),\qquad \mathcal H_\mathrm{att}\coloneqq\{(L,j):D^{(L,j)}_\mathrm{sel}\ge0.05\}. \quad\text{(20)}

We write η#L\eta_{\#L} for edit η\eta applied in layer LL only. Omitting (L,j)(L,j), we define the score difference without edits Δiorg\Delta^\mathrm{org}_i and the score changes ΔX,ipos\Delta^\mathrm{pos}_{X,i} caused by moving the same key content to the other position,

Δiorg≔eTi−1,ℓi(none)−eTi−1,ℓi′(none),(21)ΔB,ipos≔eTi−1,ℓi(swap-K#L)−eTi−1,ℓi′(none),(22)ΔA,ipos≔eTi−1,ℓi′(swap-K#L)−eTi−1,ℓi(none).(23)\begin{aligned} \Delta^\mathrm{org}_i&\coloneqq e_{T_i-1,\ell_i}(\textsf{none})-e_{T_i-1,\ell'_i}(\textsf{none}),\quad\text{(21)}\\ \Delta^\mathrm{pos}_{B,i}&\coloneqq e_{T_i-1,\ell_i}(\textsf{swap-K}_{\#L})-e_{T_i-1,\ell'_i}(\textsf{none}),\quad\text{(22)}\\ \Delta^\mathrm{pos}_{A,i}&\coloneqq e_{T_i-1,\ell'_i}(\textsf{swap-K}_{\#L})-e_{T_i-1,\ell_i}(\textsf{none}).\quad\text{(23)} \end{aligned}

With E≔{(i,L,j):(L,j)∈Hatt, ∣Δiorg∣≥1}\mathcal E\coloneqq\{(i,L,j):(L,j)\in\mathcal H_\mathrm{att},\ |\Delta^\mathrm{org}_i|\ge1\}, we define, for X∈{A,B}X\in\{A,B\},

χX,i≔∣ΔX,ipos∣/∣Δiorg∣for (i,L,j)∈E,FX≔∣{(i,L,j)∈E:χX,i≤0.5}∣/∣E∣,(24)\chi_{X,i}\coloneqq|\Delta^\mathrm{pos}_{X,i}|/|\Delta^\mathrm{org}_i|\quad\text{for }(i,L,j)\in\mathcal E,\qquad F_X\coloneqq|\{(i,L,j)\in\mathcal E:\chi_{X,i}\le0.5\}|/|\mathcal E|, \quad\text{(24)}

and, over all examples and selected heads, the weight change ΔβˉX≔meani,(L,j)∈Hatt(βX,i(L,j)(swap-K#L)−βX,i(L,j)(none))\Delta\bar\beta_X\coloneqq\mathrm{mean}_{i,(L,j)\in\mathcal H_\mathrm{att}}\bigl(\beta^{(L,j)}_{X,i}(\textsf{swap-K}_{\#L})-\beta^{(L,j)}_{X,i}(\textsf{none})\bigr). Without edits, we define, for Q∈{Al,Bo}Q\in\{\mathrm{Al},\mathrm{Bo}\} and (L,j)∈{0,…,NL−1}×{0,…,Hq−1}(L,j)\in\{0,\dots,N_L-1\}\times\{0,\dots,H_q-1\},

DQ,(L,j)≔1n∑i(βA,iQ,(L,j)−βB,iQ,(L,j)),DˉQ≔1∣Hatt∣∑(L,j)∈HattDQ,(L,j),(25)ϕBo≔1∣Hatt∣∣{(L,j)∈Hatt:DBo,(L,j)<0}∣.(26)\begin{gathered} D^{Q,(L,j)}\coloneqq\tfrac1n\textstyle\sum_i\bigl(\beta^{Q,(L,j)}_{A,i}-\beta^{Q,(L,j)}_{B,i}\bigr),\qquad \bar D^{Q}\coloneqq\tfrac{1}{|\mathcal H_\mathrm{att}|}\textstyle\sum_{(L,j)\in\mathcal H_\mathrm{att}}D^{Q,(L,j)},\quad\text{(25)}\\ \phi^\mathrm{Bo}\coloneqq\tfrac{1}{|\mathcal H_\mathrm{att}|}\bigl|\{(L,j)\in\mathcal H_\mathrm{att}:D^{\mathrm{Bo},(L,j)}<0\}\bigr|.\quad\text{(26)} \end{gathered}

For form f∈{F0,F1a,F1b,F2a,F2b}f\in\{\mathrm{F0},\mathrm{F1a},\mathrm{F1b},\mathrm{F2a},\mathrm{F2b}\}, with the same Hatt\mathcal H_\mathrm{att} for every form and question,

diQ,f≔1∣Hatt∣∑(L,j)∈Hatt(βA,iQ,f,(L,j)−βB,iQ,f,(L,j)),DˉQ,f≔1n∑idiQ,f,(27)ψpairf≔1n∑i1[diAl,f>0∧diBo,f<0],ψlastf≔1n∑i1[diAl,f<0∧diBo,f>0].(28)\begin{gathered} d^{Q,f}_i\coloneqq\tfrac{1}{|\mathcal H_\mathrm{att}|}\textstyle\sum_{(L,j)\in\mathcal H_\mathrm{att}}\bigl(\beta^{Q,f,(L,j)}_{A,i}-\beta^{Q,f,(L,j)}_{B,i}\bigr),\qquad \bar D^{Q,f}\coloneqq\tfrac1n\textstyle\sum_i d^{Q,f}_i,\quad\text{(27)}\\ \psi^f_\mathrm{pair}\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}\bigl[d^{\mathrm{Al},f}_i>0\land d^{\mathrm{Bo},f}_i<0\bigr],\qquad \psi^f_\mathrm{last}\coloneqq\tfrac1n\textstyle\sum_i\mathbb{1}\bigl[d^{\mathrm{Al},f}_i<0\land d^{\mathrm{Bo},f}_i>0\bigr].\quad\text{(28)} \end{gathered}

Because the query of layer LL is unchanged under swap-K#L\textsf{swap-K}_{\#L}, in exact arithmetic

ΔB,ipos=q~⊤(ropeℓi−ropeℓi′)(kˉB)dh,(29)\Delta^\mathrm{pos}_{B,i}=\frac{\tilde q^{\top}(\mathrm{rope}_{\ell_i}-\mathrm{rope}_{\ell'_i})(\bar k_B)}{\sqrt{d_h}}, \quad\text{(29)}

and likewise for ΔA,ipos\Delta^\mathrm{pos}_{A,i}, so Δpos\Delta^\mathrm{pos} is due to the RoPE phase alone.

Recording and edits in all layers Scores are recorded in float32 before the causal mask. For an edit η\eta, write ηall\eta_\mathrm{all} for the edit in all layers. Repeating the measurement after editing all layers shows how much the query of layer LL itself changes: eTi−1,s(ηall)−eTi−1,s(η#L)e_{T_i-1,s}(\eta_\mathrm{all})-e_{T_i-1,s}(\eta_{\#L}) is due only to the query, because the key at ss is the same.

G.6 KV heads of the selected heads, and head-wise knockout

We write a KV head of layer LL as u=(L,g)u=(L,g), with U≔{0,…,NL−1}×{0,…,Hkv−1}\mathcal U\coloneqq\{0,\dots,N_L-1\}\times\{0,\dots,H_{kv}-1\} the set of all KV heads; the KV heads of the selected heads are UH≔{(L,g(j)):(L,j)∈Hatt}\mathcal U_\mathrm{H}\coloneqq\{(L,g(j)):(L,j)\in\mathcal H_\mathrm{att}\}, and for S⊆U\mathcal S\subseteq\mathcal U,

swap-V@S:vℓi,g(L)↔vℓi′,g(L)for (L,g)∈S,(30)\textsf{swap-V@}\mathcal S:\quad v^{(L)}_{\ell_i,g}\leftrightarrow v^{(L)}_{\ell'_i,g}\quad\text{for }(L,g)\in\mathcal S, \quad\text{(30)}

with every other KV head unchanged. For each model mm, the control with swap-V@UH\mathcal U_\mathrm{H} draws Nmrnd≤10N^\mathrm{rnd}_m\le10 random sets of KV heads Rrunit⊆U\mathcal R^\mathrm{unit}_r\subseteq\mathcal U, r∈{1,…,Nmrnd}r\in\{1,\dots,N^\mathrm{rnd}_m\}; in every layer, each set has as many KV heads as UH\mathcal U_\mathrm{H}, sampled uniformly at random from that layer's KV heads. A random set may overlap UH\mathcal U_\mathrm{H} but may not equal it. We also swap every KV head except those of the selected heads, swap-V@(U∖UH)\textsf{swap-V@}(\mathcal U\setminus\mathcal U_\mathrm{H}). Under the Alice question, let mv(η)≔ΠAB(none,η)\mathrm{mv}(\eta)\coloneqq\Pi_{AB}(\textsf{none},\eta), which the criterion of Table 3 uses. The judgment is undetermined by construction when the KV heads of UH\mathcal U_\mathrm{H} shared by all random sets make up at least half of UH\mathcal U_\mathrm{H}, because the random sets then share much of the selected set, as happens in models with few KV heads.

Head-wise knockout (Appendix H.3) restricts the attention knockout of Geva et al. [11], which blocks all heads in a window of layers, to one head set. It hides a color-word position from the final positions only in H∗\mathcal H^\ast or in one of three random head sets Rrhead\mathcal R^\mathrm{head}_r, r∈{1,2,3}r\in\{1,2,3\}, with the same number of heads per layer as H∗\mathcal H^\ast. We form H∗\mathcal H^\ast by taking heads in decreasing order of DselD_\mathrm{sel} until they cover half of ∑max⁡(Dsel,0)\sum\max(D_\mathrm{sel},0), with at most half of the heads of each layer; this gives 10–17 heads per model. Its positive control requires that blocking H∗↛ℓi\mathcal H^\ast\not\to\ell_i without edits lowers clA\mathrm{cl}_A by at least 30 percentage points.

G.7 Models

Table 11 lists the six models and, below the rule, Olmo-3-7B-Instruct. Olmo-3-7B-Instruct's sliding-window layers, with a window of 4096 tokens, see the whole prompt in short contexts.

Model Identifier NLN_L HqH_q HkvH_{kv} dhd_h
Qwen2.5-3B [27] Qwen/Qwen2.5-3B-Instruct 36 16 2 128
Qwen2.5-7B [27] Qwen/Qwen2.5-7B-Instruct 28 28 4 128
Mistral-7B [28] mistralai/Mistral-7B-Instruct-v0.3 32 32 8 128
Llama-3.1-8B [29] meta-llama/Llama-3.1-8B-Instruct 32 32 8 128
Phi-3.5-mini [30] microsoft/Phi-3.5-mini-instruct 32 32 32 96
OLMo-2-7B [31] allenai/OLMo-2-1124-7B-Instruct 32 32 32 128
Olmo-3-7B [32] allenai/Olmo-3-7B-Instruct 32 32 32 128

Table11|Models, by their Hugging Face identifiers. NLN_L: layers; HqH_q, HkvH_{kv}: query and KV heads; dhd_h: head dimension.

H. Result details

H.1 Value swap: story prompts, three people and other details

Story prompts In the story prompts (Table 12), swap-V and swap-K give Bob's color in 87.5%–100.0% of examples in all six models except Llama-3.1-8B, and swap-KV gives Alice's in 98.3%–100.0% in all six models.

Model none mask-A patch-V swap-V swap-K swap-KV
accA\mathrm{acc}_A
Qwen2.5-3B 1.000 0.267 0.000 0.000 0.050 1.000
Qwen2.5-7B 1.000 0.342 0.017 0.008 0.017 1.000
Mistral-7B 0.992 0.183 0.117 0.058 0.067 0.992
Llama-3.1-8B 1.000 0.992 0.108 0.558 0.617‡^\ddagger 1.000
Phi-3.5-mini 1.000 0.233 0.000 0.000 0.117 0.983
OLMo-2-7B 1.000 0.492 0.000 0.017 0.058 1.000
accB\mathrm{acc}_B
Qwen2.5-3B 0.000 0.633 1.000 1.000 0.950 0.000
Qwen2.5-7B 0.000 0.358 0.967 0.942 0.933 0.000
Mistral-7B 0.000 0.042 0.858 0.900 0.875 0.000
Llama-3.1-8B 0.000 0.008 0.892 0.442 0.383‡^\ddagger 0.000
Phi-3.5-mini 0.000 0.617 1.000 1.000 0.883 0.017
OLMo-2-7B 0.000 0.475 1.000 0.983 0.942 0.000

Table12|accA\mathrm{acc}_A and accB\mathrm{acc}_B in the story prompts, with the edits and nn of Table 7. ‡^\ddaggerComputed with RoPE tables in the model dtype; with float32 tables, 0.625 (accA\mathrm{acc}_A) and 0.375 (accB\mathrm{acc}_B) (Appendix A).

Asking about Bob Without edits, all six models answer both questions correctly in every example. Under the Bob question, the value-swap criterion is not satisfied in Qwen2.5-3B, where the answer stays Bob's color in 14.2% of examples, and the judgment for Llama-3.1-8B is undetermined (Table 1).

Question form Under the forms F2a and F2b (Table 13 in Appendix H.3), the answer class changes to that of the other person in the swap in only 64.2% of examples in Qwen2.5-3B under the F2a Bob question and in 78.3% in OLMo-2 under the F2b Alice question, below the 80% required by the value-swap criterion.

Other names and attributes With pets (S2) and drinks (S3), the attribute word of the other person in the swap is not determined by that of the queried person, so the value-swap changes in these sets (Table 9) cannot come from answering the opposite of Alice's attribute word. Most judgments that are not satisfied or undetermined are in Llama-3.1-8B, Mistral-7B and Qwen2.5-3B. Because the sets also differ in the names, the sentences and the number of attribute words, we do not attribute their differences to the attribute alone.

H.2 Attention: single-layer scores, all-layer edits and the controls

Single-layer scores The set E\mathcal E of (example, layer, selected head) triples whose score difference without edits Δorg\Delta^\mathrm{org} between Alice's and Bob's scores (Section §4.4) has magnitude at least 1 contains most of the (example, layer, selected head) triples (Table 8). The attention weights follow the moved key content: ΔβˉA<0\Delta\bar\beta_A<0 and ΔβˉB>0\Delta\bar\beta_B>0 in every model (Table 8), and no 95% bootstrap interval over examples contains 0. Swapping the keys or the values of a single layer, run on 40 examples in all six models except OLMo-2, gives Bob's color in at most 25% of examples (layer 31 of Qwen2.5-3B). We did not measure attention with three people, after key duplication or in long documents.

After editing all layers After the runs, we measured, on the same edited keys, how much of the change in score comes from the query alone. Table 8 gives, for each model, the median ratio of the absolute change to the score difference without edits ∣Δorg∣|\Delta^\mathrm{org}|, over both color-word positions of each triple in E\mathcal E, and the fraction of these cases in which this ratio exceeds 1/2. Both are largest in Llama-3.1-8B and are about the same after swap-V and after swap-K. We did not establish whether these query changes are small enough for the attention without edits to describe the mechanism under all-layer swaps. The fraction of triples that follow the key content falls from FXF_X to FXtotF^\mathrm{tot}_X, which is FXF_X computed with the all-layer key swap (Table 8).

Question form: the name that appears last Under F2a and F2b, DˉAl,f\bar D^{\mathrm{Al},f} is 0.064–0.316 and DˉBo,f\bar D^{\mathrm{Bo},f} ranges from −0.311-0.311 to −0.117-0.117 in the six models and Olmo-3, and ψlastF2a=ψlastF2b=0%\psi^\mathrm{F2a}_\mathrm{last}=\psi^\mathrm{F2b}_\mathrm{last}=0\% in every model (Eqs. (27) and (28)). The judgment for Mistral-7B is undetermined because it answers both F2a questions of an example correctly in only 63.3% of examples (ppairF2ap^\mathrm{F2a}_\mathrm{pair}), below the required 90%, although its weights alone satisfy the attention thresholds (ψpairF2a=80.8%\psi^\mathrm{F2a}_\mathrm{pair}=80.8\%). The mean is taken over a fixed set of heads, and the heads re-selected in each form overlap Hatt\mathcal H_\mathrm{att} with a Jaccard index of 0.737–0.976 in F2b but 0.314–0.913 in F2a, so these measurements do not show that the same heads are used in every form. Placing the other person's name last does not rule out narrower cues, such as the name next to "favorite color".

Other names and attributes Applying the original Hatt\mathcal H_\mathrm{att}, selected with colors, to the three sets gives DˉAl>0\bar D^\mathrm{Al}>0, DˉBo<0\bar D^\mathrm{Bo}<0 and ϕBo=1.000\phi^\mathrm{Bo}=1.000 in every set, in all six models and in Olmo-3.

H.3 KV heads of the selected heads, masking and head-wise knockout

Model Question form Selected heads' KV heads
asked last swap-V phase 2 people 3 people H∗\mathcal H^\ast
Qwen2.5-3B ✓ ×\times ×\times ✓ cb^b c c
Qwen2.5-7B ✓ ×\times ✓ ✓ ×a\times^a ×\times ✓e^e
Mistral-7B ? ? ? ? ?c^c ? ?
Llama-3.1-8B ✓ ×\times ×\times ✓ ?d^d ? ?
Phi-3.5-mini ✓ ×\times ✓ ✓ ✓ ✓ ✓
OLMo-2-7B ✓ ×\times ×\times ✓ ✓ ✓ ✓
met 5 0 2 5 2 2 3
Olmo-3-7B ✓ ×\times ✓ ✓ ✓ ✓ ✓

Table13|Judgments of the controls with other question forms and with swap-V@UH\mathcal U_\mathrm{H}. The columns are the criteria of Table 3: "Question form, asked", "last", "value swap" and "phase"; "Selected heads' KV heads" (2 people), "Selected heads' KV heads, three people" (3 people) and "Selected heads' KV heads, H∗\mathcal H^\ast". Olmo-3-7B is not counted in the row "met". ✓: met; ×\times: not met; ?: undetermined; c: undetermined by construction.

Values of the KV heads of the selected heads In Olmo-3, swap-V@UH\mathcal U_\mathrm{H} changes the answer to Bob's color in 100.0% of examples, compared with 0% for the random sets. With three people, swapping only the values of UH\mathcal U_\mathrm{H} changes the answer to the color of the other person in the swap in 98.3% of examples in Phi-3.5-mini, 99.2% in OLMo-2 and 98.3% in Olmo-3, and to that of the third person in no example, compared with at most 2.5% moving to the partner's color for the first three random sets.

In Qwen2.5-7B, the KV heads of the selected heads change the answer to Bob's color in 94.2% of examples [89.2%, 97.5%], but one of the ten random sets also changes the answer to Bob's color in 94.2% of examples. The criterion, which requires a margin of 20 percentage points over every random set, is therefore not met, although the selected set exceeds the mean over the random sets by 51.2 [47.8, 54.6] percentage points. The KV heads of the heads H∗\mathcal H^\ast (Appendix G.6) are a subset of UH\mathcal U_\mathrm{H} evaluated on the same examples, so this analysis is not an independent replication. With them, the criterion is also satisfied in Qwen2.5-7B (Table 13).

All KV heads except those of the selected heads Swapping every KV head except those of the selected heads changes the answer to Bob's color in no example in any of the six models or in Olmo-3, although pambp_\mathrm{amb} is then 65.8% in Mistral-7B and 30.8% in Llama-3.1-8B.

Masking After a key-only or value-only swap, masking tests whether the answer depends on the position that holds Alice's key content; because this position also holds Bob's value, the test does not separate the key from the value, and a drop does not rule out contributions from other positions. Masking hides a position P∈{ℓi,ℓi′}P\in\{\ell_i,\ell'_i\} from every query at t≥cit\ge c_i in all heads; head-wise knockout hides it only in one head set (Appendix G.6). With two people, masking one position leaves only one color-word token visible, so a model that answers with the visible color would pass the two-person test even if the key did not select the position; with three people, two color-word tokens stay visible. With two people, after swap-K or swap-V, masking the position that then holds Alice's key content lowers clB\mathrm{cl}_B by at least 50 percentage points, while masking the other position lowers it by at most 10 percentage points, in OLMo-2, Phi-3.5-mini and Qwen2.5-3B. In the other three models the judgment is undetermined because of amb\mathrm{amb} answers. With three people, after the key swap, masking the position of the other person in the swap lowers the fraction of answers classified as that person's color by at least 50 percentage points, while masking Carol's position lowers it by at most 10 percentage points, in the same three models. In the other three models and in Olmo-3, the three-person judgment is undetermined.

Head-wise knockout Head-wise knockout is undetermined in all six models because, without edits, blocking the edges from the heads H∗\mathcal H^\ast to Alice's color-word token lowers the fraction of answers classified as Alice's color by only 0–23.3 percentage points, below the 30 percentage points required by the positive control.

H.4 Key duplication and Alice's color without her color-word token

Key duplication Copying Alice's key content to Bob's position (dupK_AB) changes the answer class away from Alice's color in at least 20% of examples in OLMo-2, Phi-3.5-mini and Qwen2.5-3B in both kinds of prompts, and in 0%–0.8% of examples in the other three models. In the templated prompts, the answer class changes mostly toward Bob's color (Table 8). In Qwen2.5-3B and Phi-3.5-mini the answer changes only in examples with Alice's fact first. Copying Bob's key content to Alice's position (dupK_BA) lowers clA\mathrm{cl}_A by at least 50 percentage points only in Qwen2.5-7B among the models with a determined judgment, from 100.0% to 50.0%. The dupK_BA criterion is not satisfied in four of the six models and is undetermined in Mistral-7B, whose answers are all amb\mathrm{amb}; in the story prompts it is satisfied in no model and undetermined in three. Some met key-duplication judgments are at or near their thresholds (Appendix C). With the attention function used to record weights (Appendix A), dupK_BA in Qwen2.5-7B gives pamb=25.8%p_\mathrm{amb}=25.8\%, so its judgment would be undetermined. With pets and drinks, dupK_AB satisfies its criterion in none of the six models, compared with three with colors: the answer class changes away from Alice's attribute word in only 0%–17.5% of examples.

Alice's color without her color-word token Alice's color-word token is not always needed for her color: masking it (mask-A) still leaves Alice's color in 100.0% of examples with templated prompts in Llama-3.1-8B, 44.2% in OLMo-2 and 35.0% in Qwen2.5-7B, and 99.2%, 49.2% and 34.2% of examples with story prompts. In the three-person task, in the three models that satisfy the masking criterion, we also mask the position of the other person in the swap in the examples where the key swap gives that person's color. The answer then changes to Alice's color in 26.7%–55.0% of all 120 examples and to Carol's in 35.8%–65.8%.

H.5 Llama-3.1-8B: order of the facts and final positions

Order of the facts In the templated prompts, in 46 and 47 of the 58 examples with Bob's fact first, where swap-V and swap-K never give Bob's color (Section §4.3), the answer instead attributes Alice's original color to Bob ("color is actually Bob's favorite ..."). In the story prompts, with the key swap computed with the float32 RoPE tables (overall rate 37.5%; Appendix A), the rates of Bob's color are 56.9% (swap-V) and 61.5% (swap-K) when Alice's fact comes first and 29.1% and 9.1% when Bob's fact comes first. In the templated prompts, patch-V gives Bob's color in all examples in both fact orders (Table 7), so Llama-3.1-8B does read an edited value; because both positions then carry the same color, this edit does not show which position supplies the answer's color. No answer after swap-V, swap-K or patch-V is the same string as the answer without edits (0 of 120 for each).

On the first 40 examples with templated prompts, we move the start of the final positions one token earlier at a time. Including the assistant header token <|start_header_id|> raises accB\mathrm{acc}_B by 45 (value swap) and 40 (key swap) percentage points over starting at the next token, about as much as letting only the last token of the prompt and the generated tokens read the edit raises it over no edit (38 and 48 percentage points). One possible explanation is that this token carries the original color onward, as the later delimiter tokens of Li [10] carry a decision computed from an earlier field of the prompt; we did not measure which positions carry it.

When the edits are read from the position right after the later of the two color-word tokens onward, the positions between the two tokens keep their original computation. Bob's color after swap-V and swap-K in Llama-3.1-8B then rises from 40.0% and 45.8% to 80.0% and 74.2%, and swap-KV keeps Alice's color in 100.0% of examples. When Alice's fact comes first, the two rates are 100% and 98%, and when Bob's fact comes first, they are 59% and 48%. In the other four models run this way (Qwen2.5-3B, Qwen2.5-7B, Mistral-7B and Phi-3.5-mini), swap-V and swap-K give Bob's color in 64.2%–98.3% of examples.

H.6 Long documents: context length, preliminary experiment and test prompts

Model ΔK\Delta_K ΔV\Delta_V ΔK−ΔV\Delta_K-\Delta_V min. unedited accA\mathrm{acc}_A
Qwen2.5-3B 0.342 [0.150, 0.525] 0.033 [−-0.025, 0.125] 0.308 [0.117, 0.492] 0.983
Qwen2.5-7B 0.308 [0.108, 0.508] 0.117 [−-0.058, 0.308] 0.192 [−-0.042, 0.433] 0.992
Llama-3.1-8B 0.100 [−-0.100, 0.283] −0.017-0.017 [−-0.200, 0.175] 0.117 [−-0.125, 0.350] 0.958
Mistral-7B 0.417 [0.217, 0.600] 0.225 [0.042, 0.417] 0.192 [0.025, 0.375] 0.833
Phi-3.5-mini −0.058-0.058 [−-0.250, 0.142] 0.100 [−-0.025, 0.250] −0.158-0.158 [−-0.317, 0.008] 0.875
Olmo-3-7B 0.183 [−-0.017, 0.383] 0.292 [0.092, 0.492] −0.108-0.108 [−-0.283, 0.083] 0.667
OLMo-2-7B†^\dagger 0.192 [0.067, 0.317] 0.208 [0.092, 0.325] −0.017-0.017 [−-0.167, 0.133] 0.883

Table14|Drops of accB\mathrm{acc}_B under the key swap (ΔK\Delta_K) and the value swap (ΔV\Delta_V) from about 1k tokens to the longest length (Section §4.6). Brackets: 95% bootstrap intervals over examples (Appendix C). Last column: minimum over lengths of accA\mathrm{acc}_A without edits. Olmo-3-7B: only its eight full-attention layers are swapped at the longest length. †^\daggerLongest length about 3.5k tokens.

Context length At approximately 1k and 4k tokens, and most often under mask-A, some answers contain neither color within six tokens, so the rates there may miss colors that appear later in the answer. From the short context of the story prompts to about 16k tokens, Bob's color under the key swap falls from 95% to 29% in Qwen2.5-3B and from 93% to 42% in Qwen2.5-7B, and under the value swap from 100% to 96% and from 94% to 75%. These drops have two parts, and we attribute neither to length alone: one from the synthetic short context to Wikipedia documents of about 1k tokens, where the kind of document also changes, and one from about 1k to 16k tokens within the same Wikipedia construction. The key-swap effect in Llama-3.1-8B is already small at approximately 1k tokens (35%), so its drop says little about the key. Its short-context key-swap point in Figure 4 (37.5%) comes from the run with float32 RoPE tables, whereas Table 12 gives the model-dtype value 38.3% (Appendix A). In Olmo-3 the value effect drops more than the key effect, from 87.5% to 58.3% under the value swap and from 55.8% to 37.5% under the key swap between about 1k and 16k tokens. At 16k, however, only its eight full-attention layers are swapped, so length cannot be separated from the layer range or from the answers without edits that lack the queried color. The runs of OLMo-2 at approximately 1k and 3.5k tokens each failed, in one example, the check that the cache built for the edits reproduces the answer without edits; both mismatches keep Alice's color, and their effect on the edited answers was not checked. Swapping both the keys and the values also keeps Alice's color less often: from the short context to about 16k tokens, 100% to 46% in Qwen2.5-3B, 100% to 67% in Qwen2.5-7B and 99% to 58% in Mistral-7B, which gives her color in 83.3% of examples without edits at 16k.

Prompts and models of the long-document test In the prompts of Appendix D, the two color-word tokens are 187–704 tokens apart (near) or 1,757–2,852 tokens apart (far). Qwen2.5-3B, Qwen2.5-7B and Mistral-7B were included because at the three context lengths swapping both had lowered Alice's color at long lengths in them. Llama-3.1-8B was included as a model in which Alice's color had stayed high when both were swapped (88% at approximately 16k tokens), and Olmo-3 and OLMo-2 as models with multi-head attention and openly documented training. Phi-3.5-mini is excluded, as its RoPE scaling changes beyond 4k tokens, which would mix a change in RoPE with length.