Simple Algorithm
Deep Learning · Representation · 24 min

Neural Scaling Laws

Power laws in loss versus parameters, data and compute, across modalities, and compute-optimal training.

A frontier training run happens once, at a price that rules out trial and error. Its model size, token count and final loss are nevertheless chosen in advance, by extrapolating from runs a thousand times cheaper. This lesson derives the compute bill of a transformer, solves a fitted loss surface for the best split between parameters and data, dissects why two landmark studies disagreed, and maps where scaling laws hold beyond text and where they bend.

What you’ll learn

  • Derive C≈6NDC\approx6ND from the FLOPs of a transformer's matrix products, together with the attention term it leaves out and when that term matters.
  • Fit power laws with an irreducible floor, and solve L(N,D)=E+A/Nα+B/DβL(N,D)=E+A/N^\alpha+B/D^\beta under C=6NDC=6ND for the compute-optimal NN and DD.
  • Explain why Kaplan et al. (2020) and Hoffmann et al. (2022) reached different allocations, and why the optimal tokens per parameter depend on how a fit was made.
  • Describe scaling laws for images, video, games and transfer, and the ways laws fail: broken power laws, inverse scaling and hard-to-predict downstream tasks.

Power laws, measured

A scaling law summarizes many training runs with a power law. Kaplan et al. (2020) trained decoder-only transformers with 768 to 1.5 billion non-embedding parameters on WebText2, about 23 billion tokens of web text, and measured the test loss in nats per token. Whenever one resource was the bottleneck, the loss followed a power law in it:

L(N)=(NcN)0.076,L(D)=(DcD)0.095,L(Cmin⁡)=(CcCmin⁡)0.050L(N)=\Big(\frac{N_c}{N}\Big)^{0.076},\qquad L(D)=\Big(\frac{D_c}{D}\Big)^{0.095},\qquad L(C_{\min})=\Big(\frac{C_c}{C_{\min}}\Big)^{0.050}
NN excludes embeddings, Nc≈8.8×1013N_c\approx8.8\times10^{13} and Dc≈5.4×1013D_c\approx5.4\times10^{13} tokens; Cmin⁡C_{\min} is the compute of the most efficient run that reaches a given loss. Each law needs the other resources to be plentiful: L(N)L(N) is for models trained close to convergence on ample data, L(D)L(D) for large models stopped early on a dataset of DD tokens.

The same study found regularities that make extrapolation possible:

  • Shape barely matters. At fixed NN, changing the aspect ratio dmodel/nlayerd_{\text{model}}/n_{\text{layer}} by a factor of 40 changed the loss only slightly.
  • Overfitting is predictable. In their joint fit L(N,D)L(N,D) the penalty for limited data depends on N0.74/DN^{0.74}/D, so a model 8 times larger needs only about 5 times more data to avoid it.
  • Bigger models are more sample-efficient: they reach a given loss in fewer steps and with fewer tokens.

Hestness et al. (2017) had already seen power-law learning curves in translation, language modeling, image classification and speech recognition, and noticed that better architectures shifted the curves without changing their exponents.

Predict before you look

Kaplan et al.'s compute law has exponent 0.0500.050 and no floor. By what factor must compute grow to halve the loss? Give log⁡10\log_{10} of the factor.

Show the answer

6

