Inference, Serving and GPU Performance Interview Questions
Short answers to 15 inference, serving and gpu performance interview questions.
Questions and answers (15)
Answers are written in plain English and reviewed for technical accuracy. Each answer states the point first, then the reason.
1. Explain the prefill and decode phases. Why is prefill compute-bound and decode memory-bandwidth-bound?
Prefill processes the whole prompt in one parallel pass. Decode generates one token per step and reads the full model and KV cache each time. Prefill is compute-bound because many tokens multiply the same weights. Decode is memory-bandwidth-bound because each step moves all weights for one token of work.
2. What is continuous (in-flight) batching and why did it replace static batching?
Continuous batching adds and removes requests at every decode step. Static batching waits for the slowest request in a fixed batch. Continuous batching replaces it because idle slots waste GPU time. A short request can leave early and a new request fills the slot at once.
3. How does PagedAttention work, and what problem of KV-cache fragmentation does it solve?
PagedAttention stores the KV cache in fixed-size blocks, like pages in an operating system. A block table maps logical token positions to physical blocks. This design removes the need to reserve one contiguous buffer per request. It cuts KV-cache fragmentation and lets requests share blocks for a common prefix.
4. What is speculative decoding? Why is output quality preserved, and when does it not help?
Speculative decoding uses a small draft model to propose several tokens, and the large model verifies them in one pass. Output quality is preserved because the verify step accepts a token only under the exact target distribution. It does not help when the draft model is slow or the acceptance rate is low. A typical acceptance rate of 0.7 to 0.9 gives a speedup of about 2x.
5. Explain prefix caching / prompt caching. When should you use it, and what invalidates a cached prefix?
Prefix caching stores the KV cache of a shared prompt prefix and reuses it for later requests. Use it when many requests share a long system prompt or a fixed document. Any change to the prefix tokens invalidates the cache. A different tokenizer output or a changed position also invalidates it.
6. Compare FP16, BF16, FP8, INT8, INT4 and FP4 for serving. What breaks at each step down?
FP16 and BF16 are the safe baseline, and BF16 has a wider range. FP8 halves memory and works well for weights and activations with scaling. INT8 needs calibration and can lose accuracy on outlier channels. INT4 and FP4 cut memory again but need group scales and often hurt quality. At each step down, the main risks are range loss, quantization error, and slower dequantization.
7. Compare tensor, pipeline, data, sequence and expert parallelism. When do you combine them?
Tensor parallelism splits each layer across GPUs and needs fast links. Pipeline parallelism splits layers into stages and needs many micro-batches. Data parallelism copies the model and splits the batch. Sequence parallelism splits long sequences, and expert parallelism splits MoE experts. Combine tensor and pipeline parallelism to fit a large model, then add data parallelism for throughput.
8. Estimate the GPU memory needed to serve a 70B model: weights, KV cache, activations, fragmentation.
Weights need about 140 GB in FP16 for 70B parameters. The KV cache depends on context length and batch size. For 70B with 80 layers and 8 KV heads of size 128, one token costs about 320 KB in FP16. Activations add a few GB, and fragmentation adds 10 to 20 percent. Plan for about 160 to 180 GB before the KV cache.
9. What are TTFT, TPOT, ITL and throughput, and how do they trade against each other?
TTFT is the time to first token. TPOT is the time per output token after the first. ITL is the gap between two output tokens. Throughput is the total tokens served per second. A large batch raises throughput but also raises ITL and TPOT. A small batch lowers latency but wastes GPU capacity.
10. Do the roofline maths: how many tokens/sec can one H100 produce for a 70B model at batch size 1?
One H100 produces about 20 to 30 tokens/sec for a 70B model at batch size 1. The decode step is memory bound. Each step reads about 140 GB of weights in FP16. The H100 HBM bandwidth is about 3.35 TB/s. So the step time is about 140 GB / 3.35 TB/s = 42 ms, which gives about 24 tokens/sec.
weights = 70e9 * 2 bytes = 140 GB
bw = 3.35e12 bytes/s
step = 140e9 / 3.35e12 = 0.042 s
tps = 1 / 0.042 = 24 tokens/s
11. When would you choose vLLM vs SGLang vs TensorRT-LLM vs a custom stack?
Choose vLLM for fast setup and wide model support. Choose SGLang for complex prompts and prefix reuse. Choose TensorRT-LLM for top speed on NVIDIA GPUs with fixed models. Choose a custom stack only for special needs that no framework meets. vLLM and SGLang are easy to change. TensorRT-LLM needs more build work but gives lower latency.
12. How would you cut LLM serving cost by 10x? Enumerate every lever and rank them.
The biggest lever is higher batch size with paged attention and a KV cache. The next lever is smaller models or quantized weights. Then come prefix caching, speculative decoding, and better GPU use. Ranked by impact: batch and KV cache first, quantization second, caching third, then routing and spot capacity. A 10x cut usually needs two or three levers together.
13. Your p99 latency doubled after a deploy with no model change. Walk through the diagnosis.
First compare TTFT and TPOT separately to find the slow stage. Then check batch size, queue depth, and KV cache hit rate. Then check the tokenizer version, the prompt template, and the traffic mix. A common cause is a longer system prompt or a lower cache hit rate. Another cause is a new driver or a full KV cache that forces preemption.
14. What is chunked prefill, and why does it improve tail latency under mixed traffic?
Chunked prefill splits a long prompt into small pieces. The scheduler runs these pieces beside decode steps. A long prefill can block decode for hundreds of milliseconds. Chunking caps that block and lowers p99 ITL. The tradeoff is a small drop in peak throughput.
15. Explain disaggregated prefill/decode serving and when it pays for itself.
Disaggregated serving runs prefill on one pool and decode on another pool. It pays off when prefill and decode have very different needs. Prefill is compute bound and decode is memory bound. It helps at high load with long prompts and strict ITL goals. It costs extra KV cache transfer and more complex scheduling.