Real World Deployment

DeepInfer's Inference Stack

Advanced

DeepSeek open-sourced DeepInfer, the inference framework behind its DeepSeek V4.1 Flash service, together with a detailed deployment Q&A. It's a rare look at how a frontier model is served at scale: how the cluster is split, how load is balanced, how KV cache is kept for days, and the techniques that cut wasted compute.

DeepSeek's production stack at a glance

Everything on this page comes from DeepSeek's DeepInfer repository and its V4.1 Flash deployment Q&A. pairs DeepSeek's kernel libraries (FlashMLA, DeepGEMM, DeepEP and TileLang kernels) with an inference engine that started from vLLM, and it powers the DeepSeek V4.1 Flash service.

Tokens served per day

155T

by a single cluster

Revenue per GPU-hour

US$38

at the off-peak price

SSD for KV cache

~100 PiB

3FS, 10+2 erasure coding

KV cache retention

3-7 days

agent vs chatbot traffic

Three design goals

Accelerators from more than one vendor

The same framework runs on NVIDIA SM100 (Blackwell) GPUs and Huawei Ascend 950 NPUs, with kernels written in TileLang so each platform gets its own tuned versions.

Commodity hardware for each stage

Ordinary 8-GPU machines run prefill and ordinary 64-128 GPU supernodes run decode, with computation, communication and scheduling designed around how differently the two stages load a GPU.

KV cache kept for more than 72 hours

A long reuse window saves far more repeated prefill through cache hits. The price is the capacity and management that long retention needs.

One request through the system

DeepInfer runs three ways: a vision encoder service for images, a service and a service, each with its own load balancer, so time to first token and time between tokens can be tuned separately. Attention runs data-parallel and the MoE layers run expert-parallel, with as many attention replicas as expert ranks. A dedicated storage cluster holds the KV cache.

1/8

1.Tokenize

The request arrives as API JSON (Chat Completions, Responses or Messages). DeepSeek Recipe encodes it into a token list plus sampling parameters.

User request (JSON)User response (JSON)tokens + sampling paramsoutput tokenspullimagesembeddingspushKV P→DGDRwrite-backDeepSeek RecipeAPI JSON <-> tokensEntrypointhash-chain prefix matchvs kvcache-storeVision Encoder LBfewest image patchesPrefill LBengines pull · 4 tiersDecode LBpushes · global viewVision Encoder1 GPU per instanceimages -> embeddingsPrefill serviceEP2-8 / DP2-8Expert-parallel LBDecode serviceEP64-128 / DP64-128 (Wide-EP)Expert-parallel LBExternal KV cache storage (3FS)shared by every prefill engine
RequestKV cacheLoad balancerEPLBExpert-parallel load balancer

Small groups for prefill, wide EP for decode

The two stages get opposite parallelism. Prefill uses the smallest group that fits in memory (2 to 8 GPUs), because a long prompt already gives every expert a big batch, and small groups balance better and send less NVLink traffic. Decode uses the widest group available, 64 to 128 GPUs ("wide EP"): each GPU holds fewer experts, so each step reads far fewer weight bytes. Neither stage uses tensor parallelism, which costs too much communication, or context parallelism, which ran up to 5% slower end to end. Prefill and decode GPUs run at roughly 1:1, so the smallest efficient unit is 64 prefill plus 64 decode GPUs.

Benchmark

DeepSeek V4.1 Flash · context 131,072 · MTP nextn=3 at 75% per-token acceptance → 3.25 tokens accepted per step

Requests per DP rank (decode batch)Drag, or click a dot64 requests / rank
05k10k15k20k25k30k050100150200250300350tokens/s per user (interactivity) →↑ output tokens/s per GPU81632641282568163264128256
EP64/DP64 · 384 routed + 64 redundant expertsEP8/DP8 · 384 routed + 32 redundant expertslabels: requests per DP rank

EP64 per GPU

15,700

output tokens/s

EP8 per GPU

12,650

output tokens/s

EP64 per user

246

tokens/s vs 198 on EP8

EP64 gain

+24%

per user · +24% per GPU

Wider expert parallelism serves each user faster

At the same batch per rank, EP64 serves each user faster: spreading the experts over 64 GPUs leaves fewer experts on each GPU, so every decode step reads less expert weight memory. The per-user edge is about 1.35x at small batches and narrows as the batch grows; in tokens/s per GPU the gap is widest at mid batch sizes (64-128 requests per rank), and the two curves nearly meet at 256.

