Dims & Sums

DEEPSEEK-V4.1-FLASH

The Input Bill

chapter 1 of 7 · about 5 minutes

DeepSeek-V4.1-Flash is a 552B-parameter Mixture-of-Experts (MoE) model with a one-million-token context. Images and text go in. Text comes out.

Its 40 layers split in half. The causal encoder reads the full prompt. The decoder mostly reads state the encoder prepared, rather than rebuilding a separate cache for every layer.

That split changes the serving bill. Prefill runs about 8B active parameters per prompt token. Decode runs about 16B per generated token. The extra decoder cost buys a state that can be reused across many turns.

The architecture: a split stack with two cache paths

inputimage + textvision grid + textembeddings togethercausal encoder · layer IDs 0–19all prompt tokens read once0–1: sliding window onlylayers 2, 8, 14: Full CSA2, m = 2Engram modules at 1 and 14H_encoder_finalfinal encoder state at every positiondecoder layer 20 · Full CSA2projects global main KV from H_encoder_finalmakes the decoder candidate pooldecoder layers 21–39 · m = 124, 28, 32, 36 Reindex; the other 15 Reuse main KVwhat is shared, what stays localglobal main KVfour Full CSA2 sources: 2, 8, 14, 2034 later CSA2 layers reuse compatible KVreported combined global footprint: 890 B / tokenSWA KV, separate pathevery layer makes its own FP8 recent-tail state128-token windowshort-lived host-memory pool, not persistent KVEngram side table2-, 3-, and 4-gram lookup moduleslayers 1 and 14; background host-memory prefetchDSpark decode sidecarfive-position draft, confidence-scheduled verification
DeepSeek-V4.1-Flash is not one repeated 40-layer block. The causal encoder handles the full prefix; its final state seeds the decoder's global main KV. A separate FP8 sliding-window path carries the newest 128 tokens in every layer.

Agent traffic makes that reuse valuable. A coding or browser agent repeatedly sends its instructions, repo state, and old tool output. Most of a later request is the prefix the service has already read.

V4.1-Flash is built around that case. Its reported global cache costs 890 bytes per token, roughly one quarter of DeepSeek-V4-Flash. Its persistent cache footprint is roughly one eighth, because SWA state is no longer kept in the persistent tier and the remaining global KV is smaller.

the model (config.json + report):
  backbone     552B parameters, 40 layers: 20 encoder + 20 decoder
  extra table  196B Engram parameters, read by lookup, not multiplied
  experts      384 routed + 1 shared per layer, 6 routed active per token
  active       8B per token on prefill, 16B per token on decode
  context      1M tokens · image and text in, text out · MIT license
  trained on   45T multimodal tokens, sparse attention from 64K

the cache at 1M tokens (report abstract + §3.2):
  global       890 bytes per token · 1/4 of V4-Flash · 437x under V1
  persistent   ~1/8 of V4-Flash: SWA KV moves out of persistent cache

the meter on the API (pricing page, checked 2026-09-13):
  off-peak     $0.15 in · $0.003 cached · $0.60 out per M tokens
  peak         double those rates, weekdays 01:00-04:00 and 06:00-10:00 UTC
A cache hit costs 1/50 of fresh input, $0.003 against $0.15 per million tokens. The ratio matters more than the headline price: it rewards a service that can keep a working prefix resident between turns.

The 40 layers, as shipped

Two layers use only sliding-window attention, so they read the newest 128 tokens and nothing older. The other 38 use Compressed Sparse Attention 2 (CSA2).

Full layers write the shared cache and its search index. Reindex layers keep that cache but pick a fresh set of entries to read. Reuse layers take both as they are.

The storage is compressed along two axes. Encoder layers write one entry per two tokens. Four Full CSA2 layers write global main KV; 34 later CSA2 layers reuse compatible KV. Layers 0 and 1 are SWA-only.

causal encoderdecodermoderatio281420039builds the cacheFullreuses the cachereuses it, picks againwindow only, no cachecache from every 2 tokens2 tokensevery tokenFull sources: 2, 8, 14, 20. The 34 later CSA2 layers reuse compatible KV.Layers 0–1 are SWA-only; layer IDs are zero based.
The shipped zero-based layer map. Full CSA2 layers 2, 8, 14 and 20 write main KV. The 34 later CSA2 layers reuse compatible KV; Reindex layers 24, 28, 32 and 36 refresh only their Top-K selection. Compression is two tokens per entry in the encoder and one in the decoder.

Send an agent turn through the cache

Choose a turn, then run it. Green phrases are returned from a prefix the service has already read.

the request the agent sends

system: fix the flaky cache testrepo: src/cache.ts and cache.test.tsearlier tool result: cacheKey changed after deploytest output: expected warm prefix, got a miss

prefix service sees

nothing stored yet

send

encoder has to read

the whole first request

toy chunks stand in for token ranges, not tokenizer counts
This is the request shape V4.1-Flash is built around: a long working prefix survives from one agent turn to the next, while each tool call adds a small fresh suffix. Its cache-hit price only helps when that prefix still matches.
receipts, every claim in this chapter, checked 2026-08-31