Interpretable
Module 5.2 · ~3h

Editing Weights & Learning on the Fly

ROME, MEMIT, test-time training — what it takes to change what a model knows.

You'll be able to
  • Explain causal tracing and where facts live in MLPs
  • Run a ROME edit and probe its ripple effects
  • Compare ICL, LoRA, and editing for on-the-fly adaptation
Learn

Where does a fact live?

“The Eiffel Tower is located in” → “Paris”. Somewhere in a hundred billion floating-point numbers, that association is stored. Not metaphorically — you can find it, and you can change it, and the second thing is the subject of this module.

The technique that located it is causal tracing, and it is activation patching (Module 3.5) pointed at a new question. Three runs:

cleanTheEiffelTowerislocatedinp(Paris) = 0.73corruptedThenoisenoiseislocatedinp(Paris) = 0.05restoredThenoisenoiseislocatedinp(Paris) = 0.62copy one clean hidden state back in (here: layer 6 at “Tower”)
Causal tracing in three runs. Corrupt the subject to destroy the answer, then copy exactly one clean hidden state back in and see how much of the answer returns. Sweep over every (layer, token) pair and you get a map of which states the answer causally depends on.
average indirect effect (AIE)
The recovery attributable to one restored state, averaged over many facts: AIE=E[prestoredpcorrupt]\mathrm{AIE} = \mathbb{E}\big[p_{\text{restored}} - p_{\text{corrupt}}\big]. High AIE means the answer causally flows through that state.

Run that sweep and a specific shape appears — the one you will click around in the widget below. Two hot regions, not one. An early site at the last token of the subject in early-to-middle layers, and a late site at the final token in late layers. Restoring MLP outputs recovers the early site and not the late one; restoring attention outputs does the reverse.

Key idea
The model looks up “which city” at the token “Tower” — before it has read the words “located in”. Mid-layer MLPs at the subject do the retrieval; late attention heads at the last position do the transport. Facts are recalled speculatively at the subject and moved into place later.

Why MLPs? Because an MLP layer is shaped exactly like a lookup table. Write it as MLP(x)=Woutσ(Winx)\mathrm{MLP}(x) = W_{\text{out}}\,\sigma(W_{\text{in}} x): the rows of WinW_{\text{in}} are keys that fire when the input matches a pattern, and the corresponding columns of WoutW_{\text{out}} are the values that get written to the residual stream when they do. Geva et al. (2020) argued this “key-value memory” reading directly; ROME took it seriously enough to edit with it.

Two-thirds of the parameters
In a standard transformer the MLPs hold roughly two-thirds of the weights. If you had to guess where a model puts memorized facts before running a single experiment, “the big lookup tables” would be a reasonable prior — and it is nice, for once, when the experiment agrees with the prior.
Learn

Editing: one rank-one update, and everything it breaks

Take the key-value picture literally. If the down-projection W=WoutW = W_{\text{out}} is a linear associative memory mapping keys to values, then inserting a new memory is a constrained least-squares problem: change WW as little as possible, subject to mapping one new key to one new value.

W^=argminW~  W~KWKFsubject toW~k=v\hat W = \arg\min_{\tilde W} \; \big\| \tilde W K - W K \big\|_F \quad \text{subject to} \quad \tilde W k_* = v_*

The solution has a closed form, and it is rank one:

W^=W+Λ(C1k),Λ=vWk(C1k)k\hat W = W + \Lambda \, (C^{-1} k_*)^{\top}, \qquad \Lambda = \frac{v_* - W k_*}{(C^{-1}k_*)^{\top} k_*}

Term by term. kk_* is the MLP's internal activation at the last subject token — the key for “Eiffel Tower”. vv_* is a value vector found by gradient descent, chosen so that writing it there makes the model say “Rome”. CC is the uncentered covariance E[kk]\mathbb{E}[kk^{\top}] of keys over a big text sample — it is what makes the update respect which directions in key space are actually used, so you disturb common memories least. The whole change is an outer product of two vectors: one new memory, written in place, in about a second.

Woriginal MLP+Λ(C⁻¹k*)ᵀrank 1=Ŵedited MLPŴk* = v*Ŵk ≈ Wkotherwise
ROME's update is an outer product — one column direction times one row direction. Keys orthogonal to C⁻¹k* pass through completely unchanged, which is why the edit can be surgical at all. MEMIT generalizes the same algebra to thousands of memories spread over a range of layers.

It works. Editing papers report near-100% efficacy (the edited prompt gives the new answer) and strong generalization (paraphrases give it too), with specificity (unrelated facts untouched) and fluency as the guardrail metrics. MEMIT scales the same algebra to thousands of simultaneous edits by spreading the update over a range of critical layers instead of one.

