Serving DeepSeek-V4: why million-token context is an inference systems problem
DeepSeek-V4's 1M-token context comes from compressing the token axis of the KV cache: Compressed Sparse Attention (stride 4, top-k selection), Heavily Compressed Attention (stride 128, dense over ~8K entries) and a 128-token Sliding Window Attention path. The model leaves the serving engine to juggle multiple cache layouts with different sizes and lifetimes. In Together's bring-up on NVIDIA HGX B200, SWA state handling dominated capacity, and keeping only SWA states likely to be reused raised per-node KV capacity from ~1.2M to ~3.7M tokens. Prefix caching becomes a per-cache-type storage policy (full SWA store, checkpoints, or recompute-on-hit). Gains appear first in long-context decode-heavy workloads, while short-context prefill depends on kernel maturity, so teams should benchmark in their own regime and use workload-specific endpoint profiles.
Related posts
- DeepSeek-V4: a million-token context that agents can actually use
Hugging Face hardMasterDeepSeek-V4 (Pro: 1.6T total/49B active; Flash: 284B/13B active) is a MoE model family whose 1M-token context is made practical by a hybrid attention design that interleaves Compressed Sparse Attention (4x KV compression plus an FP4 lightning indexer selecting top-k blocks) with Heavily Compressed Attention (128x compression with dense attention), plus FP8 KV storage. At 1M tokens V4-Pro needs 27% of V3.2's per-token FLOPs and 10% of its KV cache, about 2% of a bf16 GQA-8 cache. Agent-focused post-training preserves reasoning across user turns when tools are involved, adds an XML-based |DSML| tool-call schema to reduce escaping and type errors, and relies on DSec, a Rust sandbox platform for RL rollouts. Agent benchmarks land near frontier closed models (SWE Verified 80.6, MCPAtlas 73.6), and MRCR 8-needle retrieval holds 0.59 at 1M tokens.
- Mastering Long Contexts in LLMs with KVPress
Hugging Face mediumAdeptKV cache memory grows linearly with context length: Llama 3-70B at 1M tokens in bfloat16 needs about 330GB of KV cache, roughly 70% of total memory. NVIDIA's KVPress is a Python toolkit of "presses" that prune low-importance KV pairs during prefill via forward hooks on attention layers. Examples include KnormPress, SnapKVPress and ExpectedAttentionPress, each tuned with a compression_ratio and usable through a custom transformers pipeline. On Llama 3.1 8B at 128k context, 50% compression cuts peak memory from 45GB to 37GB and raises decoding from 11 to 17 tokens/s on an A100, while RULER benchmarks show accuracy dropping as compression rises.
- Unlocking Longer Generation with Key-Value Cache Quantization
Hugging Face mediumAdeptHugging Face Transformers adds KV cache quantization, inspired by the KIVI paper, that stores keys and values per-token in int2/int4/int8 via quanto or HQQ backends. A residual cache of the most recent tokens (128 by default) stays in full precision to avoid re-quantizing on every step and to preserve accuracy. On Llama-2-7B, int4 matches fp16 on PG-19 perplexity and LongBench, while int2 degrades noticeably. Int4 gives roughly 2.5x memory savings and, with FlashAttention on an 80GB A100, raises max context from 40k to 128k tokens, at the cost of slower generation at larger batch sizes and about 3x slowdown when combined with weight quantization.
- Cache-aware prefill–decode disaggregation (CPD) for up to 40% faster long-context LLM serving
Together AI hardMasterCache-aware prefill–decode disaggregation (CPD) extends standard PD serving with a dedicated pre-prefill tier for low-reuse (cold) long prompts, a router that estimates prefix-cache reuse per request, and a three-level KV cache hierarchy (GPU memory, host DRAM, RDMA-connected distributed cache). Cold prefills compute new context and write KV state to the distributed cache, so warm requests on normal prefill nodes fetch KV blocks instead of queueing behind multi-second prefills. On B200 GPUs with a synthetic coding-agent workload, CPD raised sustainable throughput from about 0.75–0.8 to 1.1–1.15 QPS per GPU (~40%) and kept median TTFT far lower near saturation, without worsening p90 tail latency. The gains come from scheduling and cache reuse on the prefill path, not faster model execution.
- How Specializing the Vocabulary of SLMs Can Cut Inference Cost by 77% in Real Applications
Hugging Face hardMasterVocabX rebuilds a fine-tuned small model's tokenizer by choosing tokens for the cost they save rather than how often they appear. Saved tokens are weighted by field, because a generated token cost 7.4x an input token in their setup. The method works at two layers under one criterion: sub-word merges plus multi-word "macro tokens" found by five span miners. It estimates gains for candidates that never appear in the sample rather than scoring them zero. On a Qwen3-4B Portuguese essay grader, responses shrank from 350 to 101 tokens and measured inference cost fell 77%, while bench score rose from 0.703 to 0.810. Fusing grades into JSON macro tokens hurt quality, so the decision tokens the model exists to make were kept separate.