AILearn AI
LearnGlossarySources
ID/EN
Learn AI — open material for learning AIEvery lesson cites its original sources.
✎Large Language Models
  1. Tokenization: how text becomes numbers
  2. How LLMs work: next-token prediction at scale
  3. Decoding: greedy, beam search, temperature, top-k, top-p
  4. Scaling laws: parameters, data and compute
  5. Fine-tuning & alignment: SFT, RLHF, DPO, LoRA/QLoRA
  6. Prompting: zero-shot, few-shot, chain-of-thought, structured output
  7. Retrieval-Augmented Generation (RAG)
  8. Agents & tool use: ReAct, function calling, MCP
Modules
  1. ◎ AI Foundations
  2. ∿ Classical Machine Learning
  3. ⌬ Neural Networks
  4. ↘ Training Results & Evaluation
  5. ▦ Deep Learning Architectures
  6. ✎ Large Language Models
  7. ◐ Image Generation
  8. ♪ Audio & Speech AI
  9. ◈ Multimodal, Video & 3D
  10. ↻ Reinforcement Learning
  11. ⚙ ML Development & MLOps
  12. ★ Advanced & Frontier Topics
Learn/Large Language Models

Scaling laws: parameters, data and compute

Language-model loss falls as a smooth power law in model size, data and compute. Learn the Kaplan and Chinchilla results, the 6·N·D compute rule, why ~20 tokens per parameter became a rule of thumb, why modern models deliberately overtrain, and what “emergent abilities” really are.

Advanced~20 min·6 references
Key terms
Scaling lawsPretrainingParameterPerplexityLarge language model (LLM)

Training a frontier model costs millions of dollars, so labs need to know in advance: how big should the model be, how many tokens should it see, and what loss will we get? Scaling laws answer this. Small pilot runs are fitted with simple power-law curves and extrapolated to the big run — and, remarkably, the predictions hold across many orders of magnitude[1][2].

≈
Analogy: brain size vs. books vs. study hours
A student with a huge brain but only ten books plateaus quickly — there is nothing left to learn. A student with a small brain and a million books cannot absorb them. If your total study hours are fixed (the compute budget), there is a best balance between “brain size” (parameters) and “books read” (tokens). Scaling laws tell you where that balance is.

Loss follows power laws

Kaplan et al. (OpenAI, 2020) trained many transformers and found that test loss depends mainly on three quantities — parameters N (excluding embeddings), dataset size D in tokens, and training compute C — and only weakly on shape details like depth versus width. When one factor is the bottleneck, loss is a straight line on a log-log plot[1]:

L(N) ≈ (N_c / N)^0.076 L(D) ≈ (D_c / D)^0.095 L(C) ≈ (C_c / C)^0.050
Kaplan et al. exponents. Example: 10× more parameters multiplies loss by 10^(−0.076) ≈ 0.84 — steady but diminishing returns.
In words: When only one resource is the bottleneck, test loss falls as a power law of it: multiplying parameters, data or compute by a fixed factor always multiplies the loss by the same fixed factor. On a log–log plot each law is a straight line.
Symbols(hover a symbol in the formula)
L(N)
test loss (nats per token) of a model with N parameters trained to convergence on plenty of data
N
number of non-embedding parameters
N_c
fitted constant, ≈ 8.8 × 10¹³
D
number of training tokens
D_c
fitted constant, ≈ 5.4 × 10¹³ tokens
C
training compute (used optimally)
C_c
fitted constant, ≈ 3.1 × 10⁸ PF-days
^0.076
the exponent: how fast loss falls (small = slow, steady gains)
▸Worked example
N = 10⁹: L ≈ (8.8 × 10¹³ / 10⁹)^0.076 = 88,000^0.076 ≈ 2.376 N = 10¹⁰: L ≈ 8,800^0.076 ≈ 1.994 (ratio 0.839 = 10^(−0.076)) 2× parameters: × 2^(−0.076) = 0.9487 → about 5% lower loss, every time you double.
C ≈ 6 · N · D FLOPs
Training compute: ~2 FLOPs per parameter per token forward, ~4 backward. 70B params × 1.4T tokens ≈ 5.9·10²³ FLOPs.
In words: Training cost is about 6 floating-point operations per parameter per token: roughly 2 for the forward pass (a multiply and an add per weight) and 4 for the backward pass.
Symbols(hover a symbol in the formula)
C
total training compute
6
≈ 2 (forward) + 4 (backward) operations per parameter per token
N
number of model parameters
D
number of training tokens
FLOPs
floating-point operations (a count, not per second)
▸Worked example
GPT-3: 6 · 175 × 10⁹ · 300 × 10⁹ = 3.15 × 10²³ FLOPs Chinchilla: 6 · 70 × 10⁹ · 1.4 × 10¹² = 5.88 × 10²³ FLOPs At 10¹⁵ FLOP/s of real throughput, 3.15 × 10²³ FLOPs take 3.15 × 10⁸ s ≈ 10 GPU-years.