And then you ask the model what country the Eiffel Tower is in, and it says France.

Key idea
An edit changes one association. It does not change the beliefs that depended on that association, because nothing in a transformer recomputes downstream beliefs — there is no inference engine, only more stored associations. After the edit the model holds a set of beliefs that describe no possible world: a tower in Rome, in France, surrounded by French speakers.

Cohen et al. (2023) made this measurable with a benchmark of ripple effects — logical implications, compositions, two-hop questions, subject aliasing — and found editing methods that score in the nineties on standard efficacy score far lower once the neighbourhood is probed. The simulator below lets you feel the shape of it: generalization and specificity trade off along one dial, and ripple consistency is not on that dial at all.

Localization does not tell you where to edit
The tidiest story in this module is: causal tracing finds the fact at layer \ell, therefore edit at layer \ell. Hase et al. (2023) tested that story and it failed. Where tracing says a fact is localized turns out to be essentially uncorrelated with where editing that fact works best; you can successfully edit at layers tracing calls unimportant. Both techniques are sound and they answer different questions — where does information flow is not where can I write information. It is the single most useful piece of epistemic hygiene in this module, and it generalizes: a causal claim about a forward pass is not automatically a claim about weights.
Learn

Learning on the fly: what actually works

You came to this course partly wanting models that learn while you talk to them. Here is the honest state of it, arranged from cheapest to most invasive.

In-context learning is the one that already works. The residual stream is a scratchpad, induction heads (Module 3.2) are a copy-from-context mechanism, and the effect of a few-shot prompt is often well described as an implicit weight update — the “fast weights” framing. Nothing is stored, so nothing is corrupted; the trade is that it lasts exactly as long as the context window and costs tokens every single call.

Test-time training is the interesting middle. Hardt and Sun (2023) build a nearest-neighbour index over a large corpus, retrieve the neighbours of the current input, take a few gradient steps on them, answer, and throw the update away. Perplexity gains are large, and largest on exactly the data a model is worst at: rare, tail, domain-specific text. The cost is a training step inside your request path — which is a lot to ask of a serving stack, and the main reason you do not see it in products.

Fine-tuning and LoRA are the durable option, and the one that pays the classic tax:

catastrophic forgetting
Training on new data overwrites the representations that supported old behavior, because gradient descent has no notion of “leave that part alone”. Named in the connectionist literature in 1989 and never solved, only managed — with replay of old data, with parameter regularization, or by constraining the update to a low-rank subspace as LoRA does.

Editing is the most surgical and the most brittle, for all the reasons above. And the brittleness compounds: sequential edits applied one after another degrade the model, and papers on large-scale sequential editing report accumulating damage to fluency and to unrelated knowledge well before you reach the number of edits a real deployment would need.

Key idea
No frontier model in production today updates its weights from your conversations. What ships as “memory” is retrieval: text written to a store and pulled back into context. That is not a stopgap for the lack of a better method so much as a consequence of everything in this module — weight updates are irreversible, hard to evaluate, hard to attribute, and hard to roll back, and text in a database is none of those things.

The open research direction is the one you would guess: architectures with a separate, addressable, revisable memory, so that learning a new fact is a write to a store rather than a perturbation of the function that computes everything. Nobody has made that work at frontier scale. It remains one of the more attractive open problems in the field, and it is unusually well suited to someone who thinks like an engineer about state management.

Safety tie-in
Editing is quietly a safety topic in three directions. First, unlearning: if a model has memorized something dangerous, targeted removal is much more attractive than retraining — but current evaluations repeatedly find that “removed” knowledge is recoverable by rephrasing, by fine-tuning on adjacent data, or by asking in another language, which means the information was suppressed rather than deleted. Second, attribution: a rank-one edit is a tiny, targeted, hard-to-detect change to open weights, which is a supply-chain problem waiting to happen. Third, the pattern you should carry into 5.3: an intervention that passes your eval and fails your neighbourhood probes has not fixed the model, it has fixed your eval. Sleeper Agents is the same lesson in a much scarier setting.
Explore

Play: find the fact, then break it

First locate the fact, then move it and watch the neighbourhood. These two widgets are the module in miniature: the first is why people believed editing would work, the second is why it mostly doesn't.

Causal tracing: where does “Paris” live?
Corrupt the subject tokens with noise and p(Paris) collapses from 0.73 to 0.05. Now restore one clean hidden state at a time and see how much comes back. Click any cell. Hand-authored to match ROME's qualitative result on GPT-2 XL, not copied from its tables.
Restore which component?
TheEiffelTowerislocatedin012243647layer
recovers nothingrecovers the answer
layer 6 · token Tower · effect 63% · p(Paris) restored to 0.48

