Scaling laws and costs
How much does a model cost and what do you get by making it bigger?
Lesson complete
If you like:
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?
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.
Review modeComment on this stepI finished the lesson
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
- Scaling a model means turning three knobs: more parameters (N), more training tokens (D), and more compute (C).
- 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.
- 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.
- 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.
- 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.
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 (cross-entropy, in nats per token) against the number of parameters , with plenty of data:
Taking logarithms, : a straight line with slope when both axes are on a logarithmic scale. Multiplying by multiplies by : by 10, . There are similar lines for data (, that is ×0.80 per ×10) and for well-allocated compute (, ×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:
On the way forward, each parameter takes part in one multiplication and one addition per token: about FLOPs (Kaplan et al., eq. 2.2, ignoring the attention term, small when ). 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 . In total, per token and
Hoffmann et al. (2022, table A4) compared their exact count with for models from 73M to 6.8B parameters: the ratio was 0.99 to 1.10. For GPT-3, ; the paper reports with $N=174.6$B.
A fixed budget (Chinchilla)
Hoffmann et al. propose for the loss
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 with fixed gives and with : parameters and data grow together, and their table 3 gives about 20 tokens per parameter (1B → 20.2B tokens; 10B → 205B). Kaplan had found : 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 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 per GPU and a utilization fraction (MFU, model FLOPs utilization, Chowdhery et al., 2022),
is GPU-hours and the time with GPUs at once. Since does not depend on , 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
- Scaling law A measured regularity, not a law of nature: a model’s loss falls as a power of its parameters, its data, or its compute. On a logarithmic scale it looks like a straight line: each ×10 multiplies the loss by the same number.
- FLOP, FLOPs Floating-point operation: an addition or a multiplication with decimals. A training run’s compute is counted in total FLOPs (≈ 6·N·D); a chip’s speed, in FLOPs per second.
- Chinchilla A DeepMind model (2022; 70 billion parameters, 1.4 trillion tokens) and the rule it left: with a fixed budget, parameters and data should grow together, about 20 tokens per parameter.
- Compute budget The total number of FLOPs you decide to spend on training a model. Since C ≈ 6·N·D, it fixes the “area” split between model size and amount of data: if one goes up, the other goes down.
- Parameter Each of the numbers a model adjusts while training and in which it stores what it learned.
- Loss function A single number that summarizes how wrong a model is on its data. Training is the search for the parameters that make it as small as possible.
- Token A piece of text (a word, a word fragment, a symbol, or a basic code) taken from the vocabulary. It is the unit the model reads and generates, and the unit you are billed for.
- GPU Graphics processing unit: a chip with hundreds or thousands of simple cores, built to draw graphics and very efficient at multiplying matrices in parallel, the central operation of training.
- Compute The amount of arithmetic operations needed to train or run a model. Along with data and algorithms, it is one of the three engines of progress in machine learning.
- Backpropagation An algorithm that computes the gradient of the loss with respect to every weight of a network in a single backward sweep, applying the chain rule layer by layer. It computes the blames; it does not move the weights (in the 1986 paper, the name covered the whole learning procedure).
- Pretraining The first stage of training a language model: over a huge corpus, the model guesses the next piece of text again and again and adjusts its parameters to lower the error. The result is a base model.
- Base model A language model that has only gone through pretraining: it can continue texts, but it is not tuned to follow instructions or converse like an assistant.
- Language model A model that, given some text (the context), gives a probability to every word or piece that can come next. It writes by adding one piece at a time.
- Model A form of rule with adjustable numbers. Once trained, it is the learned rule.
Full transcript
Sources
- Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., Amodei, D. (2020). Scaling Laws for Neural Language Models
- Hoffmann, J., Borgeaud, S., Mensch, A., et al. (2022). Training Compute-Optimal Large Language Models (Chinchilla)
- Rae, J. W., Borgeaud, S., Cai, T., et al. (2021). Scaling Language Models: Methods, Analysis & Insights from Training Gopher
- Brown, T. B., et al. (2020). Language Models are Few-Shot Learners (tabla D.1: cómputo de GPT-3)
- Biderman, S., Schoelkopf, H., Anthony, Q., et al. (2023). Pythia: A Suite for Analyzing Large Language Models Across Training and Scaling
- Grattafiori, A., et al. (Llama Team, AI @ Meta) (2024). The Llama 3 Herd of Models
- Meta (2024). Llama 3.1 Model Card (horas de GPU de entrenamiento)
- NVIDIA (2022). NVIDIA H100 Tensor Core GPU (especificaciones)
- Pool, J., Sawarkar, A., Rodge, J. (NVIDIA) (2021). Accelerating Inference with Sparsity Using the NVIDIA Ampere Architecture and NVIDIA TensorRT (tabla 1: rendimiento denso frente a disperso)
- Chowdhery, A., et al. (2022). PaLM: Scaling Language Modeling with Pathways (definición de MFU)
- Wei, J., Tay, Y., Bommasani, R., et al. (2022). Emergent Abilities of Large Language Models
- Schaeffer, R., Miranda, B., Koyejo, S. (2023). Are Emergent Abilities of Large Language Models a Mirage?
- Besiroglu, T., Erdil, E., Barnett, M., You, J. (2024). Chinchilla Scaling: A replication attempt
- Sardana, N., Portes, J., Doubov, S., Frankle, J. (2024). Beyond Chinchilla-Optimal: Accounting for Inference in Language Model Scaling Laws
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