By Cameron Voss (pen name) · Updated November 28, 2026
- DeepSeek V4 supports 1,048,576-token context by replacing full attention with two compressed attention types. CSA compresses every 4 tokens into one KV entry and runs a top-k search; HCA compresses every 128 tokens into one entry and attends to all of them.
- Both keep a 128-token window for recent tokens, and the mixed KV states are stored in two separate caches.
- At 1M tokens,
deepseek-v4-prouses about 27% of V3.2's per-token FLOPs and 10% of its KV cache;deepseek-v4-flashuses about 10% and 7%. - Those figures come from a fixed implementation, precision setup and batch size. Serving the model also needs FP4/FP8 kernels and a paged cache sized for both the window and the compression ratios.
Why did DeepSeek rebuild attention for 1M tokens?
Because at a million tokens, the KV cache and the memory bandwidth to read it cost more than the matrix math. In standard full attention, every new token looks back at every earlier token. During training that is one big matrix multiply. During generation it means storing a K/V pair for each past token and reading that growing cache on every step. GQA and MQA cut the number of KV heads but still keep one entry per token. V4 instead shortens the sequence the attention has to read.
What do CSA and HCA actually do?
CSA keeps detail through cheap retrieval; HCA keeps a cheap global view. Compressed Sparse Attention folds every 4 tokens into one KV entry using a learned, gated pooling step. A small Lightning Indexer scores the compressed entries and passes only the top ones to the main attention. V4-Pro selects 1,024 entries per query and V4-Flash selects 512. Heavily Compressed Attention takes a coarser route: it folds every 128 tokens into one entry and runs dense attention over the short result, with no top-k step. Layers alternate between the two, and every layer also keeps the last 128 tokens uncompressed so recent text stays exact.
Why isn't the KV cache one uniform buffer anymore?
Because the three kinds of KV state have different lifetimes and sizes, and treating them alike wastes memory. V4 splits storage into a classical KV cache and a state cache. The classical cache holds the stable, compressed CSA and HCA entries from completed blocks. These align cleanly and can be written to disk and reused across requests that share a prefix. The state cache holds the uncompressed sliding-window KV and the hidden states of tail tokens that have not yet filled a compression block. Those are short-lived and bounded in size.
For on-disk reuse, compressed entries are simple: write them out, read them back up to the last complete block on a prefix hit, and recompute the tail. The sliding-window KV is close to eight times larger per token, so V4 offers three policies. Full SWA Caching writes all of it and avoids recompute. Periodic Checkpointing saves a window snapshot every p tokens. Zero SWA Caching saves nothing and rebuilds the window on a hit. The right pick depends on how often your prefixes repeat and how much SSD write traffic you can accept.
What do the efficiency numbers actually say?
They describe one test setup. Against V3.2 at 1M context, the technical report puts V4-Pro at roughly 27% of the per-token FLOPs and 10% of the KV cache, and V4-Flash at roughly 10% and 7%. Against a BF16, GQA-8, head-dimension-128 baseline, reported KV cache at 1M context is about 2%. These numbers come from a fixed implementation, precision setup and batch size. The indexer still scores every compressed entry, so your own FLOPs and latency will depend on whether your runtime has fused kernels for sparse attention, the FP4 and FP8 paths, and the compressed KV layout.
What breaks if you deploy it like V3?
Four assumptions from older models no longer hold, and each one can hurt latency or break a request. Check these before you serve the model:
- Keep compressed KV compressed. If your loader expands it back into dense K/V, you lose the cache saving.
- Match the quantization to the checkpoint. Expert weights are FP4, most other matrices are FP8 or BF16, and the last 64 RoPE dimensions stay BF16. Your kernel needs the same scale format.
- Handle shared KV correctly under tensor parallelism. There is one KV head; query heads are 128 on Pro and 64 on Flash.
- Size paged-cache blocks for both the 128-token window and the compression ratios. A block size that fits plain V3 will not align with compressed entries.
A single MTP layer gives speculative decoding an extra prediction head. It does not guarantee two tokens per step.
Common questions
- Does DeepSeek V4 use one attention type or several?
- Several. Layers alternate between CSA, HCA, and plain sliding-window attention, and the pattern differs between V4-Pro and V4-Flash. Reading the layer table in the config is more reliable than assuming a fixed order.
- Is the 1M context limit only a config change?
- No.
max_position_embeddingsis 1,048,576 in both models, but a working system also needs YaRN-style RoPE scaling, the compression schedule, the sliding window, and a KV cache that can hold mixed entry types. - Can a KV cache be reused across requests?
- Yes. Compressed entries from complete blocks are stable and can be written to disk and reused when a new request shares the prefix. The sliding-window part is usually recomputed or checkpointed.
Want to try it without building the stack?
We host deepseek-v4-pro and deepseek-v4-flash with the serving setup already handled. If that saves you a few weeks of infrastructure work, have a look at our subscription plans.