Scaling Laws and Compute Arithmetic
One of the most useful empirical facts about language models is that their loss falls predictably as model size, data and compute grow: smooth power laws over many orders of magnitude. Scaling laws let labs predict a large model's loss from small experiments and decide how to split a fixed compute budget between parameters and training tokens. The headline result (Hoffmann et al., 2022, "Chinchilla"): train with roughly 20 tokens per parameter.
Power laws
A power law is a straight line on log-log axes: . Doubling always multiplies by the same factor . Fitting a line to recovers the exponent.
The Chinchilla form
With parameters and training tokens, the loss is well described by
is the irreducible loss (the entropy of text); the other terms are the penalties for a finite model and finite data. Published fits are about , , , , (nats per token, for their data and tokenizer; the exact values vary across setups).
Compute-optimal allocation
Training compute is (Counting Parameters and FLOPs). For a fixed , substitute and minimize over . Setting the derivative to zero gives and , both close to : grow parameters and tokens in equal proportion.
import numpy as np
E, A, B, a, b = 1.69, 406.4, 410.7, 0.34, 0.28
L = lambda N, D: E + A / N**a + B / D**b
for C in (1e21, 1e22, 1e23, 1e24):
Ns = np.logspace(7, 12, 4001)
losses = L(Ns, C / (6 * Ns))
i = np.argmin(losses); N, D = Ns[i], C / (6 * Ns[i])
print(f"C = {C:.0e}: best N = {N:.2e}, D = {D:.2e}, tokens/param = {D / N:5.1f}, loss {losses[i]:.3f}")C = 1e+21: best N = 1.82e+09, D = 9.13e+10, tokens/param = 50.0, loss 2.329
C = 1e+22: best N = 5.16e+09, D = 3.23e+11, tokens/param = 62.6, loss 2.139
C = 1e+23: best N = 1.46e+10, D = 1.14e+12, tokens/param = 78.4, loss 2.005
C = 1e+24: best N = 4.13e+10, D = 4.03e+12, tokens/param = 97.6, loss 1.911
With these constants the optimal ratio comes out at roughly 50 to 100 tokens per parameter and drifts upward with compute. The Chinchilla paper combined several estimation methods and settled on about 20; the exact ratio is sensitive to the fitted constants, but the conclusion that parameters and tokens should grow together is robust.
Fitting an exponent
import numpy as np
rng = np.random.default_rng(0)
N = np.logspace(6, 9, 8) # small models, 1M to 1B parameters
L_red = 406.4 / N**0.34 * np.exp(rng.normal(0, 0.01, 8)) # reducible loss with 1% noise
slope, intercept = np.polyfit(np.log(N), np.log(L_red), 1)
print(f"fitted exponent alpha = {-slope:.3f} (true 0.34), coefficient A = {np.exp(intercept):.1f}")
pred = np.exp(intercept) * 1e11**slope
print(f"extrapolated reducible loss at N = 1e11: {pred:.4f} (true {406.4 / 1e11**0.34:.4f})")fitted exponent alpha = 0.339 (true 0.34), coefficient A = 398.2
extrapolated reducible loss at N = 1e11: 0.0750 (true 0.0740)
Over-training for inference
Chinchilla-optimal minimizes training compute for a given loss. But a model that will serve billions of requests should be smaller and trained longer: inference cost scales with , so spending extra training compute to shrink pays off. Many recent open models train on hundreds or thousands of tokens per parameter, far past the compute-optimal point, accepting diminishing returns in loss.
Caveats
- The constants depend on data, tokenizer and architecture; only exponents and trends transfer roughly.
- Loss is not capability: some downstream skills appear abruptly as loss improves smoothly.
- Data is finite: repeating data beyond a few epochs gives diminishing returns, so high-quality tokens are a binding constraint.
In software
- Scaling studies train a grid of small models (e.g. to parameters), fit the law, and extrapolate before committing to a large run.
np.polyfiton log-log data, or a nonlinear least-squares fit of , recovers the parameters.- P parametrization makes the best learning rate nearly independent of width, which keeps small-scale experiments predictive.
Exercises
Exercise 1: Tokens for a 7B model
Using 20 tokens per parameter, how many tokens does a compute-optimal 7B model need, and what is the training compute?
Answer
tokens (140 billion) and about FLOPs.
Solution
tokens (140 billion). FLOPs.
Exercise 2: Doubling the model
With , by what factor does the parameter term shrink when doubles?
Answer
To about of its value.
Solution
.
Exercise 3: Budget split (code)
With and the rule , find and for FLOPs.
Answer
, .
Solution
, so .
import numpy as np
C = 1e23
N = np.sqrt(C / 120)
print(f"N = {N:.2e}, D = {20 * N:.2e}")N = 2.89e+10, D = 5.77e+11
Test yourself
On log-log axes, a power law appears as…
- an exponential curve
- a straight line with slope
- a parabola
- a step function
The Chinchilla result says that, for a fixed compute budget, parameters and training tokens should…
- favor parameters heavily
- grow roughly in equal proportion, about 20 tokens per parameter
- favor tokens only
- be independent of compute
Why do many deployed models train on far more than 20 tokens per parameter?
- Training is free
- A smaller model trained longer is cheaper to serve
- Scaling laws do not apply to them
- To increase perplexity