Skip to content

DeepSeek-V4.1-Flash: Pushing the Limits of KV Cache Compression

optionalcorefrontierpaperrubric 11/122026 · ~50 min

DeepSeek-AI

Read first: DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence

Status

TL;DR. V4.1-Flash is a 552B-parameter multimodal MoE, plus 196B parameters in Engram n-gram tables. It supports 1M tokens of context. Its global KV cache is 890 bytes per token, about 1/4 of V4-Flash and 437× smaller than DeepSeek-V1. Three changes get it there. A causal encoder-decoder (CED) lets the top 20 layers read KV projected from layer 20. Compressed Sparse Attention 2 (CSA2) shares KV and top-k indices across layers. The main KV is stored in FP4. The model activates 8B parameters per prompt token and 16B per generated token, and it beats V4-Flash on most agent benchmarks.

Why it matters now. Agent loops are prefill-heavy: every tool result is new input, and caches are saved and resumed between turns. V4.1 targets exactly that cost. It halves prefill compute, cuts the cache held on the GPU (HBM) and cuts the cache persisted to SSD to about 1/8 of V4-Flash. For retrieval-heavy agents, this changes how much evidence you can keep in context per dollar.

CSA2 compresses along three axes at once. Each KV entry is small (one shared 512-dim entry in FP4). The sequence is compressed (m=2m=2 in the encoder, m=1m=1 in the decoder). And layers share caches. Each CSA2 layer has one static mode:

  • Full: compute main KV and indexer keys, then score and pick the top-kk.
  • Reindex: reuse the latest main KV and indexer keys, but score them with this layer’s own indexer query.
  • Reuse: reuse both the KV and the latest top-kk indices; just attend.

In CED, decoder layers do not compute global KV from their own hidden state. The decoder’s Full layer projects it from the encoder output:

Cl=HL/2 WlKV,l>L/2.C_l = H_{L/2}\,W^{KV}_l,\qquad l > L/2 .

So prefill runs only the encoder for global KV, and the cost drops from O(NL)O(NL) to about O(NL/2)O(NL/2). A hierarchical indexer helps decode. The first decoder Full layer keeps the 2,048 best 8-position blocks (16,384 candidates), and later Reindex layers only score inside that pool.

DeepSeek-V4.1-Flash: causal encoder-decoder with CSA2 layer modes Two rows of layer blocks. The encoder row has 2 sliding-window layers, then 3 groups of one Full layer and five Reuse layers at compression 2. The decoder row has 5 groups of four layers at compression 1; the first group starts with a Full layer, the other four start with a Reindex layer, and the rest are Reuse layers. An arrow shows the encoder's last hidden state feeding the decoder's global KV. A side panel lists what each mode computes and the resulting 890 bytes per token. Causal encoder-decoder, 40 layers Encoder L1–20 SWA F5 × Reuse F5 × Reuse F5 × Reuse m = 2: one entry per 2 tokens hidden state of layer 20 → decoder global KV Decoder L21–40 F3 × Ru Ri3 × Ru Ri3 × Ru Ri3 × Ru Ri3 × Ru m = 1; Reindex picks from a 16,384-position pool Prefill: encoder + decoder KV projections (+128-token SWA replay): 8B active. Decode runs all 40 layers: 16B active. Every layer keeps its own SWA KV. CSA2 modes F · Full new KV + indexer keys + new top-k Ri · Reindex shared KV, own indexer query → new top-k Ru · Reuse shared KV and the last top-k; just attend Stored global KV (3 × 0.5 + 1) entries/token × (288 B KV + 68 B key) = 890 B per token
Original sketch. Encoder and decoder layers grouped by CSA2 mode. Only Full layers store global KV; Reindex layers pick new entries from the shared cache, and Reuse layers copy the last selection.
  • Efficiency (§1, §6). Global KV is 890 B per token, about 1/4 of V4-Flash. Persistent KV is about 1/8 of V4-Flash. FP4 main KV nearly halves storage relative to V4’s FP8 (§2.4.4).
  • Base model (Table 1, §4.3.2). The base model is reported as on par with V4-Pro-Base on knowledge, and close to or better on reasoning and code, while activating far fewer parameters.
  • Agents (Table 3, Max effort). Terminal-Bench 2.1: 90.6 (V4-Flash 82.7, Opus-5 89.1). DeepSWE v1.1: 74.2 (V4-Flash 54.4, Opus-5 74.0). HLE with tools: 63.9 (Opus-5 63.6). Terminal-Bench 4.0: 31.2, well behind Opus-5 at 51.8.
  • Reasoning. GPQA Diamond 90.9 and Codeforces 3471, above V4-Pro’s 3348. HLE without tools is 36.8, below the closed models.
  • Effort control (§5.3.3). Going from effort 25 to 100 lifts Terminal-Bench 2.1 from 82.4 to 90.6 at about 2.5× more output tokens.

