Home / Companies / Together AI / Blog / Post Details
Content Deep Dive

KV cache explained: how it works and what it costs

Blog post from Together AI

Post Details
Company
Date Published
Author
Together AI
Word Count
1,683
Company Posts That Month
10
Language
English
Hacker News Points
-
Post removed?
No
Summary

A KV cache preserves the attention key and value tensors generated for previously processed tokens in every transformer layer, allowing each new decoding step to compute state only for the latest token while increasing GPU memory use linearly with context length and batch size. This trade shifts generation from repeatedly recomputing an entire prompt to a memory-bandwidth-bound process, making cache capacity a major constraint on concurrent long-context requests. Cache requirements can be estimated from a model’s layers, key/value heads, head dimension, numerical precision, sequence length, and batch size; for some models, a full-context cache can consume more memory than the model weights themselves. Architectural approaches such as multi-query attention, grouped-query attention, multi-head latent attention, sliding-window attention, and sparse attention reduce cache size by sharing, compressing, or limiting stored token state. Serving techniques including PagedAttention reduce allocation waste through block-based storage, while prefix caching reuses exact matching prompt prefixes to avoid repeated prefill work and improve time to first token. Additional options include lossy KV quantization, exact offloading to slower storage, and lossy eviction strategies, each involving trade-offs among memory capacity, speed, and output quality; effective deployment therefore requires sizing caches for expected workloads and benchmarking performance at realistic context lengths and concurrency levels.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
LLM 4 6,550 1,238 234 +8%
Serverless 1 1,384 325 108 +12%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.