Anthropic interview questions
AI lab · 10 questions reported
- junior 0
- mid 3
- senior 7
These are 10 technical questions candidates reported being asked in Anthropic interviews for AI engineer, ML engineer and applied AI engineer roles, each with a model answer you can say out loud in a minute or two. They cover latency & throughput, attention, where the time goes, cost per request, structured outputs and fine-tuning & alignment: 0 junior, 3 mid-level and 7 senior questions. Every question comes from a public interview write-up that names Anthropic.Updated
Anthropic attention and the transformer block questions
Model answer
def sdpa(q, k, v, mask=None): # mask True = may attend
s = q @ k.transpose(-2, -1) / q.size(-1) ** 0.5
if mask is not None:
s = s.masked_fill(~mask, float("-inf"))
s = s - s.amax(-1, keepdim=True)
p = s.exp()
return (p / p.sum(-1, keepdim=True)) @ v
Scale by √d so scores don't saturate softmax. Subtract the row max before exp so nothing overflows; torch's softmax does this internally. A fully masked row gives NaN, since max minus max is inf minus inf, so guard it. In FP16, compute scores and softmax in FP32. FlashAttention does the same blockwise with a running max.
Anthropic latency, throughput and goodput questions
Model answer
Batch at the iteration level: with continuous batching, finished sequences leave and queued ones join every decode step, so short requests never wait for long ones. The scheduler admits work while KV-cache memory allows, using paged allocation, and chunks long prefills so they don't stall decodes.
Scroll sideways to see the whole diagram
Two requests are decoded together: A needs 8 more tokens, B needs 64.
Text version
- Two requests are decoded together: A needs 8 more tokens, B needs 64.
- In request-level batching the batch finishes together. A's reply is ready after 8 steps but waits 56 more for B.
- In continuous batching A is returned as soon as its last token is generated.
- Its seat is filled by a waiting request at the very next step, so the batch stays full.
- Orca calls this iteration-level scheduling: the batch is decided again before every step.
After AI Engineering, Ch. 9, "Batching", and Orca (Yu et al., OSDI 2022). Illustrative lengths.
Route by queue depth and free cache, preferring a replica that holds the prompt prefix. Autoscale on queue length and time to first token, not GPU utilisation, keep warm spares because loading weights is slow, and shed batch traffic first under overload.
Model answer
If a batch costs 100 ms whatever its size, throughput is batch size divided by 0.1 s, so bigger batches are free until memory runs out. Latency is the wait for the next batch plus 100 ms. A batcher fires when the batch fills or a timeout expires. Bound the queue and reject when full, so latency stays predictable. For long generations, batch per decode step instead.
Model answer
Three jobs. Admission: per-tenant quotas counted in tokens, not requests, with token buckets and priority classes so interactive traffic beats batch. Fair scheduling inside each replica: weighted fair queuing across tenants, so one heavy tenant can't fill every batch slot. Routing: choose replicas by load and prefix-cache affinity, so repeated system prompts hit warm KV cache, spilling over when a replica runs hot.
Scroll sideways to see the whole diagram
Put what never changes first. The cache can reuse everything up to the first token that differs.
Text version
- Put what never changes first. The cache can reuse everything up to the first token that differs.
- Put something that changes at the top, like a date, and the match ends at token one: nothing is reused.
- This is not a provider quirk. Through attention, each position's keys and values depend on everything before it, so only an identical prefix gives identical values.
Matching rule: Anthropic and OpenAI prompt-caching docs (fetched 2026-10-21). Illustrative prompts.
Track time to first token and per-token latency per tenant against SLOs, and under overload shed the lowest priority first with retry-after errors.
Anthropic where the time goes: bandwidth, batching and memory questions
Model answer
Write the three costs down, then compare times.
# d model, f hidden (often 4d), T tokens, bf16
flops = 2 * (2 * T * d * f) # two matmuls
w_bytes = 2 * d * f * 2 # both weights
act_bytes = T * (2 * d + f) * 2 # in, out, hidden
# tensor parallel over n GPUs: one all-reduce of T*d
comm = 2 * (n - 1) / n * T * d * 2 # bytes per GPU
t_compute = flops / n / peak_flops
t_hbm = (w_bytes / n + act_bytes) / hbm_bw
t_net = comm / link_bw
Scroll sideways to see the whole diagram
Every forward pass has to bring the model's weights from memory to the arithmetic units: about 498 MB for GPT-2 small in 32-bit floats.
Text version
- Every forward pass has to bring the model's weights from memory to the arithmetic units: about 498 MB for GPT-2 small in 32-bit floats.
- A decode step does that whole read to produce one token for one sequence, plus that sequence's KV cache. About 2 operations per weight, 4 bytes per weight: half an operation per byte.
- Decode 8 sequences together and the same read serves all 8. Only the KV caches grow with the batch.
- Prefill pushes every prompt token through in one pass, so one read of the weights serves all 960.
- Operations per byte decides the limit. Few, and the chip waits on memory; many, and it waits on arithmetic. The next pages measure both on one laptop.
GPT-2 small (124,439,808 weights, float32); KV cache from the Module 01 formula at a 128-token context.
The largest time binds. With few tokens, as in decode, intensity is roughly T FLOPs per byte, below a GPU's FLOPs-to-bandwidth ratio, so HBM binds; big prefill batches turn compute-bound. Sharding divides compute and weights by n but not the all-reduce, so over slow inter-node links the network binds.
Anthropic cost per request questions
Model answer
Clients submit a job with an idempotency key; the API stores it durably and returns a job id, the same id for any retry. Jobs queue per tenant and priority, with quotas against starvation.
Workers resolve the prompt version pinned in the request, route to a model by task and budget, and store results; clients poll or get a signed webhook. Control cost with token estimates at admission, budget caps, batch APIs for non-urgent work, prompt caching and per-tenant metering. Failures back off, then dead-letter.
Anthropic examples and structured outputs questions
Model answer
Don't parse generated text; read the next-token distribution after the prompt.
import torch
def p_yes(logits, yes_ids, no_ids):
# logits: (V,) next-token logits
lp = logits.log_softmax(-1)
ly = torch.logsumexp(lp[yes_ids], -1)
ln = torch.logsumexp(lp[no_ids], -1)
return torch.sigmoid(ly - ln)
Each label has several token spellings, so combine each group with log-sum-exp, then renormalise over the two groups: a sigmoid of the difference. Threshold it after calibrating on labelled data, since raw probabilities are often skewed, and check token ids, because a leading space changes them.
Anthropic fine-tuning and alignment questions
Model answer
GRPO samples a group of answers per prompt, scores them, and uses each answer's reward minus the group mean, over the group's standard deviation, as its advantage: no value model needed. The ratio is the new policy's probability of a token over the old policy's that sampled it, clipped near 1 as in PPO. Typical bugs: the ratio built from the wrong log-probs, such as the reference model's, or not detached; a missing exp of the log difference; padding left unmasked; advantages normalised over the batch instead of the group.
Anthropic mixture of experts and parallelism questions
Model answer
Count every live tensor.
# Y = X @ W; X (m, k), W (k, n); bf16 = 2 bytes
fwd = 2 * (m * k + k * n + m * n)
# m = k = n = 65536: 8 GiB each, 24 GiB total
Training adds gradients, and mixed-precision Adam needs about 16 bytes per parameter with its FP32 copies. Tensor parallelism splits W itself, so each GPU holds a slice and every step needs an all-reduce or all-gather, best over NVLink. Pipeline parallelism gives whole layers to stages and passes only activations, fine across nodes but with bubbles. It can't split a single matmul too big for one GPU; tensor parallelism can.
Anthropic mL system design questions
Model answer
size = 500e9 # bytes
link = 10e9 / 8 # 1.25e9 bytes per second
t_floor = size / link # 400 s per receiver
t_naive = 1000 * t_floor # 4e5 s from one source
Each worker must receive 500 GB through its own 10 Gbps link, so 400 seconds is the floor; serving everyone from one source takes about 4.6 days. To approach the floor, every receiver also uploads: split weights into chunks and pipeline them down chains or trees, or swarm BitTorrent-style. Time becomes roughly 400 s plus a few chunk times per hop. Respect topology: one copy crosses each rack uplink, then fans out locally. Checksum chunks and resume on failure.
Each question comes from a public interview write-up or video that names Anthropic; the answers are ours. Not affiliated with Anthropic.