The early site. Restoring this one state brings back most of the answer — the model has already looked up “which city” at the subject token, long before it reads “located in”.

Restore the whole residual stream at one (layer, token). Two hot regions appear: the last subject token early on, and the final token late. Something decisive happens at the subject before the model has even read the relation.
Edit-ripple simulator
Apply the canonical ROME edit — Eiffel Tower · located-in · Paris → Rome — then probe the neighbourhood one question at a time. Nothing here is a live model; the outcomes follow what the knowledge-editing literature reports.
located-inin-countryspeakslocated-innicknamedcontrol (already Rome)Eiffel TowersubjectCITY?COUNTRY?LANGUAGE?Louvre?“city of love”?Colosseum?
Efficacy:
Generalization:
Specificity:
Ripple:
EfficacyThe Eiffel Tower is located in
GeneralizationYou can find the Eiffel Tower in the city of
GeneralizationThe tower Gustave Eiffel built stands in
GeneralizationOù se trouve la Tour Eiffel ?
RippleWhat country is the Eiffel Tower in?
RippleWhat language is spoken where the Eiffel Tower is?
SpecificityThe Louvre is located in
SpecificityWhich city is known as the city of love?
ControlThe Colosseum is located in
The locality dial is the real lesson. Generalization and specificity sit on opposite ends of one slider, so buying one spends the other — and the ripple probes do not move at all, because multi-hop consistency is a different failure with no dial on this panel.

Things to try: (1) In the heatmap, switch between MLP-only and attention-only and watch the hot region jump from the subject to the last token — that single contrast is ROME's whole argument for editing MLPs rather than attention. (2) Click a cell at the last token in layer 5 and one at “Tower” in layer 5: same layer, wildly different effect. Position matters more than depth here. (3) In the simulator, set λ low, run all probes, and note which column is red; then set λ to 95 and run again. You should be able to state the tradeoff in one sentence. (4) Find the probe that is secretly useless and work out what makes it useless before reading its note — then go check whether your own evals at work contain one like it.

Practice

Problem set

Problem 2 is the one to do carefully — once you have verified the rank-one update by hand, ROME stops being a black box forever. The three-way comparison in problem 4 is the most useful thing in this module for actual engineering work.

1.Read the tracepencil & paper

Using the heatmap widget: (a) Why is the early site at “Tower” rather than at “Eiffel”? (b) The tokens “located” and “in” show almost no effect at any layer, even though they are the relation. What does that tell you about when the lookup happens? (c) Predict the heatmap for the prompt “The city containing the Eiffel Tower is” — where the subject now ends one token before the prediction — and say specifically what would change.

2.Verify the rank-one updatepencil & paper

Let W=IW = I (2×2), C=IC = I, k=(1,0)k_* = (1,0)^{\top} and v=(0,2)v_* = (0,2)^{\top}.

(a) Compute Λ\Lambda and W^\hat W from the formula. (b) Check W^k=v\hat W k_* = v_*. (c) Compute W^k\hat W k for k=(0,1)k = (0,1)^{\top} and explain the result in terms of specificity. (d) In a real model CIC \neq I — what does the C1C^{-1} actually buy you?

3.Move the Eiffel Towercode

Using EasyEdit (github.com/zjunlp/EasyEdit) or the original ROME repository (github.com/kmeng01/rome), apply ROME to GPT-2 XL or GPT-J to make the Eiffel Tower be in Rome.

Then run the probe suite from the simulator against the real edited model: the edited prompt, three paraphrases, one cross-lingual phrasing, the two-hop country and language questions, and two unrelated Paris facts.

Success check: a table of nine prompts × (pre-edit, post-edit) answers, plus a one-paragraph verdict naming which of efficacy, generalization, specificity and ripple consistency your edit actually achieved.

4.ICL vs LoRA vs ROME on the same factcode

Take one fact your model gets wrong and install it three ways: (1) in context, as a sentence in the prompt; (2) with a LoRA fine-tune on ~50 generated sentences expressing the fact and its consequences; (3) with a single ROME edit.

Evaluate all three on the same probe suite from problem 3, and additionally on a 100-item general benchmark (a slice of MMLU or just perplexity on a held-out corpus) to measure collateral damage.

Success check: a 3 × 5 table — method by (efficacy, generalization, ripple consistency, specificity, general capability delta) — plus wall-clock cost per method and one sentence on when you would choose each.

5.Design a ripple-effect eval you would actually shippencil & paper

Your team wants to correct a factual error about your product in a deployed open-weights model, using an edit rather than a retrain. Write the eval that decides whether the edit ships.

It must cover: the edited fact, paraphrases, two-hop consequences, subject aliases, the negation, the temporal version (“what was true before”), unrelated neighbours, and a general-capability regression check. For each category, give three example items and the pass threshold you would defend to a sceptical reviewer.