Benchmark points read from the DeepInfer repository's plots; values are approximate.

Keeping hot experts from stalling the batch

In a model some experts are far more popular than others, and every step waits for the busiest GPU. DeepInfer's expert-parallel load balancer () gives each GPU a few spare expert slots that host copies of hot experts, measures expert load over a sliding window, and reshuffles the placement over NVLink on a fixed schedule. The result is measured as the slowest GPU's load divided by the average.

Illustrative simulation · 8 GPUs, 32 routed experts, skewed load

Redundant expert slots per GPUEach slot can host a replica of a hot expert2 per GPU (6 slots)

Static placement, no rebalance yet. Press Rebalance to fill the redundant slots.

0x0.5x1x1.5x2xE8E16GPU 0E9slowestGPU 1E18GPU 2E3E11E27GPU 3E12E20GPU 4E5E13E29GPU 5E6E14E22GPU 6E7E15E23E31GPU 7mean
expert (four hottest darker)replica in a redundant slot (load split across copies)bar height: this step's load relative to the mean GPU

moe_lb = slowest GPU / mean

1.629

1.0 = perfectticks: measured2.6

moe_lb

1.63

every GPU waits for the slowest

Idle per step

39%

average GPU time spent waiting

Replicas placed

0

not rebalanced

Why it repeats every M steps

Rebalancing replicates the hottest experts into the redundant slots and splits their traffic, pulling the slowest GPU toward the mean. But which experts are hot drifts with the traffic, so a placement fitted to the last N steps goes stale and the imbalance creeps back. DeepInfer collects expert load over a window and reassigns experts on a fixed cadence, shuffling the weights over NVLink.

Measured in DeepInfer (DeepSeek V4.1 Flash)

SetupSpare / GPUWindow / everymoe_lb
Prefill EP4/DP44100 / 1,0001.074
Prefill EP2/DP24100 / 1,0001.045
Decode EP64/DP6411,000 / 10,0001.090

Window and reassignment cadence in steps. Redundant counts are rounded up so the total expert count divides evenly by the EP size. At EP64 that works out to 7 experts per GPU, excluding the shared expert.

Simulation values are illustrative (Zipf-like expert load with per-step jitter); the table shows DeepInfer's settings and measured results.

Load balancing: prefill pulls, decode pushes

Balancing whole replicas matters as much as balancing experts. Prefill engines pull work when they are about to run out, from queues split by context length, and size each chunk to a time budget. The decode balancer pushes each new request to the GPU that keeps request counts and KV lengths closest to the average, because a request stays on its decode GPU until it finishes. Together they reach roughly 80% of a perfectly balanced offline benchmark.

Load balancer

1 · Tiers by context length

Traffic mix (illustrative)

TierShare of requestsShare of compute
<16K
25%
2%
16-64K
40%
15%
64-256K
28%
46%
≥256K
7%
37%

16 prefill engines (illustrative), redistributed by each tier's share of compute demand in the last round:

1
2
2
2
3
3
3
3
3
3
3
4
4
4
4
4
Tier 1 (<16K): 1Tier 2 (16-64K): 3Tier 3 (64-256K): 7Tier 4 (≥256K): 5

A few long requests can need most of the compute, so their tiers get most of the engines. Each tier also caps the compute quota per batch. There is no prefix-affinity routing: KV lives in shared 3FS, so any engine can hit any prefix.

2 · When an engine pulls

GPU compute
step 1
step 2
step 3
Pull + prepare
2
3
4

An engine pulls its next batch when the time left in its current step is just enough to prepare it. Fetching and preparing overlap the computation, so the batch is ready the moment the step ends. The engine never idles, and time to first token stays low.

3 · Chunk size solved from a time budget

Each prefill step gets a time budget. A fitted quadratic model cost(q, c) predicts the step time for q new tokens on top of a prefix of c already-computed tokens; the scheduler takes the largest q that fits, capped at 32,768 tokens.

Step time budget150 ms
Prefix already computed (c)64K tokens

Solved chunk q

8,359

tokens this step

Predicted step

150 ms

of 150 ms budget

Prefix share

73%

of step time spent on c

per-token workattention to prefix (q x c)attention within chunk (q²)bar = full budget
08K16K24K32K32,768 cap0K64K128K192K256Kprefix already computed (c)

Solved chunk q (tokens) vs prefix length: longer prefix, smaller chunk, since every new token has more cached context to attend to.

