A document-QA product re-sends the same 60k-token contract across many sessions spread over hours, so GPU prefix-cache hits are rare. Would you offload KV cache to CPU memory or SSD and reload it instead of recomputing? Show the arithmetic.
Answer
Model answer, written in a candidate's voice
In short
- Cache size: 2 x 32 layers x 8 KV heads x 128 x 2 B = 128 KiB/token; x 60k tokens ≈ 7.3 GiB (7.9 GB) in bf16 for an 8B-class GQA model
- Recompute cost: 2 x params x tokens ≈ 9.6e14 FLOPs plus a causal attention term of similar size at 60k (≈ 9.4e14) → ≈ 10–19 s at 100–200 effective TFLOP/s
- Reload cost: 7.9 GB ÷ tier bandwidth — host memory over PCIe (~25 GB/s) ≈ 0.3 s; network store (~10 GB/s) ≈ 0.8 s; local NVMe (~5 GB/s) ≈ 1.6 s
- Verdict: reload wins when transfer is faster than prefill and the tier has capacity — likelier for long prompts, large models and fast links; pipelining transfer with compute narrows the gap further
- System pieces: KV layer such as LMCache or a Mooncake-style distributed store, cache-aware routing, eviction policy and TTLs
- Risks: stale caches after model, tokenizer or template changes (include them in the cache key), tenant isolation, storage cost, measure hit rate and TTFT before/after
In full
Yes, for this workload offloading and reloading is likely to win, but the arithmetic should decide it. For an 8B-class GQA model (32 layers, 8 KV heads of dimension 128) the KV cache is about 128 KiB per token in bf16, and a 60k-token contract needs about 7.3 GiB.
At this length the attention term roughly doubles the simple 2 x params x tokens estimate, which strengthens the case. Reload wins whenever the transfer is faster than prefill and the tier has capacity, which is likelier for long prompts, large models and fast links, and pipelining the transfer layer by layer with compute narrows the gap further, so even NVMe is competitive here. I would put a KV layer such as LMCache or a Mooncake-style distributed store in front of the GPUs, with cache-aware routing so requests land where the cache lives, plus an eviction policy and TTLs so stale entries do not linger. The risks are stale caches after a model, tokenizer or chat-template change (the cache key must include them), tenant isolation of cached content, storage cost (7.9 GB per contract adds up quickly), and the need to measure hit rate and TTFT before and after rollout rather than assume the win.
What a strong answer covers
- Computes cache size from the model config, e.g. 128 KiB per token × 60k tokens ≈ 7.5 GiB in bf16 for an 8B-class GQA model
- Compares reload time (size ÷ effective bandwidth of the tier: tens of GB/s for host memory over PCIe, a few GB/s for local NVMe, network for remote stores) with recompute time (≈ 2 × params × tokens ÷ effective FLOP/s)
- Concludes that reloading wins when the transfer is faster than prefill and the tier has capacity, which is likelier for long prompts, large models and fast links; pipelining transfer with compute narrows the gap further
- Names system pieces: a KV layer such as LMCache or a Mooncake-style distributed store, cache-aware routing so requests land where the cache is, eviction policy and TTLs
- Covers risks: stale caches after model or prompt changes, tenant isolation of cached content, storage cost, and measuring hit rate and TTFT before and after
Common mistakes
- Assuming any cache hit is faster without comparing transfer and recompute time
- Forgetting that a different model version or chat template invalidates the cache
Follow-ups
- How does the answer change for a hybrid linear-attention model?