Halving needs (C′/C)0.05=2(C'/C)^{0.05}=2, so C′/C=21/0.05=220≈106C'/C=2^{1/0.05}=2^{20}\approx10^{6}: a millionfold more compute. Small exponents are why scaling is expensive, and why measuring them is delicate: with 0.040.04 or 0.060.06 instead, the factor becomes 3×1073\times10^{7} or 10510^{5}. An error of 0.010.01 in an exponent moves such extrapolations tenfold or more.

Counting FLOPs

Scaling laws are stated in FLOPs, so the bill must be counted with care. Take a decoder-only transformer with nlayern_{\text{layer}} layers of width dd, attention width dd and an MLP of width 4d4d.

DerivationFLOPs per training token
  1. N≈12 nlayerd2,Cweights≈2N FLOPs per token, forwardN\approx12\,n_{\text{layer}}d^2,\qquad C_{\text{weights}}\approx2N\ \text{FLOPs per token, forward}

    A weight matrix W∈Rm×nW\in\R^{m\times n} applied to one token's vector costs mnmn multiply-adds: 2 FLOPs per weight. Each layer holds 4d24d^2 attention weights (WQ,WK,WV,WOW_Q,W_K,W_V,W_O) and 8d28d^2 MLP weights, so

  2. Cforward≈2N+2 nlayer nctx dC_{\text{forward}}\approx2N+2\,n_{\text{layer}}\,n_{\text{ctx}}\,d

    Attention also does work that involves no weights. A query scores each key it can see (2d2d FLOPs) and adds up the matching values (another 2d2d). Under a causal mask token tt sees tt keys, nctx/2n_{\text{ctx}}/2 on average, which gives 2nctxd2n_{\text{ctx}}d per layer:

  3. Ctrain≈6N+6 nlayer nctx d  FLOPs per token⟹C≈6NDC_{\text{train}}\approx6N+6\,n_{\text{layer}}\,n_{\text{ctx}}\,d\ \ \text{FLOPs per token}\qquad\Longrightarrow\qquad C\approx6ND

    Backpropagation through Y=XWY=XW needs ∂L/∂X=(∂L/∂Y) W⊤\partial\loss/\partial X=(\partial\loss/\partial Y)\,W^\top and ∂L/∂W=X⊤(∂L/∂Y)\partial\loss/\partial W=X^\top(\partial\loss/\partial Y): two products the size of the forward one. Attention's backward pass is likewise about twice its forward pass, so a training step costs three forward passes:

  4. 6 nlayer nctx d6N≈nctx12 d\frac{6\,n_{\text{layer}}\,n_{\text{ctx}}\,d}{6N}\approx\frac{n_{\text{ctx}}}{12\,d}

    Divide the attention term by the weight term, using N≈12nlayerd2N\approx12n_{\text{layer}}d^2:

  5. Attention adds little while the context is short compared with 12d12d, which is why C≈6NDC\approx6ND serves for most published models; past 12d12d it dominates. The unembedding adds another 2d ∣V∣2d\,\abs{\mathcal V} FLOPs per token, a large share for small models with big vocabularies, and one that Kaplan et al. left out.

Predict before you look

A model of width d=4096d=4096 is trained with a context of 8,1928{,}192 tokens. By what percentage does attention raise the training FLOPs above 6N6N per token?

Show the answer

16.7 %

8192/(12×4096)=1/6≈17%8192/(12\times4096)=1/6\approx17\%. With a 32,76832{,}768-token context it would be 67%67\%, and C≈6NDC\approx6ND would badly undercount. GPT-3, with d=12,288d=12{,}288 and a 2,0482{,}048-token context, sits at 1.4%1.4\%.

The compute-optimal allocation

Kaplan et al. concluded that a growing budget should go mostly to parameters, Nopt∝C0.73N_{\text{opt}}\propto C^{0.73} and Dopt∝C0.27D_{\text{opt}}\propto C^{0.27}, with large models stopped far short of convergence. Hoffmann et al. (2022) attacked the same question three ways, with over 400 runs from 70 million to over 16 billion parameters:

ApproachMethodaa in Nopt∝CaN_{\text{opt}}\propto C^a
  1. Training-curve envelope
each model size trained with 4 schedule lengths; at every FLOP count, keep the lowest loss reached by any run0.500.50
  1. IsoFLOP profiles
9 budgets from 6×10186\times10^{18} to 3×10213\times10^{21} FLOPs; at each, vary NN, fit a parabola in log⁡N\log N and take its minimum0.490.49
  1. Parametric fit
fit L(N,D)=E+A/Nα+B/DβL(N,D)=E+A/N^\alpha+B/D^\beta to all runs by minimizing a Huber loss on log⁡L\log L0.460.46
All three put the exponents of NoptN_{\text{opt}} and DoptD_{\text{opt}} near 0.50.5: grow both equally. The printed fit of Approach 3 is E=1.69E=1.69, A=406.4A=406.4, B=410.7B=410.7, α=0.34\alpha=0.34, β=0.28\beta=0.28.
DerivationSolving the parametric law
  1. L(N)=E+AN−α+B(C6)−βNβ,dLdN=−αAN−α−1+βB(C6)−βNβ−1=0L(N)=E+AN^{-\alpha}+B\Big(\frac C6\Big)^{-\beta}N^{\beta},\qquad\frac{dL}{dN}=-\alpha AN^{-\alpha-1}+\beta B\Big(\frac C6\Big)^{-\beta}N^{\beta-1}=0

    Substitute D=C/6ND=C/6N and minimize over NN:

  2. αA N−α=βB D−β⟺A/NαB/Dβ=βα\alpha A\,N^{-\alpha}=\beta B\,D^{-\beta}\qquad\Longleftrightarrow\qquad\frac{A/N^{\alpha}}{B/D^{\beta}}=\frac{\beta}{\alpha}

    Multiply by NN and put DD back. At the optimum the two reducible terms stand in a fixed ratio:

  3. Nopt=G(C6)βα+β,Dopt=G−1(C6)αα+β,G=(αAβB)1α+βN_{\text{opt}}=G\Big(\frac C6\Big)^{\frac{\beta}{\alpha+\beta}},\qquad D_{\text{opt}}=G^{-1}\Big(\frac C6\Big)^{\frac{\alpha}{\alpha+\beta}},\qquad G=\Big(\frac{\alpha A}{\beta B}\Big)^{\frac1{\alpha+\beta}}

    Solve for NN, then D=C/6ND=C/6N:

  4. Lopt−E ∝ C−αβα+β,DoptNopt=G−2(C6)α−βα+βL_{\text{opt}}-E\ \propto\ C^{-\frac{\alpha\beta}{\alpha+\beta}},\qquad\frac{D_{\text{opt}}}{N_{\text{opt}}}=G^{-2}\Big(\frac C6\Big)^{\frac{\alpha-\beta}{\alpha+\beta}}

    Both reducible terms then fall at one rate, and the ratio of tokens to parameters drifts unless α=β\alpha=\beta:

  5. With the printed α=0.34>β=0.28\alpha=0.34>\beta=0.28 the ratio grows like C0.097C^{0.097}, so the fit itself does not say "20 tokens per parameter" (the paper's own Approach 3 projections rise from 27 tokens per parameter at 1 billion parameters to 61 at 67 billion): that rule comes from Approaches 1 and 2 and from Chinchilla, 70 billion parameters on 1.4 trillion tokens. Besiroglu et al. (2024) refitted Approach 3 to data reconstructed from the paper's figures. They found the printed estimates inconsistent with the other two approaches and their confidence intervals implausibly narrow, traced this to a fitting optimizer that had stopped before converging and to rounding in the printed values, and obtained α≈0.35<β≈0.37\alpha\approx0.35<\beta\approx0.37: about 20 tokens per parameter, almost constant.

Predict before you look

With the printed exponents α=0.34\alpha=0.34 and β=0.28\beta=0.28, what is aa in Nopt∝CaN_{\text{opt}}\propto C^a?

Show the answer

0.45

a=β/(α+β)=0.28/0.62≈0.45a=\beta/(\alpha+\beta)=0.28/0.62\approx0.45, close to the 0.460.46 Hoffmann et al. report from unrounded values; the re-fit gives 0.366/0.714≈0.510.366/0.714\approx0.51. Either way about half of each extra factor of compute goes to parameters and half to data, against Kaplan's 0.730.73.

Why the two studies disagreed

Kaplan et al. found a≈0.73a\approx0.73, Hoffmann et al. about 0.50.5; extrapolated to Chinchilla's budget, the first prescribes a model roughly ten times larger. The gap turned out to be methodological, and taking it apart shows how fragile fitted exponents are:

  • Learning-rate schedules. Hoffmann et al. pointed out that Kaplan et al. read losses part-way through runs whose cosine schedule was set for a longer horizon. Such losses overstate what a shorter, fully decayed run reaches, which undervalues training on fewer tokens; they proposed this as the cause of the gap.
  • What counts as a parameter. Kaplan et al. excluded embedding parameters, a large share of small models. Simulating Chinchilla-like training curves for Kaplan's range of model sizes and fitting in non-embedding parameters gives local exponents of 0.740.74 to 0.780.78, close to Kaplan's (Pearce & Song, 2024).
  • Compute, warmup and tuning. Porian et al. (2024) reproduced Kaplan's result (a≈0.835a\approx0.835 in their setup) and removed the discrepancy one factor at a time: counting the last layer's FLOPs (0.710.71), shortening a fixed warmup that was too long for small models (0.600.60), and tuning the learning rate, batch size and AdamW β2\beta_2 at each model size (0.500.50). Matching the learning-rate decay to each run's length, the explanation Hoffmann et al. offered, changed little (0.600.60 to 0.570.57): their tuned runs reproduced the Chinchilla law with a constant learning rate.
python
import numpy as np

def isoflop_minimum(N, L):
    """Approach 2: final losses L of models of sizes N, all trained with one budget C."""
    c2, c1, _ = np.polyfit(np.log(N), L, deg=2)   # parabola in log N
    return np.exp(-c1 / (2 * c2))                 # its vertex estimates N_opt(C)

def fit_exponent(C, N_opt):
    """N_opt = k * C**a is a straight line on log-log axes."""
    a, log_k = np.polyfit(np.log(C), np.log(N_opt), deg=1)
    return a, np.exp(log_k)

# n_opt = [isoflop_minimum(N_c, L_c) for N_c, L_c in runs_per_budget]
# a, k = fit_exponent(budgets, np.array(n_opt))

The core of an IsoFLOP study. Everything that matters happens before this code runs: how NN and CC are counted, and whether every run was trained with hyperparameters suited to its size and length.

Check your understanding

You fit Nopt∝CaN_{\text{opt}}\propto C^a from runs between 101710^{17} and 101910^{19} FLOPs, using one learning rate and warmup tuned for your largest model. What is the main risk?

  1. None: the exponent does not depend on hyperparameters
  2. The fit will be too noisy to give any exponent at all
  3. Runs of other sizes are handicapped by unsuitable hyperparameters, which shifts where each iso-FLOP minimum falls and biases aa
  4. The largest model will overfit, so aa comes out too small
Show the answer

C. Runs of other sizes are handicapped by unsuitable hyperparameters, which shifts where each iso-FLOP minimum falls and biases aa

A scaling law compares well-tuned runs. If small models get a learning rate or warmup that suits large ones, their losses are inflated by different amounts at different sizes, and the minima of the iso-FLOP curves move. Porian et al. traced much of Kaplan's exponent to exactly this kind of effect.

Beyond language, and where laws bend

SettingFindingSource
Images, video, image↔text, mathloss is a power law plus a constant in compute, in every domain; Nopt∝C≈0.7N_{\text{opt}}\propto C^{\approx0.7}, measured with Kaplan et al.'s methods (fixed 3,000-step warmup included)Henighan et al., 2020
Vision transformerserror against compute follows a double-saturating law E=a(C+d)−b+cE=a(C+d)^{-b}+c; bigger models are more sample-efficientZhai et al., 2022
Board games (Hex, AlphaZero)play at fixed compute degrades predictably with board size; each extra 10×10\times of training compute saves about 15×15\times of test-time searchJones, 2021
Transfer (text to Python)pretraining is worth extra fine-tuning data DT=k DF0.18N0.38D_T=k\,D_F^{0.18}N^{0.38}: it multiplies the fine-tuning setHernandez et al., 2021
The same functional forms recur across modalities; the exponents and constants do not.

Laws also bend and break:

  • Broken power laws. Many curves change slope. A smoothly broken power law, power-law segments joined smoothly, fits and extrapolates them better than a single power law, including double descent and late, sharp inflections such as those on arithmetic tasks (Caballero et al., 2023).
  • Inverse scaling. On some tasks larger language models do worse. A public contest collected 11 such tasks and identified four causes: repeating memorized text instead of following instructions, imitating undesirable patterns in the data, latching onto an easy distractor task, and misleading few-shot examples. Some of these trends later reversed into U shapes (McKenzie et al., 2023).
  • Downstream tasks. Loss falls smoothly, but accuracy is a nonlinear function of loss, so a single task can look flat and then jump. Whether such emergent abilities are real or created by all-or-nothing metrics is debated (Wei et al., 2022; Schaeffer et al., 2023). Averages over many tasks are more predictable: Gadre et al. (2024) linked perplexity to average top-1 error with a power law and predicted it for models trained with 20 times more compute than the runs used for the fit.
  • Inference. A model that will serve many requests (on the order of a billion or more) should be trained smaller and longer than compute-optimal. In tests, quality kept improving up to 10,000 tokens per parameter, though fits made at ordinary ratios overestimated the gains at such extremes (Sardana et al., 2024).

Key takeaways

  • Loss follows power laws in NN, DD and CC when the others are plentiful, best fitted with a floor, L=E+Ax−αL=E+Ax^{-\alpha}. Small exponents make scaling costly: halving the loss at exponent 0.050.05 takes about 10610^6 times more compute.
  • Training costs 6N+6nlayernctxd6N+6n_{\text{layer}}n_{\text{ctx}}d FLOPs per token: C≈6NDC\approx6ND holds while nctx≪12dn_{\text{ctx}}\ll12d, and the unembedding matters for small models.
  • Minimizing E+A/Nα+B/DβE+A/N^\alpha+B/D^\beta at fixed C=6NDC=6ND balances αA/Nα=βB/Dβ\alpha A/N^\alpha=\beta B/D^\beta and gives Nopt∝Cβ/(α+β)N_{\text{opt}}\propto C^{\beta/(\alpha+\beta)}; tokens per parameter stay constant only if α=β\alpha=\beta. Chinchilla's 20 comes from Approaches 1 and 2 and the re-fitted Approach 3, not from the printed fit.
  • Kaplan's C0.73C^{0.73} versus Chinchilla's C0.5C^{0.5} came from method: parameter and FLOP counting, warmup and per-size tuning at small scale.
  • Similar laws hold for images, video, games and transfer, but curves can break, invert on specific tasks, and translate unpredictably into downstream accuracy.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A transformer has width d=2048d=2048. At roughly what context length does the attention term of its training FLOPs equal the 6N6N term?

  1. 2,0482{,}048 tokens
  2. 12,28812{,}288 tokens
  3. 24,57624{,}576 tokens
  4. 49,15249{,}152 tokens
Show the answer

C. 24,57624{,}576 tokens

The ratio is nctx/(12d)n_{\text{ctx}}/(12d), which reaches 11 at nctx=12×2048=24,576n_{\text{ctx}}=12\times2048=24{,}576. Beyond that, a FLOP count of 6ND6ND undercounts by more than half.

Question 2

At the compute-optimal point of L=E+A/Nα+B/DβL=E+A/N^\alpha+B/D^\beta with C=6NDC=6ND, which statement holds?

  1. The model term equals the data term: A/Nα=B/DβA/N^\alpha=B/D^\beta
  2. αA/Nα=βB/Dβ\alpha A/N^\alpha=\beta B/D^\beta, so the model term is β/α\beta/\alpha times the data term
  3. D=20ND=20N, whatever the constants
  4. N=DN=D
Show the answer

B. αA/Nα=βB/Dβ\alpha A/N^\alpha=\beta B/D^\beta, so the model term is β/α\beta/\alpha times the data term

Setting dL/dN=0dL/dN=0 with D=C/6ND=C/6N gives αAN−α=βBD−β\alpha AN^{-\alpha}=\beta BD^{-\beta}. Each term's elasticity balances, not its size; the terms are equal only if α=β\alpha=\beta.

Question 3

Hoffmann et al.'s printed parametric fit has α=0.34\alpha=0.34 and β=0.28\beta=0.28. What does it imply about the optimal tokens per parameter?

  1. A constant 20 at every budget
  2. It shrinks as compute grows, as Kaplan et al. found
  3. It is undefined, because the fit has no optimum
  4. It grows as compute grows, like C(α−β)/(α+β)≈C0.1C^{(\alpha-\beta)/(\alpha+\beta)}\approx C^{0.1}: about 50 at 102110^{21} FLOPs and 78 at 102310^{23}
Show the answer

D. It grows as compute grows, like C(α−β)/(α+β)≈C0.1C^{(\alpha-\beta)/(\alpha+\beta)}\approx C^{0.1}: about 50 at 102110^{21} FLOPs and 78 at 102310^{23}

Dopt/Nopt∝C(α−β)/(α+β)D_{\text{opt}}/N_{\text{opt}}\propto C^{(\alpha-\beta)/(\alpha+\beta)}, and α>β\alpha>\beta makes it grow. The 20-tokens rule comes from Approaches 1 and 2 and from Chinchilla itself; Besiroglu et al.'s re-fit of Approach 3, with α<β\alpha<\beta, recovers about 20.

Question 4

Porian et al. (2024) reproduced Kaplan et al.'s allocation and then recovered Hoffmann et al.'s. Which change turned out not to be needed?

  1. Matching the learning-rate decay to each run's length
  2. Counting the last layer's FLOPs
  3. Shortening the warmup for small models
  4. Tuning the learning rate, batch size and AdamW β2\beta_2 at each model size
Show the answer

A. Matching the learning-rate decay to each run's length

Their fully tuned runs used a constant learning rate and still gave a≈0.50a\approx0.50. Cosine decay lowers the loss, but the allocation came from FLOP counting, warmup and per-size tuning.

Question 5

What is inverse scaling?

  1. Training loss rising as models grow
  2. Performance on a specific task getting worse as models grow, even as their overall loss improves
  3. Smaller models generalizing better because they overfit less
  4. Loss falling faster than any power law
Show the answer

B. Performance on a specific task getting worse as models grow, even as their overall loss improves

McKenzie et al. (2023) collected 11 tasks where bigger language models did worse, caused by things like distractor tasks and imitation of undesirable patterns in the data; some trends later turned U-shaped. Aggregate loss can improve while a particular behavior degrades.

Go deeper

Further reading

  • J. Kaplan et al., "Scaling laws for neural language models," arXiv:2001.08361 (2020).
  • J. Hoffmann et al., "Training compute-optimal large language models," NeurIPS (2022).
  • T. Besiroglu, E. Erdil, M. Barnett & J. You, "Chinchilla scaling: A replication attempt," arXiv:2404.10102 (2024).
  • T. Porian, M. Wortsman, J. Jitsev, L. Schmidt & Y. Carmon, "Resolving discrepancies in compute-optimal scaling of language models," NeurIPS (2024).
  • T. Henighan et al., "Scaling laws for autoregressive generative modeling," arXiv:2010.14701 (2020).