Chapter 11 of 40 · ~22 min read & lab+80 XP
Chapter 11 · Generative AI

LLM Scaling Laws: Kaplan, Chinchilla Compute-Optimal & Over-Training

How smooth power-law scaling laws predict LLM loss before spending $10M+ on GPUs, why Chinchilla's 20-tokens-per-parameter rule overturned GPT-3, and why LLaMA 3 deliberately 'over-trains' for 2,000 tokens/parameter!

What Is It?

LLM Scaling Laws (Kaplan & Chinchilla) mathematically relate pretraining loss to model parameters N, training tokens D, and compute FLOPs C ≈ 6ND.

Why Is It Required?

Before spending millions on a GPU cluster, scaling laws tell you the optimal balance between model size and dataset size—and why smaller over-trained models (like Llama-3 8B) win at inference.

Everyday Analogy: Engineering blueprints that predict bridge strength before pouring concrete, preventing you from building an oversized engine with too little fuel.
Why ML Engineers & Data Scientists Actually Need This

No AI lab spends $50M training a frontier LLM blind — Scaling Laws let you run small 100M–1B pilot experiments and predict the exact validation loss of a 70B+ model before launching the cluster!

ML / AI Engineer

Memorizing C ≈ 6 · N · D and GPU MFU (Model FLOPs Utilization, ~35%–50%) lets you estimate training cost, cluster size, and wall-clock days on the back of an envelope.

Data Scientist

Understanding inference-optimal over-training explains why LLaMA 3 8B (trained on 15 Trillion tokens — 94× past Chinchilla!) crushes older 70B models while costing 8× less to serve!

Interview & Debug Edge

Classic AI strategy & research interview question: 'Why did Chinchilla say an 8B model should only train on 160B tokens, yet Meta trained LLaMA 3 8B on 15 TRILLION tokens?'

Step 0 · Test Your Gut Before Any Math!

Approximately how many floating-point operations (FLOPs) does it take to pre-train a dense Transformer with N parameters on D tokens?

What You Will Master in This Chapter
  • Compute pre-training FLOPs from model size N and training tokens D using the canonical rule C ≈ 6 · N · D
  • Contrast Kaplan et al. (2020) parameter-heavy scaling with DeepMind's Chinchilla (2022) compute-optimal 20:1 tokens-per-parameter rule
  • Interpret the Chinchilla parametric loss equation L(N, D) = E + A/N^α + B/D^β and the irreducible entropy floor E
  • Explain why modern inference-heavy models (LLaMA 3 8B on 15T tokens!) deliberately over-train far past Chinchilla-optimal
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 4
C≈6NDC \approx 6 N DSay aloud:“training compute in FLOPs”
Plain-English Meaning
Total floating-point operations to train N dense parameters on D tokens
Everyday Example
70B × 2T tokens → 8.4 × 10²³ FLOPs
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Think of training an LLM like studying for an exam with a fixed budget of 100 hours (Compute CC). You can either build a giant brain (NN) that only skims 10% of the textbook (DD) — that was GPT-3 (under-trained!) — OR you can pick the exact balance where brain size and pages read scale equally (D≈20ND \approx 20 N, Chinchilla-optimal!). Better yet: if millions of users will query your brain every day afterward, it pays to train a smaller, faster brain on 100× more books (Inference-Optimal Over-Training, like LLaMA 3)!

1. The 6·N·D Compute Budget & Power-Law Loss

Everyday Story First (Zero Math Yet!)

On a log-log plot, LLM cross-entropy loss falls along a remarkably straight line across 7+ orders of magnitude of compute — until it approaches the irreducible entropy floor EE of natural language.

Neural Scaling Power Law: Log(Loss) Drops Linearly With Log(Compute C)Log₁₀(Training Compute FLOPs) → L(N, D) = E + A/N^α + B/D^β
Cross-Entropy loss follows predictable smooth power laws across 6+ orders of magnitude in Compute, Data, and Parameters — letting labs predict 100B-model loss from tiny 1B test runs!

The Parametric Scaling Law

L(N,D)=E+ANα+BDβL(N, D) = E + \frac{A}{N^\alpha} + \frac{B}{D^\beta} with empirical Chinchilla exponents α≈0.34,β≈0.28\alpha \approx 0.34, \beta \approx 0.28, and irreducible entropy E≈1.69E \approx 1.69 nats (natural language always has genuine unpredictability!).

  • Core Consequence: If you increase NN while leaving DD small, the B/DβB/D^\beta term stalls your loss; if you increase DD while leaving NN tiny, the A/NαA/N^\alpha term stalls your loss. Both must grow together!
