vLLM, SGLang and llama.cpp internals interview questions
Interview questions on LLM inference engine internals: how vLLM, SGLang and llama.cpp work, RadixAttention, GGUF and mmap, CUDA graphs, kernel fusion, host overhead, and how to choose an engine.
Engine questions check that you have looked under the hood of the tools you list on your CV. You do not need to know every flag, but you should be able to explain what each engine is optimised for and what happens between an HTTP request arriving and a token coming back.
Question 1
Walk through what happens inside vLLM from request to token.
Model answer
- The API server receives an OpenAI-style request, applies the chat template and tokenises the prompt.
- The request goes to the engine core, which in vLLM's current architecture runs in its own process so the scheduler and GPU work are not slowed by HTTP handling and detokenisation.
- Each step, the scheduler decides which requests run, how many prompt tokens to prefill (chunked prefill) and which KV cache blocks they get. Prefix caching looks up hashes of full blocks to skip already computed prefixes.
- The model runner prepares inputs (token IDs, positions, block tables), runs the forward pass (using CUDA graphs for decode-sized batches to remove kernel launch overhead), with paged attention kernels from backends such as FlashAttention or FlashInfer.
- The sampler applies temperature, top-p, penalties and any structured output mask, and picks tokens.
- New tokens go back to the front end, which detokenises incrementally and streams them out, while finished requests release their blocks.
The design points to mention: continuous batching, paged KV cache, prefix caching, chunked prefill, CUDA graphs, and overlap of CPU scheduling with GPU execution.
Likely follow-up questions
- Why does vLLM capture CUDA graphs only for specific batch sizes?
- Which part of this path would you suspect if GPU utilisation is low at high request rates?
- How does tensor parallelism change the picture inside vLLM?
Question 2
How does SGLang differ from vLLM?
Model answer
Both are high-throughput serving engines with continuous batching, paged KV memory, prefix caching, quantisation and speculative decoding. The differences people usually cite:
- RadixAttention: SGLang keeps the KV cache of past requests in a radix tree keyed by token sequences, matches the longest shared prefix for each new request, and evicts least recently used leaves. Its scheduler can order queued requests to maximise cache hits, which helps agent workflows, few-shot prompting and multi-turn chat.
- Front-end language: SGLang began as a way to write multi-call LLM programs (generation, branching, forking) so the runtime can see and share their prefixes.
- Structured output: it uses a compressed finite-state machine approach to decode several forced tokens in one step when the grammar allows only one continuation.
- Scheduler overlap: an overlap scheduler prepares the next batch on the CPU while the GPU runs the current one.
In practice their performance leapfrogs between releases, so the honest answer is to benchmark both on your model and traffic shape.
Likely follow-up questions
- Why is a radix tree a natural structure for prefix caching?
- For which workloads would you expect SGLang's cache-aware scheduling to matter most?
- What would make you choose TensorRT-LLM over either?
Question 3
How does llama.cpp run large models on a laptop?
Model answer
- GGUF: a single-file format holding the tensors, tokenizer and metadata, with many quantisation types (legacy Q4_0 and Q8_0, k-quants like Q4_K_M, and i-quants for very low bit widths). Block-wise scales keep 4-bit models close to full quality.
- mmap: the file is memory-mapped, so loading is nearly instant, the OS pages weights in on demand, and several processes can share them.
- ggml: a small C tensor library that builds a compute graph and runs it on backends for CPU (with SIMD, multi-threading), Metal, CUDA, Vulkan, ROCm and others.
- Partial offload: the number of layers on the GPU is configurable, so a model larger than VRAM can split between GPU and CPU RAM, at a speed set by the slower part.
- Hand-written quantised kernels: matrix-vector products that dequantise on the fly, because single-user decode is memory-bound and fewer bytes means more tokens per second.
Its server supports parallel slots with continuous batching, but it is designed for local and edge use first, while vLLM and SGLang target data-centre throughput.
Likely follow-up questions
- Why does llama.cpp prompt processing on CPU lag far behind generation?
- What does Q4_K_M mean, roughly?
- When would you choose llama.cpp for a production service?
Question 4
What are kernel fusion and CUDA graphs, and why do they matter for decode?
Model answer
A decode step for a small batch launches hundreds of small kernels per layer (norms, projections, rotary embeddings, attention, activations, residual adds). Each launch costs a few microseconds of CPU and GPU overhead, and unfused element-wise kernels each read and write their tensors to HBM.
- Kernel fusion combines adjacent operations (for example RMSNorm with the residual add, or the SiLU with the gate multiply, or quantisation into the matmul epilogue) into one kernel, saving launches and memory round trips.
- CUDA graphs record a sequence of kernel launches once and replay it with a single launch, removing per-kernel CPU overhead. Because a graph has fixed shapes, engines capture one per batch size bucket and pad batches up to the nearest bucket.
- torch.compile and similar compilers do some fusion automatically.
For small models or small batches, where the GPU finishes each kernel in microseconds, these can make decode 1.5 to several times faster. For large prefill batches they matter much less.
Likely follow-up questions
- Why are CUDA graphs usually used for decode but not for prefill?
- How would you find launch overhead in a profile?
- What does padding to a graph bucket cost?
Question 5
How would you choose an inference engine for a new project?
Model answer
Ask what the deployment needs, then test the shortlist:
- Hardware and platform: data-centre NVIDIA or AMD GPUs point to vLLM, SGLang or TensorRT-LLM; Apple Silicon and laptops to llama.cpp or MLX; CPUs and edge devices to llama.cpp and similar.
- Model support: day-one support for new architectures (MoE, MLA, hybrid attention, multimodal) varies; check that the exact model and quantisation are supported.
- Workload: many users and high throughput favour vLLM and SGLang; heavy shared prefixes and agent workflows favour strong prefix caching; strict latency on fixed NVIDIA hardware can justify TensorRT-LLM's compile step.
- Features: OpenAI-compatible API, structured output, LoRA adapters, speculative decoding, multi-node serving, metrics.
- Operations: release cadence, stability, community, and how easy it is to upgrade.
Then run the same benchmark with your prompts, output lengths and SLOs on each candidate and choose on goodput and cost, not on published numbers.
Likely follow-up questions
- What would make you switch engines after launch?
- How do you keep benchmark comparisons fair between engines?
- What are the risks of using a managed inference API instead?
The lesson behind these answers · 15 min · free
Engines compared from the inside: llama.cpp, vLLM, SGLang, TGI, TensorRT-LLM, Dynamo
Worked numbers, step-through diagrams and a quiz, so you can derive the answer in the interview instead of reciting it.
Read the lesson →- The software stack: from CUDA kernels to inference engines · The Software Stack14 min · Pro
- Kernel fusion, launch overhead and kernel selection: where small-batch decode time really goes · The Software Stack13 min · Pro
- The host side: CPU overhead, tokenisation, sampling and streaming · The Software Stack14 min · Pro
- vLLM for production serving · Runtimes24 min · Pro
- llama.cpp: build, run and serve · Runtimes13 min
- Loading weights: the GGUF file format and memory mapping · Engine Core20 min · Pro
- The forward pass end to end: a Llama-style engine in 100 lines · Engine Core25 min
Articles on this topic
- vLLM vs TensorRT-LLM: which inference engine should you serve with? (8 min read)
- FP8 vs INT4 vs FP4: choosing a quantisation for LLM serving (8 min read)
- What is a GPU kernel? The code where LLM inference actually spends its time (7 min read)
- llama.cpp vs vLLM: laptop engine or server engine? (7 min read)
Related interview questions
- PagedAttention interview questions (5 questions)
- Structured output interview questions (constrained decoding) (6 questions)
- Batching and continuous batching interview questions (5 questions)
- LLM quantization interview questions (5 questions)
- LLM benchmarking interview questions: latency vs throughput (5 questions)