Unwrite: Deleting Records from Linear Attention Memory without Replay

Yihao Qiao1, Sihao Hu2
1New York University, 2Georgia Institute of Technology
Panel (a): a user gives a wrong deadline, May 3, corrects it to May 10, and asks for the deadline. Panel (b): softmax attention keeps one key and one value per token, so deleting the message drops its columns and the model answers May 10. Panel (c): linear attention adds every token's write to one state, so May 3 is in every entry and there is no entry to drop.

Deleting a message from softmax attention and from linear attention. (a) The user corrects a wrong deadline and deletes the wrong message. The model should answer May 10, as a model that never read that message would. (b) Softmax attention drops the message's keys and values. (c) Linear attention adds every token's write $\bm{v}_t \bm{k}_t^\top$ to one state, which has no entry to drop. One layer is drawn.

Abstract

Deleting a record read at inference time is important for language model assistants when a user has entered wrong or sensitive information. Softmax attention can drop the keys and values of the record, but linear attention mixes every token into fixed-size recurrent states without per-token entries. We identify two limitations of the existing remedies: (i) replay reprocesses everything read after the record, and (ii) cheaper remedies subtract a difference saved when the record is read and miss the record's effect on later tokens. We propose Unwrite, which addresses both limitations by maintaining the record-free state alongside the model as it reads the text. Specifically, Unwrite runs the model on a copy of its state that skips the record and stores the difference between the two states at low rank. This copy reads every later token in the same forward pass as the model and thus captures the record's effect on these tokens. While needing neither the text nor a checkpoint, a single deletion is one addition that equals replay at full rank on purely recurrent models. Empirically, Unwrite matches replay on answers on three linear attention models and removes more of the record's effect than attention masking on a hybrid model. Since its extra work is done during reading, a deletion takes about 1.4 ms and is up to $739\times$ faster than checkpoint replay on Gated DeltaNet 1.3B.

Background

The reference is the record-free state $\mathbf{M}^-_T$: the state the same model reaches on the same context with the record omitted. We write $\mathbf{M}^+_t$ for the state of the run that read the record and align the two runs by the tokens after the record, so that both read $x_{\tau+1}, \ldots, x_T$. Let $\bm{\Delta}_t = \mathbf{M}^+_t - \mathbf{M}^-_t$ be the difference between the two runs in one head of one layer.

$$\bm{\Delta}_T = \underbrace{\bm{\Delta}_\tau\, \bm{\Phi}_{\tau+1:T}}_{\text{initial condition response}} \; + \; \underbrace{\sum_{s=\tau+1}^{T} \mathbf{F}_s\, \bm{\Phi}_{s+1:T}}_{\text{forced response}}$$

The first term is what the record wrote, carried forward by the transitions of the run that read it. The second term did not exist when the record was written. A later token produces a different key, value or gate when the record is present, because the layers below it computed different hidden states.

Existing Methods

Subtraction saves $\bm{\Delta}_\tau$ when the record ends and subtracts it at time $T$. Propagation carries $\bm{\Delta}_\tau$ through the record-present transitions, $\bm{\Delta}_\tau \bm{\Phi}_{\tau+1:T}$, and subtracts it. It keeps the first term and drops the second. Thus, its error is the forced response. Replay keeps every term by recomputing $\mathbf{M}^-_T$, at the price of the record-free text and a forward pass over everything read after the record.

Carrying the Counterfactual

When a record begins, Unwrite copies the current state into a second row of the batch, the counterfactual row $\widehat{\mathbf{M}}$. The record-present row reads the record. The counterfactual row does not. Without any approximation, $\widehat{\mathbf{M}}_t = \mathbf{M}^-_t$ for every $t \ge \tau$: the counterfactual row is replay, performed while the text is read rather than after a deletion request. The truncation is applied when the record ends and then every $k$ tokens. At deletion time $T$ the record-present state is replaced by $$\mathbf{M}^{\mathrm{Unwrite}}_T = \mathbf{M}^+_T + \mathcal{P}_r\bigl(\widehat{\mathbf{M}}_T - \mathbf{M}^+_T\bigr),$$ a single addition per head that needs neither the text of the record nor the text read after it.

