Sub topic 13
Scale: parameters, data, compute, and scaling laws
This chapter assumes you know how the transformer block and the pretraining loss work from earlier chapters. You should also be comfortable with logarithms and power functions like x ** -0.3. Here we look at the three quantities that set how good a model can get: the number of parameters, the amount of training data, and the compute spent. We also look at the empirical rules, called scaling laws, that link them.
The three quantities
Every training run is described by three numbers.
| Symbol | Name | Meaning |
|---|---|---|
| N | Parameters | Count of learned weights (not counting activations) |
| D | Training tokens | Number of tokens the model is trained on, counting repeats |
| C | Compute | Total floating-point operations (FLOPs) for training |
N and D are choices. C is the cost of those choices, and in practice a fixed budget of hardware, money, and time sets C first. The main question of scaling is how to split a budget C between a bigger model (N) and more data (D).
Counting parameters
For a decoder-only transformer with L layers and hidden width d, almost all parameters sit in two places.
- Attention: four
d × dmatrices per layer (queries, keys, values, output), so about4d². - Feed-forward network: two matrices that expand to
4dand project back, so about8d².
That gives roughly 12 · L · d² for the blocks. The token embedding table adds V · d for a vocabulary of size V. Biases, layer norms, and positional parameters are tiny by comparison.
def approx_params(n_layers, d_model, vocab_size):
blocks = 12 * n_layers * d_model ** 2
embeddings = vocab_size * d_model
return blocks + embeddings
# GPT-3 175B configuration: 96 layers, width 12288, vocabulary 50257
n = approx_params(96, 12288, 50257)
print(f"{n / 1e9:.1f} billion parameters")This prints about 174.6 billion, close to the published 175 billion. The estimate ignores small terms, so expect an error of a percent or two.
Dense models and mixture-of-experts
The formula above describes a dense model, where every parameter is used for every token. A mixture-of-experts (MoE) model has many feed-forward "experts" and routes each token to only a few. Its total parameter count is large, but the active parameters per token are much smaller. When you read a parameter count, check whether it means total or active. Compute per token follows the active count, while memory follows the total.
Estimating compute
A useful rule of thumb is C ≈ 6 · N · D FLOPs for training a dense model.
- The forward pass does about 2 FLOPs per parameter per token (one multiply and one add).
- The backward pass costs about twice the forward pass, so about 4 FLOPs per parameter per token.
The sum is 6. The rule ignores the attention score computation, which grows with context length. That is a small share of compute when the context is much shorter than the model width, and a larger share for very long contexts.
Compute is usually reported in FLOPs, or in petaflop/s-days (one petaflop per second sustained for a day, about 8.64e19 FLOPs). Real hardware rarely reaches its peak speed. A utilization of 30 to 50 percent of peak is typical for large runs.
Scaling laws: loss as a power law
Researchers found that the pretraining loss falls smoothly and predictably as N, D, or C grow, as long as the other factors do not become bottlenecks. The relationship is a power law plus a floor:
L(N) = E + A / N^α
Here E is the irreducible loss, which comes from the natural unpredictability of text. The second term is the part that more scale can remove. On a log-log plot, the reducible part is a straight line.
Two consequences matter in practice.
- Returns diminish. A power law with a small exponent means that each doubling of scale buys a smaller absolute loss reduction than the last.
- Results are predictable. You can train several small models, fit the curve, and forecast the loss of a much larger run before paying for it. Labs use this to choose settings and to detect a broken large run.
The Chinchilla result
Early scaling studies (Kaplan et al., 2020) suggested that when compute grows, most of it should go into a bigger model. Models trained that way, such as GPT-3, saw only about 300 billion tokens. A later study from DeepMind (Hoffmann et al., 2022) refit the curves with more careful experiments and reached a different conclusion: for a fixed compute budget, N and D should grow in roughly equal proportion.
They fit a joint loss function of the form
L(N, D) = E + A / N^α + B / D^β
with fitted values of about E = 1.69, A = 406.4, B = 410.7, α = 0.34, and β = 0.28. A model that is too large for its data is limited by the B / D^β term. A model that is too small is limited by the A / N^α term.
Minimizing this function under C = 6ND gives a rule of thumb of about 20 training tokens per parameter. They tested it by training Chinchilla, a 70 billion parameter model on 1.4 trillion tokens. It used the same compute as the 280 billion parameter Gopher model, which was trained on 300 billion tokens, and it beat Gopher on most benchmarks.
import math
def chinchilla_loss(n_params, n_tokens):
E, A, B, alpha, beta = 1.69, 406.4, 410.7, 0.34, 0.28
return E + A / n_params ** alpha + B / n_tokens ** beta
def compute_optimal(compute_flops, tokens_per_param=20):
# C = 6 * N * D and D = tokens_per_param * N, so N = sqrt(C / (6 * ratio))
n = math.sqrt(compute_flops / (6 * tokens_per_param))
return n, tokens_per_param * n
n_opt, d_opt = compute_optimal(5.76e23)
print(f"optimal N = {n_opt / 1e9:.0f}B, D = {d_opt / 1e12:.2f}T tokens")
print("Gopher ", round(chinchilla_loss(280e9, 300e9), 3))
print("Chinchilla ", round(chinchilla_loss(70e9, 1.4e12), 3))The first line recovers roughly 69 billion parameters and 1.39 trillion tokens. The two loss lines are about 1.99 for Gopher and 1.94 for Chinchilla. Both used about the same compute, and the better balanced split gives the lower predicted loss.
Training compute versus inference cost
Compute-optimal means the lowest loss for a given training budget. It ignores what happens after training. A deployed model is run many times, and every request costs compute proportional to N. A smaller model is cheaper to serve, has lower latency, and fits on less hardware.
So many recent models are deliberately overtrained: they see far more than 20 tokens per parameter, sometimes hundreds. This spends extra training compute to get a smaller model with the same quality. The decision depends on expected usage. A model with heavy traffic favors a smaller N and more data. A one-off research model favors the compute-optimal point.
Data: the other side of scale
Scaling data raises three practical issues.
- Quality matters as much as quantity. Filtering, deduplication, and a good mix of web text, code, books, and reference material often improve loss more than adding raw tokens. Duplicated text also increases memorization.
- Supply is finite. Estimates of high-quality public text are in the tens of trillions of tokens. Training on a trillion tokens or more approaches that limit, which is sometimes called the data wall.
- Repetition has a cost. Training for a few epochs (passes) over the same data works almost as well as fresh data. Beyond roughly four epochs, returns drop quickly.
Proposed responses include synthetic data generated by other models, more code and multilingual data, and better filtering. Synthetic data can reinforce the errors of the model that produced it, so it needs checking.
What scaling laws do not tell you
Smooth loss curves can hide uneven changes in specific abilities. Some tasks, such as multi-digit arithmetic, appear to jump from near-chance to good performance as models grow. These are called emergent abilities. Later work argued that many of these jumps come from the metric, not the model. Exact-match accuracy is all-or-nothing, so a steadily improving model looks like it suddenly succeeds. When the same tasks are scored with a smooth metric such as per-token likelihood, the improvement looks gradual.
Other limits:
- Loss is not usefulness. A lower pretraining loss does not guarantee better instruction following, honesty, or safety. Those depend on post-training and evaluation.
- Extrapolation is risky. Fits are reliable inside the tested range. Far beyond it, new bottlenecks can appear, such as data quality, optimization instability, or hardware limits.
- Hyperparameters change with scale. Learning rate and batch size need retuning as models grow, and a bad choice can hide the true curve.
- The floor
Eis not zero. Past some point, scale only improves the model slightly, and the remaining errors come from real ambiguity in text.
Exercise
A team trains a 7 billion parameter dense model on 2 trillion tokens. (a) Estimate the training compute with C ≈ 6ND. (b) How many tokens would the 20-tokens-per-parameter rule suggest for this model size, and roughly how many times more data did the team use? (c) Give one reason the team might choose this over-trained setup.
Show answer
(a) C ≈ 6 × 7e9 × 2e12 = 8.4e22 FLOPs. (b) The rule suggests 20 × 7e9 = 1.4e11, or 140 billion tokens. The team used 2e12 / 1.4e11, about 14 times more. (c) The model will be served many times, so a small N keeps inference cheap. The extra training compute buys a lower loss than a 7 billion parameter model trained to the compute-optimal point.
Exercise
Using the formula 12 · L · d² + V · d, estimate the parameter count of a model with 32 layers, width 4096, and a vocabulary of 32000. Which term dominates?
Show answer
Blocks: 12 × 32 × 4096² = 12 × 32 × 16,777,216 ≈ 6.44e9. Embeddings: 32000 × 4096 ≈ 1.31e8. Total ≈ 6.57 billion parameters. The transformer blocks dominate, with the embedding table about 2 percent of the total.