Amazon interview questions
Big tech · 13 questions reported
- junior 1
- mid 6
- senior 6
These are 13 technical questions candidates reported being asked in Amazon 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 moe & parallelism, tokenization, attention, context & kv cache, latency & throughput and context selection: 1 junior, 6 mid-level and 6 senior questions. Every question comes from a public interview write-up that names Amazon.Updated
Amazon tokenization questions
Model answer
Train byte-level BPE on a sample of the real mix of languages and code, so nothing is unknown. Vocabulary size trades shorter sequences against bigger embedding and output tables. Add digit and whitespace rules and chat tokens.
KL-regularised SFT adds β times the KL divergence from a frozen base model's next-token distributions to the cross-entropy loss. It limits drift and forgetting; β sets how far it may move.
Amazon attention and the transformer block questions
Model answer
import math
def sigmoid(x):
if x >= 0:
return 1 / (1 + math.exp(-x))
e = math.exp(x) # x is negative: no overflow
return e / (1 + e)
def softmax(xs):
m = max(xs) # shift so the largest exp is 1
es = [math.exp(x - m) for x in xs]
s = sum(es)
return [e / s for e in es]
def attention(Q, K, V):
d = len(Q[0])
out = []
for q in Q:
scores = []
for k in K:
dot = 0.0
for a, b in zip(q, k):
dot += a * b
scores.append(dot / math.sqrt(d))
w = softmax(scores)
row = [0.0] * len(V[0])
for wi, v in zip(w, V):
for j in range(len(v)):
row[j] += wi * v[j]
out.append(row)
return out
The trap is overflow: exp of a large number blows up. Branch sigmoid on the sign, and subtract the max before softmax, which leaves the result unchanged. Attention is then dot products, scaled by √d, a softmax per query, and a weighted sum of values.
Amazon context windows and the KV cache questions
Model answer
Write it once as GQA: plain MHA is the case where key-value heads equal query heads, and multi-query is one key-value head.
import torch, torch.nn as nn, torch.nn.functional as F
class GQA(nn.Module):
def __init__(self, d, n_q, n_kv):
super().__init__()
self.hd, self.nq, self.nkv = d // n_q, n_q, n_kv
self.q = nn.Linear(d, d, bias=False)
self.kv = nn.Linear(d, 2 * n_kv * self.hd,
bias=False)
self.o = nn.Linear(d, d, bias=False)
def forward(self, x, cache=None):
B, T, _ = x.shape
q = self.q(x).view(B, T, self.nq, self.hd)
k, v = self.kv(x).view(
B, T, 2, self.nkv, self.hd).unbind(2)
q, k, v = (t.transpose(1, 2) for t in (q, k, v))
if cache is not None:
k = torch.cat([cache[0], k], dim=2)
v = torch.cat([cache[1], v], dim=2)
cache = (k, v) # n_kv heads: the memory saving
r = self.nq // self.nkv
k = k.repeat_interleave(r, dim=1)
v = v.repeat_interleave(r, dim=1)
S = k.shape[2] # cached + new positions
# new query i sits at position S - T + i
m = torch.ones(T, S, dtype=torch.bool,
device=x.device).tril(S - T)
a = q @ k.transpose(-2, -1) / self.hd ** 0.5
a = a.masked_fill(~m, float("-inf"))
y = F.softmax(a, dim=-1) @ v
y = y.transpose(1, 2).reshape(B, T, -1)
return self.o(y), cache
Interviewers check three things: the mask is offset by the cached length, the cache stores keys and values before repeating them, so it shrinks by the group factor, and cached decoding reproduces a full forward pass token for token.
Amazon latency, throughput and goodput questions
Model answer
A decoder-only model runs prefill, then one decode step per token, and decode is memory-bound, so the win is batching many requests.
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.
Continuous batching adds and removes requests at every step instead of waiting for a whole batch to finish. PagedAttention stores each request's KV cache in fixed-size blocks, like memory pages, so nothing is reserved for the maximum length and wasted: more requests fit, and shared prefixes can share blocks.
Amazon selecting, ordering and compressing context questions
Model answer
First find which cost hurts: attention compute grows quadratically with length and dominates long prefills, while the KV cache grows linearly and caps decode batch size.
Exact fixes first. FlashAttention tiles the work in on-chip memory, never storing the n × n score matrix: same result, memory linear in n. For the cache: grouped-query attention, quantisation, paged allocation.
Then approximations that change the model: sliding-window or sparse patterns like Longformer's local plus global attention, or linear-attention and state-space layers. Past one GPU, ring attention splits the sequence across devices. Re-check long-context quality.
Amazon prompt versions and regression tests questions
Model answer
Two loops. Offline: a versioned eval set scored by cheap deterministic checks first, like schema, required facts and banned content, then an LLM judge calibrated against human labels, gating every change. Online: the same checks on live outputs, sampled judge scores, and user signals such as retries, sliced by task. Failures flow back into the eval set, and humans review a sample so the judge doesn't drift.
Amazon retrieval-augmented generation questions
Model answer
Offline: parse documents, chunk on their structure, embed, and index chunks with metadata and permissions in a vector and keyword index, updated incrementally.
Scroll sideways to see the whole diagram
Search your own documents for passages related to the question, with keywords, embeddings or both.
Text version
- Search your own documents for passages related to the question, with keywords, embeddings or both.
- A reranker reads the question with each candidate and keeps the few that actually answer it.
- The kept passages go into the prompt, with instructions to answer only from them.
- The model answers from evidence in its context instead of memory alone, so the answer can be checked against its sources.
The pattern of Lewis et al. (2020), Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, as used in production systems.
Online: rewrite the query, run hybrid search filtered by the user's access, rerank, and pack the best passages into a prompt that says to cite them and abstain when the answer isn't there.
Around it: an eval set scoring retrieval and faithfulness separately, logged passages, caching, and a per-stage latency budget.
Amazon fine-tuning and alignment questions
Model answer
GRPO drops PPO's value network. It samples a group of answers per prompt and uses each answer's reward minus the group mean, over the group standard deviation, as its advantage, inside PPO's clipped objective with a KL penalty to a reference model. No critic saves memory.
Rollout workers run data-parallel inference; the trainer shards with FSDP or tensor and pipeline parallelism, syncing weights each step. Rewards should be verifiable, like exact answer match, unit tests or a format check, not a learned reward model that's easier to game.
Amazon agents questions
Model answer
It's a loop: observe, decide, act, check. Perception pairs a screenshot with the accessibility tree when one exists; the tree gives element names and ids, which are far more reliable to target than raw coordinates. Without one, mark candidate elements on the image and let the model pick a mark.
Scroll sideways to see the whole diagram
The context holds the tool definitions and the user's question.
Text version
- The context holds the tool definitions and the user's question.
- The model emits a structured call: a tool name and JSON arguments. With Anthropic's API the reply stops with stop_reason "tool_use".
- The call is text the model generated. Your code checks it before anything runs.
- Your code executes the function. The model has no hands: it only asked.
- The output goes back into the context (a tool_result block) and the model runs again, until it answers instead of calling.
After AI Engineering, Ch. 6 "Function calling", and Anthropic, "Tool use with Claude" (fetched 2026-10-21). Illustrative call.
Actions are typed tools: click, type, scroll, key press. After each, a fresh screenshot verifies the effect. Run in a sandboxed VM, treat on-screen text as data, not instructions, and ask the user before irreversible steps. Measure task success on benchmarks like OSWorld.
Amazon mixture of experts and parallelism questions
Model answer
An MoE layer swaps one feed-forward block for many experts and a small router that sends each token to the top few, often 2.
Scroll sideways to see the whole diagram
The feed-forward block is replaced by several experts, each its own feed-forward network, and a small router.
Text version
- The feed-forward block is replaced by several experts, each its own feed-forward network, and a small router.
- For each token the router picks the top 2 experts. The other 6 do no work for this token.
- The two outputs are mixed by the router's weights. Total parameters grow with the experts; compute per token stays near that of two.
Shazeer et al. (2017), Outrageously Large Neural Networks; Jiang et al. (2024), Mixtral of Experts (8 experts, top-2 routing).
Parameters grow, but each token uses a slice: Mixtral 8×7B has about 47B parameters and uses about 13B per token. Expert parallelism places experts on different GPUs and ships tokens to them in an all-to-all exchange, so the costs become communication and load balance.
Model answer
Tensor parallelism splits each weight matrix across GPUs, so every layer needs a collective step: fast only over very fast links, usually inside one machine. Pipeline parallelism gives each GPU a run of consecutive layers and passes activations along: little communication, but GPUs sit idle in the pipeline bubble unless the batch is split into micro-batches. Large runs combine both with data parallelism.
Model answer
All-reduce sums gradients across data-parallel replicas, and partial results in tensor parallelism. All-gather and reduce-scatter are its two halves: sharded training such as ZeRO or FSDP gathers each layer's weights just before use and reduce-scatters its gradients after. All-to-all routes tokens to experts in MoE. Each costs bytes over links, so a good layout puts the chattiest collectives on the fastest links.
Model answer
A transformer stacks blocks of attention, which mixes tokens, and an MLP, each with a residual. MoE swaps the MLP for many experts and a router picking a few per token.
Scroll sideways to see the whole diagram
The feed-forward block is replaced by several experts, each its own feed-forward network, and a small router.
Text version
- The feed-forward block is replaced by several experts, each its own feed-forward network, and a small router.
- For each token the router picks the top 2 experts. The other 6 do no work for this token.
- The two outputs are mixed by the router's weights. Total parameters grow with the experts; compute per token stays near that of two.
Shazeer et al. (2017), Outrageously Large Neural Networks; Jiang et al. (2024), Mixtral of Experts (8 experts, top-2 routing).
Training runs whole sequences in parallel under the causal mask; MoE adds a load-balancing loss so experts don't collapse. Inference prefills the prompt, then decodes token by token with a KV cache; every expert stays in memory though each token uses few.
Each question comes from a public interview write-up or video that names Amazon; the answers are ours. Not affiliated with Amazon.