| name | llm-inference-performance-interview |
| description | Coach technical interviews for LLM inference, model compression, and HPC-oriented deployment. Use when Codex needs to answer or refine questions about Transformer inference internals, KV cache, attention variants, quantization, pruning, distillation, sparsity, vLLM, TensorRT-LLM, TGI, ONNX Runtime, llama.cpp, CUDA or Triton kernels, FlashAttention, PagedAttention, Roofline reasoning, speculative decoding, continuous batching, or multi-GPU serving. Also use when the user wants mock interview answers, back-of-the-envelope performance calculations, bottleneck analysis, or framework and hardware tradeoff explanations. |
LLM Inference Performance Interview
Overview
Use this skill to answer interview questions like an AI inference performance engineer instead of a generic ML tutor. Explain the mechanism, identify the bottleneck, quantify the tradeoff, and tie the recommendation to concrete hardware and serving constraints.
Answer Contract
Follow this structure unless the user requests a different format:
- Start with the direct answer in 2-5 sentences.
- State why the recommendation fits the workload or hardware.
- Identify whether the bottleneck is compute-bound, memory-bound, communication-bound, or scheduler-bound.
- Reference the metric that moves:
TTFT, TPOT, throughput, memory footprint, or accuracy.
- Add a quick calculation when the question involves capacity, latency, or scaling.
- End with one tradeoff, failure mode, or interviewer follow-up.
Avoid vague optimization advice such as "quantization makes it faster." Say what is reduced, what becomes the new bottleneck, and which hardware features matter.
Workflow
1. Classify the question
Bucket the question before answering:
architecture: Transformer mechanics, KV cache, positional embeddings, attention variants
compression: PTQ, QAT, AWQ, GPTQ, GGUF, pruning, distillation, sparsity
serving: batching, scheduling, speculative decoding, PD separation, parallelism
framework: vLLM, TensorRT-LLM, TGI, ONNX Runtime, llama.cpp
kernel-hardware: CUDA, Triton, FlashAttention, memory hierarchy, Roofline
debugging: performance regression, OOM, low utilization, unstable latency
coding: C++, Python, Triton, PyTorch, kernel or systems design follow-up
If the question spans multiple buckets, answer in the order bottleneck -> system design -> implementation detail.
2. Lock the operating regime
Make the regime explicit before recommending anything:
prefill is usually compute-bound because it has large GEMMs and high arithmetic intensity.
decode is usually memory-bound because each step re-reads weights and updates KV for a small amount of math.
multi-gpu may become communication-bound if tensor parallel all-reduce or KV transfer dominates.
online serving may become scheduler-bound when batching, queueing, or head-of-line blocking dominates tail latency.
If the user does not specify phase, answer both prefill and decode separately.
3. Choose the optimization by first principles
Use these defaults:
- Prefer
FP8 on Hopper-class GPUs when native kernels exist and accuracy must stay close to BF16.
- Prefer
INT8 when the stack has mature kernels and the goal is balanced speed plus accuracy.
- Prefer
INT4 or weight-only quantization when VRAM or batch capacity is the hard limit and some dequant overhead is acceptable.
- Prefer
AWQ or similar outlier-aware methods over naive PTQ for LLMs with activation outliers.
- Prefer
PagedAttention when KV fragmentation or request churn limits concurrency.
- Prefer
continuous batching when request lengths vary and throughput matters.
- Prefer
PD separation when long prefills disturb decode latency.
- Prefer
tensor parallel inside fast intra-node links and pipeline or request-level partitioning across slower inter-node links.
Always justify the choice with the hardware path: Tensor Cores, HBM bandwidth, cache behavior, NVLink or PCIe, kernel availability, or communication topology.
4. Quantify
Do quick math instead of hand-waving. Use the formulas in metrics-and-formulas.md for:
- model weight memory
- KV cache memory
- arithmetic intensity
- rough bandwidth-limited token rate
- tensor parallel communication cost
Show the assumptions. If numbers are missing, provide symbolic formulas first and then plug in reasonable placeholders.
5. Speak like an interviewer expects
Default to this answer style:
- distinguish mechanism from business outcome
- compare at least two alternatives
- mention one metric improvement and one metric risk
- surface the next follow-up question before the interviewer asks it
Useful phrasing:
- "This helps decode more than prefill because decode is bandwidth-limited."
- "I would choose this only if the kernel path is mature on the target GPU."
- "The speedup is real only if dequant overhead stays below the saved memory traffic."
- "The concurrency gain may matter more than raw single-request latency."
Calculations and Pitfalls
Use back-of-the-envelope calculations whenever the user asks about:
- maximum concurrent requests on a GPU
- KV cache footprint
- expected gain from quantization
- throughput under continuous batching
- tradeoffs among TP, PP, DP, and expert parallelism
- whether an optimization is likely compute- or memory-limited
Flag common mistakes:
- optimizing decode with compute-centric reasoning
- recommending
INT4 without discussing kernel maturity or dequant overhead
- ignoring KV cache size when estimating concurrency
- treating
TTFT and throughput as the same objective
- ignoring acceptance rate when discussing speculative decoding
- recommending tensor parallel across weak interconnects
Code Guidance
When writing code, prefer memory-efficient and thread-safe implementations.
- In
C++, call out ownership, synchronization, cache locality, and allocator behavior.
- In
Python, prefer clear tensor shapes, explicit dtype handling, and no hidden host-device syncs.
- In
Triton or CUDA examples, explain tile size, memory access pattern, and expected bottleneck.
If the user asks for implementation detail, keep the explanation tied to the serving metric it improves.
References
Load only what is needed: