Skip to content

KV-Cache Management

Overview

KV-Cache Management is a suite of methods aimed at optimizing the use of key-value (KV) cache in transformer models during inference. KV-cache stores computed keys and values for previously generated tokens, allowing for the avoidance of redundant calculations but requiring significant memory capacity.

Key Strategies

Strategy Description Effect
PagedAttention Partitioning the cache into pages, similar to virtual memory Reduces memory fragmentation
KV-Cache Quantization Storing the cache in low precision (INT8, FP8) Reduces memory usage
KV-Cache Eviction Removing the least important entries upon overflow Maintains operation with long contexts
Prefix Caching Reusing the cache for common request prefixes Accelerates repeated queries
Sliding Window Limiting the cache size with a sliding window Controls memory consumption

Practical Considerations

  • Memory: KV-cache can occupy up to 30-50% of the total GPU memory with long contexts.
  • Latency: Effective cache management reduces the time to the first token and overall delay.
  • Tools: vLLM, TensorRT-LLM, Hugging Face Transformers.

See Also

← All Terms