Knowledge Editing › Rank-one editing: the ROME mechanism

Michael BrenndoerferDecember 1, 20266 min read
Language AI HandbookAll chapters
Part 45 of 67Knowledge, Memory, Editing, and Unlearning
Chapter 347Knowledge Editing › Rank-one editing: the ROME mechanism
Reading section 3 of 11 · Rank-one editing: the ROME mechanism · 6 minSection 3 of 11 · 6 min

Section 3 of 11 · 6 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The Rank-One Model Editing (ROME) algorithm makes the FFN-as-associative-memory view precise. Treat a single FFN's second linear layer, with weight matrix W∈Rd×dffW \in \mathbb{R}^{d\times d_{\mathrm{ff}}} mapping from hidden dimension dffd_{ff} back to the residual width dd, as a key-value store. The FFN computes, for an input activation k=σ(W1h)∈Rdffk = \sigma(W_1 h) \in \mathbb{R}^{d_{ff}} (post-activation), the output

FFN(h)=W k.\text{FFN}(h) = W\, k.

For this associative-memory view, WkWk is the current value retrieved by kk. The desired value v⋆v^\star fixes one new output, so the new matrix must satisfy W^k=v⋆\widehat W k=v^\star. In a key space of dimension greater than one there are many possible matrices that do this. They can differ in what they retrieve for keys that the edit never mentioned. To choose among them, specify a distribution of reference keys and minimize the movement of their outputs while satisfying the edit.

Under this objective the solution has the form of a rank-one update,

W^=W+Λ(C−1k)⊤,\hat{W} = W + \Lambda (C^{-1} k)^\top,

where CC is the uncentered second moment of the reference keys and Λ∈Rd\Lambda\in\mathbb R^d is in value space. If KK stacks the reference vectors in its columns, KK⊤KK^\top is proportional to the empirical second moment. A common positive scaling of CC cancels in the normalized update. Take CC to be positive definite, using a diagonal ridge when appropriate, and kk to be nonzero. Define β=(C−1k)⊤k\beta=(C^{-1}k)^\top k. The new output at the edit key is Wk+ΛβWk+\Lambda\beta. Therefore

Λ=v⋆−Wkβ,β=(C−1k)⊤k.\Lambda = \frac{v^\star - W k}{\beta}, \qquad \beta = (C^{-1} k)^\top k.

Let Δ=W^−W\Delta=\widehat W-W, r=v⋆−Wkr=v^\star-Wk and b=C−1kb=C^{-1}k. We minimize tr⁡(ΔCΔ⊤)\operatorname{tr}(\Delta C\Delta^\top) under Δk=r\Delta k=r, where the trace is the expected squared output shift under the unregularized reference moment. The proposed solution Δ∗=rb⊤/β\Delta_*=rb^\top/\beta is feasible. Write another feasible solution as Δ∗+Z\Delta_*+Z. The constraint gives Zk=0Zk=0. Since Cb=kCb=k, the cross term in the objective vanishes. The remaining difference from the objective at Δ∗\Delta_* is tr⁡(ZCZ⊤)\operatorname{tr}(ZCZ^\top), which is positive for nonzero ZZ when CC is positive definite. This proves the global minimum among feasible matrices. The corresponding objective for an empirical set is the average squared movement of its members; this follows by expanding each squared norm and summing the outer products of the sampled keys. If we add a diagonal ridge to the moment, the extra term is proportional to the squared Frobenius norm of the update. This keeps the objective well defined for directions that the reference set scarcely samples.

The denominator β\beta describes how strongly the input-side direction responds to the edited key. Dividing by it makes the output change equal to rr. If the reference second moment is a scalar multiple of the identity, the direction is parallel to kk and the update reduces to a Euclidean minimum-norm solution. With an anisotropic moment, inverse eigenvalues give different weights to different input directions. The formula then reflects which directions are costly to change under the reference keys.

What rank one guarantees

The nonzero update is the outer product of one value-space vector and one key-space vector. It may modify many entries of the weight matrix. Its rank describes the structure of the change, with all output shifts lying along the same value-space direction. The disturbance bound comes from the optimization objective and the reference data, so the rank alone does not guarantee that a language model's outputs stay local to one fact.

Applied to a key k′k', the update returns r(b⊤k′)/βr(b^\top k')/\beta. The input-side direction determines which keys move. A key orthogonal to bb retains its output. Orthogonality to kk gives the same criterion only when bb is parallel to kk. For a general second moment, a control orthogonal to kk may still move. That distinction is why the exact hand calculation below checks a condition specific to its reference moment.

In the original ROME method, the key averages post-activation vectors collected over contexts at the last subject token. To choose the value, ROME temporarily substitutes a candidate vector at one MLP output and optimizes for the new object and a preservation prompt. The persistent operation is then a rank-one change to that layer's output projection. There is no permanent insertion of a runtime hidden state. The surrogate supplies the desired value directly, so you can examine the write without optimizing a language-model output.

Compare two updates on the same reference keys

To compare the effect of weighting, fix an edit key with two coordinates and a desired scalar change of one. The Euclidean minimum-weight-change direction assigns equal coefficients to the coordinates of the edit key. The reference keys vary more along the first coordinate, so movement in that direction is more costly in the weighted objective. Compute both directions against the same target and check the movement on the same 40 sampled reference keys. This comparison fixes the requested change instead of comparing updates of different target strength.

The solid and dashed series below share key ordering and units. Each point records the absolute value of the output change on one reference key. The figure sorts by the Euclidean update's change to make the order reproducible and uses a dashed line for the weighted update. An individual key can still move more under the weighted update even if pooled squared movement is smaller. This is why a useful evaluation retains individual control cases as well as a pooled summary.

This example uses a small diagonal ridge in the weighted solve and the same reference sample for constructing and showing the disturbance objective. A fresh validation set would be needed to estimate population disturbance on other keys.

PythonIn [6]
CollapseExpand
rng = np.random.default_rng(SEED + 4)
other_keys = rng.normal(size=(40, 2)) * np.array([1.0, 0.25])
target_key = np.array([1.0, 1.0])
reference_moment = other_keys.T @ other_keys / len(other_keys)
reference_moment += 0.02 * np.eye(2)
naive_direction = target_key / (target_key @ target_key)
weighted_direction = np.linalg.solve(reference_moment, target_key)
weighted_direction /= target_key @ weighted_direction
naive_shifts = np.abs(other_keys @ naive_direction)
weighted_shifts = np.abs(other_keys @ weighted_direction)
key_order = np.argsort(naive_shifts)
key_rank = np.arange(1, len(other_keys) + 1)
VisualizationOut [7]
CollapseExpand
Two marked lines compare absolute output changes on the same sorted reference keys. The weighted line is generally lower but varies from key to key.
Absolute output change on 40 reference keys, sorted by their movement under the Euclidean update. Both rules move the target key's output by one. The second-moment-weighted rule reduces mean squared movement on this reference sample. Individual keys can move more.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy