Made by systemdesign.academy, the site with 984 interactive system design and AI engineering lessons.
See all 150 questions in this pack16 sections, in the order the PDF prints them. The answers are in the PDF; 5 are free below.
How language models work (9)
1.What is a parameter, and what does '7B' in a model name tell you? junior
2.What does a large language model actually compute when it writes text? junior
3.What are logits, and how does softmax turn them into probabilities? junior
4.What is the difference between a base model and an instruction-tuned (chat) model? junior
5.Why is text generation autoregressive, and what does that mean for speed? mid
6.Your training run reports a loss of 11.8 at step 0 and 2.1 a day later. What do these numbers tell you, and how do you debug a loss that plateaus or turns NaN? mid
7.What is perplexity, and what does a perplexity of 10 mean? mid
8.What is a chat template, and what goes wrong if you use the wrong one? mid
9.Why can an LLM give different outputs for the same prompt even at temperature 0? senior
Tokenization (9)
10.What is a token, and why do models not just use whole words or single characters? junior
11.Why are LLMs bad at counting letters or reversing a word? juniorfree below
12.Walk me through how Byte Pair Encoding (BPE) builds its vocabulary. mid
13.What is byte-level BPE, and why does it never produce an unknown token? mid
14.How do BPE, WordPiece and Unigram (SentencePiece) tokenizers differ? mid
15.Why does the same sentence cost more tokens in some languages, and why does it matter? mid
16.How does vocabulary size trade off against sequence length and model size? mid
17.What breaks when a model upgrade comes with a new tokenizer? senior
18.How would you extend a tokenizer for a new language or domain, and what does it cost? staff
Embeddings and similarity (10)
19.What is an embedding? junior
20.Cosine similarity, dot product and Euclidean distance: how are they different? junior
21.How is a model's input embedding table different from a sentence embedding model? mid
22.How are sentence embedding models trained with contrastive learning? mid
23.Why normalize embeddings, and when does dot product equal cosine similarity? mid
24.What are Matryoshka embeddings, and why would you shorten a vector? mid
25.Bi-encoder vs cross-encoder: why do retrieval systems add a reranker? mid
26.How does approximate nearest neighbor search with HNSW work, and what does it give up? senior
27.How do you choose an embedding model for a production retrieval system? senior
28.How would you migrate a 100-million-vector index to a new embedding model without downtime? staff
Transformer architecture (12)
29.What are the main parts of a decoder-only transformer? junior
30.Encoder-only, decoder-only and encoder-decoder: what is each one good for? junior
31.Why do transformers need residual connections? junior
32.What does one transformer block contain, in order, in a modern pre-norm LLM? mid
33.What does the feed-forward (MLP) layer do, and why is it wider than the model dimension? mid
34.Count the parameters of Llama 3 8B from its config. mid
35.LayerNorm vs RMSNorm, and pre-norm vs post-norm: what changed and why? mid
36.What is SwiGLU, and why did modern LLMs adopt it? mid
37.How do causal masking and teacher forcing let training run in parallel? mid
38.Where does the compute go in a transformer at short and at long context? senior
39.What is weight tying between the input embeddings and the output layer? senior
40.Walk me through the life of a token, from raw text to the next-token probability. staff
Self-attention math (12)
41.Explain self-attention in plain English. junior
42.Write out scaled dot-product attention with the shape of every tensor. midfree below
43.Where does the 1/sqrt(d_k) attention scale live in a kernel, and what breaks if it is wrong? mid
44.Where do Q, K and V come from, and what does each one mean? mid
45.What is the difference between self-attention and cross-attention? mid
46.Why do we cache K and V during generation but never Q? mid
47.Attention outputs NaN in FP16 for some batches but not others. Where do you look? senior
48.Which attention memory grows with n squared, which grows with n, and which one limits you in training vs serving? senior
49.Why split attention into many heads instead of using one big head? senior
50.What do padding masks do, and why does left padding matter for batched generation? senior
51.How does FlashAttention compute exact attention without storing the full score matrix? staff
52.Linear attention and state space models such as Mamba: what do they gain and what do they give up? staff
Attention variants (7)
53.Why did transformers replace RNNs for language modeling? junior
54.What are multi-query attention (MQA) and grouped-query attention (GQA)? mid
55.How much KV-cache memory does grouped-query attention save for Llama 3 70B? mid
56.What is sliding-window attention, and how far can information still travel? mid
57.What is Multi-head Latent Attention (MLA), at a concept level? senior
58.What is an attention sink, and why do streaming methods keep the first few tokens? senior
59.How would you design the attention for a model that must handle a 1-million-token context? staff
Positional encodings (7)
60.Why does a transformer need position information at all? junior
61.Sinusoidal vs learned absolute position embeddings: how do they work? mid
62.How does RoPE (rotary position embedding) work? mid
63.After converting a checkpoint, your RoPE model is fine up to 8K tokens but degrades beyond it, or is bad everywhere. What do you check? senior
64.What is ALiBi, and how does it differ from RoPE? senior
65.How do you extend the context length of a RoPE model (position interpolation, NTK scaling, YaRN)? senior
66.Why do models fail beyond their trained context, and how would you test length generalization? staff
Pretraining and scaling (11)
67.What is pretraining, and what data is it done on? junior
68.Causal language modeling vs masked language modeling: what is the difference? junior
69.What is fill-in-the-middle training, and why do code models use it? mid
70.What does a learning-rate schedule with warmup and cosine decay look like, and why? mid
71.How much compute does it take to train a model? Use C = 6ND. mid
72.Why are modern models trained on far more tokens than Chinchilla-optimal? senior
73.How do teams clean pretraining data: deduplication, filtering and contamination? senior
74.What is a loss spike in pretraining, and how do teams handle it? senior
75.What do scaling laws say? Compare Kaplan and Chinchilla carefully. staff
76.Your team wants to move training from BF16 to FP8 on H100s. What changes, what can break, and how do you decide? staff
77.Estimate the GPU-hours and wall-clock time to pretrain a 70B model on 15T tokens. staff
Decoding (11)
78.Greedy decoding vs sampling: what is the difference? junior
79.What does temperature do to the next-token distribution? junior
80.Top-k vs top-p (nucleus) sampling: how do they cut the tail? junior
81.How does beam search work, and why do chat models rarely use it? mid
82.How do repetition, frequency and presence penalties change the logits? mid
83.How do stop sequences, max tokens and the end-of-sequence token end generation? mid
84.What is min-p sampling, and what problem with top-p does it address? senior
85.How does constrained decoding guarantee valid JSON? senior
86.How does speculative sampling keep exactly the target model's distribution? seniorfree below
87.When would you use a reasoning model instead of a larger standard model, and how do you control its cost and latency? senior
88.Choose decoding settings for code generation, creative writing, classification and extraction. staff
Fine-tuning and PEFT (13)
89.What is fine-tuning, and when should you not do it? junior
90.Prompting vs RAG vs fine-tuning: how do you choose? junior
91.What is supervised fine-tuning (instruction tuning), and how is the data formatted? mid
92.Why does full fine-tuning need about 16 bytes of GPU memory per parameter, and how would you fit a 70B full fine-tune? mid
93.How does LoRA work? mid
94.How many parameters does LoRA train? Work it out for one layer and a whole model. mid
95.What is QLoRA, and how does it fit a large model on one GPU? mid
96.How do you choose LoRA rank, alpha, target modules and learning rate? senior
97.What is catastrophic forgetting, and how do you detect and limit it? senior
98.Why do we mask the loss on prompt tokens during supervised fine-tuning? senior
99.Should you merge a LoRA adapter into the base weights or keep it separate? senior
100.Can fine-tuning teach a model new facts? senior
101.Design an end-to-end fine-tuning pipeline for a customer-support model. staff
Alignment: RLHF and DPO (11)
102.What is RLHF, in simple terms? junior
103.How is a reward model trained from human preference pairs? mid
104.In PPO-based RLHF, what do the policy, reference, reward and value models each do? mid
105.Why does RLHF add a KL penalty against the reference model? mid
106.What is sycophancy, and how can preference training cause it? mid
107.You are running DPO. How does it avoid a separate reward model, and what do you monitor during training? senior
108.What is reward hacking? Give examples and mitigations. senior
109.What are Constitutional AI and RLAIF? senior
110.What is GRPO, and how do verifiable rewards train reasoning models? seniorfree below
111.DPO vs PPO: what are the practical trade-offs? staff
112.How would you collect preference data, and how do you know alignment worked? staff
Context length and hallucination (9)
113.What is a context window, and what happens when you go past it? junior
114.What is hallucination, and why do LLMs hallucinate? junior
115.How do training and evaluation incentives push models to guess instead of saying 'I don't know'? mid
116.What is the 'lost in the middle' effect in long contexts? mid
117.What is calibration, and how do you measure it? mid
118.How do you reduce hallucinations in a production LLM system? senior
119.How can you detect hallucinations automatically? senior
120.Long context vs RAG: when do you use which? senior
121.Design a system that answers questions from 300-page contracts accurately. stafffree below
Mixture of experts (6)
122.What is a mixture-of-experts (MoE) layer? junior
123.Total vs active parameters: work it out for Mixtral 8x7B. mid
124.What is the load-balancing loss, and what happens without it? senior
125.Why is an MoE model cheap in compute per token but not cheap in memory? senior
126.What are expert capacity and token dropping? senior
127.A dense 70B model or a 47B-total, 13B-active MoE: which would you deploy, and why? staff
Multimodal and diffusion (10)
128.How does a vision-language model 'see' an image? junior
129.What is a diffusion model, in plain terms? junior
130.How does a Vision Transformer turn an image into tokens? Work the shapes for 224 x 224. mid
131.What does a diffusion denoiser predict, and what is its training loss? mid
132.How does CLIP train an image encoder and a text encoder together? mid
133.What is latent diffusion, and why does it make image generation cheaper? senior
134.What is classifier-free guidance, and what does the guidance scale do? senior
135.Why can a diffusion sampler use 50 steps instead of 1,000? senior
136.How do speech and audio models turn sound into tokens? senior
137.For invoice understanding, would you use a vision-language model or OCR plus an LLM? staff
Evaluating models (9)
138.How do you evaluate an LLM? What kinds of evaluation exist? junior
139.When is perplexity the right metric in your work, and when does it mislead? junior
140.How is a multiple-choice benchmark like MMLU scored, and what are the pitfalls? junior
141.What is pass@k, and how do you compute it without bias? mid
142.What biases does an LLM-as-a-judge have, and how do you validate a judge? senior
143.How do you detect and handle benchmark contamination? senior
144.How many evaluation examples do you need to trust a difference between two models? senior
145.How do pairwise comparisons and Bradley-Terry (Elo-style) ratings rank models? senior
146.Build the evaluation suite for a new model release. staff
Staff-level judgment (4)
147.Open-weight model vs a closed API model: how do you decide? staff
148.When does it make sense to pretrain or continue-pretrain your own model? staff
149.A model upgrade made your product worse on 5% of queries. What do you do? staff
150.When and how would you distill a large model into a small one? staff
The word strawberry is split into the pieces st, raw and berry, which a vocabulary table maps to unrelated ids 302, 1618 and 19772.
Why it is asked: A classic check that you understand the model sees token ids, not characters, and that you know practical workarounds.
LLMs are bad at letter tasks because they never see letters: the tokenizer turns a word into a few token ids, and the model must remember from training which letters are inside each token.
Take 'strawberry'. With OpenAI's o200k_base tokenizer (used by GPT-4o) it becomes three tokens, 'st', 'raw' and 'berry', with ids 302, 1618 and 19772. With cl100k_base it is 'str', 'aw', 'berry'. To the model these are three arbitrary numbers. Nothing in id 19772 says 'two r letters'. The model can only answer 'how many r letters?' if it learned the spelling of each token from text where words were spelled out, and then added the counts correctly. That is indirect, so it fails often, especially for rare words.
Reversing a word is harder still: the model must spell each token, reverse the letters, and then write output whose tokens cut the word at completely different places.
The same cause explains other weaknesses: arithmetic on long numbers (digits are grouped into tokens in uneven ways), rhymes, anagrams, and character-level edits.
Workarounds:
- Ask the model to spell the word with separators first ('s-t-r-a-w...'), so each letter becomes its own token, then count.
- Give it a tool: a code interpreter does 'strawberry'.count('r') = 3 exactly.
- For products, never rely on the model for exact character work such as validating IDs or lengths; do it in code.
Newer reasoning models do better because they spell words out step by step, but it is still the tokenizer that makes the task hard.
What the interviewer listens for
The model sees token ids, not letters
'strawberry' is 3 tokens in o200k_base: st, raw, berry
Letter knowledge per token is learned indirectly
Fix: spell out with separators, or use code tools
Follow-ups the interviewer may ask
Why are LLMs weak at multiplying large numbers? Hint: digits are chunked into tokens unevenly, and carrying needs exact step-by-step work.
How do you make letter counting reliable? Hint: call a code tool or force one token per character.
Would a character-level model fix this? Hint: yes for spelling, at the cost of much longer sequences.
Common mistakes
Saying the model is just 'bad at math'
Assuming the word is one token or one token per letter
Trusting the model for exact string validation in production
Matrix diagrams show Q of shape 32 by n by 128 times K transposed giving a 32 by n by n score tensor, then the softmax weights times V giving the n by 4,096 output after merging heads.
Why it is asked: Tests precision: can you write the formula and track every shape, including heads and GQA, the way you would when debugging a kernel?
Attention(Q, K, V) = softmax(Q K^T / sqrt(d_k) + M) V, where M is the mask (0 where allowed, minus infinity where blocked).
Each tensor (a multi-dimensional array of numbers) has a shape. Use batch B, sequence n, model width d, h query heads of size d_k (d = h x d_k). Example: Llama 3 8B, B = 1, n = 8,192, d = 4,096, h = 32, 8 key-value heads, d_k = 128.
- Input X: [B, n, d] = [1, 8192, 4096].
- Q = X W_Q, reshaped to [B, h, n, d_k] = [1, 32, 8192, 128].
- K = X W_K and V = X W_V: [B, 8, n, 128]. With GQA (grouped-query attention) each KV head is read by its 4 query heads (the snippet copies it with np.repeat for clarity; real kernels do not copy).
- Scores Q K^T: [B, h, n, n] = [1, 32, 8192, 8192]. Multiply by 1/sqrt(128) = 0.0884 and add the causal mask.
- Softmax over the keys (last axis): each row sums to 1.
- Weights x V: [B, h, n, d_k] = [1, 32, 8192, 128].
- Transpose and merge heads: [B, n, h x d_k] = [1, 8192, 4096], then the output projection W_O keeps [B, n, d].
The shape that matters for cost is the score tensor. Stored in BF16 (2 bytes per number) it is 32 x 8,192 x 8,192 x 2 bytes = 4.29 GB for one layer of one sequence, which is why kernels such as FlashAttention, which works in small on-chip tiles, never store it.
What the interviewer listens for
softmax(QK^T / sqrt(d_k) + mask) V
Q is [B, h, n, d_k]; K and V use the number of KV heads
Scores are [B, h, n, n]: quadratic in sequence length
Softmax is over the key axis, one distribution per query
Heads are merged back to [B, n, d] and projected by W_O
Follow-ups the interviewer may ask
What changes for decode? Hint: Q has one row; scores are [B, h, 1, context].
Where does d_v enter? Hint: V's head size; usually equal to d_k but it does not have to be.
How large is the score tensor for 32 layers if kept for backward? Hint: about 137 GB at 8K, which is why it is recomputed.
Common mistakes
Softmax over the query axis instead of the key axis
Scaling by d_k instead of sqrt(d_k)
Giving K and V the query head count in a GQA model
Sequence diagram of a draft model proposing four tokens, the target model scoring them in one pass, and the sampler accepting, rejecting and resampling.
Why it is asked: Speculative decoding is a standard speed-up; senior candidates must show why it is lossless, not just that it is fast.
It accepts each draft token with probability min(1, p(x)/q(x)) and, on rejection, resamples from the leftover distribution max(0, p - q), normalized; this makes every output token follow exactly the target model's distribution p.
Setup (Leviathan et al. 2023; Chen et al. 2023): a small draft model q proposes gamma tokens one by one (gamma is the number of draft tokens). The large target model p then scores all of them in one forward pass, which costs about one normal decode step because decode is memory-bound.
Verification, left to right for each draft token x:
1. Accept with probability min(1, p(x)/q(x)). If the target likes the token at least as much as the draft did, it is always kept.
2. On the first rejection, sample a replacement from max(0, p - q), renormalized, and stop this round.
3. If all gamma tokens pass, sample one bonus token from p at the next position.
Why the output equals p. Let residual(x) = max(0, p(x) - q(x)), normalized to sum to 1. Token x can come out two ways:
- accepted draft: q(x) x min(1, p(x)/q(x)) = min(p(x), q(x));
- rejection, then resample: P(reject) x residual(x) = p(x) - min(p(x), q(x)).
The two add up to p(x). The code checks this exactly and by simulation: acceptance rate 0.70, output equal to p.
Speed: with alpha, the chance one draft token is accepted, and gamma drafts, expected tokens per target pass is (1 - alpha^(gamma+1)) / (1 - alpha): 2.31 for alpha 0.6 and gamma 4, 3.36 for alpha 0.8. Under greedy decoding the rule reduces to accepting a draft token only if it equals the target's argmax.
What the interviewer listens for
Accept with min(1, p/q); on reject sample from norm(max(0, p - q))
Why is the verification pass cheap? Hint: decode is memory-bound; scoring gamma + 1 positions reads the weights once.
What happens at high temperature? Hint: draft and target disagree more, acceptance falls, speed-up shrinks.
Why does speculative decoding help less at large batch sizes? Hint: decode becomes compute-bound, so verifying extra draft tokens is no longer free; draft-free variants such as Medusa heads and EAGLE reduce the overhead.
Common mistakes
Saying speculative decoding approximates the target and loses quality
Accepting only exact matches when sampling, which changes the distribution
Bar chart for a group of eight sampled answers where three right answers get bars up to plus 1.29 and five wrong answers get bars down to minus 0.775 from a zero baseline.
Why it is asked: GRPO with checkable rewards is how many recent reasoning models are trained. The interviewer wants the group-relative advantage and the practical failure modes.
GRPO (Group Relative Policy Optimization, from DeepSeekMath, Shao et al. 2024) is a PPO variant without a value model: it samples a group of answers per prompt and scores each against the group's average.
How it works:
- The policy (the model being trained) samples G answers to one prompt, for example G = 8.
- With verifiable rewards a checker scores each: does the math answer match, do the tests pass, is the format right.
- Each answer's advantage (how much better it did than the group) = (r_i - group mean) / group standard deviation, the typical distance from the mean. If 3 of 8 answers are correct (reward 1, others 0), the mean is 3 / 8 = 0.375 and the standard deviation 0.484. Correct answers get (1 - 0.375) / 0.484 = +1.29; wrong ones get -0.775. Every token in an answer shares its advantage.
- Update with a PPO-style clipped loss. The original adds a KL penalty (a cost for drifting from a frozen reference model) to the loss; DAPO (Yu et al. 2025), a later recipe, drops it on purpose.
Rule-checked rewards are harder to fool than a learned reward model; DeepSeek-R1 (2025) used GRPO with them.
Failure modes:
- If every answer in a group gets the same reward, the advantage is zero and the prompt teaches nothing. Choose prompts of medium difficulty.
- Length bias: the original averages each answer's loss over its own length, which penalizes long wrong answers less per token. Dr. GRPO (Liu et al. 2025) and DAPO change this averaging.
- Checker gaps (extraction bugs, gameable tests) and falling entropy (less exploration).
What the interviewer listens for
Group of samples per prompt; advantage = (r - group mean) / group std
No value model, so less memory and less tuning than PPO
Verifiable rewards: checkers for answers, tests and format
All-same groups give zero signal; pick medium-difficulty prompts
Harden the checker and watch length and entropy
Follow-ups the interviewer may ask
Why does group normalization work as a baseline? Hint: the group mean estimates the expected reward for that prompt, which is what the value model approximated.
How large should G be? Hint: larger groups give better baselines but cost more generation; 8 to 64 is common, measure it.
Where does the wall-clock time go in GRPO training? Hint: rollout generation; teams run a fast inference engine for rollouts, sync weights to it, and watch for entropy collapse.
Common mistakes
Saying the original GRPO has no KL term (it has one in the loss; some later recipes such as DAPO drop it on purpose)
Training on prompts the model always solves or never solves
Trusting a regex answer checker without testing it
A left-to-right architecture from PDF parsing and clause splitting, through keyword and vector indexes, to reranking, cited answering and a quote verifier that can abstain.
Why it is asked: Tests whether you can turn a vague accuracy goal into a pipeline with structure-aware ingestion, grounded citations, abstention and a real evaluation plan, instead of saying 'use a long context model'.
I would build a retrieval system that respects the contract's structure, answers only from quoted clauses, and says "not found" when the text does not support an answer. Pasting the whole contract into a long-context model is the baseline to beat.
Size first. 300 pages at about 500 words a page is 150,000 words, roughly 195,000 tokens (assume 1.3 tokens per word), too big for a 128K window such as Llama 3.1's. At an assumed $3 per million input tokens, each question costs about $0.59 with the whole contract in the prompt, against about $0.03 with 10,000 retrieved tokens. Long prompts also have the "lost in the middle" problem (Liu et al. 2023): models use facts in the middle of a long context less reliably.
The pipeline:
- Ingestion: a layout-aware parser keeps section numbers, headings, tables and page numbers.
- Chunk by clause, not by fixed size, and store the section path ("12.3 Termination (b)") as metadata.
- A defined-terms index: a word like "Affiliate" is defined once and used everywhere, so pass its definition too.
- Cross-reference expansion: when a clause says "subject to Section 14", fetch Section 14 too.
- Hybrid retrieval: BM25 (keyword search, for example Elasticsearch) for exact terms plus dense vectors (for example Qdrant) for meaning, then a reranker, a model that scores each question and chunk pair.
- Answer with clause citations, then a verifier checks every quote exists word for word. No support means abstain.
Measure on a golden set written with lawyers: answer accuracy, citation precision, and the abstain rate on questions the contract does not answer. Version amendments so the newest one wins.
What the interviewer listens for
Clause-level chunking with section paths, not fixed-size chunks
Defined terms and cross-references must be pulled into context
Hybrid retrieval plus reranking, answers cite clause ids
A verbatim quote check and an explicit 'not found' path
Golden set built with lawyers; measure citation precision and abstention
Follow-ups the interviewer may ask
Why not just use a 1M-token context model? Hint: cost per question, latency, weaker use of mid-context facts, and no citation guarantee; keep it as a baseline in the eval.
How do you handle amendments? Hint: store document version and date, retrieve across the base and amendments, and let the newest amendment override with both cited.
How do you handle tables like payment schedules? Hint: parse tables to structured rows and answer numeric questions from the table, not from flattened text.
Common mistakes
Fixed 512-token chunks that cut clauses in half and lose the section number
Trusting the model's answer without checking that the cited text exists
Evaluating only on questions that have answers, so the model never learns to abstain
Transformers, attention, tokenization, fine-tuning, RLHF and DPO, embeddings and decoding.
150 questions and 173 diagrams, each with why it is asked, a full answer, what the interviewer listens for, follow-ups, common mistakes and a diagram. By Roni Das.