Dims & Sums

DEEPSEEK-V4.1-FLASH

Replay, Don't Store

chapter 5 of 7 · about 6 minutes

Every layer keeps a sliding window over the newest 128 tokens. DeepSeek-V4 persisted that per-layer state so a cached conversation could resume without recomputation. V4.1-Flash no longer keeps it in the persistent KV cache.

The window now lives in a host-memory pool for minutes. Global KV remains in the persistent cache for at least 72 hours. One is short-lived session state; the other is reusable history.

That distinction produces the storage reduction. Removing SWA KV from persistent storage nearly halves that footprint. The remaining global KV is roughly one quarter of V4's, making the persistent footprint roughly one eighth under identical workloads.

Why exact replay is too expensive

The compressed global cache cannot reconstruct a layer's window state. Each layer produced that state from its own hidden states.

Generic exact recovery replays L × nwin tokens. The decoder-specific CED case would run 20 decoder layers across a 2,560-token prompt tail. Those are different units from the bounded replay's 128-token input tail.

Bounded replay feeds only the latest 128 prompt tokens through the relevant layers under SWA truncation. The authors report negligible response-quality impact in evaluated settings and simulate it in post-training.

generic exact SWA recoverywork grows as L × nwinCED decoder exact path: 20 layersacross a 2,560-token prompt tailprompt-tail length and layer work are different unitsbounded replaystarts from a 128-token prompt tailthen traverses the relevant layersapproximate; report finds negligible impact in evaluated settingswhat persistent KV holds for a cached prefixV4-Flashglobal KVSWA KVV4.1-Flash≈1/8 persistent footprintSWA KV: distributed host-memory pool, minutes TTLglobal KV: persistent cache with at least 72 hours' lifetimebounded replay handles a global-hit / SWA-miss path without restoring persistent SWA KV
Exact and bounded recovery are not the same unit of work. Exact recovery grows with layer depth and window length. Bounded replay starts from a 128-token tail, then still traverses the relevant layers. Separately, SWA KV leaves persistent storage while global KV shrinks to roughly one quarter of V4's footprint.

Two replay paths, and a runtime decision

Encoder replay handles a global-cache hit whose encoder window is gone. It replays the end of the cached prefix alongside the new suffix, while reusing global cache entries without overwriting them.

Decoder replay handles the decoder window needed for the first generated words. It is the path that lets prefill stop at the encoder for almost the whole prompt.

The same text can produce slightly different window state depending on where replay begins. That is an explicit approximation, and post-training sees it too.

Resume a real conversation

Choose how the reader returns, then run the server trace. The colored lines show what gets reused and what gets recomputed.

the stored conversation

system: repair the flaky cache test
tool: cacheKey started including deploymentId
assistant: that makes the old prefix miss
user: patch the key to use stable repository state
tool: tests pass after the change
assistant: prepare the final explanation

global cache

hit

retained for long-lived prefixes

window state

gone

host-memory pool, minutes not days

extra encoder work

tail only

toy trace, not token counting

global cache remains, the short window state has expired
This toy shows the encoder-SWA fallback after a global-cache hit and SWA miss. The full system replays a 128-token tail rather than the two lines shown here. Decoder SWA bounded replay is a separate path used at every prefill.
The point is not to make replay free. It trades a small, bounded recomputation for a much smaller persistent cache. That trade pays when prefixes outlive the short window state.
receipts, every claim in this chapter, checked 2026-08-31