Chinchilla: compute-optimal training

Kaplan’s analysis suggested spending most extra compute on bigger models, so models like GPT-3 (175B parameters) were trained on only ~300B tokens[5]. Hoffmann et al. (DeepMind, 2022) re-examined this with over 400 models (70M to 16B+ parameters, 5B to 500B tokens) and reached a different conclusion: parameters and tokens should grow in equal proportion with compute. Their 70B-parameter Chinchilla, trained on 1.4T tokens, used the same compute as the 280B Gopher yet outperformed it on most benchmarks — and is cheaper to run[2].

L(N, D) = E + A / N^α + B / D^β E = 1.69, A = 406.4, B = 410.7, α = 0.34, β = 0.28
Chinchilla’s parametric fit. E: irreducible entropy of text. A/N^α: penalty for a finite model. B/D^β: penalty for finite data.
In words: Loss = an unbeatable floor + a penalty for having too few parameters + a penalty for having too little data. Both penalties shrink as power laws, so for a fixed budget you get the lowest loss by growing N and D together.
Symbols(hover a symbol in the formula)
L(N, D)
predicted loss for N parameters trained on D tokens
E
irreducible loss: the entropy of natural text itself
A / N^α
the part of the loss caused by limited model size
B / D^β
the part caused by limited training data
α
how fast the model-size penalty shrinks
β
how fast the data penalty shrinks
▸Worked example
Chinchilla, N = 70 × 10⁹, D = 1.4 × 10¹²: A / N^α = 406.4 / (7 × 10¹⁰)^0.34 = 0.0835 B / D^β = 410.7 / (1.4 × 10¹²)^0.28 = 0.1632 L = 1.69 + 0.0835 + 0.1632 = 1.937 Gopher, N = 280 × 10⁹, D = 300 × 10⁹ (similar compute): L = 1.69 + 0.0521 + 0.2511 = 1.993 → the 4× smaller model trained on more data wins.
N_opt ∝ C^≈0.5 D_opt ∝ C^≈0.5 ⇒ D_opt / N_opt ≈ 20 tokens per parameter
The famous rule of thumb: 10× compute → ~3.2× bigger model and ~3.2× more tokens.
In words: When the compute budget grows, split it evenly: model size and data should each grow with roughly the square root of compute. A handy rule of thumb follows — about 20 training tokens for every parameter.
Symbols(hover a symbol in the formula)
N_opt
compute-optimal number of parameters
D_opt
compute-optimal number of training tokens
∝
“is proportional to”
C^≈0.5
compute to the power of about 0.5 (≈ square root)
⇒
“therefore”
▸Worked example
Budget C = 5.88 × 10²³ FLOPs. With D = 20·N and C = 6·N·D = 120·N²: N = √(5.88 × 10²³ / 120) = √(4.9 × 10²¹) = 7 × 10¹⁰ → 70B parameters D = 20 · 70 × 10⁹ = 1.4 × 10¹² tokens — exactly Chinchilla. 4× the compute → 2× the parameters and 2× the tokens.
ModelParametersTraining tokensTokens / parameter
GPT-3 (2020)175B300B≈ 1.7
Gopher (2021)280B300B≈ 1.1
Chinchilla (2022)70B1.4T20
Llama 2 7B (2023)7B2T≈ 290
Llama 3 8B (2024)8B15T+≈ 1,900
Tokens per parameter of some well-known models (publicly reported figures).