Formula Anatomy · Click Any Colored Piece to Decode It
Anatomy of the Training Compute & Power-Law Equations

C ≈ 6·N·D and L(N, D) = E + A/N^α + B/D^β

Forward Pass FLOPs

1 multiply + 1 add = 2 FLOPs per parameter per token.

In our example: 1/3 of training compute
Put it together with real numbers: How long to train a 7B model on 1T tokens on 256 H100s (BF16 peak 989 TFLOPs, 45% MFU)? C = 6 × 7e9 × 1e12 = 4.2e22 FLOPs. Effective cluster speed = 256 × 989e12 × 0.45 ≈ 1.14e17 FLOPs/s → 3.68e5 seconds ≈ 4.3 days!

2. Kaplan (2020) vs. Chinchilla (2022) IsoFLOP Frontier

Everyday Story First (Zero Math Yet!)

Use the Chinchilla Compute Calculator mini-lab below to see how shifting a fixed FLOP budget from an under-trained 280B model to a 70B Chinchilla-optimal model slashes loss for FREE!

Chinchilla Compute-Optimal Rule (C ≈ 6·N·D): Scale Params & Tokens Equally!Old Way: Gopher 280B280B params · 300B tokensRatio: 1.1 tokens/param (starved!)4× slower & worse accuracy!Chinchilla 70B (Same FLOPs!)70B params · 1.4T tokensRatio: 20 tokens / param ✓Beat Gopher 280B across every bench!
Chinchilla (Hoffmann et al., 2022) proved earlier LLMs were massively under-trained: for a fixed training FLOP budget C ≈ 6ND, optimal scaling balances Tokens ≈ 20 × Parameters!

Why Chinchilla Overturned GPT-3 & Gopher

  • Kaplan et al. (OpenAI, 2020) held learning-rate schedules fixed and concluded NN should grow much faster than DD (N∝C0.73,D∝C0.27N \propto C^{0.73}, D \propto C^{0.27}). This led to massive, under-trained models like GPT-3 (175B on 300B tokens — 1.7 tok/param) and Gopher (280B on 300B tokens).
  • Chinchilla (DeepMind, 2022) properly tuned the cosine learning-rate decay to each token horizon and proved NN and DD should scale equally (N∝C0.5,D∝C0.5N \propto C^{0.5}, D \propto C^{0.5}) at ~20 tokens per parameter:
    • Chinchilla 70B trained on 1.4T tokens used the exact same training compute as 280B Gopher, yet crushed it on every benchmark AND was 4× cheaper to serve!
Animated Mini-Lab • 2.5

Chinchilla 6ND Compute & Over-Training Calculator

C ≈ 7.20e+23 FLOPs
Chinchilla target (20×N): 0.16T · Your ratio: 1875 tok/param (Inference-Optimal Over-Trained ✓)

3. Inference-Optimal Over-Training & Test-Time Compute Scaling

Everyday Story First (Zero Math Yet!)

Chinchilla optimizes training cost only — assuming you throw the model away after training! In the real world, a popular model serves trillions of inference tokens.

Modern Inference-Optimal Strategy: Deliberately Over-Train Small Models!LLaMA 3 8B: Trained on 15 TRILLION Tokens (~1,875 tokens/param!)Chinchilla only optimizes ONE-TIME training FLOPs — it ignores serving millions of users!Pay extra training compute ONCE → serve a tiny, blazing-fast 8B model forever!
Modern open LLMs (LLaMA 3 8B trained on 15 TRILLION tokens — ~1,800× params!) deliberately over-train smaller models far past Chinchilla to make inference 10× cheaper forever!

Why Modern LLMs Deliberately Over-Train (LLaMA 3, Gemma 2, Qwen)

If your 8B model will be downloaded millions of times or serve billions of API calls, inference cost dwarfs training cost.

  • LLaMA 3 8B was trained on 15 Trillion tokens (~1,875 tokens/parameter — nearly 100× past Chinchilla-optimal!), and its loss was still steadily improving at 15T tokens!
  • The New Frontier — Test-Time Compute Scaling (o1 / R1 / Thinking Models): As high-quality pre-training internet text runs scarce (the "Data Wall"), frontier labs added a 3rd scaling axis: spending extra compute at inference time via Reinforcement Learning & Chain-of-Thought verification (covered in Module 5.5!).
Walk Through With Me · Interactive Worked Example

Worked Example: Checking Chinchilla Ratio & Training FLOPs

Compare GPT-3 (175B, 300B tokens), Chinchilla (70B, 1.4T tokens), and LLaMA 3 8B (8B, 15T tokens).

11. GPT-3 (175B / 300B tokens)Step 1 / 3

Ratio D/N=1.7D/N = 1.7 tok/param (heavily under-trained). Compute C≈6×175B×300B=3.15×1023C \approx 6 \times 175\text{B} \times 300\text{B} = 3.15 \times 10^{23} FLOPs.

Teacher's Note: Had far too many parameters for its data budget.
Pause & Check · Quick Intuition Pulse

Why did Meta train LLaMA 3 8B on 15 Trillion tokens (~1,875 tokens/param) instead of stopping at the Chinchilla-optimal 160B tokens?

Try It YourselfStandard

You have a fixed training compute budget of C=1.2×1022C = 1.2 \times 10^{22} FLOPs. Using Chinchilla's D=20ND = 20 N and C=6NDC = 6 N D, what are the compute-optimal model size NN and token count DD?

“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Not at all! 20 tokens/param is only the minimum training compute point for a given loss. Keeping NN fixed and continuing to train to 200 or 2,000 tokens/param continues to smoothly reduce loss — it just takes more training FLOPs per unit of loss drop.

Interactive Visual Lab
Lab Challenge: Explore the 60 FPS Scaling Laws Studio past 40% progress and compare Kaplan, Chinchilla-Optimal, and Over-Trained LLaMA 3 regimes.
Interactive Animation • 2.5 Deep Lab

Chinchilla Compute-Optimal Scaling Frontier Studio

Slide your training compute budget from 10²¹ to 10²⁵ FLOPs to compute the exact Chinchilla-optimal Model Size N and Dataset Size D.

Compute Budget (FLOPs):10^23
Optimal Params N*
28.9B
Optimal Tokens D* (20×N)
0.58T
Predicted CE Loss
2.011
0%
Budget = 10^23 FLOPs
Intuition Takeaway: Pre-training compute scales as C≈6NDC \approx 6 N D; Chinchilla proved D≈20ND \approx 20 N minimizes training compute, while modern frontier labs intentionally over-train smaller models (100×–2,000× tokens/param) to minimize inference cost.
Where This Powers Real ML, Deep Learning & Generative AI

Pre-Training Pilot Extrapolation

Labs train 5–10 small models (100M–3B) across IsoFLOP curves to verify architecture tweaks (e.g., GQA, MLA, Muon optimizer) before committing to a $10M+ frontier run.

Small Language Models (SLMs) for Edge & Low-Latency APIs

Gemma 2 2B/9B, Phi-4, and LLaMA 3 8B leverage heavy over-training + synthetic data + distillation to run locally on laptops and phones.

Production NumPy & PyTorch Code Patterns
# Chinchilla Compute-Optimal Scaling Calculator: C ≈ 6 * N * D, optimal D ≈ 20 * N
def chinchilla_plan(flops_budget: float) -> dict:
    # Solve 6 * N * (20 * N) = C  =>  N = sqrt(C / 120)
    n_params = (flops_budget / 120.0) ** 0.5
    d_tokens = 20.0 * n_params
    return {
        "compute_flops": flops_budget,
        "optimal_params_B": round(n_params / 1e9, 2),
        "optimal_tokens_B": round(d_tokens / 1e9, 1),
    }

for label, C in [("7B-class budget", 6e21), ("70B-class budget", 5.8e23)]:
    print(label, "->", chinchilla_plan(C))
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Treating Chinchilla's 20 tokens/param as a hard ceiling where training stops working.
Best Practice: Always clarify: Chinchilla is training-compute-optimal, NOT inference-optimal. Modern production models intentionally over-train 10×–100× past Chinchilla!
Trap #2: Forgetting the factor of 6 in C ≈ 6·N·D (or forgetting to multiply by MFU when converting FLOPs to GPU-hours).
Best Practice: Remember 2·N·D forward + 4·N·D backward = 6·N·D, and real clusters achieve ~35%–50% MFU (Model FLOPs Utilization), never 100% peak spec!
Chapter Mastery Check (+80 XP)
Score: 0 / 2
1Using C ≈ 6·N·D, approximately how many training FLOPs are needed to train a 70B dense model on 1.4 Trillion tokens?
2What is the Chinchilla compute-optimal ratio of training tokens D to model parameters N?

Apply What You Learned — Solve Matching Coding Problems