LLM inference and serving practice problems
28 problems · 0 solved
Serving an LLM means answering many users quickly and cheaply on limited GPU memory. Generation happens one token at a time, and the model stores past keys and values in a KV cache so it does not redo work. Running a serving system is a bit like running a busy restaurant kitchen: you batch orders, reuse prepared items and keep every burner in use. These problems cover the core ideas behind modern inference engines. You will generate tokens with a KV cache, work out how many tokens fit in GPU memory, allocate KV memory in pages, evict cache blocks with LRU, count prefix cache hits with a token trie, estimate whether decoding is memory-bound, simulate continuous batching and a chunked prefill scheduler, verify draft tokens in speculative decoding, compute TTFT, TPOT and throughput, size concurrency with Little's law, and price requests with cached input tokens. Start with the Easy problems on latency metrics, memory sizing and pricing. Then do KV cache decoding, paging and prefix caching, and finish with batching, chunked prefill and speculative sampling. Inference cost drives product decisions, and these topics appear often in LLM infrastructure interviews.
Easy 11
- Trim a chat history to fit the context window
- Work out how many tokens fit in GPU memory for the KV cache
- Compute TTFT, TPOT and throughput from request timestamps
- Price an API request with cached input tokens
- Size concurrency with Little's law
- Write new keys and values into a preallocated batched KV cache
- Pick the best draft length for speculative decoding
- Measure goodput against TTFT and TPOT SLOs
- Measure the wasted slots of static batching
- Rate limit API requests with a token bucket
- Size prefill and decode pools for disaggregated serving
Medium 11
- Generate one token at a time with a KV cache
- Allocate KV cache memory in pages, like vLLMPro
- Verify a draft model's guesses in speculative decodingPro
- Is decoding memory-bound? A roofline estimatePro
- Count prefix cache hits with a token trie and block granularityPro
- Evict KV cache blocks with an LRU policyPro
- Gather a paged KV cache through a block tablePro
- Run a paged KV block allocator with a free listPro
- Route requests to replicas by shared prompt prefixPro
- Serve many LoRA adapters in one batchPro
- Compare FCFS and shortest-job-first latency for LLM requestsPro
Hard 6
- Simulate continuous batchingPro
- Simulate a chunked prefill scheduler with a per-step token budgetPro
- Accept or reject draft tokens in speculative samplingPro
- Simulate KV memory preemption with recomputePro
- Track shared KV blocks with copy-on-write for beam searchPro
- Stream text safely when stop sequences can span chunksPro