Skip to content

kv cache

Inference interview questions tagged kv cache, across every topic.

49 questions · 18 unlocked for you

Concepts behind "kv cache"

Concept pages for the mechanisms these questions lean on.

Foundational
🧮 KV Cache & Memory
The KV Cache: Bytes per Token and the Memory BudgetThe KV cache stores every past token's keys and values so decode never recomputes them. Its size per token is fixed by the attention design, and the memory left after weights and the engine's reserve decides how many sequences fit, which is the number that sets batch size, concurrency and when preemption starts.
Foundational
⌨️ Implementation Patterns
Attention With a KV Cache, From ScratchA from-scratch implementation of causal multi-head attention with grouped-query KV heads and a KV cache, in about 35 lines of numpy. Covers the offset causal mask when queries are fewer than keys, why the cache turns quadratic recompute into linear work, and the tests an interviewer runs against it.
Advanced
🧮 KV Cache & Memory🔒 Premium
Paged KV Memory and Block TablesPaged KV memory splits the cache into fixed-size blocks and gives each sequence a block table that maps logical positions to physical blocks, as virtual memory does with pages. It bounds waste to one partial block per sequence, which decides how many sequences fit and makes prefix sharing and copy-on-write possible.
Advanced
🧮 KV Cache & Memory🔒 Premium
Prefix Caching and Chained Block HashesAutomatic prefix caching keeps the KV blocks of finished requests and reuses them when a new prompt starts with the same tokens. Each full block is keyed by a hash chained from its parent block, which makes a hit mean the whole prefix matched; that decides TTFT for shared system prompts and how much cache multi-turn traffic needs.
Advanced
⏱️ Batching & Scheduling🔒 Premium
Preemption: Swap Versus RecomputeWhen the KV pool runs out mid-decode, the scheduler must evict a running sequence: either swap its cache to host memory over PCIe and copy it back later, or free it and recompute it with a fresh prefill. The cost of each depends on model size, KV bytes per token and whether prefix caching still holds the freed blocks.
Advanced
🏛️ Inference System Design🔒 Premium
Prefix-Aware and KV-Aware RoutingWhy a prefix cache is only as good as the router in front of it: round-robin spreads each shared prefix across every replica and shrinks the hit rate, prefix-affinity hashing concentrates it, and KV-aware routing scores replicas on cached blocks against load so one hot tenant cannot melt a node.