Part XXIII — Modern Architectures, Generative Models & LLM Engineering · Chapter 9

Scaling laws

Hook

Training a model 10x larger, just to see if it's worth it, can cost more than the entire rest of a project. What if four small, cheap training runs could tell you almost exactly what the expensive one would have shown, before you ever ran it?

Intuition

The same four training runs, fit two different ways. One method transforms the data before fitting a line; the other fits the raw numbers directly. Only one of them produces a sane prediction at a size fifty times bigger than anything actually trained.

Formalize

Loss often follows a power law in model size: L(N)=ANαL(N) = A \cdot N^{-\alpha}. Taking logs turns this into something linear:

logL=logAαlogN\log L = \log A - \alpha \log N
  • LL (or L(N)L(N)) — the model's loss at a given size.
  • NN — the model size (number of parameters).
  • AA — a constant scale factor in the power law, fit from data.
  • α\alpha — the scaling exponent: how fast loss falls as NN grows.
  1. Log-log OLS recovers the law directly

    Fitting ordinary least squares to (logN,logL)(\log N, \log L) recovers α\alpha and AA directly — the exact same OLS machinery from Part IX, just applied after a log transform.

  2. Fitting the raw numbers assumes the wrong shape

    Fitting a line to the raw (N,L)(N, L) pairs instead assumes a linear relationship that was never true, and extrapolates accordingly.

Play
log(N) vs log(loss): the 4 training points and the untested N=100 point all fall exactly on one line

Four training runs at sizes 1, 4, 9, and 16 — and a fifth point at N=100N=100, never trained, just computed from the true law for comparison. All five points sit exactly on one straight line in log-log space, because that line is the power law.

Worked example

True law L(N)=100N0.5L(N) = 100 \cdot N^{-0.5}, observed at N{1,4,9,16}N \in \{1, 4, 9, 16\} giving losses {100,50,33.3,25}\{100, 50, 33.\overline{3}, 25\}:

  1. Log-log OLS recovers the law exactly

    (logN,logL)(\log N, \log L) pairs: (0,4.605)(0, 4.605), (1.386,3.912)(1.386, 3.912), (2.197,3.507)(2.197, 3.507), (2.773,3.219)(2.773, 3.219).

    • Mean logN1.589\log N \approx 1.589, mean logL3.811\log L \approx 3.811
    • slope=(logNlogN)(logLlogL)(logNlogN)22.1684.3370.500\text{slope} = \dfrac{\sum(\log N-\overline{\log N})(\log L-\overline{\log L})}{\sum(\log N-\overline{\log N})^2} \approx \dfrac{-2.168}{4.337} \approx -0.500
    • intercept=logLslope×logN3.811(0.500)(1.589)4.605ln(100)\text{intercept} = \overline{\log L} - \text{slope}\times\overline{\log N} \approx 3.811-(-0.500)(1.589)\approx4.605\approx\ln(100)

    Both match the true law (α=0.5\alpha=0.5, A=100A=100) to full floating-point precision, since the training data has no noise at all.

  2. Extrapolating to N=100: almost exactly right

    log(100)4.605\log(100)\approx4.605. Plugging into the fitted line: 4.605+(0.500)(4.605)2.3034.605 + (-0.500)(4.605) \approx 2.303. Exponentiating back: e2.30310.000e^{2.303}\approx10.000 — matching the true value of exactly 1010, despite N=100N=100 being far outside the training range of 11 to 1616.

  3. Fitting the raw numbers instead: a nonsensical answer

    Raw (N,L)(N, L) pairs: (1,100)(1,100), (4,50)(4,50), (9,33.33)(9,33.33), (16,25)(16,25).

    • Mean N=7.5N=7.5, mean L52.08L\approx52.08
    • slope562.5/1294.360\text{slope} \approx -562.5/129 \approx -4.360
    • intercept52.08(4.360)(7.5)84.79\text{intercept} \approx 52.08-(-4.360)(7.5)\approx84.79
    • At N=100N=100: 84.79+(4.360)(100)84.79436.0351.2684.79 + (-4.360)(100) \approx 84.79 - 436.0 \approx -351.26

    A negative loss is meaningless; the raw-linear model was extrapolating a relationship that was never actually linear.

Checkpoint

Find the fitting method whose prediction at N=100 is a valid, non-negative loss.

Pick a method to try it
Summary
logL=logAαlogN— the same line, just plotted on the axes the relationship actually lives on\log L = \log A - \alpha \log N \qquad\text{— the same line, just plotted on the axes the relationship actually lives on}

A scaling law isn't a prediction trick specific to language models — it's ordinary least squares, applied after recognizing that a power-law relationship becomes linear in log space. Get the transform right, and four cheap runs can extrapolate to a size fifty times larger with almost no error; get it wrong, and the same four runs produce a nonsensical negative loss. The next chapter turns from what to train to how to use a model once it's trained: getting useful behavior out of a frozen model through the prompt alone, no gradient updates at all.