ML Systems interview questions: serving, pipelines, drift and monitoring

Reviewed by Mark Dickie · Last updated

5 questions on this page you can answer and see marked on the spot. Go to the first one

ML systems are the pipelines, services and monitoring that take a machine learning model from a notebook to a production product that keeps working. Interviewers expect you to reason about the whole loop: data ingestion, training, deployment, and what happens when live data stops looking like training data. Strong answers name a failure mode, such as training-serving skew or silent drift, and say how you would detect and fix it.

What does an ML systems interview test?

Questions usually cluster around a few areas. Each one has a concrete mechanism you should be able to explain.

AreaConcrete topic to know
Data and featuresFeature stores, point-in-time joins, label leakage
TrainingDistributed data parallelism, checkpointing, hyperparameter search
ServingOnline vs batch inference, dynamic batching, canary and shadow deploys
MonitoringPopulation stability index, prediction drift, delayed labels
ReliabilityTraining-serving skew, rollback of model versions, latency budgets

How should I prepare for ML systems interview questions?

Work through these steps in order, and sketch each one on paper before you check an answer.

  1. Draw an end-to-end design for a recommender or fraud model, from raw events to a served prediction.
  2. Explain how you would stop the same feature from being computed two different ways in training and in serving.
  3. Pick a latency target and describe how batching, quantization or caching would help you meet it.
  4. List which metrics you would alert on when ground-truth labels arrive days late.
  5. Describe a rollout plan that lets you revert a bad model within minutes.

Key facts

  • Tarmac has 315 ML Systems interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 144 job postings asking for ML Systems in November 2026.
  • Roles asking for ML Systems advertise a median base salary of US$219,393, across 16 job postings as of November 2026.
  • Tarmac last reviewed these ML Systems interview questions on 5 December 2026.

At a glance

Questions10 shown · 315 in the bank
Difficulty1–5 of 5
FormatsTrue / false, Ordering, Find the bug, Multiple choice, Short answer, Fill in the blank, Multiple answer, Code output, Flashcard, Design exercise

What you'll review

  1. mls sparse attention patterns
  2. mls sparse tensor formats
  3. mls structured vs unstructured sparsity
  4. mls attention memory cost

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

In sparse attention mechanisms, a "local window" pattern restricts each query token to attend only to a fixed number of neighboring tokens (e.g., within a window of ±w positions), rather than attending to all tokens in the sequence.#

Options

Show answer

True. A local-window sparse attention pattern restricts each query token to attend only to a fixed contiguous neighborhood of surrounding tokens (e.g., ±w positions) instead of every token in the sequence, reducing the quadratic cost of full self-attention to linear in sequence length.

Why:

A local (or sliding-window) attention pattern limits each query to a contiguous neighborhood around its position, which is the defining characteristic of local-window sparse attention.

Arrange the three core steps of the standard two-pass algorithm to convert a dense matrix into Compressed Sparse Row (CSR) format in the correct sequential order.#

Put these in order

Show answer

The correct order is: (1) count non-zeros per row, (2) compute the row_ptr array as the exclusive prefix sum of those counts, then (3) fill the column index and value arrays by traversing the matrix row by row using row_ptr for offsets. Each step strictly depends on the previous: prefix sum needs the counts, and filling needs the offsets from row_ptr.

Why:

In the standard two-pass CSR construction, you first count non-zeros per row because the counts are needed to determine where each row's entries begin. The exclusive prefix sum of those counts produces the row_ptr array, giving the starting offset for each row. Only after row_ptr is known can you traverse the dense matrix a second time and place each non-zero's column index and value at the correct position in col_ind and vals. Each step strictly depends on the output of the previous one.

The function below is intended to apply structured sparsity by pruning entire attention heads whose average weight magnitude falls below a threshold. A bug causes it to behave differently than intended. Identify the buggy line(s).#

import numpy as np

def prune_attention_heads(weights, num_heads, sparsity_threshold):
    """Prune entire attention heads whose average weight magnitude
    is below sparsity_threshold (structured sparsity).
    weights shape: (num_heads, seq_len, seq_len)"""
    for h in range(num_heads):
        head_magnitude = np.mean(np.abs(weights[h]))
        if head_magnitude < sparsity_threshold:
            weights[h][np.abs(weights[h]) < sparsity_threshold] = 0
    return weights

Options

Show answer

Line 10 zeros individual elements within the head instead of the entire head, turning structured pruning into unstructured pruning

Why:

The function's docstring says it should prune entire attention heads (structured sparsity). Line 10 uses weights[h][np.abs(weights[h]) < sparsity_threshold] = 0, which zeros individual elements within the head that fall below the threshold, rather than zeroing the entire head with weights[h] = 0. This converts the operation from structured (whole-head) pruning into unstructured (element-wise) pruning, defeating the purpose of the structured sparsity approach that is hardware-friendly because it eliminates entire heads.

In standard (non-sparse) self-attention, for an input sequence of length n with embedding dimension d, what is the memory complexity of storing the full attention score matrix (the softmax inputs, before any masking or sparsification)?#

Options

Show answer

The full attention score matrix in standard self-attention requires O(n²) memory because it stores one logit for every pair of tokens in the sequence. This quadratic scaling with sequence length is the core memory bottleneck that sparse-attention mechanisms aim to reduce.

Why:

Standard self-attention computes QKᵀ, producing an n×n matrix of attention logits. Storing this matrix requires memory proportional to n², regardless of the embedding dimension d. This quadratic growth in sequence length is the principal memory bottleneck of dense attention and the motivation behind sparse and linear-attention variants.

BigBird combines three types of attention patterns to achieve O(n) complexity while preserving the theoretical expressiveness of full attention. Name all three component patterns.#

Show answer

BigBird uses (1) global tokens (a small set of tokens that attend to and are attended by all positions), (2) windowed/local attention (each token attends to its immediate neighbors within a sliding window), and (3) random attention (a small number of randomly chosen edges between token pairs).

Why:

BigBird (Zaheer et al.) combines global attention, local/windowed attention, and random attention. The combination of these three sparse patterns is what allows BigBird to approximate full attention's expressiveness while reducing the O(n²) cost to O(n).

In neural network pruning, _____ sparsity removes individual weight elements at arbitrary locations, producing an irregular nonzero pattern that standard accelerators cannot efficiently load or compute. In contrast, _____ sparsity prunes entire blocks, channels, or fixed-size groups of weights, preserving a regular memory layout that maps naturally to dense tensor-core operations on GPUs and other accelerators.#

Show answer

In neural network pruning, unstructured sparsity removes individual weight elements at arbitrary locations, producing an irregular nonzero pattern that standard accelerators cannot efficiently load or compute. In contrast, structured sparsity prunes entire blocks, channels, or fixed-size groups of weights, preserving a regular memory layout that maps naturally to dense tensor-core operations on GPUs and other accelerators.

Why:

Unstructured sparsity zeros out individual weights at arbitrary positions, which creates an irregular memory access pattern that general-purpose accelerators cannot exploit without specialized sparse kernels. Structured sparsity removes entire contiguous groups (blocks, channels, or N:M groups), keeping the nonzero pattern regular so that dense hardware pathways—like GPU tensor cores—can still be used efficiently, trading some flexibility for real wall-clock speedup.

In standard (non-sparse) multi-head self-attention with sequence length N, head dimension d, and number of heads H, several intermediate tensors are materialized during the forward and backward passes. Which of the following tensors have memory footprint that scales quadratically with sequence length N (i.e., O(N²) per layer, holding d and H constant)?#

Options

Pick every one that applies.

Show answer

The quadratic-memory tensors in standard self-attention are the pre-softmax score matrix QKᵀ (N×N), the softmax-normalized attention weight matrix (N×N), and the backward-pass gradient of the attention weights (N×N) — all O(N²) per head. The query projection Q (N×d) and the output projection (N×H·d) are only linear in N, so they do not contribute to the quadratic bottleneck.

Why:

The quadratic memory cost of standard self-attention comes from the N×N attention matrix and its intermediates. The pre-softmax score matrix S = QKᵀ is (N, N) per head — O(N²). The post-softmax attention weights A have the same (N, N) shape — O(N²). During backpropagation, the gradient dL/dA is also (N, N) per head — O(N²). In contrast, the query projection Q is (N, d) — O(N·d), linear in N. The output projection is (N, H·d) — also linear in N. Thus the quadratic bottleneck in self-attention memory is precisely the attention matrix and its forward/backward intermediates, not the feature projections.

A sparse attention weight matrix is stored in COO (Coordinate) format. The code below reconstructs the dense matrix, accumulating values at duplicate coordinates (as PyTorch's to_dense does). What is the exact output printed?#

import numpy as np

# COO triples for a 3x3 sparse attention matrix
rows = np.array([0, 1, 1, 2, 1])
cols = np.array([0, 2, 2, 1, 2])
vals = np.array([3, 5, 7, 1, -2])

dense = np.zeros((3, 3), dtype=int)
for r, c, v in zip(rows, cols, vals):
    dense[r, c] += v

print(dense)
Show answer
[[ 3  0  0]
 [ 0  0 10]
 [ 0  1  0]]
Why:

COO stores (row, col, value) triples. When duplicates exist, standard implementations accumulate by summation. Tracing each entry: (0,0,3)→dense[0,0]=3; (1,2,5)→dense[1,2]=5; (1,2,7)→dense[1,2]=12; (2,1,1)→dense[2,1]=1; (1,2,−2)→dense[1,2]=10. The duplicate at (1,2) appears three times with values 5, 7, and −2, summing to 10.

In the Sparse Transformer (Child et al., 2019), three classes of sparse attention patterns are proposed to reduce the full O(n²) attention to O(n·√n). Name the two positionally-determined pattern types and describe the key structural difference between them.#

Show answer

Local window (a.k.a. fixed dense blocks): each query attends to a fixed-size neighborhood of adjacent keys — a contiguous local band around the diagonal of the attention matrix. Strided: each query attends to keys at fixed stride intervals (every √n-th key), so attention 'jumps' across the sequence rather than clustering around the diagonal. The critical distinction: local blocks capture local context (adjacent positions), while strided blocks capture periodic/distant relationships by sampling at regular geometric intervals. Both are determined purely by position, not content, so the mask can be precomputed and compiled into block-sparse kernels (e.g., cuSparse) without runtime data dependence.

Why:

This is a difficulty-5 (staff/internals) card because it requires understanding the type-level taxonomy of sparse attention patterns and the hardware-compiler implication that positionally-determined patterns enable static mask compilation — a distinction central to why block-sparse kernels achieve real speedups while content-based patterns often do not.

You are designing the serving backend for a 70B-parameter LLM that must support up to 128K-token contexts on a single 8×H100 GPU node. The attention computation dominates latency and HBM traffic at this sequence length. Your team proposes to exploit sparsity in the attention matrix to reduce the O(N²) cost. There are two families of sparsity you can target:#

Show answer

I would build the attention subsystem around block-structured sparsity with a two-phase approach: a lightweight scoring phase to select which KV blocks each query block should attend to, followed by a block-sparse attention kernel for the selected blocks.

Sparsity pattern determination (dynamic): At each generation step, I compute a coarse attention score for each (query-block, key-block) pair using a downsampled representation — e.g. compute the mean query vector per block and dot it with the mean key vector per block, or use a small learned projection (a 1-2 layer MLP on flattened block features) that outputs a relevance logit per block. I then apply top-k block selection with a configurable budget k (e.g. keep the top 16 of 128 key blocks for a 128K context). The pattern is fully dynamic per inference call — the block scores are computed from the actual query/key states. I also support a static fallback pattern (fixed local window + strided blocks) for the first decode step where query statistics are not yet available.

Structured vs unstructured sparsity and hardware: I choose structured (block) sparsity over unstructured because of how GPUs execute attention kernels. Unstructured sparsity — skipping individual (q, k) pairs — produces irregular memory access patterns: the loads from the KV cache become non-contiguous, memory coalescing breaks down, and the computation cannot be mapped onto tensor-core matrix-multiplies (which require dense tile shapes like 16×16 or 128×128). The resulting kernel either falls back to scalar processing or requires expensive gather operations that negate the FLOP savings. Block-structured sparsity sidestokes this: if I choose a block size that is a multiple of the tensor-core tile dimensions (e.g. 64 or 128 tokens per block), each selected (query-block, key-block) tile is a dense GEMM that maps directly to tensor cores. The selection mask is a block-sparse Boolean matrix that can be compiled into a series of dispatched GEMM calls (or a single grouped-GEMM kernel), preserving memory coalescing and enabling kernel fusion of the softmax with the QK and PV products within each block. The overhead of the scoring phase is O(N · N_blocks) with a small constant (one dot product per block pair), which is negligible compared to the full O(N²) dense attention.

Sparsity-ratio vs approximation error: I expose the block budget k and the block size B as configurable knobs. I set defaults by sweeping over a held-out eval set of long-context tasks (e.g. needle-in-haystack, long-document QA, summarization perplexity) and measuring downstream quality vs. wall-clock latency. I set k per-layer: early layers attend more broadly (higher k) since they tend to need wider context for positional/syntactic features, while later layers can be more aggressively sparse. I also implement an adaptive mode where if the top-block scores are all near-uniform (no clear selection), I fall back to dense attention for that layer/step to avoid dropping a high-entropy head that needs everything. Quality is continuously monitored in the serving path via a lightweight perplexity probe on a held-out calibration set; if the running average exceeds a threshold, the system can automatically increase k or disable sparsity for the affected layers.

KV-cache layout and movement: The KV cache is organized in a paged layout with a fixed page size equal to the block size B (e.g. 64 tokens per page). Each layer/head's KV state is stored as a set of page tensors in HBM, and a block table maps logical block indices to physical pages — similar to vLLM's paged-attention. When a block is selected by the scoring phase, its KV page is loaded contiguously from HBM into SRAM for the tensor-core GEMM. Because the selected blocks are contiguous in the page table, the loads are coalesced. For tensor-parallel inference across the 8 GPUs, I shard the KV cache by head (not by sequence position), so each GPU holds a subset of heads' KV pages and only loads the blocks it needs for its own heads — no cross-GPU KV movement is needed during attention; the only all-reduce is over the attention output across heads. The scoring phase operates on a replicated or all-gathered coarse key summary (one vector per block), which is small (O(N_blocks · d_head)) compared to the full KV cache, so the communication overhead is minimal.

Why:

This design exercise tests deep understanding of how structured and unstructured sparsity interact with GPU execution characteristics in the context of long-context attention serving. A strong answer must address the hardware-level reasons structured sparsity is preferred (tensor cores, memory coalescing, kernel fusion), the data-dependent pattern determination, the quality-latency trade-off, and KV-cache layout implications — all of which are staff-level ML systems concerns.

Related interview questions

Job market

See ml-systems salaries and hiring demand from live job postings.

The other 305 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 305 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.