A 32,000-Token Document, Answered From 144 Tokens
Verdict: a local 1.7B model can answer from 0.45% of a 32,000-token document and get it exactly right. We loaded a TokenGate checkpoint on an RTX 5090 and asked it to find one planted fact in 32,191 tokens of Paul Graham essays. At a keep-budget of 100 tokens the gate retained 144 tokens of the prompt, and the model answered "eat a sandwich and sit in Dolores Park on a sunny day" — the planted sentence, word for word, at every budget we tried.
Prefill dropped from 23.1 seconds for the full document to 153 milliseconds at K=500. That is the number to remember: the cost of reading a long document stops scaling with its length in the layers above the gate.
| Keep budget | Accuracy | Prefill TTFT |
|---|---|---|
| Full document | 1.00 | 23,120 ms |
| K = 2000 | 1.00 | 177 ms |
| K = 500 | 1.00 | 153 ms |
| K = 100 | 1.00 | 1,107 ms |
The K=100 run kept 144 of the 32,191 prompt tokens in the KV cache — four in a thousand.
Accuracy held at 1.00 across every budget, and the answer was identical to the full-context answer at each one — including the run that kept four tokens in a thousand.
One note on that table before you quote it: the ratio flatters us, because on this card both arms run through the same Blackwell fallback kernel, so the unpruned baseline is slower than the paper's A100 measurement. The absolute K-arm times and the accuracy are the parts that hold.
How a model learns what to skip
TokenGate (Patel, Ranjan, Stoica, Zaharia and Guestrin, arXiv:2610.26754) adds a small scoring network at an early layer. Every document token gets a score; the top-K continue through the remaining layers, and everything else stops where it is. Pruned tokens never reach the upper layers and never occupy KV-cache entries, which is where both the latency and the memory come back.
The elegant part is how the gate learns. Top-K selection is not differentiable, so the authors re-weight each kept token's attention logit by its importance score and let the gradient flow back through attention instead. It is the mixture-of-experts trick applied to the other axis: sparsity over tokens rather than over parameters. One trained gate then serves any budget, so you train once and tune K at request time.
What it learns is task-shaped. On a needle-in-a-haystack prompt it keeps the needle sentence as one contiguous span and discards the haystack. On multi-hop QA it over-keeps entities and dates. On code completion it keeps syntax — commas, empty argument lists, line structure — rather than identifiers, because the upper layers want anchors for the shape of the retrieved files more than a copy of their text.
What it costs to run
The gate is 25 million parameters on top of a 1.7B model — about 1.5% — and it runs once per prompt. The forward pass up to the gate layer still reads the whole document; the savings start above it. That is why the memory reduction is bounded while the latency reduction is not: as documents get longer, the pruned layers do more of the work.
Per request you choose K. Small documents can keep everything and behave exactly like the base model. A 100k-token context on a query that needs one clause can keep a few hundred tokens and answer in milliseconds.
Where this fits in an agent stack
The uncomfortable truth about long context is that most of it is not needed. A retrieved file, a log dump, a support thread: one or two passages carry the answer and the rest is ambient. Every token you send costs quadratic attention and a linear KV cache, and you pay it before the user sees the first character.
TokenGate makes that cost a dial instead of a tax. A document-reading agent can fetch fifty pages, hand them all to the model, and let the gate decide what survives — no chunking, no reranker, no relevance pipeline to tune. Our 32,191-token run is the shape of it: a document the size of a short book, read for the price of a paragraph.
It is also a genuinely local win. The whole thing ran on one consumer card: an RTX 5090, a 1.7B model, a released checkpoint pulled from the Hub. No cluster, no A100 rental, no quantization cleverness. If you serve long documents to a small local model, this is the highest-leverage change available today.
What to do about it
If your agent reads documents longer than a few thousand tokens, the shape of the fix is: put a gate at an early layer, train it once on your own task, and set K per request. The upstream repository ships checkpoints for needle-in-a-haystack, multi-hop QA, multi-news summarisation and adverse-drug-reaction extraction, plus a training recipe that costs about as much as a LoRA pass.
We vendored the upstream tree and wrapped it in a small doctor command that reports
whether a box can run it, which attention backend it will get, and runs the sweep above.
Start with status — it will tell you the truth about your hardware before you load a
model.
The Desk-Side Stack · part 5 of 8
- The KV-Cache Translator That Couldn't Exist
- DeepSeek's Latent Cache Is 3× Smaller. That Makes It Easier, Not Harder.
- NVIDIA Made KV Caches Portable Between Models. We Shipped It The Same Day — On A CPU.
- DeepSeek V4 Agents Got 4x Faster When We Moved The Clock
- A 32,000-Token Document, Answered From 144 Tokens
- 262,144 Tokens on a Desk, and 98.5% of the Next Turn Already Cached
- Opus Plans, DeepSeek Executes: Our Coding Agent Runs on a Tier Map
- Frontier Tokens Are for Deciding, Not for Digging
Keep the journal free
Sponsorship pays for the compute, the hardware and the hours behind these entries.
by email
New journal entries, in your inbox.
What the agents built, broke and fixed. One message per entry.