V4.1 shows ideas moving into DeepSeek: YOCO’s cross-layer KV sharing, index reuse across layers (IndexCache), and gpt-oss’s SwiGLU clamp. In the other direction, the paper says head-wise Muon was also validated by GLM 5 and Kimi-K3, so per-head preconditioning is becoming standard. The paper also states that the data filter now drops low-information model-generated text, which it calls “implicit duplication”.

  • The authors note that CSA2 selection errors and the approximate SWA replay may fail in untested edge cases. They plan more stress tests on sparse retrieval over long contexts (§6).
  • No long-context retrieval curve (MRCR, RULER) against V4-Flash is shown, so the quality cost of 4× less KV is not measured directly.
  • The gap to closed models remains on the hardest agent tasks (Terminal-Bench 3.0 and 4.0, ProgramBench).
  • Engram and DSpark are only described briefly; their gains are not ablated in this report.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    The paper reports a global KV cache of 890 bytes per token. Reconstruct this number from the layer plan (3 encoder Full layers at m = 2, 1 decoder Full layer at m = 1, Reindex and Reuse layers store nothing new), a 512-channel FP4 main KV entry with one E4M3 scale per 16 channels, and a 128-dim MXFP4 indexer key with one 8-bit scale per 32 values. State your assumptions.

    What a strong answer covers
    • Main KV entry: 512 × 4 bits = 256 B, plus 512 / 16 = 32 one-byte scales, so 288 B.
    • Indexer key: 128 × 4 bits = 64 B, plus 128 / 32 = 4 scale bytes, so 68 B. Each stored entry costs 288 + 68 = 356 B.
    • Entries per token: the encoder has 3 Full layers at m = 2 (0.5 entries each, 1.5 total) and the decoder has 1 Full layer at m = 1 (1 entry). Total 2.5 entries per token.
    • 2.5 × 356 B = 890 B, which matches the paper. Sliding-window KV is excluded because it is bounded by the 128-token window and kept in FP8.
    • The savings come from three sources at once: fewer stored layers (sharing), longer compression in the encoder, and 4-bit storage. The decoder's m = 1 is affordable only because just one decoder layer stores KV.
  2. Mechanism

    Explain how the Causal Encoder-Decoder (CED) lets V4.1-Flash activate 8B parameters per token in prefill but 16B in decode. What is computed for prompt tokens in the decoder half, and why does sliding-window attention need a replay?

    What a strong answer covers
    • The decoder's global KV is projected from the hidden state of the last encoder layer (layer L/2), not from each decoder layer's own hidden state, an idea taken from YOCO.
    • So for prompt tokens, prefill only runs the 20 encoder layers plus the decoder KV projections. Generated tokens need all 40 layers, which is why decode activates twice as many parameters.
    • Each decoder layer still has its own SWA keys and values from its own hidden state. These need the decoder layers to run over the last tokens of the prompt.
    • Exact SWA reconstruction would replay n_win × L/2 tokens. SWA Bounded Replay replays only the last n_win = 128, an approximation the paper finds nearly lossless.
    • Prefill cost goes from O(NL) to about O(NL/2), which matters for agent loops where every tool result is new prefill.
  3. What if…

    CSA2 has three layer modes (Full, Reindex, Reuse). Design an ablation that isolates the cost of sharing KV across layers from the cost of sharing top-k indices, and say which long-context metrics you would report.

    What a strong answer covers
    • Arms: every layer Full (no sharing); Full + Reindex only (shared KV, fresh indices per layer); the paper's Full + Reindex + Reuse plan; and an extreme with one Full layer and all others Reuse.
    • Keep the parameter count, data and FP4 setting fixed. Vary only the mode assignment so storage and indexer compute change in a known way.
    • Report KV bytes per token and indexer FLOPs, plus long-context retrieval (MRCR, RULER) and multi-hop QA at 128K and 1M, not only short benchmarks.
    • Also measure overlap of selected entries between adjacent layers. High overlap would explain why Reuse is cheap. Low overlap on multi-hop tasks would point to where selection errors arise, a risk the authors name in §6.
  4. Critique

    The authors say they found no systematic degradation in their tests but warn that CSA2 selection errors and approximate SWA replay may fail in untested cases. Which agent workloads are most at risk, and what evidence is missing from the paper?

    What a strong answer covers
    • Workloads that resume from a cached prefix after many turns rely on SWA Bounded Replay. Errors in the replayed local state could hurt exact copying or code edits near the boundary.
    • Tasks that need many scattered facts, such as multi-hop deep research, stress the 512-entry top-k and the 16,384-position candidate pool shared across decoder layers.
    • The paper reports agent benchmarks (Table 3) but no MRCR or RULER curve against V4-Flash at 1M, so the long-context cost of compression is not shown directly.
    • Missing evidence: replay error against an exact recomputation, recall of the hierarchical indexer against a full-scan indexer, and results by context length.
  5. Research idea

    Engram stores 196B parameters as hashed n-gram tables that are prefetched from host memory. Propose an experiment to test whether Engram tables act as a memorized knowledge store that could replace part of retrieval for factual QA.

    What a strong answer covers
    • Compare matched models with and without Engram (or with the tables zeroed at inference) on closed-book factual QA such as SimpleQA, and on retrieval-augmented QA with the same retriever.
    • If Engram stores facts, closed-book accuracy should drop sharply when tables are removed, while retrieval-augmented accuracy should drop less.
    • Probe which n-gram keys fire on entity names, and test new facts that were not in the 45T training tokens.
    • Measure cost: host-memory bandwidth and latency of RDMA prefetch against the cost of retrieving and reading passages.
  6. Connect

    V4.1-Flash and Qwen3.8-Flash-Next both add a large n-gram lookup table kept off the accelerator. Compare where it sits, how it is optimized, and what each report says about whether it helps.

    What a strong answer covers
    • V4.1: Engram modules at layers 1 and 14, n-gram orders 2–4, 8 hash heads, FP8 tables, 196B parameters, learning rate scaled 5×, optimized with a Sinkhorn-balanced momentum update.
    • Qwen3.8: one n-gram embedding at layer 2, 51B parameters, prefetched while layer 1 runs, trained with Adam and no weight decay.
    • Qwen3.8 reports that lower loss from larger tables does not translate into better benchmark scores. V4.1 does not report a matching ablation.
    • Both treat sparse memory as cheap capacity that adds no accelerator FLOPs, a different scaling axis from adding experts.

Done with this page?

Status