TAI BUI
Back to curriculum
LearnPython

Scaling Laws

A scaling law is a fitted equation that predicts loss from parameters and training tokens. Kaplan (2020) said bigger model, lower loss. Hoffmann (2022) said those models were under-trained, and the split between parameters and tokens is the real decision.

TIME: ~45 minutesPREREQUISITES: Phase 7 · 05 (Full Transformer), Phase 7 · 07 (GPT)

Learning Objectives

  • Split a fixed compute budget (C ≈ 6ND) between parameters and training tokens, and say what each knob buys.
  • Read the Hoffmann loss L(N, D) = A/N^α + B/D^β + E and explain what each term represents.
  • Run a grid search for the compute-optimal (N, D) and explain why the fitted constants give a D/N that grows with C instead of a constant 20.
  • Weigh the loss penalty of over-training against its inference savings for a heavily served model.
  • Judge emergence claims and 2026 caveats (data quality, MoE, Muon) against smooth continuous loss.

The Problem

Compute-optimal scaling is the question of how to split a fixed training budget of C FLOPs between two knobs:

  1. Parameters (N). A bigger model has more capacity.
  2. Training tokens (D). More data makes better use of that capacity.

FLOPs scale approximately as 6 × N × D. You can push N up and D down, or D up and N down. Which gets you the lower loss?

Before 2022 the answer was "push N hard." GPT-3 (2020) was 175B parameters trained on ~300B tokens, a ratio of about 1.7 tokens per parameter, and the Kaplan scaling laws backed that choice.

Hoffmann et al. (2022) trained a small family of models called Chinchilla and found a different optimum, closer to 20 tokens per parameter. By that measure GPT-3 was 10× undertrained. Chinchilla (70B params, 1.4T tokens) beat GPT-3 (175B, 300B tokens) on the benchmarks they compared, at 2.5× less inference cost.

2026 is still Chinchilla's world, with one important twist. Llama 3 8B was trained on 15 trillion tokens, a ratio of 1,875 tokens per parameter, ninety-four times past Chinchilla-optimal. Inference cost matters more than training cost for a model that will be used at scale, so over-training past Chinchilla to get a smaller deployable footprint is the 2026 default.

Warm-up0/3
1. You train a language model of fixed size on more and more text from the same source. What usually happens to its loss on held-out text?Warm-up
Four blocks of increasing width labelled 1x, 2x, 4x and 8x training text feed into one model box marked as always the same size. Below, a card reads: loss on held-out text, as the training text grows, question mark.
Schematic: block widths are not to scale.
2. Which change most directly lowers the cost of serving each request from a deployed GPT-style model?Warm-up
Flow of a user request into a deployed GPT-style model that runs once per generated token, then out as a reply. Below, a card reads: cost of serving each request, question mark.
3. What does a typical training-loss curve for a transformer language model look like as training continues?Warm-up
Empty axes: training steps along the bottom from 0 to the end, training loss up the side, and a large question mark where the curve would be.
Check: The Problem0/5
1. In the Hoffmann law, what does N count?Define
The Hoffmann law drawn as three boxes, A over N to the alpha, B over D to the beta, and E, with 'N = ?' under it. Beside it a sketch of a transformer: a token embedding table, then layer 1 and layers 2 to L, each holding attention weights and MLP weights.
Schematic of a transformer; no counts are shown.
2. What does D measure in the Hoffmann law?Define
Three documents of different lengths, drawn as rows of token cells (6, 3 and 9 cells), flow into a model box that takes one optimizer step per batch. A card asks what D in the Hoffmann law measures.
Documents and token counts are typed for illustration.
3. When spending a fixed budget of C training FLOPs, which two quantities do you trade against each other?Define
A fixed budget of C training FLOPs feeds one pretraining run, which splits it across two unnamed knobs shown as 'knob 1: ?' and 'knob 2: ?'.
4. What did Hoffmann et al. (2022) find that contradicted the pre-2022 practice of pushing model size hardest?Explain
A card for GPT-3 with 175B parameters, about 300B tokens, 1.7 tokens per parameter and the note that Kaplan scaling laws backed pushing N hard, beside a card for Hoffmann et al. 2022 reading 'finding: ?'.
GPT-3 figures are the lesson's.
5. Chinchilla (70B parameters, 1.4T tokens) beat GPT-3 (175B parameters, 300B tokens) on the compared benchmarks. What does that result show?Explain
Two cards: GPT-3 with 175B parameters and 300B tokens, and Chinchilla with 70B parameters and 1.4T tokens, above a line saying Chinchilla scored higher on the compared benchmarks.
Figures from the stem and the lesson.

