This week we examine how large language models are trained: the data pipelines, objectives, compute budgets, and the empirical scaling laws that govern the relationship between model size, data, compute, and performance.
Modern LLMs are trained in two stages:
Pre-training: self-supervised learning on massive, diverse text corpora. No human labels required. The objective is next-token prediction (or masked language modelling). This is where the vast majority of compute is spent.
Adaptation: fine-tuning, instruction tuning, or RLHF to align the model to user intent (covered Week 7).
Pre-training is what gives the model its general knowledge, reasoning ability, and language competence.
| Source | Examples |
|---|---|
| Web crawls | Common Crawl, C4, RefinedWeb |
| Books | Books1, Books2, Project Gutenberg |
| Code | GitHub, The Stack |
| Wikipedia | All languages |
| Scientific papers | arXiv, PubMed, Semantic Scholar |
| Conversations | Reddit (PushShift), StackExchange |
GPT-3 was trained on ~300B tokens. LLaMA-3 was trained on over 15 trillion tokens.
Raw Common Crawl is noisy. Standard filtering steps:
If evaluation benchmarks (e.g. MMLU, HumanEval) appear in training data, reported performance is inflated. Most labs now deduplicate against known benchmarks, but contamination remains a live concern.
For decoder-only LLMs the pre-training objective is cross-entropy loss over next-token prediction:
L = -1/T * sum_{t=1}^{T} log P(w_t | w_1, ..., w_{t-1})
This is equivalent to maximising the log-likelihood of the training corpus.
Perplexity is the exponentiated average negative log-likelihood:
PPL = exp(L)
Lower perplexity = better model. As a sanity check: a model that assigns uniform probability over a 50k vocabulary has PPL = 50,000.
Training a 70B-parameter model requires:
Kaplan et al. (2020) and Hoffmann et al. (2022) characterise how LLM performance scales with:
The approximate relationship is:
C ≈ 6 * N * D
(Each forward pass through N parameters over D tokens, times 6 for forward + backward.)
Loss follows a power law:
L(N) ∝ N^(-α_N)
L(D) ∝ D^(-α_D)
L(C) ∝ C^(-α_C)
Key finding: given a fixed compute budget, it is better to train a larger model on fewer tokens than a smaller model on more tokens.
Hoffmann et al. showed Kaplan’s recommendation was wrong — models were under-trained.
Chinchilla optimal: for a compute-optimal model, train with roughly 20 tokens per parameter.
N_opt ∝ C^0.5
D_opt ∝ C^0.5
| Model | Parameters | Tokens | Tokens / Param |
|---|---|---|---|
| GPT-3 | 175B | 300B | ~1.7 (under-trained) |
| Chinchilla | 70B | 1.4T | ~20 (optimal) |
| LLaMA-3 | 8B | 15T | ~1875 (over-trained for inference) |
LLaMA-3 deliberately over-trains small models: a smaller model trained on more tokens can be cheaper to deploy while matching a larger model trained to Chinchilla optimum.
Wei et al. (2022) document abilities that appear abruptly at a certain model scale:
These are not predictable from small-scale experiments. This makes forecasting LLM capabilities difficult.
Debate: some researchers argue emergence is an artefact of evaluation metrics — with smoother metrics, emergence looks more gradual.
Large-scale training is prone to:
max_norm parameter.Monitoring training requires tracking loss, gradient norm, learning rate, and hardware utilisation in real time.
See practicals/week06_practical.py: