Locating and Editing Factual Associations in GPT
arXiv ↗PDF ↗Paper ↗Website ↗Code ↗
Read first: A Mathematical Framework for Transformer Circuits · Towards Best Practices of Activation Patching in Language Models: Metrics and Methods
TL;DR. The paper does two things. First, causal tracing corrupts the subject of a factual prompt and restores one hidden state at a time; it finds that recall of facts like “Space Needle → Seattle” depends strongly on mid-layer MLPs at the last subject token. Second, ROME (Rank-One Model Editing) treats that MLP’s output matrix as a linear key–value memory and inserts a new fact with a closed-form rank-one update.
Why it matters now. ROME is the reference point for model editing and for the claim that MLPs store associations. It also shows the limits of that claim: later work found that the causal-tracing peak does not tell you where to edit. For retrieval people it raises a practical question: when should a RAG system fix a fact in the corpus and when in the weights? ROME also connects directly to Mor Geva’s view of FFN layers as key–value memories.
Key idea
Section titled “Key idea”Causal tracing. Run the model on the clean prompt, then on a copy whose subject token embeddings get Gaussian noise (3σ). The total effect is . Restore one hidden state from the clean run in the corrupted run; the indirect effect of that state is . Averaging over many facts gives a map over layers and positions.
MLP as key–value memory. In layer the MLP computes and writes into the residual stream. Viewing as a least-squares memory over many keys and values , . To insert a new pair while disturbing old pairs as little as possible, solve
The solution is a rank-one update:
is the uncentred covariance of keys, estimated once from 100,000 Wikipedia token states (App. E.5).
Choosing and . is the MLP key at the last subject token, averaged over random short prefixes so the edit fires in varied contexts. is optimised with Adam so that the model outputs the new object , plus a KL term on a prompt of the form {subject} is a that keeps the subject’s other properties (“essence”) intact. In GPT-2 XL the edit is at layer 18 and takes about 2 seconds on an A6000 (App. E.5).
Key results
Section titled “Key results”- Causal tracing (§2.2, GPT-2 XL, 1000 facts). Average total effect 18.6%; average indirect effect peaks at 8.7% at layer 15 at the last subject token. At the early site, MLP states carry an AIE of 6.6% vs 1.6% for attention.
- zsRE (§3.2, Table 1, 10,000 records). ROME reaches efficacy/paraphrase/specificity of 99.8/88.1/24.2. MEND trained on zsRE gets 99.4/99.3/24.1 and fine-tuning 99.6/82.1/23.2. Specificity barely moves for any method (the unedited model is 24.2), which is one reason the authors built CounterFact.
- CounterFact (§3.3, Table 4; 21,919 records, test sets of 7,500 for GPT-2 XL and 2,000 for GPT-J). On GPT-2 XL, ROME has score (harmonic mean of ES 100, PS 96.4, NS 75.4), generation entropy 621.9 and reference score 41.9. Baselines: FT 65.1 (NS 40.4), FT+L 66.9 (PS 48.7), MEND 57.9, KN 35.6; the unedited model scores 30.5 with NS 78.1. On GPT-J, ROME reaches S 91.5 (ES 99.9, PS 99.1, NS 78.9).
- Human study (§3.6). Raters were 1.8 times more likely to rate ROME as more consistent with the inserted fact than FT+L, but rated ROME 1.3 times less likely to be the more fluent one.
Limitations & open questions
Section titled “Limitations & open questions”- One fact per edit. The authors say ROME is a tool for understanding knowledge storage and not a practical method for large-scale model training (§3.7). Edited associations are also directional: editing the subject does not update the reverse relation.
- The edit changes outputs for every key that overlaps ; NS below the unedited model shows neighbouring facts are affected.
- Localisation ≠ edit target. Hase et al., “Does Localization Inform Editing?” (2301.04213, NeurIPS 2023), found that the causal-tracing result does not predict which layer is best to edit. The choice of layer predicts edit success much better.
- Causal tracing uses Gaussian noise and probability, exactly the setting activation patching best practices shows can inflate peaks.
Connections
Section titled “Connections”- Activation patching explains how corruption and metric choices change the tracing map.
- Mor Geva’s job talk covers FFN layers as key–value memories, the assumption behind the edit.
- Task arithmetic edits weights by adding whole fine-tuning deltas instead of a rank-one term.
- Weight-space programming has an LLM write targeted weight edits directly, including a projection-style edit to MLP output columns.
- DPR: is it retrieving? uses knowledge-editing methods to probe where facts live in dense retrievers.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Take a toy MLP output matrix W = I (2×2), key covariance C = I, a new key k* = (1, 0) and a target value v* = (0, 1). (a) Compute Λ and the edited matrix Ŵ with the ROME update. (b) What does Ŵ return for k* , for k = (0, 1) and for k = (1, 1)? (c) Explain what C⁻¹ changes when C is not the identity.
What a strong answer covers
- (a) Λ = (v* − Wk*)/((C⁻¹k*)ᵀk*) = ((0,1) − (1,0))/1 = (−1, 1). Ŵ = W + Λ(C⁻¹k*)ᵀ = I + (−1,1)ᵀ(1,0) = [[0,0],[1,1]].
- (b) Ŵk* = (0,1) = v*, so the new fact is stored exactly. Ŵ(0,1) = (0,1), unchanged, because that key is orthogonal to k*. Ŵ(1,1) = (0,2) instead of (1,1): keys that overlap k* are also changed.
- In general Ŵk* = Wk* + Λ·(C⁻¹k*)ᵀk* = Wk* + (v* − Wk*) = v*, so the constraint holds by construction.
- (c) With a general C, the update direction is C⁻¹k*, which is the least-squares-optimal way to change W while keeping ŴK close to V for the existing keys. It changes outputs less for keys that are common in the data (high variance directions) and more along rare directions.
- Mechanism
Explain the "MLP as key–value memory" view that ROME relies on. What are the key and the value, at which token position, and why does the rank-one update follow from a constrained least-squares problem?
What a strong answer covers
- The second MLP matrix W maps the post-nonlinearity hidden vector k (the key) at the last subject token to an output v (the value) that is added to the residual stream.
- Treat W as storing many pairs, W ≈ VK⁺ (least squares over existing keys K and values V).
- Insert a new pair by minimising ‖ŴK − V‖ subject to Ŵk* = v*. The Lagrangian solution adds Λ(C⁻¹k*)ᵀ with C = KKᵀ, which is rank one.
- k* is the average key for the subject over random short prefixes, so the edit triggers for the subject in varied contexts; v* is found by optimisation so that the model outputs the new object.
- What if…
Causal tracing reports an average indirect effect of 8.7% at layer 15 for the last subject token in GPT-2 XL, and 6.6% for MLPs vs 1.6% for attention at the early site. What does this localisation justify, and what did Hase et al. later show about using it to choose the edit layer?
What a strong answer covers
- Indirect effect: corrupt the subject embeddings with Gaussian noise, then restore one hidden state from the clean run and measure how much P(o) recovers. The peak at mid layers on the last subject token motivates editing an MLP there.
- The MLP vs attention gap at the early site suggests the fact is retrieved by MLPs while attention moves it to the final position later.
- Hase et al. (NeurIPS 2023) found that where tracing localises a fact does not predict which layer gives the best edit; the choice of layer predicts edit success far better than the tracing result.
- So causal tracing is evidence about information flow under one corruption, not a guide to where a fact is stored. Zhang and Nanda also show GN-based peaks can be inflated relative to token replacement.
- Critique
On CounterFact (GPT-2 XL), ROME scores ES 100, PS 96.4 and NS 75.4, while the unedited model has NS 78.1. Check that its score S = 89.2 is the harmonic mean of the three, and argue what NS below the unedited baseline means for using ROME to correct facts in a deployed RAG generator.
What a strong answer covers
- Harmonic mean: 3/(1/100 + 1/96.4 + 1/75.4) = 3/(0.0100 + 0.0104 + 0.0133) ≈ 3/0.0337 ≈ 89.2.
- NS measures whether neighbouring subjects keep their original object. 75.4 vs 78.1 means some nearby facts are damaged by the edit.
- The harmonic mean hides that efficacy is saturated while specificity is the weak point.
- For a RAG generator, bleed into neighbouring entities can silently corrupt answers to related questions; a falsifying test is to edit N facts and measure accuracy on held-out questions about near-duplicate entities and on retrieved-context-grounded answers.
- Design
You maintain a 7B RAG answerer and want to fix 200 outdated facts without retraining. Compare editing with ROME, editing the retrieval corpus, and fine-tuning, and state the evaluation you would run before shipping.
What a strong answer covers
- ROME edits one fact at a time with a closed-form update (about 2 seconds per edit on an A6000 for GPT-2 XL); many sequential edits may interfere because each changes W for overlapping keys.
- Editing the corpus fixes answers only when retrieval surfaces the passage and the model trusts context over its parametric memory; the parametric fact can still win.
- Fine-tuning (FT) in the paper has much weaker specificity (NS 40.4) than ROME, and FT+L has weak generalization (PS 48.7).
- Evaluation: efficacy on the edited prompts, paraphrases, neighbour subjects, generation fluency, and conflict cases where retrieved context and edited memory disagree.
- Research idea
ROME treats one MLP as the store for a fact. Propose an experiment that tests whether dense retrievers store entity facts the same way, using a DPR-style bi-encoder.
What a strong answer covers
- Run causal tracing on the query encoder: corrupt the entity tokens and restore hidden states to see where the query–passage score recovers.
- Apply a ROME-style rank-one edit at the peak MLP layer so the query embedding for "capital of X" moves toward passages about a new city.
- Measure efficacy (edited query retrieves the new passage), paraphrase generalisation, and neighbourhood damage on other entities.
- Compare with Reichman and Heck's finding that DPR training decentralises knowledge storage; if that holds, a single-layer edit should be less effective than in GPT.