6.Localization vs editing: the argument, both sidesexplore

Read Hase et al. 2023 (linked below), then write two paragraphs. First: the strongest version of their critique — what exactly did they show, and what does it invalidate?

Second: the strongest reply a ROME author could make. Does the result undermine causal tracing as a method, undermine editing as a method, or undermine only the inference from one to the other? Say which and defend it.

0 of 6 problems marked done
Check

Check yourself

1.
In causal tracing, why are the subject tokens corrupted with noise rather than replaced with a different subject?
2.
The heatmap shows the early site at “Tower” — the last subject token — and almost nothing at “located in”. The best reading is:
3.
ROME's update is W^=W+Λ(C1k)\hat W = W + \Lambda (C^{-1}k_*)^{\top}. What is the role of CC?
4.
After editing “Eiffel Tower is in Paris” → Rome, the model still says the Eiffel Tower is in France. Why?
5.
Hase et al. found that where causal tracing localizes a fact is roughly uncorrelated with where editing that fact succeeds. The right conclusion is:
6.
A colleague proposes shipping a product where the model permanently learns from each user conversation by fine-tuning on it nightly. The strongest technical objection is:
7.
You add a specificity probe to your edit eval: “The Colosseum is located in ___”, expecting Rome. Why is this a bad probe for the Paris → Rome edit?
Answer all 7 questions to submit.
Submit your answers to complete this check.
Go deeper

Go deeper

Read ROME for the method and the beauty of it, Hase immediately after for the corrective, and Cohen for what an honest evaluation looks like. The rest are for when you need them.

EssentialLocating and Editing Factual Associations in GPT (ROME)paper
Kevin Meng, David Bau, Alex Andonian, Yonatan Belinkov · 2022 · 2h
One of the best-constructed papers in the field. Read §2 (causal tracing) slowly and make sure you can redraw Figure 1 from memory — that figure is the widget above. §3 is the rank-one derivation; do problem 2 alongside it rather than after. The evaluation section is where to notice what is and is not measured: efficacy, generalization, specificity, fluency — and no ripple metric, which is precisely the gap Cohen et al. filled.
EssentialDoes Localization Inform Editing? Surprising Differences in Causality-Based Localization vs. Knowledge Editing in Language Modelspaper
Peter Hase, Mohit Bansal, Been Kim, Asma Ghandeharioun · 2023 · 1.5h
Read this straight after ROME, while the localization story still feels obvious — the effect is much stronger that way. Focus on the experimental design: what would have had to be true for tracing to predict edit success, and how they tested it. This is the paper that should permanently change how you read localization claims in any interpretability paper.
EssentialEvaluating the Ripple Effects of Knowledge Editing in Language Modelspaper
Roi Cohen, Eden Biran, Ori Yoran, Amir Globerson, Mor Geva · 2023 · 1h
The benchmark that made ripple failure a number instead of an anecdote. Read the taxonomy of ripple types (logical generalization, composition, subject aliasing, forgetfulness) and steal it wholesale for problem 5 — it is a better eval design than most people would produce from scratch.
Mass-Editing Memory in a Transformer (MEMIT)paper
Kevin Meng, Arnab Sen Sharma, Alex Andonian, Yonatan Belinkov, David Bau · 2022 · 1h
The scaled-up sequel: thousands of edits at once by spreading the update across a range of critical layers. Read §3 for the multi-layer least-squares generalization and skim the rest. The useful question to hold while reading: does editing ten thousand facts at once make the ripple problem better, worse, or neither?
Transformer Feed-Forward Layers Are Key-Value Memoriespaper
Mor Geva, Roei Schuster, Jonathan Berant, Omer Levy · 2020 · 1h
The conceptual foundation everything in this module stands on. Read §2–3 for the key-value framing and the evidence that individual keys correspond to human-recognizable input patterns. Short, clear, and it makes the ROME derivation feel inevitable rather than clever.
Test-Time Training on Nearest Neighbors for Large Language Modelspaper
Moritz Hardt, Yu Sun · 2023 · 45 min
The cleanest demonstration that a gradient step at inference time is a real option. Read the setup and the results table, and pay attention to where the gains concentrate — tail and domain-specific data, which is exactly where retrieval-only approaches also shine. Worth asking yourself which of the two you would build first.
A Comprehensive Study of Knowledge Editing for Large Language Modelspaper
Ningyu Zhang et al. · 2024 · reference
A survey plus the KnowEdit benchmark — use it as a map rather than a read. Go to it when you need to know what family a method belongs to (memory-based, meta-learning, locate-then-edit) or want a defensible baseline set for an experiment. The failure-mode discussion near the end is the part worth reading properly.