Editing Weights & Learning on the Fly
ROME, MEMIT, test-time training — what it takes to change what a model knows.
- → 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
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:
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.
Why MLPs? Because an MLP layer is shaped exactly like a lookup table. Write it as : the rows of are keys that fire when the input matches a pattern, and the corresponding columns of 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.
Editing: one rank-one update, and everything it breaks
Take the key-value picture literally. If the down-projection is a linear associative memory mapping keys to values, then inserting a new memory is a constrained least-squares problem: change as little as possible, subject to mapping one new key to one new value.
The solution has a closed form, and it is rank one:
Term by term. is the MLP's internal activation at the last subject token — the key for “Eiffel Tower”. is a value vector found by gradient descent, chosen so that writing it there makes the model say “Rome”. is the uncentered covariance 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.
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.
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.
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:
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.
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.
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.
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”.
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.
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.
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.
Let (2×2), , and .
(a) Compute and from the formula. (b) Check . (c) Compute for and explain the result in terms of specificity. (d) In a real model — what does the actually buy you?
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.
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.
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.
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.
Check yourself
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.