Writing

Introducing RAZOR

Occam's razor, turned into a price: a model pays for every write to long-term memory, and when it declines to pay, memory stays exactly as it was.

RAZOR is an ongoing experiment at Manaslu Labs. The name stands for Recurrent Attention with Zero-redundancy Occam Registers, and the name is the idea: Occam's razor, turned into a price.

The Minimum Description Length principle (Rissanen, 1978) says the total cost of a model is the cost of its errors plus the cost of its own complexity. RAZOR applies this to memory. During training, the model is penalised a little for every write it makes to long-term storage, on top of the ordinary penalty for predicting text badly.

Because writing has a price, the model learns to write only when a token carries information likely to pay for itself later (a definition, a signature, a constant) and to leave memory untouched for filler.

Three ways to keep a record, and a fourth

When a language model reads, it needs some record of the past, and every existing way of keeping that record has a cost:

  1. Storing everything runs out of memory.
  2. Compressing everything risks slow forgetting.
  3. Deleting what looks unimportant sometimes deletes the wrong things.

RAZOR tries a fourth option: a learned on/off switch that decides, as each token arrives, whether it is worth writing into long-term memory.

01

Store everything

incoming tokenslong-term memory

Exact, but memory grows with every token.

02

Compress everything

incoming tokenslong-term memorysignal × 0.999ᵀ

Fixed size, but every token blurs what is stored.

03

Delete what looks unimportant

incoming tokenslong-term memoryevicted

Bounded, but a quiet definition can be evicted before it is needed.

04

RAZOR: pay to write

incoming tokenslong-term memoryfiller: ×1.0 + 0.0

Writes only when a token is worth its price; otherwise exactly nothing changes.

Four ways to keep a record of the past. Rust marks tokens that carry information (a definition, a signature, a constant); grey marks filler.

A switch that is exactly off

The switch must be binary, because a gate left 99.9% open is still a leak. Across TT filler tokens, a stored value decays as 0.999T0.999^{T}, which after a few thousand tokens is close to nothing. So RAZOR's gate is forced to exactly 0 or exactly 1, using a straight-through estimator during training.

Each register follows the recurrence

Rt=At Rt−1+BtAt=1−zt (1−Mt),Bt=zt vt\begin{gathered} R_t = A_t \, R_{t-1} + B_t \\ A_t = 1 - z_t\,(1 - M_t), \qquad B_t = z_t \, v_t \end{gathered}

When the gate reads zt=0z_t = 0, this becomes At=1A_t = 1 and Bt=0B_t = 0. The old state is multiplied by 1.0 and exactly 0.0 is added. Not approximately: bit-for-bit. Filler tokens cannot erode what is stored.

tokengate zstate RMAX1=0421# log0the0loop0…0def1f(x)1pass0…0MAX0z = 0: Rₜ = 1.0 · Rₜ₋₁ + 0.0 (unchanged, bit-for-bit)z = 1: Rₜ = Mₜ · Rₜ₋₁ + vₜ (a paid write)
The gate is forced to exactly 0 or 1. The state only moves on paid writes; every closed step multiplies by exactly 1.0 and adds exactly 0.0.

How RAZOR is trained

Either way, training with the MDL penalty always means the task loss plus the penalty. The penalty shapes behaviour; it is not the teacher.

Native RAZOR

Trained from scratch on the ordinary task loss (predict the next token, or the answer) plus the MDL state penalty:

L=Ltask+λ(t) Lstate.\mathcal{L} = \mathcal{L}_{\text{task}} + \lambda(t)\,\mathcal{L}_{\text{state}} .

The strength λ(t)\lambda(t) stays at zero for the first part of training, then ramps up, so the model learns syntax before it is pressured to economise on writes.

RAZOR-Qwen