Why do newer models go far beyond 20 tokens per parameter? Chinchilla minimizes training compute only. But a deployed model is queried billions of times, and inference cost scales with N. A smaller model trained much longer costs more to train than “optimal”, yet is cheaper and faster for every user forever. This deliberate overtraining is now standard for open models meant to run on modest hardware.

Loading interactive…
The Chinchilla parametric fit, live. It is a fitted formula, not a simulation of training.

Try this

  • Fix N and keep increasing D: the loss falls, then flattens toward E + A/N^α — the model is “full”. Do the same with N fixed small and see how much loss is left on the table.
  • Look at the isoFLOP curve: for a fixed compute budget, a model that is too small *or* too big gets a worse loss. The minimum is the compute-optimal size.
  • Set N = 175B and D = 300B (GPT-3-like), note the loss, then move to the optimum at the same compute. How much loss did GPT-3 leave unclaimed?
  • Read the “tokens per parameter” value at the optimum and compare it with the ~20 rule of thumb. The rounded published constants do not reproduce exactly 20 at every budget — a reminder that these are approximate fits.
knobN — model parameters
What it is
Number of trainable weights. Sets capacity, memory footprint and per-token compute (training and inference).
↑ If you increase it
Lower achievable loss (A/N^α shrinks); at fixed compute, fewer tokens can be afforded, so beyond the optimum the model is undertrained. Inference gets slower and costlier.
↓ If you decrease it
Cheaper to serve and fine-tune; the loss floor rises, so no amount of data can make a tiny model as good as a large one.
Typical values
1B–8B for on-device/edge, 30B–70B for strong open models, hundreds of billions+ for frontier models.
knobD — training tokens
What it is
How many tokens the model is trained on (counting repeats).
↑ If you increase it
Lower loss (B/D^β shrinks) and better use of a fixed model; but high-quality unique data is limited, and repeating data many epochs gives diminishing returns.
↓ If you decrease it
Cheaper training; the model stays undertrained — its capacity is wasted.
Typical values
≈ 20 × N for compute-optimal; 100–2,000 × N for inference-optimized open models.
knobC — compute budget (FLOPs)
What it is
Total training compute ≈ 6·N·D. Fixed by your GPUs × time × utilization.
↑ If you increase it
Lower best achievable loss; the optimal N and D both grow roughly as √C.
↓ If you decrease it
Higher loss; you must choose a smaller model and/or fewer tokens.
Typical values
~10¹⁸–10²⁰ FLOPs for research-scale runs; ~10²³–10²⁵+ for frontier LLMs.
python
import numpy as np

E, A, B, alpha, beta = 1.69, 406.4, 410.7, 0.34, 0.28
loss = lambda N, D: E + A / N**alpha + B / D**beta

def optimal(C):
    Ns = np.logspace(7, 13, 2000)            # 10M .. 10T parameters
    Ds = C / (6 * Ns)                        # spend the whole budget
    L = loss(Ns, Ds)
    i = L.argmin()
    return Ns[i], Ds[i], L[i]

for C in [1e20, 1e22, 5.9e23, 1e25]:
    N, D, L = optimal(C)
    print(f"C={C:.0e}  N={N/1e9:7.1f}B  D={D/1e9:9.0f}B  "
          f"tokens/param={D/N:6.1f}  loss={L:.3f}")
Find the compute-optimal model size for a budget using the Chinchilla fit.

Emergent abilities — and a caveat

Wei et al. catalogued abilities that seem absent in small models and appear suddenly beyond a certain scale, such as multi-step arithmetic and some reasoning benchmarks[3]. Schaeffer et al. argued that much of this sharpness comes from the metric: exact-match accuracy gives zero credit until every token is right, so smooth underlying progress looks like a jump; with continuous metrics many curves become smooth[4]. The practical takeaway: loss is predictable; specific downstream skills much less so — always evaluate the capability you care about directly.

  • Data quality and limits: filtered, deduplicated data shifts the whole curve down; the supply of high-quality human text is finite, which motivates synthetic data and multi-epoch training.
  • Test-time compute: letting a model generate longer reasoning, sample several answers, or verify its work can improve accuracy in a way that also scales — a second axis besides pretraining compute.
  • Fine-tuning and transfer follow their own (smaller) scaling trends; bigger pretrained models generally need fewer examples to adapt.
