Lesson deck
Memory and the KV-cache flashcards
Reviewing needs JavaScript. You can read every card in the list below.
Loading your cards...
Back to the lesson13 cards in this deck
Read all 13 cards as a list
- Front
- KV-cache bytes per token?
- Back
- 2 × layers × KV heads × head dimension × bytes per value. Use KV heads, not query heads. Llama 3 8B in 16-bit: 128 KiB; 70B: 320 KiB.
- Front
- How do you turn memory into concurrency?
- Back
- KV budget = GPU memory × utilization − weights − overhead. Divide by (bytes per token × tokens per sequence). Store the cache in FP8 and the count roughly doubles.
- Front
- What does "fits is not serves" mean?
- Back
- Weights can fit in GPU memory while nothing is left for the cache and overhead, so the server cannot hold even one sequence. Fix with smaller weights, more GPUs or shorter contexts.
- Front
- How does the KV-cache limit decode speed?
- Back
- Each step reads the weights once for the batch and every sequence's own cache. At large batch and long context the caches can outweigh the weights, lowering the throughput ceiling.
- Front
- What problem does PagedAttention solve?
- Back
- Fragmentation and over-reservation. The pool is split into fixed blocks (16 tokens by default in vLLM) with a block table per sequence, so waste is at most part of one block.
- Front
- What does PagedAttention not change?
- Back
- The bytes a token's keys and values need, and the attention arithmetic. Its gains come from larger batches and from enabling block sharing and preemption.
- Front
- How does prefix caching find a match?
- Back
- Each full block is hashed from its parent hash, its tokens and extras such as a LoRA ID or cache salt. A new prompt's blocks are looked up; used blocks are reference-counted; least recently used are evicted.
- Front
- What makes a prefix cacheable?
- Back
- It must be identical and at the start of the prompt (static first, dynamic last), computed by the same model and adapter, and the request must reach the engine that holds it.
- Front
- Prefix cache versus response cache?
- Back
- Prefix caching reuses intermediate keys and values for a shared prompt start and still runs the model. A response cache returns a stored whole answer for a repeated request.
- Front
- GQA versus MQA versus MHA?
- Back
- MHA: a KV head per query head. MQA: one KV head, smallest cache, can lose quality. GQA: groups share a KV head, in between; 8 KV heads against 32 query heads is a 4 times smaller cache.
- Front
- What is MLA and what did DeepSeek-V2 report?
- Back
- Multi-head latent attention caches a compressed latent vector and expands it at use. DeepSeek-V2 reports a 93.3 percent smaller KV cache than DeepSeek 67B, a model-to-model comparison.
- Front
- What do you do before shipping a quantized KV-cache?
- Back
- Evaluate on your own set, including long contexts. Docs give no accuracy figures and recommend calibrated scales.
- Front
- What happens when the KV pool is full?
- Back
- Queue (TTFT rises), preempt (recompute or swap), or shed load. A preemption storm shows as high utilization with falling goodput. Watch the preemption count.