Illustrative cost model: cost = 0.004·q + 2e-7·q·c + 1e-7·q² ms, with made-up constants instead of DeepInfer's fitted values. In production the budget is also lowered by an all-reduce MIN across the DP group.

Overall, DeepInfer's load balancing reaches roughly 80% of a perfectly balanced offline benchmark.

A KV cache that lives for days

Most serving stacks keep for seconds or minutes in a tier of GPU memory, host memory and local disk. DeepSeek puts the paged KV cache on a dedicated storage cluster of about 100 PiB of SSD and keeps it for 3 days for agent traffic and 7 days for chatbot traffic. A shared cluster lets any prefill machine hit any prefix, so never fights the load balancer; it scales separately from compute; and it survives compute-node failures, which happen more than ten times as often as storage failures.

WhatWhere it livesCopies and ownership
In-flight block KV + stateGPU memory (HBM)Owned by the running prefill or decode instance
Sliding-window (SWA) KVHost memory of the machine that made itOne copy; other machines pull it over a 400G VLAN
Paged block KVDedicated 3FS storage clusterNo app-level copies; 3FS erasure coding protects it

Getting a hit into the GPU is overlapped with other work. The entrypoint matches a hash chain of the prefix against metadata only; a separate process fetches the KV from 3FS into host shared memory; and a thread in the engine copies it into HBM layer by layer while the forward pass runs. That last copy uses GPUDirect : the NIC saturates PCIe without using GPU cores, where the CUDA copy engine handles small KV blocks poorly. KV produced during decode is written back to storage too, to raise later hit rates.

KV cache storage cluster sizer

Online GPUs set the logical KV footprint. Add 10+2 erasure coding and an SSD fill watermark and you get the number of storage servers. TB and PB are decimal (powers of 1,000); PiB is binary (1 PiB = 2^50 bytes = 1.1259 PB).

Online GPUs1,024
Logical KV per GPUDeepInfer production: ~14.4 TB14.4 TB
SSD fill watermarkAssumption: where LRU GC holds disks80%

Logical KV capacity

14.7 PB

1,024 GPUs × 14.4 TB

Physical, 10+2 EC

17.7 PB

Logical × 12/10; survives 2 node failures per group

Storage servers

36

614.6 TB raw each, filled to 80%

Aggregate read

1.4 TB/s

36 × at least 40 GB/s

Aggregate write

180 GB/s

36 × at least 5 GB/s

Cross-DC P/D link

51.2 Tbps

Only if P and D sit in different data centers (400 Gbps per 8 GPUs)

How far does ~100 PiB go?

100 PiB of SSD is 112.6 PB (1 PiB = 1.1259 PB). After 10+2 erasure coding that holds 93.8 PB of logical KV - about 6,516 online GPUs at 14.4 TB per GPU, or about 5,212 if disks are held at a 80% watermark.

Retention sets the size as much as GPU count

  • 14.4 TB per GPU reflects production TTLs: 3 days for agent traffic and 7 days for chatbot traffic.
  • Chatbot traffic has a heavier long tail of hits: a TTL of around 3 days costs it 0.5-1% of KV cache hit rate.
  • The 72-hour agent TTL spans a weekend, so requests on the next workday can still reuse the cache.
  • The recommended servers add up to enough total capacity to retain 24 hours of data.

How 3FS stores and reclaims it

  • Data is stored with 10+2 erasure coding; each EC group tolerates two simultaneous node failures.
  • A read issues requests to all 11 storage nodes in the group simultaneously; any 10 responses are enough to decode and return.
  • One GC worker per storage node evicts the least recently used KV cache, keeping disk usage below a watermark (the fill level set above).
  • Recommended server: 20 × 30.73 TB SSDs, at least 40 GB/s read and 5 GB/s write.

How tiering, retention and reload speed play out for other models is on the KV Cache planner and Context Memory.

Bounded replay: recompute 128 tokens instead of the whole context

DeepSeek V4.1 Flash mixes compressed block KV with layers. The block KV goes to 3FS; the sliding-window KV (about 1.4 MB per sequence) stays in the host memory of the machine that made it. When the block KV hits but the sliding-window KV is missing, DeepInfer doesn't recompute the prompt. With it replays only the last 128 tokens, each attending only within that stretch. The cost stays constant, whatever the context length. Applying the same idea to the decoder layers nearly halves total prefill compute.

SWA KV cache at the hit point

Context length L64K (65,536)
1/6Request returns
token 0L65,536L - 13465,402L165,280s = L1 - 12865,152

A returning request of length L arrives. Most of its prefix was seen before.

Block KV hit (3FS)Replayed 128 tokens (SWA KV only)Computed suffixLast 134 tokens: never a hitPrefix compressed; tail to scale in 128-token blocksStored SWA KV per sequence: 20 layers × 134 tokens × 528 B (MXFP8) = 1,415,040 B.

Replay attention pattern

squery ikeysillustrativequeries

Blue band: keys max(s, i-127)..i. Red hatch: keys before s that exact SWA would read. They're dropped, so the rebuilt SWA KV cache is approximate.

Tokens recomputed on an SWA miss at 64K

SWA miss treated as a cache miss - re-prefill the whole hit prefix65,280
Bounded replay - recompute the last 128 tokens128

Both bars share one linear scale up to 1M tokens. Bounded replay stays at 128 tokens whatever the context length or layer count; a full re-prefill grows with L (510× more tokens here). The 256-token suffix is computed either way. With the miss, the hit length is 65,152.

The same trick on the decoder side

Decoder block KV is projected from the last encoder layer's hidden state, so only the decoder SWA KV cache has to be computed. Rebuilding it exactly would mean running the last 2,560 tokens through 20 decoder layers; instead each prefill replays only the last 128 tokens of the prompt in the decoder layers, for decode use only (it never enters the prefix cache). That nearly halves total prefill compute.

Exact
2,560
Replay
128

Tokens run through the decoder layers per prefill. The README's default V4.1 setting keeps 140 tokens because the retained suffix must cover the SWA window plus the maximum backtracking length.

Speculative decoding that verifies only likely tokens

With , a small draft model proposes several tokens and the main model checks them in one pass. DeepSeek's drafts 5 tokens, but a confidence head predicts how likely each one is to be accepted, and the scheduler spends verification compute only where it has the best expected return. It checks about 30% fewer tokens for nearly the same accepted length.

Spend a shared verify budget where it pays

Illustrative confidences

The draft model proposes 5 tokens per request. Each box shows the Confidence Head's score (top) and the chance that token is actually accepted (bottom: the running product, since a token only counts if every token before it was accepted too). The expected accepted length of a k-token prefix is the sum of those bottom numbers up to k.

Req A
98%.98
95%.93
92%.86
90%.77
85%.66
E[accepted] 4.19 → 4.19 (5/5)
Req B
95%.95
90%.85
85%.73
70%.51
50%.25
E[accepted] 3.29 → 3.29 (5/5)
Req C
80%.80
60%.48
40%.19
30%.06
20%.01
E[accepted] 1.54 → 1.28 (2/5)
Req D
60%.60
35%.21
25%.05
20%.01
15%.00
E[accepted] 0.87 → 0.60 (1/5)

E[accepted]: verifying all 5 → with the current budget. Dashed outline = next token in line.

Verify budget across the batchFixed-length verification always spends 20 (4 x 5)13 tokens

Next in line: Req D token 2, worth +0.21 expected tokens.

Fixed-5 verifies

20

9.90 accepted (expected)

Scheduled verifies

13

35% fewer tokens

Scheduled accepts

9.37

95% of fixed-5's expected

Accepted / verified

0.72

vs 0.50 with fixed-5

The tail of a shaky draft is almost never accepted, so verifying it burns compute for little return. DSpark sorts draft tokens by expected acceptance and picks the prefix set that maximizes effective throughput on a profiled hardware throughput curve. One more verified token is worth it only if its expected gain beats what the extra verify work costs at the current batch size. With asynchronous scheduling the CPU fixes only the total verify budget; a TileLang kernel on the GPU recomputes the per-request lengths once the step's confidences are available.

Throughput gain of dynamic-length vs fixed-5 verification

Open-PerfectBlend dataset, EP64/DP64, estimated throughput per rank. Pick a concurrency.

concurrent sequences per rank (prod = production operating point, ~60)

Verified / step

5 → 3.58

28% fewer draft tokens

Accepted length

3.30 → 3.21

fixed-5 → dynamic

Tok/s per rank

14,466

vs 13,730 fixed-5

Gain

+5.4%

at 60 seqs per rank

