Skip to content

5.4 Scaling laws

ready≈ 14 hoursNeeds: 4.6
  1. 1 Learn
  2. 2 Bridge & derive
  3. 3 Explore (Scaling-law explorer)
  4. 4 Do
  5. 5 Check

Power laws. Train language models of many sizes on enough data and the test loss falls as a power law in the number of parameters, a straight line on log-log axes, over many orders of magnitude. The same holds for dataset size and for compute (Kaplan et al. 2020). A line fitted on small, cheap runs therefore predicts large, expensive ones.

Compute-optimal training. A budget of C FLOPs buys about C = 6ND (5.1): a bigger model must see fewer tokens. Hoffmann et al. trained over 400 models and found that parameters and tokens should grow at about the same rate, roughly 20 tokens per parameter. Their 70 B-parameter Chinchilla, trained on 1.4 T tokens, beat the 280 B Gopher that used the same compute (Hoffmann et al. 2022). One of their methods fits L=E+A/Nα+B/DβL = E + A/N^\alpha + B/D^\beta and minimises it along the constraint (below). Another trains several model sizes for each fixed budget: an IsoFLOP curve. The vertex of a parabola fitted in log N gives the best size, and the vertices lie on a power law in C.

Fit with care. Power laws are fitted as straight lines in log space, and small differences in the fit become large factors far from the data. A replication found that Chinchilla’s published parametric fit does not match its own data (Besiroglu et al. 2024). Report the range your runs cover.

Beyond compute-optimal. The optimum ignores inference. A model that will serve billions of requests is cheaper to run if it is smaller and trained on many more tokens than Chinchilla suggests. LLaMA trained a 7 B model on 1 T tokens (Touvron et al. 2023; Sardana & Frankle 2023).

The compute-optimal split of a budgetstep 1 of 5
  1. min⁡N,D E+ANα+BDβsubject to6ND=C\min_{N, D}\ E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}\quad\text{subject to}\quad 6ND = C

Scaling-law explorer

Compute-optimal model size and token count

Static view on small screens. Open this page on a laptop to interact.

4567100 M1.00 B10.0 B100 Bx: model size N · y: final loss 1081091010101110121018102010221024x: budget C (FLOPs) · y: optimal N
fit to these runs: N_opt = 0.133 C0.515, D_opt ∝ C0.485 at 1023.0 FLOPs: N = 91.1 B, D = 183 B tokens (2.0 tokens per parameter), an extrapolation Chinchilla's parametric fit (Approach 3): N = 14.6 B, D = 1.14 T; the "20 tokens per parameter" rule: N = 28.9 B, D = 577 B

Each colour is one compute budget: eight models of different sizes trained with exactly that many FLOPs (data: CS336 Assignment 3). Too small a model is underpowered; too large a one sees too few tokens; the parabola's vertex is the best size for that budget. The optima lie on a straight line in log-log space: a power law, here with exponent about 0.5, so model size and data should grow together, as Hoffmann et al. (2022) found. Kaplan et al. (2020) had found an exponent near 0.73; the difference has been traced to a learning-rate schedule that did not adapt to run length (Hoffmann et al.) and to counting parameters without the embeddings (Pearce and Song 2024). The exponent agrees with Chinchilla but the constant does not: these runs favour far fewer tokens per parameter, because the ratio depends on the data, the architecture and how parameters are counted. The three predictions differ by large factors far from the data: extrapolating a fit is the point, and the risk.

Left: IsoFLOP curves from CS336 Assignment 3, final loss against model size for nine compute budgets, each with a fitted parabola in log N and its vertex circled. Right: the nine optimal sizes against compute on log-log axes, with the fitted power law extended to the budget chosen with a slider. The readout gives the fitted law, the predicted model size, tokens and tokens per parameter at that budget, and, for comparison, Chinchilla’s parametric fit and the 20-tokens-per-parameter rule. Keyboard: Tab to the budget slider and use the arrow keys.

First, the fitting, in the browser or locally, on the IsoFLOP runs that come with CS336 Assignment 3 (the course gives its own students a training API instead; the method is the same).

Chinchilla optimum and an IsoFLOP fit stubs/m5_4_scaling.py

Loading starter file…

Prefer your own editor? Edit exercises/stubs/m5_4_scaling.py and run mlc check 5.4. The tests are identical; import the results on the progress page.

Hints · isoflop_optimum 0/3 revealed
Hints · scaling_fit 0/3 revealed

Then make your own curves. Open notebooks/5.4-isoflops.ipynb on Kaggle with a GPU and paste in your 4.6 GPT and your 5.4 functions. It trains six widths of your GPT at each of three compute budgets on TinyStories, each run for exactly C / 6N tokens with a learning-rate schedule fitted to its length. It then fits your IsoFLOP curves and power law and extrapolates them. The sweep takes about 15 minutes; without a GPU it runs a tiny smoke version on Shakespeare.

1. What is an IsoFLOP curve?
2. Chinchilla found that with 10× more compute, the optimal model should be about…
3. Why fit power laws as straight lines in log-log space?
4. Why do many released models train on far more tokens than the compute-optimal amount?
  • not yet: All tests pass (0/?)
  • not yet: Checkpoint quiz ≥ 80%
Finish the items above first.
Learner log: time spent and points of confusion

Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.