BLOG / KV CACHE
When should you move KV state instead of recomputing it?
Reusing a prefix replaces computation with data movement. The useful decision compares exposed transfer time with the prefill work it avoids.
A long prefix has already been processed, but its KV cache is no longer on the GPU that needs it. The state exists in host memory, on storage, or on another worker. Should the server retrieve it or run the prefix again?
The stored prefix is an option to avoid computation. Exercising that option consumes bandwidth, destination memory, and time. A useful cache policy needs permission to decline a hit when restoring it would cost more than rebuilding it.
Define the state you are moving
This discussion concerns restoring a previously computed, compatible prefix before continuing inference. It is different from repeatedly fetching active attention state from slower memory during every decode step.
Systems such as LMCache provide mechanisms for storing and sharing KV state outside the immediate GPU cache. The performance question begins after establishing that the stored state is valid for the request.
Compatibility includes the model revision, adapter state where relevant, prefix tokens, positional interpretation, and cache representation. A cache containing the right words under a different model is not reusable model state. A different layout may require conversion before the engine can consume it.
Also identify the destination. Loading a prefix requires enough GPU memory to hold it. If the restore displaces useful state for other requests, that eviction has a cost beyond this request's first-token latency.
Compare complete alternatives
A first approximation for a serial restore is:
Restore time ≈ lookup + preparation + bytes / effective bandwidth + conversion
Use effective bandwidth measured on the actual path, including contention. A device's advertised interface speed is not the bandwidth a request receives. Multiple transfers may share a link; staging may add copies; a network path may include more than one bottleneck.
Compare that restore time with the time needed to recompute the same prefix under comparable load. Include different queue waits if restoration and recomputation use different resources.
The uncached suffix still needs processing in both cases. In a simple comparison, its common cost cancels. It does not cancel if the two choices lead to different workers or different levels of contention.
A small break-even calculation
Assume a compatible prefix contains 2 GiB of KV state. For this hypothetical example, lookup and preparation take 10 ms, conversion is unnecessary, and recomputation takes 180 ms. The two alternatives have equal queue wait.
| Effective transfer bandwidth | Data movement | Total restore | Compared with 180 ms recompute |
|---|---|---|---|
| 40 GiB/s | 50 ms | 60 ms | Saves 120 ms |
| 10 GiB/s | 200 ms | 210 ms | Adds 30 ms |
| 5 GiB/s | 400 ms | 410 ms | Adds 230 ms |
The break-even bandwidth is 2 GiB / 0.170 s, approximately 11.8 GiB/s. Below that rate, the serial restore loses under these assumptions.
The threshold belongs to this prefix and these paths. A shorter prefix can have less state but also much cheaper prefill; size alone cannot tell you whether reuse wins. Recalculate both sides when the model, prefix, precision, or serving load changes.
A fast restore can become a slow shared path
Effective bandwidth is a property of the concurrent workload. In a simplified example, two restores splitting a 40 GiB/s path equally each receive 20 GiB/s. Moving 2 GiB then takes 100 ms rather than 50 ms. Add the same 10 ms preparation and restore still wins against 180 ms recomputation, but its advantage has fallen from 120 to 70 ms.
That calculation holds recomputation cost fixed to isolate link sharing. In a real server, simultaneous restores can also interfere with GPU traffic, while recomputation consumes shared compute. Compare both alternatives under the same offered load. An isolated copy benchmark cannot settle the system-level decision.
Overlap changes the comparison again. A 100 ms transfer with 70 ms hidden behind independent work exposes only 30 ms on that path. Count the delay to the next dependent operation, and verify that the overlap exists. An asynchronous API does not by itself hide any latency.
Separate retaining state from restoring it
Retaining a prefix is a bet on future reuse. Restoring it is a decision under current conditions. A prefix worth saving can still be too expensive to fetch during a burst.
Use two separate gates. At retention time, consider reuse frequency, saved prefill, write cost, and the opportunity cost of storage. At request time, consider current transfer contention, destination memory, compatibility, and exposed restore time. A high storage hit rate says nothing about whether either decision was profitable.
A proposed restore policy should also answer what happens when its bandwidth estimate is wrong. Can the request wait within its latency budget? Can it choose recomputation before paying for a copy? Starting both paths indiscriminately spends both resources and changes the load being estimated.
The practical fallback is to bypass restoration when it has no credible advantage, provided recomputation itself is feasible. A cache hit should make another execution path available; it should not force that path.
Validate three paths separately
Compare cold recomputation, GPU-resident reuse, and restored reuse under the same arrival and prefix-popularity pattern. The resident case shows what computation reuse can save. The restored case shows how much of that saving survives movement and contention.
Record first-token tails, useful completed work, bytes moved, and destination evictions. If restores improve the requesting job but worsen the service's useful completion rate, the policy is transferring cost to other requests. That is the signal to reconsider transfer admission or retention, rather than celebrate the hit rate.
What to remember
- A reusable prefix creates an option to transfer state, not an automatic speedup.
- Compare complete paths using effective bandwidth and actual prefill cost.
- Count only exposed latency when overlap is demonstrated.
- Retain for likely future value; restore only when the current path has a credible advantage.