Dims & Sums

DEEPSEEK-V4.1-FLASH

Two Models in One

chapter 2 of 7 · about 7 minutes

A long prompt usually visits every layer before a model writes its first answer. At 100,000 tokens, a 40-layer stack makes four million layer visits before decode begins.

DeepSeek-V4.1-Flash keeps the first 20 layers as a causal encoder. They read every prompt token and leave behind the final encoder state at each position.

CED defines layer-dependent global-KV projections from that final encoder state. In the shipped CSA2 map, zero-indexed decoder layer 20 is the Full source. Later decoder layers reuse its main KV; Reindex layers refresh only the Top-K selection.

What the window costs, and what bounded replay does about it

The decoder still needs one private thing: its sliding-window state. Each layer derives that state from its own hidden states, so CED's global cache cannot supply it.

Exact decoder recovery would run 20 decoder layers across a 2,560-token prompt tail. Bounded replay instead feeds only the last 128 prompt tokens through those decoder layers under SWA truncation.

The authors report negligible response-quality impact in evaluated settings and simulate the same replay during post-training. It remains an approximation, not an equivalence guarantee.

your prompt, N tokenscausal encoder, 20 layersevery prompt token passes through, 8B params per tokenfinal encoder stateglobal main KV, source: decoder layer 20later CSA2 layers reuse itdecoder SWA window128-token tail traverses decoder layersdecoder, 20 layersruns on the newest tokens only, 16B params per tokennext token
CED at a glance. Every prompt token passes through the encoder. The final encoder state supplies global main KV; in the shipped CSA2 map, decoder layer 20 is its Full source. The last 128 prompt tokens still traverse decoder layers to make the separate SWA window.

What this buys, in layer visits

Here is a derived layer-visit toy, not a reported FLOP measurement. At the config maximum of 1,048,576 positions, a dense 40-layer pass is 41.943M visits. CED plus bounded decoder replay is 20.974M: every token through 20 encoder layers, then 128 tokens through 20 decoder layers.

That toy is 50.006% of the dense count. At 4,096 tokens it is 51.563%, and at 1,024 it is 56.250%, because the bounded decoder tail stays fixed while the prompt shrinks.

Decode gets a second benefit from the full architecture, not CED alone. With all architectural improvements combined, the report says that stretching context from 4K to 1M raises single-token decode FLOPs by about a quarter.

Trace one prompt through the two halves

Build the encoder state, ask a decoder question, then replay the recent window.

toy prompt, 17 words stand in for a long agent prefix. The final four words stand in for the real 128-token sliding window.

Thebuildfailedafterthecachekeychangedduringdeploy.Rollbackrestoredtheoldprefix.

encoder, all words

waiting for the first pass

decoder global cache

waiting for encoder state

decoder window state

waiting for replay

decoder asks:
The encoder sees the whole prefix once. Its final state supplies global KV; in the shipped CSA2 map, decoder layer 20 is the Full source and later layers reuse main KV. Each decoder layer still rebuilds its own short SWA window before generation.
There are two caches. The global main KV is shared across later CSA2 decoder layers. The SWA KV stays FP8, is local to each layer, and is rebuilt by replay when needed.
receipts, every claim in this chapter, checked 2026-08-31