ExtraBrain Interview Questions
LLM Engineer Interview Questions for 2026, With Answer Outlines
Short answer
LLM engineer interviews in 2026 mix fundamentals with serving math. Expect to explain scaled dot-product attention, size a KV cache, compare greedy and nucleus sampling, choose between prompting, RAG and LoRA fine-tuning, and design an eval that catches regressions when the model changes. Interviewers reward candidates who attach a number or a formula to each answer and can say what each optimization costs.
LLM engineer interview questions on attention, KV cache sizing, decoding, LoRA, serving and evals, with answer outlines and tested Python.
An LLM engineer loop usually has one round that feels like a machine learning exam and one that feels like a capacity-planning meeting. In the first, you derive attention on a whiteboard. In the second, someone asks why the 32k-context deployment keeps running out of GPU memory at 40 concurrent users. Both rounds test the same thing: whether you understand what the model does per token and what that costs.
The questions below come in four groups: architecture, inference, adaptation and evaluation. Each answer outline is what a strong candidate says in about two minutes, and the code runs as shown.
Architecture questions
Walk me through scaled dot-product attention. Why divide by the square root of d_k?
Each token is projected into a query, a key and a value. Attention scores are the dot products of one query with every key, scaled, passed through softmax, and used to average the values. In Attention Is All You Need, the formula is softmax(QKᵀ / √d_k)V. The authors explain the scaling: for large d_k the dot products grow large, which pushes softmax into regions with extremely small gradients. If query and key components have unit variance, the dot product has variance d_k, so dividing by √d_k brings it back to about 1.
Interviewers sometimes ask you to code one query against three keys:
import math
def softmax(xs): m = max(xs) # subtract the max for numerical stability exps = [math.exp(x - m) for x in xs] total = sum(exps) return [e / total for e in exps]
def attention(q, keys, values): d_k = len(q) scores = [sum(qi * ki for qi, ki in zip(q, k)) / math.sqrt(d_k) for k in keys] weights = softmax(scores) out = [sum(w * v[j] for w, v in zip(weights, values)) for j in range(len(values[0]))] return out, weights
q = [1.0, 0.0, 1.0, 0.0]keys = [ [1.0, 0.0, 1.0, 0.0], [0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 0.0, 0.0],]values = [ [10.0, 0.0], [0.0, 10.0], [5.0, 5.0],]out, weights = attention(q, keys, values)print([round(w, 3) for w in weights]) # [0.506, 0.186, 0.307]print([round(x, 2) for x in out]) # [6.6, 3.4]Mention the causal mask too: in a decoder, each position may only attend to earlier positions.
Why do many current models use grouped-query attention?
Standard multi-head attention keeps a key and value head for every query head, which makes the KV cache large. Multi-query attention shares one KV head across all query heads, which is fast but can hurt quality. Grouped-query attention uses an intermediate number of KV heads, and its authors report quality close to multi-head attention at a speed comparable to multi-query attention. The practical payoff shows up in the next answer.
Inference and serving questions
What does the KV cache store, and how big does it get?
During generation, the keys and values of past tokens never change, so the model stores them per layer and computes K and V only for the new token. The Hugging Face caching guide summarizes the trade: per-step attention cost becomes linear in sequence length, while memory grows linearly with every token. Sizing it is a favorite interview calculation:
def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, batch=1, bytes_per_value=2): # 2 tensors (K and V) per layer, one vector per KV head per token return 2 * layers * kv_heads * head_dim * seq_len * batch * bytes_per_value
gib = 1024 ** 3gqa = kv_cache_bytes(layers=32, kv_heads=8, head_dim=128, seq_len=32_768)mha = kv_cache_bytes(layers=32, kv_heads=32, head_dim=128, seq_len=32_768)print(f"GQA, 8 KV heads: {gqa / gib:.1f} GiB per sequence") # 4.0 GiBprint(f"MHA, 32 KV heads: {mha / gib:.1f} GiB per sequence") # 16.0 GiBFor a 32-layer model at 16-bit precision, one 32k-token sequence needs 4 GiB of cache with 8 KV heads and 16 GiB with 32. Multiply by concurrent users and you have the answer to the out-of-memory question in the introduction.
Why is each decode step slow compared with prefill?
Prefill processes every prompt token in parallel, so it keeps the GPU’s compute units busy and determines time to first token. Decode produces one token per step, and each step must read the model weights and the whole cache from memory, so it is usually limited by memory bandwidth rather than arithmetic. Batching many requests together is how servers recover throughput, and it is why time per output token rises under load.
How does vLLM fit more requests on one GPU?
The PagedAttention paper observed that KV cache memory is often wasted through fragmentation and duplication, which limits batch size. vLLM stores the cache in fixed-size blocks, much as an operating system pages memory, and reports near-zero waste and 2-4x higher throughput than the systems it compared against at the same latency. Bigger effective batches are the whole point.
Explain temperature, top-k and top-p.
Temperature divides the logits before softmax: below 1 sharpens the distribution, above 1 flattens it. Top-k keeps the k most likely tokens. Top-p (nucleus sampling) keeps the smallest set whose probability mass reaches p, then renormalizes:
import math
def next_token_probs(logits, temperature=1.0, top_p=1.0): scaled = {tok: value / temperature for tok, value in logits.items()} m = max(scaled.values()) exps = {tok: math.exp(v - m) for tok, v in scaled.items()} total = sum(exps.values()) ranked = sorted(((tok, e / total) for tok, e in exps.items()), key=lambda kv: kv[1], reverse=True) kept, cumulative = [], 0.0 for tok, p in ranked: # nucleus: smallest set whose mass reaches top_p kept.append((tok, p)) cumulative += p if cumulative >= top_p: break norm = sum(p for _, p in kept) return {tok: round(p / norm, 3) for tok, p in kept}
logits = {"Paris": 5.0, "Lyon": 3.0, "Nice": 2.5, "banana": 0.0}print(next_token_probs(logits, temperature=1.0, top_p=0.9)) # {'Paris': 0.881, 'Lyon': 0.119}print(next_token_probs(logits, temperature=0.5, top_p=0.9)) # {'Paris': 1.0}print(next_token_probs(logits, temperature=2.0)) # all four tokens, flatterThe Transformers generation guide notes that greedy decoding works for short outputs but starts repeating itself on longer ones. Add the 2026 caveat: some hosted reasoning models no longer honor these knobs. Google’s prompting strategies page, for example, notes that its newest Gemini models drop support for these three parameters, so check the provider’s docs before promising a sampling fix.
Adaptation questions
Prompting, RAG or fine-tuning: how do you choose?
Start with prompting and an eval set. Add retrieval when the model needs facts it doesn’t have or facts that change. Fine-tune when you need a consistent format, style or narrow skill that prompting can’t reach reliably, and only once you have labeled data to train and evaluate on. Facts that change often belong in retrieval, not in the weights. Our RAG engineer interview questions cover the retrieval side in detail.
How does LoRA work, and why is it cheap?
LoRA freezes the pretrained weights and learns a low-rank update, two small matrices whose product is added to selected weight matrices. The LoRA paper reports 10,000 times fewer trainable parameters and a threefold reduction in GPU memory compared with fully fine-tuning GPT-3 175B with Adam, with no added inference latency because the update can be merged into the weights. QLoRA goes further by training adapters on a frozen 4-bit base model, which let its authors fine-tune a 65B model on a single 48 GB GPU.
| Lever | What it saves | What it costs |
|---|---|---|
| Grouped-query attention | KV cache memory | A model choice, small quality risk |
| Quantized weights | GPU memory and bandwidth | Possible accuracy loss, retest |
| Paged KV cache | Wasted cache memory | Serving-stack complexity |
| Prompt caching | Repeated input cost and latency | Prefix must match exactly |
| LoRA adapters | Training memory and storage | Labeled data and an eval set |
Evaluation and cost questions
How would you evaluate an LLM feature before launch?
Write success criteria first, then a test set that mirrors real traffic plus edge cases. Grade with code where you can (exact match, JSON validity, unit tests for generated code) and with an LLM grader where you can’t, using a detailed rubric and parseable output, as Anthropic recommends in its guide to building evals. Rerun the suite on every prompt change and every model upgrade.
A 6,000-token system prompt makes every call slow and expensive. What do you do?
Trim it, then cache it. With Anthropic’s prompt caching, the cache covers the prefix in the order tools, system, messages; the default lifetime is five minutes; cache writes cost more than normal input and cache reads cost a fraction of it. Put the static instructions first and the user’s input last, or every request misses the cache.
Practice explaining the math out loud
The KV cache formula is easy to write and hard to explain while someone asks “and with an 8-bit cache?” Run a mock round with a friend, or practice with ExtraBrain transcribing so you can review where the explanation lost its thread. ExtraBrain keeps each practice session’s transcript in Session History, so you can compare your second attempt with your first. The machine learning engineer mock interview page has more prompts, and our PyTorch interview questions cover the framework side. During a real interview, follow the company’s rules on AI tools.
FAQ
Do LLM engineer interviews still include LeetCode-style coding?
Often, yes, alongside the ML rounds. Expect at least one general coding round and one where you implement something model-adjacent, such as attention, a tokenizer step or a sampling function.
How deep should I go on training?
Know pretraining versus fine-tuning, what LoRA changes and why, and how you would evaluate a fine-tuned model. Distributed training details matter mainly for research or infrastructure roles.
What numbers should I memorize?
Memorize formulas rather than numbers: KV cache size, parameter memory (parameters times bytes per parameter) and tokens per second. You can derive the rest in the room.
Will they ask about specific providers?
Sometimes, as context. Answers that rely on general mechanisms, such as caching, batching and quantization, travel across providers better than product trivia.
Sources (checked November 21, 2026)
- Vaswani et al., Attention Is All You Need
- Ainslie et al., GQA: Training Generalized Multi-Query Transformer Models
- Hugging Face, How caching works
- Kwon et al., Efficient Memory Management for LLM Serving with PagedAttention
- Hugging Face, Generation strategies
- Google, Prompt design strategies
- Hu et al., LoRA: Low-Rank Adaptation of Large Language Models
- Dettmers et al., QLoRA
- Anthropic, Define success criteria and build evaluations
- Anthropic, Prompt caching