Dynamic-length verification checks about 30% fewer draft tokens per step (5 → 3.2-4.4) for almost the same accepted length (3.29 vs 3.20 on average). The saving matters more as batches grow: in a big batch verify compute is the scarce resource, so dropping low-odds tokens frees it for useful work. The gain climbs from +1.6% at 32 sequences per rank to +11.0% at 96, and is +4-7% around the ~60-sequence production operating point (+5.4% at 60). At 16 sequences per rank there is verify capacity to spare, so the slightly shorter accepted length wins out and the result is a small loss (−1.5%).

No idle GPU between decode steps

Every decode step needs CPU work: choosing the next batch and processing the last step's tokens. Done in line, the GPU sits idle while the CPU catches up. DeepInfer's , following SGLang and NanoFlow, prepares step N+1 on the CPU while the GPU is still running step N.

One decode loop, two ways to drive it

Illustrative durations

GPU work per step: forward 8 ms + sample 2 ms. CPU work per step (schedule + post-process) is set by the slider and split evenly between the two.

CPU overhead per stepschedule + post-process4 ms

Synchronous: sync on sample(N) before post-process(N)

CPU
scheduler
GPU
kernels
fwd 1
fwd 2
fwd 3
fwd 4
idle
idle
idle
idle

Asynchronous: CPU prepares step N+1 while the GPU runs step N

CPU
scheduler
GPU
kernels
fwd 1
fwd 2
fwd 3
fwd 4
fwd 5
fwd 6
time, 10 ms ticks →
schedule (CPU)post-process (CPU)forward (GPU)sample (GPU)GPU idle
1/13t = 0 ms

GPU busy, sync

71%

idle 4 ms every step

GPU busy, async

100%

CPU work fully hidden

Steps in 60 ms, sync

4

71 steps/s

Steps in 60 ms, async

5

100 steps/s (1.40x)

In the synchronous loop the CPU needs sample(N)'s result before it can post-process step N, so the GPU waits through post-process(N) and schedule(N+1) on every step. The more CPU work, the bigger the gap. The asynchronous loop runs one step ahead: while the GPU executes forward(N) and sample(N), the CPU runs schedule(N+1), launches forward(N+1), post-processes step N-1 and launches sample(N+1), so the next kernels are already queued when the GPU finishes and it never idles. Steps counted = sample(N) finished inside the 60 ms window; steps/s is the steady state.

Running it day to day

Autoscaling on the right signal

Prefill scales on the number of non-cached tokens, decode on the number of running requests. Changes are rate-limited and bounded, and scale-in is blocked whenever quota utilization is above 0.8.

A one-minute grace period

A decode engine told to shut down gets one minute; any requests still running are forwarded, KV cache and all, to other decode engines. That way long-tail requests can't hold a 64-GPU instance hostage.

Failover by resizing EP

In a wide-EP instance all GPUs form one communication domain, so one failed GPU takes the instance down. On restart it re-forms with whatever GPUs are healthy and uses that count as its EP size.

Redundancy over fast restarts

Restarts take minutes, so resilience comes from spare prefill and decode quota plus request-level rerouting instead of faster single-engine restarts.

FP4 where it pays

The main KV cache is FP4 with one e4m3 scale per 16 values (NVFP4 without the global scale); the indexer keys and the routed-expert weights use MXFP4.

Safe, fast tokenization

DeepSeek Recipe converts the Chat Completions, Responses and Messages APIs into tokens in Rust. Control strings typed by a user are encoded as plain text, so they can't inject special tokens, and text between special tokens is encoded in parallel.

Same batch, same answer

Batch-invariant inference keeps results identical whatever else is in the batch, and deterministic sampling gives identical output for identical input and seed.

Structured output off the hot path

JSON-schema, regex and EBNF constraints are compiled to a grammar automaton on dedicated machines ahead of time; each decode step only advances it and masks illegal tokens.

What DeepSeek open-sourced

The DeepInfer release runs offline inference of DeepSeek V4.1 Flash on NVIDIA SM100 GPUs and Huawei Ascend 950 NPUs, including the kernels, expert-parallel load balancing, DSpark, bounded replay and the asynchronous scheduler. The KV cache system, the prefill/decode orchestration and the replica load balancers are tied to DeepSeek's internal infrastructure and are not included; the Q&A describes how they work. DeepSeek plans to release inference code for future models in the same repository.

Content on this page credits DeepSeek and the DeepInfer project. Figures are for DeepSeek V4.1 Flash on DeepSeek's deployment; benchmark curves are read from the repository's plots.