Module deck
ML systems and interviews flashcards
Reviewing needs JavaScript. You can read every card in the list below.
Loading your cards...
Back to the module47 cards in this deck
Read all 47 cards as a list
ML system design: framing, budgets, two-stage retrieval, serving, rollout and monitoring
- Front
- When should you not start with ML, and what do you ship instead?
- Back
- When rules already solve the problem acceptably, there is no label or feedback signal, an error is too costly without human review, or explainability rules out opaque models. Ship a heuristic baseline first, log its decisions and corrections as labels, and build a model only if the remaining errors justify the cost.
- Front
- Business goal, training objective and metric. How do they differ, and what is a guardrail?
- Back
- The goal is why the system exists (more orders). The objective is what the model optimises (probability of an order). Metrics decide whether it worked (NDCG@k offline, order rate online). A guardrail is a metric you will not let get worse, such as delivery ETA or cancellations. A proxy objective such as clicks can rise while the goal falls.
- Front
- List the nine steps of the ML system design framework.
- Back
- 1 Clarify and frame. 2 Data and labels. 3 Baseline. 4 Features. 5 Model. 6 Offline evaluation. 7 Serving. 8 Online evaluation and rollout. 9 Monitoring and risks. A suggested 35-minute split is 4, 4, 2, 4, 5, 3, 5, 3, 5 minutes. Say the trade-off, start with a baseline, name the failure mode first.
- Front
- Batch, online and streaming inference. When does each fit?
- Back
- Batch: scores computed on a schedule, good when freshness tolerates it, stale between runs. Online: computed per request, needs a tight latency budget. Streaming: features updated as events arrive, most moving parts. Real systems mix them, using the slowest mode each feature's freshness allows.
- Front
- State Little's law and use it to size a service.
- Back
- In flight L = arrival rate x time in system. Feed example: 694.44 requests per second x 0.060 s = 41.7 in flight. With 8 concurrent per server loaded to 50%, each carries 4, so 11 servers; at $0.40 per server-hour that is $5.28 per million requests. Every assumption (peak factor, service time, utilisation) is a lever to state.
- Front
- Why budget p99 latency instead of the mean, and how do parallel calls combine?
- Back
- In the script the mean was 45.2 ms but p99 was 126.2 ms and the slowest request 277.5 ms. Serial steps add; parallel calls cost the slowest one (5 + [10, 40] = 45 ms, not 55). With 10 parallel calls each slow 1% of the time, 1 - 0.99^10 = 0.0956 of requests wait on a slow one.
- Front
- What is a timeout with a fallback, and what does it cost?
- Back
- Stop waiting at a threshold and return a cheaper answer. A 100 ms timeout with a 5 ms fallback sent 3.20% of requests to the fallback and capped the slowest served request at 105.0 ms instead of 277.5 ms. The price is quality on those requests, so the fallback rate is a metric to alert on.
- Front
- Why use a retrieve-then-rank funnel, and what does each stage optimise?
- Back
- Scoring every item with the best model is too slow or costly. Candidate generation (two-tower plus ANN, popular, recent) keeps a few hundred and is judged by recall. The ranker orders them with rich features and is judged by NDCG or precision at the top. The re-ranker applies diversity, rules, fairness and exploration.
- Front
- Why does final quality depend on retrieval recall? Give the numbers.
- Back
- The ranker cannot promote an item it never sees. In the synthetic funnel, final NDCG@10 was 0.472 with 50 candidates (recall 0.165), 0.772 with 500 and 0.903 with 2,000, against 0.944 when the ranker scored all 20,000 items. More candidates raise quality and ranker cost together.
- Front
- Define recall@k and NDCG@k.
- Back
- Recall@k = relevant items in the top k divided by all relevant items. NDCG@k = DCG@k / ideal DCG@k, where DCG sums gain / log2(rank + 1). A perfect list scores 1. By hand, gains 1 and 3 in the order (1, 3) give 2.893 / 3.631 = 0.797.
- Front
- What are the special problems of fraud and ads designs?
- Back
- Fraud: extreme imbalance, delayed and selective labels (keep a random approval holdout), adaptive adversaries, a decision from costs: act when p > F / (F + L), for example 4 / 84 = 0.0476, which needs calibrated scores. Ads: value is pCTR x bid, so calibration matters; an overstated pCTR (0.04 instead of 0.02) doubles the value from $0.03 to $0.06.
- Front
- How do you keep training and serving features consistent?
- Back
- Use one feature definition for both paths, re-use code, log the features actually served, and train on the logs. A feature store (offline side with point-in-time joins, online side for low latency) gives the definition a home; it adds a system to run, so it pays off when many models share features.
- Front
- Name the four serving levers and the cost of each.
- Back
- Cache: stale answers and a hit rate that depends on skew (0.391 at 1% of keys in the script). Batching: throughput up, latency up (batch 16 gives 1000 items/s at 16 ms). Quantisation: 400 MB to 100 MB for 100M parameters, some accuracy lost. Distillation: train a smaller student from a larger teacher, pay for training twice.
- Front
- Describe the rollout ladder.
- Back
- Offline evaluation, then shadow (score and log, users see nothing), canary (small share of real traffic), A/B test (randomised, primary metric with guardrails), ramp to 100%, with rollback ready at each stage. Each step answers a different question: does it run, does it break anything, is it better, does it hold at scale.
- Front
- What is a feedback loop in an ML system, and how do you limit it?
- Back
- The model's output changes what users see, which changes its next training data. In the toy loop, always showing the best observed item gave one item 0.998 of impressions and found the truly best item in 14 of 100 runs. Exploring 10% of the time found it in 55 of 100. Keep an exploration or random holdout slice and log propensities.
- Front
- What should you monitor after launch beyond accuracy?
- Back
- Data quality, feature drift, score drift, and performance once labels mature, plus latency percentiles, error and timeout rates and the fallback rate. A fallback rate that rises unnoticed means users quietly get a worse answer while accuracy on the requests the model did answer looks fine.
- Front
- Name the ML-specific risk factors from the technical debt paper and a defence for one.
- Back
- From its abstract: boundary erosion, entanglement, hidden feedback loops, undeclared consumers, data dependencies, configuration issues, changes in the external world, system-level anti-patterns. Defence example: for undeclared consumers, version your outputs and keep a registry of who reads them. Every part needs an owner, a test and a monitor.
- Front
- What belongs in a fallback and human-review design?
- Back
- A fallback ladder (full model, cheaper model, cached or popular default, rule) decided in advance, timeouts shorter than each call's budget share, an explicit fail-open or fail-closed choice for safety checks, and human review for the uncertain middle band and costly errors. Reviewer capacity and alert fatigue limit how wide that band can be.
Training at scale: memory arithmetic, parallelism, mixed precision and scaling laws
- Front
- How much memory per parameter does mixed-precision Adam need, and what is in it?
- Back
- 16 bytes, before activations. 2 for fp16 weights, 2 for fp16 gradients, and 12 for optimizer states (an fp32 copy of the weights plus two fp32 Adam moments). A 7B model needs 112 GB of state; 1.5B needs 24 GB; 70B needs 1,120 GB. Activations, buffers and fragmentation come on top.
- Front
- Which memory line item grows with batch size and sequence length?
- Back
- Activations. Weights, gradients and optimizer states depend on the parameter count and the optimizer. So a model whose state fits can still run out of memory when you raise the batch, and the fixes (smaller micro-batch, checkpointing) target activations.
- Front
- What is the linear scaling rule, and why warmup?
- Back
- Multiply the batch by k, multiply the learning rate by k, keep other hyperparameters. It assumes the gradient barely changes over k steps, which fails early in training, so ramp the rate gradually to the target. In the ImageNet study it held from batch 64 to 8,192 and degraded after. Re-tune for adaptive optimizers.
- Front
- How do you accumulate gradients correctly, and what does it not fix?
- Back
- Add the per-sample gradients of each micro-batch and divide by the total number of samples once, so a short last chunk counts for its size. In the lesson script the weighted result matched -28.885, an unweighted mean gave -35.375 and an undivided sum -106.125. Batch norm still sees only the micro-batch. For token-level losses (causal LMs), sum the token losses and divide by the total non-padding tokens of the effective batch, not by an average of per-micro-batch means.
- Front
- Why master weights, loss scaling, and dynamic scale in fp16 training?
- Back
- Master weights, because 1.0 + 0.0001 rounds back to 1.0 in fp16, so small updates must accumulate in fp32 (100 updates give 1.0100 against 1.0). Loss scaling, because a gradient of 1e-8 flushes to 0 in fp16 and is kept at scale 1,024. Dynamic scale, because too large a scale overflows to infinity (max 65,504): skip the step and halve on overflow, double after a clean run.
- Front
- What does DDP do, and what does it not do?
- Back
- Every device holds a full model copy, runs its slice of the batch, and the gradients are averaged with a bucketed all-reduce overlapped with the backward pass, so all copies apply the same update. It does not reduce memory per device. Ring all-reduce time is about 2S/B almost regardless of the device count.
- Front
- What do the ZeRO stages shard, and what does FSDP call them?
- Back
- Stage 1 shards optimizer states, stage 2 adds gradients, stage 3 adds weights. For a 7B model on 8 devices that is 38.5, 26.2 and 14.0 GB against 112 GB. Stage 3 costs about 50% more communication in the paper. FSDP FULL_SHARD is the stage-3 analogue and SHARD_GRAD_OP the stage-2 analogue; HYBRID_SHARD shards in a node and replicates across nodes. PyTorch 2.15 also ships FSDP2 (fully_shard, per-parameter DTensor sharding) and suggests FSDP1 users consider migrating.
- Front
- Tensor versus pipeline parallelism. Where does each run, and what is the bubble?
- Back
- Tensor parallelism splits matrices inside a layer and communicates in every layer, so keep it inside a server. Pipeline parallelism splits layers into stages and passes activations. The bubble is the idle share, (p - 1) / (m + p - 1): 8 stages with 63 microbatches give 10%. More stages need more microbatches, so a bigger batch.
- Front
- What does activation checkpointing trade, and how much?
- Back
- Memory for compute. Keep k segment boundaries and recompute the rest in the backward pass. Peak is about k + n/k layer units, best near the square root of n (100 layers: 100 units down to 20). The price is one extra forward pass, about a third more compute if backward is twice forward. Chen et al. report about 30% more time.
- Front
- How do you tell a data-loader bottleneck, and how many workers do you need?
- Back
- Accelerator utilisation is low and step time falls when you add loader workers or does not depend on the model. A step takes max(compute, load / workers). With compute 0.25 s and load 0.9 s per worker, 1 to 4 workers give 0.9, 0.45, 0.3 and 0.25 s. Workers beyond 4 change nothing.
- Front
- What goes in a checkpoint, and how often should you write one?
- Back
- Weights, optimizer states, schedule and step position, data position and random states, written per shard in sharded training so they can reshard on load. First-order best interval is sqrt(2 x write x MTBF): 3 min write and a failure every 360 min give 46.5 min and about 13% of time lost. Reproducible experiments, not bit-identical runs.
- Front
- Estimate the cost of training a model.
- Back
- FLOPs about 6ND (N parameters, D tokens: 2N forward, 4N backward per token), days = FLOPs / (devices x peak x utilisation x 86,400). 7B parameters on 1T tokens is 4.2e22 FLOPs, 3.96 days on 1,024 devices at an assumed 300 TFLOP/s peak and 40% utilisation. State the assumptions. The rule ignores attention cost. Against the paper's 5.76e23 for Gopher's budget, 6ND is 12.5% low for Gopher and 2.1% high for Chinchilla.
- Front
- What did Kaplan and Hoffmann find about model size and data?
- Back
- Kaplan et al.: loss follows power laws in size, data and compute, and large models on modest data are compute-efficient. Hoffmann et al.: scale model size and tokens in equal proportion. Chinchilla (70B, 1.4T tokens) beat Gopher (280B, 300B tokens) at the same compute. About 20 tokens per parameter is that one result's ratio, not a law, and ignores serving cost.
The ML interview playbook: structure, answer method, debugging procedures, estimates and project defence
- Front
- Name the common ML interview round types and the method for each.
- Back
- Fundamentals (ladder: intuition, maths, code, pitfall), coding (clarify, simple version, edge cases, then speed), system design (nine steps), applied case (ten-step method), project deep dive and behavioural (STAR). This is a common pattern, not a verified list for any company, so ask the recruiter what each round covers.
- Front
- How should you treat the six-round map of an ML interview loop?
- Back
- As a common pattern. Loops differ by company and level, rounds overlap (a coding question can turn into how you would evaluate it), and names vary. Check the actual loop with the recruiter.
- Front
- List the ten steps of the answer method for an open ML question.
- Back
- 1 Clarify, 2 state assumptions, 3 baseline, 4 metric, 5 data, 6 model, 7 evaluation, 8 failure modes, 9 trade-offs, 10 monitoring. Say the step names aloud so the interviewer can redirect you. The baseline and metric come before the model.
- Front
- What is the ladder for explaining a concept, and which rung signals experience?
- Back
- Intuition, maths, code, pitfall. The pitfall rung (when it fails, what is commonly misread) signals that you have used the idea. Stop at the rung where the interviewer signals enough.
- Front
- What do you do when you are stuck or cannot recall a formula?
- Back
- Restate the question, start from the smallest case, state assumptions, name a baseline, or ask a clarifying question. Say plainly that you do not remember the exact form, then give the idea and how you would derive it. Do not invent a half-remembered formula.
- Front
- Loss is NaN. What is the first step?
- Back
- Find the first step at which anything is non-finite before changing anything. NaN at step 0 points to data, labels or the loss code (log of zero, softmax overflow). A loss that rose first points to a too-high learning rate. A sudden jump points to a bad batch or a division by zero variance.
- Front
- Loss is flat from step 1. What is the first step?
- Back
- Check the starting loss against the expected value (about ln C for C classes, since a uniform prediction gives ln C), then try to overfit a tiny batch. If it cannot, suspect a pipeline bug. If it can, tune the learning rate, initialisation or normalisation.
- Front
- Validation score is too good to be true. Name three checks.
- Back
- Each catches a different leak. Shuffle the labels and rerun the whole pipeline: a score well above chance means label-using preprocessing (target encoding or feature selection on all rows). Count ids shared between training and validation: group leaks. Inspect the top feature: proxies known only after the outcome (a proxy falls to chance on shuffled labels, so the shuffle misses it). In the script a proxy scored AUC 1.000 against 0.718 for an honest feature, the chance baseline on shuffled labels was 0.503, and a target-encoded noise category scored 0.758, still 0.784 on shuffled labels.
- Front
- Offline metric up, A/B flat. In what order do you check?
- Back
- Cheapest first: the experiment itself (assignment, sample ratio, power), then serving features against training features (skew), then whether the offline metric matches the business metric, then novelty or interference. Do not extend the test until it turns significant.
- Front
- Give the base-rate formula and the worked example.
- Back
- PPV = pi s / (pi s + (1 - pi) f). With 10,000 people, 1% sick, 99% sensitivity and a 5% false-positive rate: 99 sick positives and 495 healthy positives, so 99 / 594 = 0.1667.
- Front
- Why compute the majority baseline, and what did the script show?
- Back
- Accuracy means nothing without it. With 100 frauds in 10,000, always predicting legitimate scores 0.9900. A model at 0.9920 accuracy had precision and recall of 0.60 each, which is what tells its story.
- Front
- How do you count parameters and forward FLOPs of a dense network?
- Back
- A layer has in x out weights plus out biases. A forward pass costs about 2 x batch x in x out operations. Widths 784, 256, 128, 10 give 235,146 parameters (0.94 MB in fp32) and 469,504 operations per example. State your throughput assumption (an assumed 10 GFLOP/s gives 3.0 ms for a batch of 64).
- Front
- How sure is 182 correct out of 200, and why is 3 points over 176 not a claim?
- Back
- The 95% Wilson interval is 0.862 to 0.942, against 0.828 to 0.918 for 176 of 200, so they overlap heavily. With ten times the data they are 0.897 to 0.922 and 0.865 to 0.894. Both models share the test items, so compare them with a paired test.
- Front
- What does a strong project story contain beyond STAR?
- Back
- The baseline you compared against, the evaluation design (split by time or group, leakage checked), a measured result with its uncertainty, and what you would change. One university career centre (UW) suggests roughly 20% situation, 10% task, 60% action and 10% result. Claim only what you measured.
- Front
- Name five common traps in ML interview answers.
- Back
- Hand-waving, a metric without a baseline, ignoring leakage, jumping to a model before the frame, false precision, reciting without a failure case, silence, bluffing a formula, over-claiming a team's work.
- Front
- What is a repeatable mock-interview routine?
- Back
- Short daily drills (90 seconds aloud), a weekly 45-minute mock (5 intro and project, 12 fundamentals, 25 design or coding, 3 your questions), and a one-line rule for each miss, re-answered cold a few days later. That time split is this course's suggestion, not a rule.