Memory & RAG
~8 min readUpdated: December 2026

Unwrite: Zero-Replay Record Deletion in Linear Attention & Gated DeltaNet

Unwrite zero-replay low-rank state deletion for Gated DeltaNet linear attention in Smoke Monkey

Unwrite (arXiv:2612.04321) enables exact, zero-replay deletion of wrong or sensitive records from linear attention and Gated DeltaNet recurrent states in ~1.4 ms—up to 739x faster than checkpoint replay. By maintaining a low-rank difference state between the active model and a record-skipping shadow copy during the forward pass, Unwrite captures how the deleted record affected every subsequent token.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

Unwrite: Zero-Replay Record Deletion in Linear Attention & Gated DeltaNet: Unwrite (arXiv:2612.04321) enables exact, zero-replay deletion of wrong or sensitive records from linear attention and Gated DeltaNet recurrent states in ~1.4 ms—up to 739x faster than checkpoint replay. By maintaining a low-rank difference state between the active model and a record-skipping shadow copy during the forward pass, Unwrite captures how the deleted record affected every subsequent token. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Exampleunwrite-rollback-agent.ts
unwrite-rollback-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Agent equipped with an Unwrite-capable linear-attention inference backend for instant state rollback
const agent = createAgent({
agentId: 'unwrite-rollback-agent',
provider: 'openai-compatible',
baseUrl: 'http://127.0.0.1:8000/v1',
model: 'Qwen/Qwen3.5-9B',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'ask',
run_command: 'ask',
},
});
async function main() {
const result = await agent.run(
'If a user corrects an earlier credential or deadline, invoke state rollback on the superseded span before planning edits.'
);
console.log('Rollback-safe agent summary:', result.summary);
}
main().catch(console.error);
Video Guides

Watch: Related Video Guides

Hybrid Attention and Gated DeltaNet: How 2026 LLMs Actually Work

Beyond Softmax — Linear Attention

What Is Unwrite and Why Do Linear Attention States Need It?

Unwrite (Qiao & Hu, arXiv:2612.04321) is an inference-time memory deletion algorithm for linear attention and hybrid architectures such as Gated DeltaNet and Qwen3.5. Softmax attention stores separate key-value columns per token so an obsolete message can be dropped, whereas linear attention compresses every token into a single fixed-size d x d recurrent matrix M_t = M_{t-1} A_t + B_t, entangling deleted records with every later token.

On 100 needle-replacement benchmarks where a later user sentence updates an earlier key string, Gated DeltaNet 1.3B returns the updated value in only 32/100 contexts if the obsolete sentence remains in state—versus 100/100 after full replay. Unwrite matches replay accuracy at 1.4 ms per deletion (up to 739x faster than checkpoint replay).

Deletion MethodRequires Text / Checkpoint?Models Post-Record TransitionsCaptures Forced ResponseComplexity at DeletionExactness on Pure Linear Attention
Checkpoint ReplayYes (full suffix)YesYesO(suffix tokens), up to 739x slowerExact
Naive SubtractionSnapshot at record endNoNoO(1)Drifts as suffix grows
State PropagationSnapshot at record endYes (frozen transitions)NoO(1)Leaves forced-response residual
Unwrite (Rank r=32 / Full)NoYesYes (via shadow pass)~1.4 ms single additionExact at full rank; ~1% residual at r=32

How Low-Rank Shadow Tracking Captures Suffix Contamination

When a record is read at inference time, Unwrite avoids keeping the input text or a checkpoint. Instead, it tracks the exact difference Delta_t between the active recurrent state and a parallel record-free state as subsequent tokens arrive:

  1. Co-Forward Shadow Execution: After the target record ends, every subsequent token updates both the main matrix state M_t and the low-rank difference state (typically rank r = 32) in the same forward pass, capturing both the initial-condition transition Phi_{tau+1:T} and the forced response.
  2. O(1) Deletion Without Re-Prefill: When a user corrects an earlier fact or an agent rolls back an aborted tool call, Unwrite applies a single matrix addition—taking ~1.4 ms on Gated DeltaNet 1.3B—with zero re-tokenization.
  3. TOFU & Hybrid Attention Behavior: Across TOFU unlearning benchmarks at 128 and 1024 post-record tokens, Unwrite with r = 32 leaves roughly 1% residual effect across three tested linear-attention backbones, and removes significantly more residual contamination than KV attention masking alone on hybrid Qwen3.5 models.

Combine Unwrite With KV Masking on Hybrid Models

In hybrid architectures (such as Qwen3.5 or Qwen3.8 with 75% Gated DeltaNet and 25% full attention), Unwrite cleans the recurrent linear-attention layers while standard KV dropping or KVEraser handles the remaining softmax attention layers.

Reproducible Unwrite Evaluation and Gated DeltaNet Benchmark

Run the official open-source Unwrite implementation to reproduce the 1.4 ms deletion latency and needle-overwrite recovery on Gated DeltaNet 1.3B and hybrid checkpoints:

bash
# 1. Clone the official Unwrite repository
git clone https://github.com/yihao-qiao/Unwrite.git
cd Unwrite

# 2. Install PyTorch and Flash Linear Attention (FLA) dependencies
pip install -e .

# 3. Benchmark Unwrite (rank r=32) vs checkpoint replay on Gated DeltaNet 1.3B
python scripts/eval_needle_and_tofu.py \
  --model fla-hub/gated-deltanet-1.3B \
  --rank 32 \
  --suffix-tokens 1024 \
  --measure-latency
Google Search Questions & Answers

Frequently Asked Questions

Q:Why cannot linear attention models delete prompts by dropping KV cache entries?

Unlike softmax attention, linear attention and Gated DeltaNet fold every token into a single fixed-size d x d recurrent state matrix per head, so no isolated columns belong exclusively to an earlier prompt span.

Q:How fast is Unwrite compared to checkpoint replay on Gated DeltaNet 1.3B?

Unwrite completes a deletion in approximately 1.4 ms via a single state addition—up to 739x faster than replaying the suffix from a checkpoint.

Q:Does Unwrite work on hybrid models like Qwen3.5 that mix linear and full attention?

Yes. Unwrite removes contamination from the recurrent linear-attention layers and composes directly with KV cache dropping or KVEraser on the full-attention layers.

Q:What rank does Unwrite need to match full-replay behavior?

At full rank on purely recurrent models, Unwrite is mathematically identical to replay; empirically, rank r=32 reduces residual record effect on TOFU benchmarks to roughly 1%.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness