LLMs
Transformer basics at interview depth
Attention, prefill vs decode, mixture-of-experts and positional encodings — enough to reason about cost and behaviour.
What it is and why it exists
A decoder-only transformer turns tokens into vectors, then stacks layers of self-attention (each token looks at earlier tokens) and feed-forward blocks, and finally predicts a distribution over the next token. Attention cost grows with sequence length; positional schemes like RoPE tell the model token order; mixture-of-experts layers route each token to a few expert networks, so a model can have many parameters but use only some per token.
Quick prototype
Not something you build — you need it to explain trade-offs.
In production, at scale
Use it to reason: why long prompts raise TTFT (prefill over all tokens), why decode is memory-bound (read all weights per token), why MoE models are cheap per token but need lots of memory, why context extension tricks degrade recall.
Vendors and tools
| “Attention Is All You Need” | The 2017 paper |
|---|---|
| nanoGPT / minGPT | Small, readable implementations |
| FlashAttention | IO-aware exact attention kernels |
How it fails
- Hand-waving “it predicts the next word” when asked why something is slow or expensive
What the interviewer asks next
Why is decoding memory-bandwidth bound?
Each new token needs a pass over all the weights (and the KV cache) but does little arithmetic per byte read, so the GPU waits on memory. Batching many sequences shares each weight read.
What does mixture-of-experts buy you?
Each token activates only a few experts, so compute per token is like a much smaller model while total capacity is large. The catch: all experts must sit in memory.