(a) A time axis with the record and a later record: the record-present run reads both, the counterfactual run skips the record and stores a rank-r difference every k tokens, and at the end the stored difference is added to the record-present state. (b) The same operations as small matrices in one head: one model step per token, the top r directions every k tokens, and one addition at deletion.
Unwrite on a time axis and in one head. (a) The record-free run is drawn for reference only. (b) The same three operations in a small head ($d = d_k = d_v = 6$, $r = 2$). Blue: state. Orange: carried difference.
Four columns, Instruction-only, Propagation, Replay and Unwrite, and three steps, record, later tokens and deletion. Instruction-only saves nothing and appends an instruction; propagation saves the difference and carries it through the record-present transitions; replay keeps the text and recomputes; Unwrite runs a second row that skips the record and adds its stored low-rank difference once.
Step-by-step comparison of four deletion methods. One head of a purely recurrent model is drawn.

TOFU Records

On TOFU contexts Unwrite with $r = 32$ leaves a residual effect of about $1\%$ on all three models at both lengths. Propagation matches replay on these answers too. They differ in the state, where Unwrite leaves a smaller residual than propagation on all three models at both lengths.

GLA 340MGDN 340MGDN 1.3B
Method128102412810241281024
(a) Residual effect (%) → 0
Record present100.0100.0100.0100.0100.0100.0
Replay0.00.00.00.00.00.0
Instruction-only (quote)155.8419.0117.0225.6105.3112.4
Instruction-only (neutral)89.589.789.189.899.7101.9
Subtraction−19.9−110.9−15.8−82.0−9.5−24.9
Propagation0.2−0.60.20.10.1−0.3
Unwrite ($r{=}16$)4.14.95.14.96.44.1
Unwrite ($r{=}32$)0.91.10.80.90.80.7
Unwrite ($r{=}64$)0.10.10.10.10.10.1
(b) Residual difference ↓
Subtraction1.7453.2581.0161.8851.6483.504
Propagation0.3590.4190.2510.3180.3540.451
Unwrite ($r{=}16$)0.3020.2830.3210.3540.4330.471
Unwrite ($r{=}32$)0.1630.1600.1670.2150.2640.321
Unwrite ($r{=}64$)0.0520.0610.0690.1170.1300.188

Deleting one TOFU record (test contexts, $k{=}64$). 128 and 1024: tokens after the record. Negative residual effects overshoot replay. Bold and underlined: closest and second closest to replay in each column; a column is not marked where its closest value and the next distinct value differ by less than the larger of their 95% intervals. Entries that tie at the closest printed value are all marked.

Needle Data

In the needle data the retained needle repeats the key string of the target needle, and the probe for its number asks for that key string. Therefore, the retained needle is where collateral damage shows. Unwrite with $r = 32$ does none: the retained needle's loss matches that of replay on all three models, and the first generated number is the retained needle's as often as after replay. Propagation also removes the target needle, but its collateral damage is as large as the effect of leaving the record in place, and larger on both Gated DeltaNet models.

1K contextGDN 1.3B
MethodGLA 340MGDN 340MGDN 1.3B2K4K8K
(a) First generated number is the retained needle's (%) → replay
Record present43.070.032.056.045.036.0
Replay74.073.0100.096.092.066.0
Instruction-only3.022.06.05.02.01.0
Subtraction12.00.05.02.01.00.0
Propagation47.051.038.058.050.030.0
Unwrite ($r{=}16$)73.073.099.093.092.061.0
Unwrite ($r{=}32$)73.074.0100.097.092.065.0
Unwrite ($r{=}64$)74.072.0100.096.092.066.0
(b) Retained-needle loss increase over replay (nats/token) → 0
Record present0.27 (0.04)0.19 (0.03)0.24 (0.02)0.180.180.20
Instruction-only0.61 (0.08)0.28 (0.04)0.15 (0.02)0.210.330.51
Subtraction0.83 (0.12)1.75 (0.13)1.07 (0.07)1.321.601.81
Propagation0.25 (0.06)0.30 (0.04)0.39 (0.03)0.300.350.48
Unwrite ($r{=}16$)0.01 (0.01)0.000.000.000.000.01
Unwrite ($r{=}32$)0.000.000.000.000.000.00
Unwrite ($r{=}64$)0.000.000.000.000.000.00
(c) Target-needle residual (%) → 0
Propagation−7.62.9−1.0−0.5−0.2−0.4
Unwrite ($r{=}16$)2.31.73.93.03.22.4
Unwrite ($r{=}32$)0.20.30.30.40.40.4
Unwrite ($r{=}64$)0.00.10.00.10.10.2
(d) Residual difference ↓
Propagation0.8480.8491.0141.0051.0061.005
Unwrite ($r{=}16$)0.3130.3470.4360.4240.4240.428
Unwrite ($r{=}32$)0.1690.2030.2890.2890.2980.309
Unwrite ($r{=}64$)0.0640.1050.1670.1750.1890.204

KVEraser needle data. (b) At 1K, the half-width of the 95% interval in parentheses, omitted where it rounds to zero. (d) Mean over items. The instruction, which leaves the record in place, is not ranked. Bold and underlined: closest and second closest to replay in each column of (a) and (b); bold: closest in (c) and (d). A column is not marked where its closest value and the next distinct value differ by less than the larger of their 95% intervals (bootstrap over items; not shown except in (b) at 1K).

Hybrid Models

Hybrid models such as Kimi Linear and Qwen3.5 interleave recurrent layers with full-attention layers, which keep one key and one value per token. On the Kimi contexts with Qwen3.5, propagation alone does nothing: the record stays in the attention cache and the lift is as large as with the record present. Attention masking removes most of the lift, and masking + propagation removes more. At the ranks selected on calibration contexts, Unwrite and Unwrite with tracked attention leave a lift of about $0.005$ nats per token.

Kimi contextsQwen contextsTOFU
MethodLift → 0$\Delta$AUC → 0Short ↓Long ↓128 → 01024 → 0
Record present2.5742 (0.1186)98.91.0001.000100.0100.0
Replay0.00000.00.0000.0000.00.0
Instruction-only2.4127 (0.1141)98.91.357 (0.023)1.747 (0.031)100.7 (0.5)101.6 (0.4)
Propagation2.5755 (0.1184)98.90.522 (0.007)0.579 (0.005)99.2 (0.3)99.8 (0.1)
Attention masking0.0813 (0.0137)14.51.0001.0007.8 (1.0)2.1 (0.4)
+ propagation0.0174 (0.0065)3.40.522 (0.007)0.579 (0.005)1.0 (0.3)0.2 (0.3)
Unwrite ($r{=}16$)$^{\ast}$0.0049 (0.0053)−0.10.335 (0.013)0.476 (0.008)1.0 (0.2)0.4 (0.3)
Unwrite ($r{=}32$)0.0037 (0.0054)−0.30.285 (0.015)0.447 (0.009)0.4 (0.2)0.2 (0.3)
Reference: Unwrite with tracked attention (not ranked)
$r{=}8$$^{\ast}$0.0053 (0.0019)1.60.332 (0.006)0.406 (0.007)1.8 (0.2)0.6 (0.1)
$r{=}32$−0.0006 (0.0006)−1.40.095 (0.002)0.148 (0.003)0.20.1

Qwen3.5-4B-Base. Kimi contexts: lift (nats/token) and $\Delta$AUC, the relative difference of the AUC from that of replay (%), on the 40 evaluation contexts. Qwen contexts: the per-layer relative error, short and long suffix. TOFU: residual effect (%) on the test contexts. In parentheses, the half-width of the 95% interval, omitted where it rounds to zero. $^{\ast}$Rank selected on calibration contexts. Instruction-only uses the forget prompt of on the Kimi contexts and the quote prompt of KVEraser on the Qwen contexts and TOFU. Bold and underlined: closest and second closest to replay in each column except lift, $\Delta$AUC and 1024 tokens, whose closest and next distinct values differ by less than their intervals. Entries that tie at the closest printed value are all marked. The interval of $\Delta$AUC (bootstrap over contexts) is not shown.

Cost

We time the deletion of one record on GDN 1.3B on one H200 GPU, in float32 as in the accuracy runs. Unwrite deletes a record in a time that does not depend on the number of tokens read after it, since it adds the product of the stored factors to the state and copies one convolution cache. Checkpoint replay takes up to $739$ times as long as Unwrite after 16K tokens. Over a whole read, one tracked record therefore costs about four times a replay of the same text at $k = 256$.

Two panels on GDN 1.3B. (a) Time of one deletion against the tokens read after the record: Unwrite stays near one millisecond while replay from the start and checkpoint replay grow with the text. (b) Time of reading with Unwrite tracking one record, for ranks 16, 32 and 64, against the truncation interval.
Cost of deletion and of tracking. GDN 1.3B on one H200. (b) Reading 4096 tokens with truncation every $k$ tokens, where $m{=}0$ is the plain model reading in pieces of $k$ tokens.

BibTeX

@article{qiao2026unwrite,
  title   = {Unwrite: Deleting Records from Linear Attention Memory without Replay},
  author  = {Qiao, Yihao and Hu, Sihao},
  journal = {arXiv preprint arXiv:2612.04321},
  year    = {2026}
}