Reusing KV Cache Across Requests in DeepInfer: A Single-Node, Eight-GPU Experiment
How sharing KV pages lets independent requests reuse cached prefixes, with a throughput benchmark on one eight-GPU node.
Suppose you ask an AI assistant to summarize a long meeting transcript, then ask it to extract the action items. Both prompts start with the same transcript. Only the instructions at the end change.
These are two independent requests. Once the first answer is complete, can the second request reuse the intermediate states computed for the transcript and avoid processing the same input again?
When DeepInfer was open-sourced, DeepSeek published prefill and decode performance curves along with production data. DeepSeek also explained that the inference system's KV cache management and load balancing are tightly coupled to its internal infrastructure and that the full code for those components had yet to be released. DeepInfer deployment Q&A
Drawing on our experience running inference clusters, we extended local prefix caching and request admission in an experimental branch so independent requests could reuse an existing prefix automatically. We then ran DeepSeek-V4.1-Flash-1017 on a single node with eight GPUs. We measured throughput and latency and compared our results with two references: DeepSeek's published figures and our team's earlier SGLang tests on the same hardware configuration.
#How a shared input prefix saves computation
The server arranges the system prompt, transcript, and task instructions according to the model's chat format, adding role and message-boundary markers. A tokenizer then encodes the result as a sequence of token IDs. Tokens are the units the model processes. A token can represent a different amount of text depending on the input, and its ID is the number assigned to it. DeepSeek chat format
Tokenization prepares the input for the model. During prefill, the model processes that input and produces intermediate states, including key–value (KV) data. During decode, the model uses those states to generate the response. The KV cache stores the KV data so it can be read by later computation.
To let the action-items request reuse work from the summary request, the engine needs to keep the relevant states after the summary finishes. When the new request arrives, the engine looks for a matching input prefix, restores the cached states on a hit, and processes the uncached tail and any newly added input. It matches the consecutive token IDs from the start of the input. Even with the same model and a compatible configuration, changes to the system prompt, content order, or chat format can affect how much of the prefix matches.

Figure 1. Tokenization prepares the input, and prefix caching reuses states the model has already computed. Even on a hit, prefill must process the tail and new input before decode generates the answer.
#From explicit page sharing to automatic prefix matching
DeepInfer already had paged KV management and a native scheduler. A KV page is a fixed-size block of GPU memory allocated by the engine. Each request has its own page table listing the KV page IDs it uses. For an ordinary new request, the engine allocates the necessary KV pages and computation state, then releases the corresponding resources when the request ends.
With fork_seq(), the caller can name a source request whose prefix has already been computed and create a new request from it. The requests can share full KV pages. The tail page, which can still change, and the computation state are handled separately. DeepSeek's benchmark script precomputes a prefix for one source request and forks it to create a batch of requests with a shared prefix. DeepInfer benchmark examples
The summary and action-items requests are separate HTTP requests. The second request does not tell the engine to fork the first. The engine has to find the common prefix itself and retain reusable states after the summary request ends. We call the set of cached data that lets a new request resume computation from a prefix position a prefix checkpoint.
In Figure 2, request A asks for a summary and request B asks for action items. The diagram shows an L1 cache hit with the full-page-sharing implementation we ultimately adopted. The next two sections explain how the implementations differ.

Figure 2. P1–P3 are the full KV pages for the common prefix. On the full-page-sharing path, the left and right sides show the same pages in use at different times. The labels a and b represent each request's task input and the tail it still needs to compute.
#First implementation: Copying snapshots
In the first implementation, once the engine finished computing the input, it saved the reusable prefix in a standalone snapshot. The snapshot stayed in the cache after the summary request completed. When the action-items request arrived, the engine used an exact token-sequence match within the same cache scope to find the longest saved checkpoint. On a hit, it copied the KV pages, restored the window KV, and computed the rest of the input.
This avoided recomputing the matched portion of the transcript, but each hit still copied the prefix KV. If several people asked questions about the same transcript concurrently, GPU memory could hold multiple copies of the same data.
To resume computation, the new request also needs to restore its window KV. Paged KV holds past results, while window KV holds the KV for a recent span of tokens and is updated as the request progresses. Window KV is part of the KV cache and lives in each request's computation state. That state also includes intermediate values accumulated while producing compressed KV, which we call intermediate compression state.
In this configuration, we snapshotted window KV for some layers and copied those snapshots into the new request on restore. Other, later layers rebuilt their window KV by computing the tail. This tail computation limits the prefix length we can reuse. At the aligned boundary, the engine resets the intermediate compression state, which then builds up again as the request continues.
Suppose the action-items request contains 4,096 tokens after encoding the system prompt, transcript, task instructions, and chat-format markers. How much can it reuse with this model and configuration?
Maximum reusable prefix length = floor((4096 − 140) / 128) × 128 = 3840
Remaining input on a checkpoint hit = 4096 − 3840 = 256 tokens
The formula reserves 140 tokens and uses floor to round down to a 128-token page boundary. If a matching checkpoint already exists for the first 3,840 tokens, the engine reuses that prefix and computes the remaining 256. Without a matching checkpoint, it computes the input as usual. Reusing one more page would leave only 128 tokens in the tail, short of the 140 required by this configuration.
This tail computation uses the code's YoCo prefill truncation mode (
compact), which limits how much input some later model layers process during prefill. We setDEEPINFER_YOCO_PREFILL_TRUNCATION_MODE=compactandDEEPINFER_YOCO_PREFILL_KEEP_TOKENS=140. The retained input must cover the sliding window and the maximum rollback length. The 140-token value is a configuration setting. It does not mean that every layer recomputes exactly 140 tokens.
The snapshot-copying implementation saved one prefix checkpoint after computing the input, at the position determined by this rule.
#Improved implementation: Sharing full KV pages
With full-page sharing, the cache retains the original request's completed full KV pages when saving the prefix. The only separate snapshot is for window KV. A later request that hits the transcript's common prefix can use those retained pages directly.
When multiple requests hit the same cache entry within one worker process, the engine writes the same full KV page IDs into each request's page table. The page tables are independent, while the prefix KV they reference is shared. Each request can still carry out a different task and generate its own answer. It writes subsequent KV to its own allocated pages and maintains its own window KV and intermediate compression state, so requests cannot overwrite each other's state.

