The interview problem
A model fits on a GPU but long concurrent requests cause out-of-memory failures during decoding. Design admission control around growing attention key/value state.
Original practice, not a reported company interview. All worked numbers are illustrative. Interview date: not applicable. Written October 3, 2026.
1. Scope and assumptions
Use a simplified decoder with 32 layers, 8 KV heads, head dimension 128 and 2 bytes per cached value. Count key and value tensors. Assume no sharing or compression; real layouts, sharding and allocator overhead must be measured.
2. Architecture and decisions
Prompt and output cap → KV estimate → memory reservation → paged allocation → decode → release
Estimate bytes per token from the model’s KV heads, not necessarily its query heads. Reserve an explicit output allowance as well as prompt tokens. Account separately for weights, activations, temporary kernels and allocator overhead before declaring capacity available. Use per-tenant queues to prevent one long-context workload from consuming every slot.
A hard maximum reservation is safe but underutilizes memory when outputs are short. Incremental reservations improve utilization only if the system has a defined action when growth is denied: pause, preempt with recoverable state, or reject before partial output under the product contract. Never rely on an allocation failure as the normal scheduler signal.
3. Work through the example
Bytes/token = 2 × 32 × 8 × 128 × 2 = 131,072 bytes, or 128 KiB. An 8,192-token combined prompt/output cap requires 1 GiB of KV state. If 20 GiB remains after non-KV allocations and 4 GiB is reserved as headroom, the simplified maximum is 16 such requests before fragmentation and block rounding.
4. Failure cases and trade-offs
Using query-head count overestimates grouped-query cache requirements; ignoring layers underestimates them. Prefix sharing makes accounting reference-based rather than a simple sum. Memory-safe admission can still violate latency goals, so enforce compute and queue limits too. Report utilization against the chosen reservation policy.
5. Validation and acceptance
Check allocations at maximum output length, block boundaries and cancellations. Compare estimated and observed peak memory for each model configuration. Stress simultaneous growth and confirm releases occur after device work no longer references the blocks.
6. Follow-ups and self-review
How does tensor parallelism change per-device accounting? Reward dimensional arithmetic, output growth, non-KV headroom and an explicit denial policy.
Sources and related practice
vLLM’s PagedAttention paper discusses KV-cache memory management; this admission example is an original simplified calculation.
Read the primary technical reference
Reference retrieved October 3, 2026. Retrieval date is not an interview or source publication date. The reference supports the named concept; scenario, architecture, examples and rubric are original.
Continue with GPU Scheduler System Design: Fairness and Preemption; Design a streaming LLM inference service.
Continue your preparation
Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.