The Concept

Chinchilla curves: loss vs compute at various N/D ratios

The Hoffmann law

The Hoffmann law is a fitted formula for the loss of a model with N parameters trained on D tokens. From the Chinchilla paper:

L(N, D) = A / N^α + B / D^β + E
  • N = parameters (non-embedding).
  • D = training tokens.
  • α ≈ 0.34, β ≈ 0.28 (roughly symmetric).
  • E ≈ 1.69, the irreducible loss ceiling.
  • A ≈ 406, B ≈ 411.

The two terms trade against each other as you scale. Substitute D = C / (6N) and minimize over N at fixed compute. Because α and β differ, the optimum is a power law in C with a different exponent for each knob:

N_opt ∝ C^a,  a = β / (α + β) ≈ 0.45
D_opt ∝ C^b,  b = α / (α + β) ≈ 0.55
D_opt / N_opt ∝ C^(b - a) ≈ C^0.1

The prefactors depend on A and B. Since b > a, tokens per parameter creeps upward as compute grows instead of sitting at one constant. The grid search in main.py with the constants above prints about 27 tokens per parameter at 1e18 FLOPs, 65 at 1e22, 85 at 1e23, and 120 at 1e25. Published fits put the optimum near 20 tokens per parameter across the range Chinchilla studied (roughly 1e22 to 1e23 FLOPs), and that is the headline number to remember. The fitted constants here don't reproduce it exactly.

Why over-training anyway

Chinchilla-optimal minimizes training loss per training FLOP. But you pay training cost once, and you pay inference cost for as long as the model is served.

For a chatbot that serves a trillion tokens per month, inference dominates total cost. Llama's approach is to train smaller and longer. 8B at 15T tokens is deeply inference-optimized:

  • It fits on consumer GPUs.
  • Latency is a fraction of a 70B Chinchilla-optimal model.
  • Quality is close enough for most tasks.

DeepMind's 2024 paper ("Over-training is the new optimal") formalized this. For inference-dominated workloads, the right ratio is closer to 100–500 tokens per parameter depending on serving volume.

Emergence vs smoothness

Emergence is the claim that certain abilities (arithmetic, multi-step reasoning, chain-of-thought following) appear suddenly at some scale.

Schaeffer et al. (2023) argued this is a measurement artifact. Emergent metrics use discontinuous scoring (exact match, accuracy at threshold), which hides smooth improvement in the underlying logits. Continuous metrics such as cross-entropy show smooth curves.

In 2026 the consensus is that predictions via continuous loss are reliable, and benchmark jumps are often scorer artifacts. Plan budgets against continuous metrics.

The 2026 picture

Scaling laws still work, with some caveats:

FactorChanged how
Data qualityCurating "good" tokens (Phi-style) shifts curves by >2× effective compute
MoETotal params decouple from active FLOPs; scaling laws per-active-FLOP
Post-trainingSome capabilities (instruction following, code) shift with SFT+RLHF more than pretraining
MultimodalityImage + text tokens scale together; separate curves per modality
Synthetic dataModels generate training data; effective compute can compound

The Muon optimizer (Kimi Moonlight, 2024) showed a ~2× effective-compute gain over AdamW at matched data. Some 2026 training runs use Muon by default. It changes the absolute constant in the scaling law, not its shape.

Check: The Concept0/19
1. What does 'Chinchilla-optimal' refer to?Define
A card for the Chinchilla model: 70B parameters, 1.4T training tokens, 20 tokens per parameter. Beside it a card reading: 'Chinchilla-optimal' refers to, question mark.
Chinchilla figures are the lesson's.
2. What is over-training in this lesson?Define
A log number line from 1 to 10,000 tokens per parameter with four labelled dots: GPT-3 175B at 1.7, Chinchilla 70B at 20.0, Llama 2 70B at 28.6 and Llama 3 8B at 1,875.
Ratios computed from the lesson's main.py model table.
3. In L(N, D) = A / N^α + B / D^β + E, what does the E term represent?Define
The Hoffmann law as three boxes, A over N to the alpha, B over D to the beta, and E, with the E box highlighted and 'E = ?' beneath, above a card of the fitted constants alpha 0.34, beta 0.28, A 406, B 411, E 1.69.
4. What is meant by an 'emergent capability' of a language model?Define
Three rows naming arithmetic, multi-step reasoning and chain-of-thought following, each with 'score as size grows: ?' and an arrow from small to large model size above.
Abilities are the ones the lesson names; no scores are drawn.
5. What does 'effective compute' capture?Define
A falling curve of loss against raw training FLOPs on a log axis from 1e18 to 1e25, with the question 'what does effective compute capture?' and a question mark below.
Curve computed from the lesson's fitted frontier loss.
6. In L(N, D) = A / N^α + B / D^β + E, a model has a huge N but is trained on very few tokens. What happens to the loss?Explain
The Hoffmann law as three boxes with the note that N is huge and D is very few, and 'total loss L(N, D) = ?' below.
7. Minimizing the fitted loss at fixed compute gives N_opt ∝ C^a and D_opt ∝ C^b. What are the exponents and what follows for D/N?Explain
A card of fitted constants alpha 0.34 and beta 0.28 beside a card for the result of minimizing: N_opt proportional to C^a with a unknown, D_opt proportional to C^b with b unknown, and D over N proportional to C^(b minus a).
Constants from the lesson.
8. Why does Llama 3 8B, trained on 15 trillion tokens (about 94x past Chinchilla-optimal), make sense?Explain
A card for Llama 3 8B: 8B parameters, 15T tokens, 1,875 tokens per parameter, about 94 times past Chinchilla-optimal; beside it a card asking why train this way, with a question mark.
Figures from the stem and main.py.
9. What ratio does the Why over-training anyway section give for inference-dominated workloads?Explain
An empty log axis from 1 to 10,000 tokens per parameter with a dashed band labelled 'inference-dominated workloads: ?'.
10. What argument did Schaeffer et al. (2023) make about emergent abilities?Explain
Three metric rows: exact match, accuracy at a threshold and cross-entropy, each with 'curve vs size: ?'.
Metric names are the ones in the lesson's emergence section.
11. According to the 2026 table in The Concept, what does MoE change about how scaling laws apply?Explain
A token enters a router, which sends it to two of four experts, expert 2 and expert 4, highlighted in orange; experts 1 and 3 are drawn dim.
Schematic with typed counts (4 experts, 2 used); real models differ.
12. What did Muon (Kimi Moonlight, 2024) show, according to The Concept?Explain
Two optimizer boxes, AdamW as baseline and Muon trained on the same matched data, both pointing into a box reading 'effect on the scaling law: ?'.
13. Phi-style curation of 'good' tokens shifts scaling curves by more than 2x effective compute. What does that mean in practice?Explain
Two training sets, unfiltered web tokens and curated good tokens in the Phi style, both leading into a box reading shift of more than 2x effective compute, with 'in practice: ?' below.
14. Using the fitted exponents (a ≈ 0.45, b ≈ 0.55), compute grows 10x. By roughly what factors do N_opt and D_opt grow?Apply
Two cards: the exponents a about 0.45 and b about 0.55, and a budget growing 10 times with the growth factors of N_opt and D_opt shown as question marks.
15. A benchmark's exact-match score jumps from near 0 to 60% between two model sizes, while cross-entropy fell smoothly across the same sizes. What is the most likely explanation?Analyze
Two cards for the same pair of model sizes: exact-match score near 0 for the smaller and 60% for the larger, and cross-entropy that falls smoothly across the sizes; below, 'most likely explanation: ?'.
Values from the stem; no curve is drawn between the two sizes.
16. A startup trains a Chinchilla-optimal model for a chatbot and finds the serving bill dwarfs the training bill. Which assumption failed?Analyze
Two schematic bars: a short blue training bill and a much longer orange serving bill, with the question 'which assumption failed? ?' below.
Schematic: the stem says serving dwarfs training; bar lengths are not to scale.
17. Your team has a fixed pretraining budget and expects to serve the model to millions of users every day. Which plan fits the lesson's guidance best?Design
Flow: a fixed pretraining budget goes into 'pick N and D, plan: ?', and the resulting model is then served to millions of users daily.
18. A research group will train a prototype, run it a few hundred times for experiments, then discard it. Their budget is fixed. Which plan fits?Design
Flow of a prototype: train on a fixed budget, run experiments a few hundred times, then discard; below, 'plan to pick: ?'.
19. You must forecast whether the next model size will pass 50% on an exact-match benchmark before committing a budget. Which approach follows the lesson?Design
A grid with two rows, exact-match benchmark and cross-entropy, and three columns, smaller 1, smaller 2 and next size, all filled with question marks, above the question of whether the next size passes 50% and which method to use.
No values drawn: the stem gives none.

Build It

The code is in code/main.py. It implements the Chinchilla loss equation and solves for compute-optimal (N, D) at each of several compute budgets.

Step 1: Chinchilla loss

python
def chinchilla_loss(N, D, A=406.4, B=410.7, alpha=0.34, beta=0.28, E=1.69):
    return A / N ** alpha + B / D ** beta + E

main.py has no plotting. To see the valley yourself, evaluate L on an (N, D) grid and draw a contour (matplotlib's contourf works). The minimum along any fixed C = 6ND line is what Step 2 searches for.

Step 2: compute-optimal frontier

For eight compute budgets, one per decade from 1e18 to 1e25 FLOPs, compute_optimal finds the (N, D) that minimizes loss subject to 6ND = C. It grid-searches 200 log-spaced values of N from 1e5 to 1e13, sets D = C / (6N), skips any point with D < 1e6, and keeps the lowest loss. Then check the ratio D/N. With these fitted constants it is not constant: the printed optimum is 27.1 at 1e18, 29.4, 38.3, 50.0, 65.3 at 1e22, 85.2 at 1e23, 92.4, and 120.5 at 1e25. The printout notes that published fits put it near 20 for the Chinchilla range, so treat 20 as a published headline, not something this code reproduces.

Step 3: over-training cost

Fix C = 1e24, take the compute-optimal (N_opt, D_opt), then compute the extra loss you pay to train a 10× smaller model (N_opt / 10, 10 × D_opt, which spends the same compute). Report the inference FLOP savings (proportional to N) you get in exchange. main.py prints a loss penalty of +0.059 for a 10× inference saving.

Step 4: compare to real models

main.py drops in known (N, D) pairs for seven models: GPT-3 175B, Chinchilla 70B, Llama 2 70B, Llama 3 8B, Llama 3 70B, DeepSeek-V3 (active params), and Qwen 2.5 72B. It prints each model's D/N and the loss the fitted equation predicts, nothing else. If you want a predicted-vs-reported comparison, add the reported losses yourself.

Check: Build It0/5
1. You run the Step 2 grid search in main.py across 1e18 to 1e25 FLOPs. What does the printed D/N do?Apply
Terminal showing python main.py output: the compute-optimal table header and eight rows for compute 1e18 to 1e25 with the loss column, and a question mark in every N*, D* and D/N cell.
Real output of the lesson's main.py with the N*, D* and D/N columns replaced by '?'.
2. In compute_optimal at C = 1e18, the grid reaches N = 1e13. What happens to that point?Apply
Excerpt of main.py's compute_optimal showing the grid limits 1e5 to 1e13 and the line D equals C over 6N, with the rest of the loop body elided, above a log axis for N from 1e5 to 1e13 with the point N equals 1e13 marked.
Code lines copied from main.py; the lines after D = C_flops / (6 * N) are left out.
3. At C = 1e24, main.py trains a model with N/10 parameters on 10x the optimal tokens. What does Step 3 report?Apply
Terminal showing the Step 3 section of main.py: compute budget 1e24 FLOPs, the Chinchilla-optimal line with N 42.5B and D 3.9T, the over-trained line with N 4.2B and D 39.2T, and question marks for its loss, the loss penalty and the inference savings.
Real output of the lesson's main.py with the results replaced by '?'.
4. main.py's model table lists Llama 3 8B trained on 15T tokens. What D/N does that give, compared with the ~20 headline?Apply
A table of seven models from main.py with parameters and tokens: GPT-3 175B 175.0B and 300.0B, Chinchilla 70B, Llama 2 70B, Llama 3 8B 8.0B and 15.0T highlighted, Llama 3 70B, DeepSeek-V3 active and Qwen 2.5 72B.
N and D columns as main.py prints them; D/N and loss columns left out.
5. A teammate runs main.py, sees the printed D/N rise from 27 to 120, and says this confirms a constant 20 tokens per parameter. What is wrong with that reading?Analyze
Terminal with the real main.py compute-optimal table, D/N from 27.1 at 1e18 to 120.5 at 1e25, and below it a card quoting a teammate who says this confirms a constant 20 tokens per parameter.
Real output of the lesson's main.py; the quote is from the stem.

Use It

You're unlikely to train a frontier model yourself. Scaling laws still tell you three things:

  1. Whether your fine-tune has enough data. If your task-specific data is below 20 tokens per param of the base model, expect saturation at some loss floor.
  2. Whether to pick a bigger base model. If you're spending your whole budget on inference, prefer a smaller, longer-trained model.
  3. Where the returns diminish. Beyond 1000× Chinchilla-optimal, log-loss changes become noise.

The research trajectory in 2026:

  • Data-constrained regime. The web has a finite number of high-quality tokens (~5–10 trillion English after filtering), and frontier pretraining is approaching that ceiling. Synthetic data, multilingual, multimodal, and RLHF-scaled fine-tuning are the next levers.
  • Compute-multiplier tricks. Muon optimizer, MoE, and better data curation each shift the absolute constants, not the asymptote.
  • Scaling laws for RL. Still an open question. Early evidence suggests a power law in RL samples, but with very different exponents than pretraining.
Check: Use It0/2
1. What is the data-constrained regime, and what is known about RL scaling laws, according to Use It?Define
Bars of training tokens: Llama 3 70B 15T, DeepSeek-V3 14.8T and Qwen 2.5 72B 18T, with a line 'scaling laws for RL: ?' below.
Token counts from the lesson's main.py.
2. You will fine-tune a 7B base model on 500M tokens of task data. What does the 20-tokens-per-parameter check from Use It predict?Apply
Two cards: a base model with 7B parameters and task data of 500M tokens, and a line asking for the prediction of the 20-tokens-per-parameter check, with a question mark.

Ship It

The skill in outputs/skill-training-budget-estimator.md picks (N, D, hours, GPU) for a new training run given a compute budget, deployment constraints, and a target loss.

Check: Ship It0/1
1. What does the training-budget-estimator skill in Ship It do?Define
A terminal listing the outputs folder, which holds skill-training-budget-estimator.md, with the question 'what does this skill do? ?' below.
Filename from the lesson; contents deliberately not shown.
Author's Note

I'd treat the 20 tokens per parameter figure as a number to check, not a constant to memorize. The formulas in The Concept give N_opt and D_opt the same expression, which can't produce a ratio of 20 on its own. main.py grid-searches the fitted constants instead, and the optimum D/N it finds grows with C: about 27 at 1e18, 65 at 1e22, and 85 at 1e23. Its printout notes that published fits put the optimum near 20 for the range Chinchilla studied, so the fitted constants here and the headline ratio don't agree.

My bet is that the over-training step is the most useful one to run for your own numbers. It takes the 1e24 budget, shrinks N by 10×, grows D by 10×, and prints the loss penalty next to the inference savings (about N_opt / N_under, so 10x). Set that trade against how much serving you expect, since the case for Llama-style training rests on inference volume.

I'd also read the real-model table as predicted loss from the fitted equation, not as a comparison against published numbers. main.py prints chinchilla_loss for each model and has no reported-loss column, so Step 4's "predicted vs reported" is a comparison you'd add yourself.

Exercises

  1. Easy. Run code/main.py. Print Chinchilla-optimal (N, D) for compute budgets 1e20, 1e22, 1e24. Compare to the real model table.
  2. Medium. Implement the Hoffmann loss-as-function-of-compute curve. Plot loss vs log10(C) for the compute-optimal frontier. Identify when the law predicts we'd need >10^28 FLOPs for the next 0.1 reduction in cross-entropy.
  3. Hard. Fit your own scaling law on 5 tiny models (100K to 10M params) trained on the same dataset. Estimate α and E. How well do your exponents match published ones?

Key Terms

TermWhat people sayWhat it actually means
Parameters (N)"Model size"Non-embedding weight count; determines capacity.
Tokens (D)"Training data"Number of training tokens seen; determines how well the parameters get used.
Compute (C)"FLOPs spent"Approximately 6 × N × D for a standard transformer.
Chinchilla-optimal"D/N ≈ 20"Ratio that minimizes loss per FLOP of pretraining. Published fits put it near 20; the fitted constants in this lesson give a ratio that grows with C.
Over-training"Past Chinchilla"Spend extra training FLOPs to save inference FLOPs; D/N >> 20.
Irreducible loss"The floor"The E term in the scaling law; the entropy of the data itself.
Emergent capability"Sudden jumps at scale"Often a scorer artifact; continuous loss is smooth.
Effective compute"Training-efficiency multiplier"Better data / optimizer / architecture multiplies how far a FLOP goes.

Further Reading

Code

Ships With