24

Scaling laws and costs

How much does a model cost and what do you get by making it bigger?

13 minExecutive path

Scaling laws and costs

With voice. You can pause and jump to any step.

Lesson complete

Subtitles

In the last lesson, Pythia, with one point four billion parameters, learned by reading three hundred billion tokens. Today: if we make it bigger, how much better does it get? And what does it cost?

Voice

No voice: the lesson advances on its own with subtitles.

The voice for this lesson is being recorded: for now it advances on its own with subtitles.

0:00 / 0:00

What you will achieve

  • Explain what scaling a model means (more parameters, more data, more compute) and why the loss falls predictably, but less and less.
  • Read a chart on a logarithmic scale and recognize a scaling law: each ×10 in parameters multiplies the loss by the same number.
  • Calculate a training run’s compute with C ≈ 6·N·D and turn it into GPU-hours and money, telling real figures from assumptions.

Key ideas

  1. Scaling a model means turning three knobs: more parameters (N), more training tokens (D), and more compute (C).
  2. The loss falls predictably but with diminishing returns: on a logarithmic scale it is a straight line, and each ×10 in parameters multiplies it by ≈ 0.84 (Kaplan et al., 2020). That is called a scaling law.
  3. Training compute is C ≈ 6·N·D FLOPs: 2N per token forward and 4N backward. Divided by a GPU’s useful speed it gives GPU-hours; times the hourly price, money. More GPUs shorten the time, not the cost.
  4. With a fixed budget, parameters and data should grow together: about 20 tokens per parameter. Chinchilla (70B) beat Gopher (280B) with almost the same compute.
  5. Loss is predictable; specific abilities, much less so. Part of what looks “emergent” depends on how it is measured (Schaeffer et al., 2023).

What many people believe

Common belief A model with more parameters is always better: just make it bigger.

What is true How the compute is spent matters. With almost the same budget, Chinchilla (70 billion parameters, 1.4 trillion tokens) beat Gopher (280 billion, 300 billion tokens). And each ×10 in size lowers the loss by a fixed proportion while the cost multiplies.

Check yourself

Four questions. No grade, no account: they just show whether the idea stuck.

ConceptOn the chart with both axes on a logarithmic scale, loss versus model size is a straight line. What does that mean in practice?
ConceptWith a fixed compute budget, what did Hoffmann and colleagues show with Chinchilla?
CalculationA 7-billion-parameter model is trained on 140 billion tokens. With C ≈ 6·N·D, how many FLOPs does it need?
ApplicationA vendor says its model is better “because it has 500 billion parameters,” and another offers to train yours “twice as fast with twice the GPUs.” What do you reply?

Under the hoodFor those who want the math and the code. You do not need it to follow the course.

The power law and the logarithmic scale

Kaplan et al. (2020) trained transformers from 768 to 1.5 billion parameters (not counting embeddings) on WebText2 text and fitted the loss LL (cross-entropy, in nats per token) against the number of parameters NN, with plenty of data:

L(N)=(NcN)αN,αN≈0.076,Nc≈8.8⋅1013L(N)=\left(\frac{N_c}{N}\right)^{\alpha_N},\qquad \alpha_N\approx 0.076,\quad N_c\approx 8.8\cdot 10^{13}

Taking logarithms, log⁡L=αNlog⁡Nc−αNlog⁡N\log L=\alpha_N\log N_c-\alpha_N\log N: a straight line with slope −αN-\alpha_N when both axes are on a logarithmic scale. Multiplying NN by kk multiplies LL by k−αNk^{-\alpha_N}: by 10, 10−0.076≈0.8410^{-0.076}\approx 0.84. There are similar lines for data (αD≈0.095\alpha_D\approx 0.095, that is ×0.80 per ×10) and for well-allocated compute (αC≈0.050\alpha_C\approx 0.050, ×0.89). The constants depend on the vocabulary and the data, and outside the measured range everything is extrapolation. The lesson draws this published formula, not the raw measurements.

Why six: C≈6NDC\approx 6ND

On the way forward, each parameter takes part in one multiplication and one addition per token: about 2N2N FLOPs (Kaplan et al., eq. 2.2, ignoring the attention term, small when dmodel≫nctx/12d_{\text{model}}\gg n_{\text{ctx}}/12). The way back computes two things, the gradient with respect to the weights and with respect to the activations, and each costs about as much as the forward pass (Brown et al., 2020, table D.1): about 4N4N. In total, 6N6N per token and

C≈6NDC\approx 6ND

Hoffmann et al. (2022, table A4) compared their exact count with 6ND6ND for models from 73M to 6.8B parameters: the ratio was 0.99 to 1.10. For GPT-3, 6⋅175⋅109⋅300⋅109=3.15⋅10236\cdot 175\cdot 10^{9}\cdot 300\cdot 10^{9}=3.15\cdot 10^{23}; the paper reports 3.14⋅10233.14\cdot 10^{23} with $N=174.6$B.

A fixed budget (Chinchilla)

Hoffmann et al. propose for the loss

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

