4.3.1Pretraining & Fine-Tuning LLMs

GPT family architecture evolution

2,122 words10 min readdifficulty · medium1 backlinks

WHY does GPT exist at all?

WHAT is the objective? Maximize the probability of each next token given all previous tokens:


HOW is one GPT block built (from scratch)

A single decoder layer does two things: mix information across positions (attention) then process each position independently (MLP). Each is wrapped with a residual connection + normalization.

Figure — GPT family architecture evolution

The evolution timeline (WHAT actually changed)


Why scale works: the scaling laws (Forecast-then-Verify)


Common mistakes (Steel-man + fix)


Worked examples


Recall Feynman: explain to a 12-year-old

Imagine you're reading a sentence and covering the words after where you are, trying to guess the next word. GPT is a machine that plays this "guess the next word" game billions of times until it's amazing at it. Each version of GPT is the same game machine, just built bigger — more brain cells (parameters) and more books to read (data). The clever trick called "masking" is like a rule: you're not allowed to peek at words you haven't reached yet, so you truly learn to predict instead of copying the answer. When the machine got big enough, something magical happened: you could just show it a couple of examples in your question and it would figure out the pattern by itself — nobody had to retrain it.


Connections


Flashcards

What sub-part of the original Transformer does GPT keep?
Only the decoder (masked/causal self-attention stack); no encoder, no cross-attention.
What probability rule justifies the autoregressive factorization?
The chain rule of probability, applied repeatedly (telescoping) — it's exact, no approximation.
Why divide attention scores by dk\sqrt{d_k}?
The dot product's variance grows as dkd_k; dividing keeps scores O(1)O(1) so softmax doesn't saturate and gradients don't vanish.
What is the role of the causal mask MM?
Sets scores for future positions to -\infty so they become 0 after softmax — prevents a token from seeing the future, enforcing autoregression.
Key architectural change from GPT-1 to GPT-2?
Move LayerNorm to pre-activation (pre-LN) inside the residual branch + add a final LayerNorm → stable deep training.
What emergent capability defined GPT-3?
In-context / few-shot learning — solving tasks from prompt examples with frozen weights, no fine-tuning.
GPT-3 parameter count and depth?
~175B parameters, 96 layers, d=12288, 96 heads, 2048 context.
What distinguishes GPT-3.5 (InstructGPT) — architecture or training?
Training: instruction tuning + RLHF (alignment). The backbone architecture is essentially unchanged.
What are GPT-4's widely-believed additions?
Multimodality (text + image) and Mixture-of-Experts; details undisclosed.
How does test loss scale with parameters NN?
As a power law L(N)(Nc/N)αNL(N)\approx(N_c/N)^{\alpha_N} with αN0.076\alpha_N\approx0.076; a straight line on a log-log plot.
Why use log-likelihood instead of raw likelihood?
Products of many small probabilities underflow; log turns products into sums with stable gradients.
Per-layer attention parameter count in terms of dd?
4d24d^2 (from WQ,WK,WV,WOW_Q,W_K,W_V,W_O), so params grow quadratically with width.

Concept Map

drop encoder

objective

chain rule

train via

built from

mixes positions

masked by

scale scores

per position

stabilized by

enables

drives

optimizes

2017 Transformer encoder-decoder

Decoder-only GPT

Autoregressive LM

Joint factorization

Cross-entropy NLL loss

Decoder block

Causal self-attention

Causal mask -inf on future

Divide by sqrt of d_k

Position-wise MLP 4d

Residual + pre-LN

Stack deeper and wider

GPT family evolution

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, GPT ki sabse badi baat yeh hai ki har naya version koi bilkul naya jaadu nahi hai — woh same decoder-only Transformer block hai, bas usko deeper aur wider bana diya aur zyada data pe train kiya. Original 2017 Transformer mein encoder aur decoder dono the, lekin GPT ne encoder phenk diya kyunki language modeling mein sirf "agla word predict karo" karna hai — future dekhne ki zaroorat hi nahi. Yeh "future mat dekho" wala rule causal mask se lagta hai, aur yahi GPT ka dil hai.

Training ka objective simple hai: chain rule of probability se poore sentence ka probability tod do next-token predictions mein, aur cross-entropy loss minimize karo. Attention mein jo dk\sqrt{d_k} se divide karte hain woh koi random cheez nahi — dot product ki variance dkd_k ke saath badhti hai, toh usko control karke softmax ko saturate hone se bachate hain. Yeh chhoti-chhoti baatein exam aur interview dono mein poochi jaati hain.

Evolution yaad rakhne ka short trick: GPT-1 ne fine-tuning introduce kiya, GPT-2 ne zero-shot dikhaya aur pre-LN ka stability trick laaya, GPT-3 (175B) ne few-shot in-context learning ka magic dikhaya — sirf prompt mein examples daal do, weights freeze rehte hain. GPT-3.5 ne RLHF se alignment kiya (architecture same), aur GPT-4 multimodal + Mixture-of-Experts maana jaata hai. 80/20 funda: 80% badlav sirf scale hai, baaki 20% yeh key tweaks — inhi 20% pe focus karo.

Aur ek important galti se bacho: log mat bhoolo ki GPT-3 ko har task ke liye fine-tune nahi kiya jaata — usko prompt hi mein examples dikha dete hain. Yeh in-context learning scale se emerge hoti hai, planned feature nahi thi.

Go deeper — visual, from zero

Test yourself — Pretraining & Fine-Tuning LLMs

Connections