A bolt-on version for a pretrained model. We freeze the entire Qwen2.5-Coder-1.5B backbone (1.54 billion parameters) and train only small gates, about 1.4 million parameters across 28 layers, under 0.09% of the model. The objective combines three terms:

  • ordinary prediction error;
  • a self-distillation term: the gated model imitates its own ungated self, so no human labels are needed;
  • the MDL write penalty.

A feedback controller (dual ascent) adjusts the penalty strength at every step so the fraction of retained cache lands on a chosen budget, here 15%:

λ←max⁡ ⁣(0,  λ+η (keep rate−0.15)).\lambda \leftarrow \max\!\big(0,\; \lambda + \eta\,(\text{keep rate} - 0.15)\big).

At inference, the cache keeps three kinds of positions and physically slices out the rest:

Sinks · 4Gate decides: kept only if z = 1, otherwise sliced out of memoryRecent 32older ← KV cache positions → newerpromoted by gatealways keptevicted (memory freed)
RAZOR-Qwen's cache. Positions are kept if they are among the first 4, the most recent 32, or promoted by the learned gate. Everything else is physically removed from the cache tensors, not just masked.

What the lab's tests show

Tracking one bit through noise

Native models were trained on 64-token sequences with about 85% noise tokens, then tested on much longer ones. The task is to track a single bit of state (parity) through the noise. Chance is 50%.

Noisy parity tracking, accuracy by test length (N = 200 each)

ModelT = 642565121,0242,048
RAZOR100.0%100.0%100.0%98.5%98.0%
Soft gate, no MDL100.0%100.0%99.5%99.0%94.0%
Gated DeltaNet49.0%50.0%52.0%52.5%52.5%
Sliding window56.0%49.5%51.5%48.0%50.0%
Full attention58.0%45.5%47.0%50.5%45.5%
Trained at T = 64; every longer length is out of distribution. The tick marks chance (50%).

RAZOR holds 98.0% through 2,048 tokens of noise. The same recurrence with a continuous gate and no penalty is close behind until it starts to drift at the longest length, which is the leak the binary gate is meant to close.

Remembering variables through distractors

Four variable bindings at the start of a sequence, up to 2,000 distractor tokens, then a query for one of them.

Associative variable recall, accuracy by test length (N = 200 each)

ModelT = 642565121,0242,048
RAZOR100.0%100.0%100.0%100.0%100.0%
Full attention100.0%99.5%99.0%100.0%100.0%
Soft gate, no MDL98.0%98.5%98.5%99.0%98.0%
Gated DeltaNet9.0%11.5%15.0%12.0%9.0%
Sliding window8.5%10.0%15.0%11.5%7.5%
Full attention matches RAZOR here, but its memory grows with every token; RAZOR's register bank is a fixed size.

A frozen Qwen model with 85% less cache

On the lab's passkey test, a secret number is placed in filler and asked for at the end. With 15% of the cache retained, RAZOR-Qwen gets every sample right at every length we tested.

Qwen2.5-Coder-1.5B passkey retrieval at a 15% cache budget (N = 50 each)

Cache policyT = 1282565121,024
RAZOR (15%)100.0%100.0%100.0%100.0%
Full cache (100%)100.0%100.0%100.0%100.0%
H2O (15%)18.0%16.0%100.0%100.0%
StreamingLLM (15%)12.0%28.0%18.0%42.0%
Random eviction (15%)16.0%18.0%16.0%24.0%
H2O also scores perfectly at 512 and 1,024 tokens; it fails at shorter lengths, where it evicts the passkey before the question arrives.

The same pattern holds on two other lab tasks at 256 tokens: tracking Python variables defined long before they are used, and keeping intermediate facts in multi-step maths problems.

Lab tasks at T = 256 with a 15% cache budget (N = 50 each)

Cache policyCode variablesMath facts
RAZOR (15%)100.0%100.0%
Full cache (100%)100.0%100.0%
StreamingLLM (15%)44.0%32.0%
H2O (15%)38.0%30.0%
Random eviction (15%)36.0%26.0%