Figure 3. Requests share full KV pages, copy window KV snapshots separately, and maintain their own pages for subsequent writes and their own computation state.
The engine uses reference counts to track who holds a shared page. It decrements the count on cache eviction or when a request completes or is canceled. If a restore fails, it rolls back the increments made for that restore. The page can be reallocated only after its reference count reaches zero and the associated GPU operations have finished.
The transcript illustrates the mechanism. The measurements below come from fixed-length load tests. The historical tests for both implementations used 77K input tokens, one output token, and a target cache rate of 96%. We ran four concurrency levels for 180 seconds each. When constructing test samples, we set the target cache rate as the share of input tokens intended for reuse. We calculate total throughput across the eight GPUs by summing the input tokens, including reused tokens, and output tokens from completed requests, then dividing by the measurement duration.

Table 1. Total throughput on one eight-GPU node, in units of 10,000 tokens per second.
With full-page sharing, throughput rose at some concurrency levels and fell at others. The largest improvement was at concurrency 512, where mean time to first token also fell from 5.337 to 4.910 seconds. The experiment report from that period also recorded a decrease of about 31.6 GiB in peak GPU memory usage per GPU. Both tests used the same workload configuration, but we do not have verifiable snapshots of the engine versions or launch arguments. The figures describe what changed between the two iterations. They cannot isolate the effect of page sharing.
We later optimized resource reclamation and reference-count maintenance and adjusted expert placement. The best observed total throughput at concurrency 196 was 7,668,000 input and output tokens per second.
#Extending checkpoints to host memory and SSD
If someone comes back to the transcript later, its reusable prefix may no longer be on the GPU. To allow reuse after eviction from GPU memory, we added checkpoint backups in local host memory and on a local SSD. We call the three tiers L1 (GPU memory), L2 (local host memory), and L3 (local SSD).
Before restoring a checkpoint, the engine compares matching prefix lengths across tiers and checks the resource budget. L1 data is already on the GPU, so requests can share full KV pages directly. L2 data must be loaded back onto the GPU. For L3, the engine first reads from SSD into host memory, then loads the data onto the GPU.

Figure 4. Writing and restoring checkpoints across the three tiers. Dark blue shows the write sequence, bright blue shows the normal restore path, and dashed arrows show the fallback.
If several requests about the transcript are waiting on the same checkpoint, they can share one read and one GPU reload. The restored full KV pages become a shared L1 checkpoint. The other requests use those pages when resources allow and restore their window KV individually. If a resource check fails, the engine falls back to a shorter L1 prefix or computes the input normally.
Requests waiting on a read stay outside the native scheduling queue, so ready requests can continue to run. Preparing host buffers, restoring window KV, and confirming completion still incur overhead.
We later added checkpoints within long inputs and at conversation branches. In the L2 and L3 restore validation runs, generated tokens matched the corresponding reference runs. All DeepInfer throughput figures in this article come from the earlier L1 experiments and exclude these later extensions.
#How the eight-GPU results compare with DeepSeek's published figures

Figure 5. Each workload is compared independently against DeepSeek's historical curves or production figures. Table 2 gives the deployment and measurement details.

Table 2. Experimental setup and measurement methods compared with the published references. Offline benchmark setup · Production deployment Q&A
Uncached input throughput was close to the published reference. High-cache input throughput and the generation rate at the selected point still differed. The comparisons use different deployments, workloads, and measurement methods, so the gaps cannot be attributed directly to engine efficiency.
#Whole-node throughput on the same hardware configuration
DeepSeek's published results came from different hardware or deployment conditions, so we also used our earlier SGLang load-test results as a reference. Both sets of tests ran the same model on the same single-node, eight-GPU hardware configuration, which lets us compare whole-node throughput on three fixed-length workloads. The SGLang version we tested had yet to incorporate the relevant DeepInfer optimizations.

Figure 6. Whole-node throughput for DeepSeek-V4.1-Flash-1017 on the same hardware configuration. Each measurement point ran for about 180 seconds.
