Home / Fundamentals

F1

Transformer Architecture

Tokenization, attention, positional encodings, normalization, mixture-of-experts, and the arithmetic of parameters, FLOPs and memory.

Guides

01

Tokenization and embeddings

How text becomes integer IDs and vectors: BPE from scratch, byte-level fallback, vocabulary-size trade-offs, tied embeddings and tokenizer pathologies.

12 min
02

Self-attention from first principles

Scaled dot-product attention with shapes and code, why √d_k, masking, multi-head attention, FLOP accounting, FlashAttention's online softmax, and MQA/GQA/MLA.

16 min
03

Positions, normalization and the residual stream

Sinusoidal, learned, RoPE and ALiBi positions; context extension; LayerNorm vs RMSNorm; pre-norm vs post-norm; SwiGLU; and the residual-stream view of a transformer.

15 min
04

The transformer by the numbers

Parameter counts, FLOPs per token for training and inference, the 6N rule, KV-cache size, MFU and worked examples you should be able to do on a whiteboard.

12 min

Interview questions

30-second answer plus a full 40-minute walkthrough for each.

Q1

What is a token, and why do LLMs use subword tokenization instead of words or characters?

Junior
Q2

Explain scaled dot-product attention, implement it, and justify dividing by √d_k.

Mid
Q3

Compare MHA, MQA, GQA and MLA. What problem do they solve?

Senior
Q4

Why is attention O(n²), how does FlashAttention help, and how do models handle long context?

Senior
Q5

How do rotary position embeddings (RoPE) work, and how do you extend a model's context length with them?

Senior
Q6

Why do modern LLMs use pre-norm and RMSNorm? What are the trade-offs?

Mid
Q7

Estimate the parameters, training FLOPs and training time for a 7B-parameter transformer.

Mid
Q8

How does a Mixture-of-Experts transformer work, and what are its training and serving challenges?

Senior
Q9

Why did transformers replace RNNs and LSTMs for language modelling?

Junior