!
Pitfalls when using scaling laws
(1) The constants belong to a specific setup — tokenizer, data mix, architecture, learning-rate schedule. Refit them for your own pipeline instead of copying numbers. (2) Extrapolating many orders of magnitude beyond your fitted range is risky. (3) A badly tuned learning-rate schedule can make small pilot runs look worse than they should and bias the fit (one of the reasons Kaplan and Chinchilla disagreed). (4) C ≈ 6ND ignores attention FLOPs, which matter for very long contexts. (5) Lower loss does not guarantee every behaviour you care about improves.
▸Go deeper: deriving the optimum

Minimize L(N, D) = E + A/N^α + B/D^β subject to 6ND = C. Substituting D = C/(6N) and setting the derivative to zero gives αA/N^α = βB/D^β, i.e. at the optimum both penalty terms are balanced (weighted by their exponents). Solving:

N_opt = G · (C/6)^(β/(α+β)), D_opt = G⁻¹ · (C/6)^(α/(α+β)), G = (αA / (βB))^(1/(α+β))
In words: Minimizing L(N, D) = E + A/N^α + B/D^β under the constraint 6·N·D = C gives these closed-form answers. The exponents say how the budget is shared: data gets the larger share when α > β.
Symbols(hover a symbol in the formula)
N_opt
loss-minimizing number of parameters for budget C
D_opt
loss-minimizing number of tokens for budget C
C/6
the compute budget expressed as N·D (since C ≈ 6·N·D)
G
a constant built from the fitted A, B, α, β
G⁻¹
1 / G
α
model-size exponent (0.34)
β
data exponent (0.28)
A
model-size coefficient (406.4)
B
data coefficient (410.7)
▸Worked example
α + β = 0.62 → β/(α+β) = 0.4516, α/(α+β) = 0.5484 G = (0.34 · 406.4 / (0.28 · 410.7))^(1/0.62) = (138.18 / 115.0)^1.613 = 1.345 C = 5.88 × 10²³ → C/6 = 9.8 × 10²² N_opt = 1.345 · (9.8 × 10²²)^0.4516 ≈ 3.2 × 10¹⁰ (32B) D_opt = (9.8 × 10²²)^0.5484 / 1.345 ≈ 3.0 × 10¹² tokens Check: 6 · 3.25 × 10¹⁰ · 3.02 × 10¹² ≈ 5.88 × 10²³ ✓

With α = 0.34 and β = 0.28, N grows as C^0.45 and D as C^0.55 — close to the equal split found by Chinchilla’s other two estimation methods. The idea that error falls predictably as a power law of data and model size predates LLMs; Hestness et al. documented it across translation, language modeling, vision and speech[6].

Quiz

1.
According to the Chinchilla results, if your compute budget grows 100×, how should you scale the model and data?
2.
Roughly how many FLOPs does it take to train a 7B-parameter model on 2T tokens?
3.
Why do many recent open models train far beyond ~20 tokens per parameter?
4.
In L(N, D) = E + A/N^α + B/D^β, what happens to the loss as N → ∞ with D fixed?
5.
What did Schaeffer et al. argue about “emergent abilities”?
Score: 0/5

References

  1. [1]
    Scaling Laws for Neural Language Models
    PaperKaplan et al.2020arxiv.org
  2. [2]
    Training Compute-Optimal Large Language Models (Chinchilla)
    PaperHoffmann et al.2022arxiv.org
  3. [3]
    Emergent Abilities of Large Language Models
    PaperWei et al.2022arxiv.org
  4. [4]
    Are Emergent Abilities of Large Language Models a Mirage?
    PaperSchaeffer et al.2023arxiv.org
  5. [5]
    Language Models are Few-Shot Learners (GPT-3)
    PaperBrown et al.2020arxiv.org
  6. [6]
    Deep Learning Scaling is Predictable, Empirically
    PaperHestness et al.2017arxiv.org
← Previous
Decoding: greedy, beam search, temperature, top-k, top-p
Next →
Fine-tuning & alignment: SFT, RLHF, DPO, LoRA/QLoRA