EE is the loss that cannot be removed; the second term is what is missing from having a finite model; the third, from having seen finite data. Minimizing L^\hat L with 6ND=C6ND=C fixed gives Nopt∝CaN_{\text{opt}}\propto C^{a} and Dopt∝CbD_{\text{opt}}\propto C^{b} with a≈b≈0.5a\approx b\approx 0.5: parameters and data grow together, and their table 3 gives about 20 tokens per parameter (1B → 20.2B tokens; 10B → 205B). Kaplan had found Nopt∝C0.73N_{\text{opt}}\propto C^{0.73}: with 10 times more compute, 5.5 times more parameters and only 1.8 times more data. Besiroglu et al. (2024) refitted the five constants on data reconstructed from the paper’s plots: the published ones did not agree with the paper’s other two methods, and theirs do (their point estimate gives about 26 tokens per parameter). Llama 3 ran its own fit and, for 3.8⋅10253.8\cdot 10^{25} FLOPs, predicted a 402B model with 16.55 trillion tokens.

Twenty is a guide for spending training compute well, not a law. If the model will be used a lot, a smaller one trained on more tokens pays off, because each answer costs less (Sardana et al., 2024): the 8B Llama 3.1 read over 15 trillion tokens.

From FLOPs to hours and money

With a peak speed PP per GPU and a utilization fraction (MFU, model FLOPs utilization, Chowdhery et al., 2022),

H=6ND3600⋅P⋅MFU,t=HG,cost=H⋅price per hourH=\frac{6ND}{3600\cdot P\cdot\text{MFU}},\qquad t=\frac{H}{G},\qquad \text{cost}=H\cdot\text{price per hour}

HH is GPU-hours and tt the time with GG GPUs at once. Since HH does not depend on GG, doubling the GPUs halves the time and leaves the cost unchanged, as long as utilization holds. The H100 datasheet gives 1,979 teraFLOPS in BF16 “with sparsity”; without it, it is half (NVIDIA, 2021: 2:4 sparsity doubles peak throughput), about 989. Llama 3 405B measured 380 to 430 teraFLOPS per GPU, an MFU of 38 to 43% (table 4), with up to 16,384 GPUs and 466 interruptions over a 54-day period. PaLM reports 46.2% and estimates 21.3% for GPT-3.

In code

def training(n, d, useful=400e12, price=2.0, gpus=16384):
    flops = 6 * n * d                  # C ≈ 6·N·D
    hours = flops / useful / 3600      # GPU-hours
    return flops, hours, hours / gpus / 24, hours * price

models = [("Pythia 1.4B", 1.4e9, 300e9), ("GPT-3", 175e9, 300e9),
          ("Chinchilla", 70e9, 1.4e12), ("Llama 3.1 405B", 405e9, 15.6e12)]
for name, n, d in models:
    c, h, days, usd = training(n, d)
    print(f"{name:15} C = {c:.2e}  hours = {h:9.0f}  days = {days:5.1f}  USD {usd:9.0f}")

print(round(10 ** -0.076, 3))          # ×10 in N: the loss is multiplied by this

Output:

Pythia 1.4B     C = 2.52e+21  hours =      1750  days =   0.0  USD      3500
GPT-3           C = 3.15e+23  hours =    218750  days =   0.6  USD    437500
Chinchilla      C = 5.88e+23  hours =    408333  days =   1.0  USD    816667
Llama 3.1 405B  C = 3.79e+25  hours =  26325000  days =  66.9  USD  52650000
0.839

The 400 trillion useful operations per second, the 2 dollars per hour, and the 16,384 GPUs are assumptions (the first two are neither prices nor measurements for each model; GPT-3 and Chinchilla were trained on other hardware). The figure covers only the final run: no experiments, failures, data, or people. Meta reported 30.84 million H100 GPU-hours for Llama 3.1 405B.

What comes next

Lesson 25 counts bytes instead of operations: which model fits in a GPU’s memory and how the work is split. Lesson 26 measures the cost of using the model, which with heavy demand outweighs the cost of training it. Lesson 27 reuses a base model instead of repeating this arithmetic.

Decision lens

What this idea means if your job is to decide, not to code.

  • Training from scratch is out of reach for almost every organization: with modest assumptions, the final run alone of a model like Llama 3.1 405B costs tens of millions of dollars in compute, without experiments, failures, data, or staff. The real decision is which model to use, whether to adapt it (lesson 27), and what it costs to serve (lesson 26).
  • When you hear “bigger = better,” ask how many tokens and how much compute it was trained with, and ask for results on your tasks. With almost the same compute, Chinchilla (70 billion parameters) beat Gopher (280 billion).
  • Returns diminish: each ×10 in parameters costs about ten times more and lowers the loss by a fixed proportion (×0.84). Before paying for the next jump, ask what that improvement is worth in your case; and remember that a lower loss does not guarantee a specific ability.
  • Faced with a training budget, ask for the breakdown: FLOPs (6·N·D), GPU-hours, assumed useful speed, and hourly price. More GPUs shorten the calendar, not the cost; and large clusters lose time to failures (Llama 3: 466 interruptions in 54 days).

Terms in this lesson

Full transcript
CommentsThis lesson’s public conversation: questions, facts to check, ideas.

Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub

Sources