EngineeringUpdated 2026-10-24

KV Cache

Caching keys and values of processed tokens during inference so history is not recomputed for every new token.

#推理#显存#性能

In plain language

Autoregressive generation attends to the full history at every step. KV caching stores keys and values of past tokens so a new token only computes its query and appends to the cache, cutting latency substantially. The cost is memory that grows with context length and concurrency, so long-context serving uses paged caches (PagedAttention), quantized caches or conversation trimming. Cache hit rate directly affects inference cost and time-to-first-token.

Example

Keeping the KV cache across turns avoids recomputing prior context, but memory grows with context length.

Recommended tools

Related terms