Because evicted positions are sliced out of the cache tensors rather than masked, the savings are real memory:

Measured KV cache per sequence at T = 1,024 (all 28 layers, fp16)

Full cache
28 MB
RAZOR6.7× smaller
4.18 MB
StreamingLLMwindow only
0.98 MB

What it costs, and where it fails

Compression is not free. In a separate run on public benchmarks (gates calibrated to retain 12.56% of the cache), the frozen Qwen model keeps most of its coding ability but not all of it:

HumanEval pass@1, Qwen2.5-Coder-1.5B (N = 30)

Full cache (100%)
86.7%
RAZOR (12.56%)
70.0%
StreamingLLM (15%)
13.3%
H2O (15%)
13.3%
WikiText-2 perplexity (lower is better)T = 512T = 1,024
Full cache (100%)15.0212.43
H2O (15%)20.9717.12
RAZOR (12.56%)20.9719.60
StreamingLLM (15%)27.5826.68

On language modelling, RAZOR ties H2O at 512 tokens and trails it at 1,024. And on RULER's multi-key passkey task (1,024 to 4,096 tokens), RAZOR, H2O and StreamingLLM all score 0 of 25, while the full cache scores 25 of 25. A perfect score on our own passkey test does not carry over to a harder one.

Update: RULER, with a gate trained end to end

The RULER result above was the hardest one in this post, so it is where we went next. Instead of calibrating gates by hand, we trained RAZOR's write price directly into a cache-eviction gate for Qwen3-1.7B, and scored it with NVIDIA's open-source kvpress harness, against the methods that harness ships.

The gate is the same small MLP that KVzap uses, so the comparison is about how it is trained, not its size. KVzap trains it to imitate a hand-designed importance score. RAZOR trains it on the objective itself: the compressed model must predict the same next token as the full model, and every token it keeps has a price.

L=KL(pfull ∥ pevicted)+λ⋅keep rate\mathcal{L} = \mathrm{KL}\left(p_{\text{full}} \,\Vert\, p_{\text{evicted}}\right) + \lambda \cdot \text{keep rate}

The keep decision is hard and binary in the forward pass, exactly as in the rest of this post, and λ\lambda adjusts itself during training to hold a target keep rate of 30%. The most recent 128 tokens are never evicted. One training run took about 40 minutes on a single GPU.

RULER at 4,096 tokens, Qwen3-1.7B (650 samples, 13 tasks)

Full cachenothing evicted
88.9%
RAZOR gate76% evicted
86.7%
KVzip+76% evicted
86.5%
KVzap-style gate76% evicted
79.6%
Average RULER score. KVzap-style: the same MLP trained by us on KVzap's recipe and data, with its threshold set to match RAZOR's compression. KVzip+ is the slower scoring method KVzap learns to imitate.

At matched compression, the RAZOR gate keeps 97.6% of the full cache's score and beats the gate trained to imitate KVzip+ by 7 points. It matches KVzip+ itself, which scores the cache by running the model again over the context. The KVzap-style gate loses most on multi-key retrieval and variable tracking, exactly where a dropped token cannot be recovered.

The gap holds across compression levels. Sweeping each gate's threshold on a smaller 195-sample slice:

GateCache evictedRULER score
RAZOR70%86.8
RAZOR76%86.4
RAZOR82%83.8
KVzap-style60%85.8
KVzap-style71%82.5
KVzap-style80%73.8
KVzap-style86%60.8

The KVzap-style gate has to keep 40% of the cache to reach the score RAZOR holds while keeping 24%. Two RAZOR gates trained from different seeds land within half a point of each other at the same threshold (86.4 and 87.0).

What's next

Those runs are finished, and the full results are in our paper: RAZOR: learning what to forget in the KV cache.

Product

Introducing Relay

Fix it once, never twice. Relay is a gateway for coding agents that learns the fixes your model makes and applies them itself the next time the same failure shows up, with no model call.

5 min read