TExcelTAD
Home › Math for Deep Learning & LLMs › Scaling Laws and Compute Arithmetic

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 L(x)=a x−αL(x) = a\,x^{-\alpha} is a straight line on log-log axes: log⁡L=log⁡a−αlog⁡x\log L = \log a - \alpha\log x. Doubling xx always multiplies LL by the same factor 2−α2^{-\alpha}. Fitting a line to (log⁡x,log⁡L)(\log x, \log L) recovers the exponent.

The Chinchilla form

With NN parameters and DD training tokens, the loss is well described by

L(N,D)=E+ANα+BDβL(N, D) = E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}

EE 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 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 (nats per token, for their data and tokenizer; the exact values vary across setups).

Compute-optimal allocation

Training compute is C≈6NDC \approx 6ND (Counting Parameters and FLOPs). For a fixed CC, substitute D=C/(6N)D = C/(6N) and minimize over NN. Setting the derivative to zero gives N∗∝Cβ/(α+β)N^* \propto C^{\beta/(\alpha + \beta)} and D∗∝Cα/(α+β)D^* \propto C^{\alpha/(\alpha + \beta)}, both close to C0.5C^{0.5}: grow parameters and tokens in equal proportion.

python · try it yourself
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

python · try it yourself
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 NN, so spending extra training compute to shrink NN 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. 10710^7 to 10910^9 parameters), fit the law, and extrapolate before committing to a large run.
  • np.polyfit on log-log data, or a nonlinear least-squares fit of E+A/Nα+B/DβE + A/N^\alpha + B/D^\beta, recovers the parameters.
  • μ\muP 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

1.4×10111.4 \times 10^{11} tokens (140 billion) and about 5.9×10215.9 \times 10^{21} FLOPs.

Solution

D=20⋅7×109=1.4×1011D = 20 \cdot 7 \times 10^9 = 1.4 \times 10^{11} tokens (140 billion). C=6ND=6⋅7×109⋅1.4×1011=5.88×1021C = 6ND = 6 \cdot 7 \times 10^9 \cdot 1.4 \times 10^{11} = 5.88 \times 10^{21} FLOPs.

Exercise 2: Doubling the model

With α=0.34\alpha = 0.34, by what factor does the parameter term A/NαA/N^\alpha shrink when NN doubles?

Answer

To about 0.790.79 of its value.

Solution

2−0.34=e−0.34ln⁡2≈e−0.236≈0.7902^{-0.34} = e^{-0.34\ln 2} \approx e^{-0.236} \approx 0.790.

Exercise 3: Budget split (code)

With C=6NDC = 6ND and the rule D=20ND = 20N, find NN and DD for C=1023C = 10^{23} FLOPs.

Answer

N≈2.9×1010N \approx 2.9 \times 10^{10}, D≈5.8×1011D \approx 5.8 \times 10^{11}.

Solution

C=6N⋅20N=120N2C = 6N \cdot 20N = 120N^2, so N=C/120N = \sqrt{C/120}.

python · try it yourself
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 L=ax−αL = ax^{-\alpha} appears as…

  1. an exponential curve
  2. a straight line with slope −α-\alpha
  3. a parabola
  4. a step function

The Chinchilla result says that, for a fixed compute budget, parameters and training tokens should…

  1. favor parameters heavily
  2. grow roughly in equal proportion, about 20 tokens per parameter
  3. favor tokens only
  4. be independent of compute

Why do many deployed models train on far more than 20 tokens per parameter?

  1. Training is free
  2. A smaller model trained longer is cheaper to serve
  3. Scaling laws do not apply to them
  4. To increase perplexity