Sub topic 13
Scale: parameters, data, compute, and scaling laws
This chapter assumes you know how a decoder-only transformer is built and how pretraining uses cross-entropy loss. It covers what "large" means in a large language model and how scale affects training.
Three quantities that define scale
- Parameters (N) are the learned weights in the model. A transformer with
n_layerslayers and hidden sized_modelhas roughly12 * n_layers * d_model²weights in its blocks, plusvocab_size * d_modelfor the embedding table. - Data (D) is the number of tokens the model trains on. Count tokens, not documents or words.
- Compute (C) is the total floating-point operations (FLOPs) used for training. For dense transformers, a standard estimate is
C ≈ 6 * N * D. Each token costs about 2N FLOPs in the forward pass and about 4N in the backward pass.
The three are linked. For a fixed compute budget, a larger model sees fewer tokens, and a smaller model can see more.
Estimating size and cost in code
This script applies the formulas above to GPT-3's published configuration (96 layers, hidden size 12288, vocabulary of 50257, about 300 billion training tokens).
def parameter_count(n_layers, d_model, vocab_size):
blocks = 12 * n_layers * d_model ** 2
embeddings = vocab_size * d_model
return blocks + embeddings
def train_flops(n_params, n_tokens):
return 6 * n_params * n_tokens
n = parameter_count(96, 12288, 50257)
d = 300e9
print(f"parameters: {n:.3g}")
print(f"training FLOPs: {train_flops(n, d):.3g}")
print(f"tokens per parameter: {d / n:.2f}")It prints about 1.75e+11 parameters and 3.14e+23 FLOPs, close to the reported figures for GPT-3. It also prints about 1.7 tokens per parameter, which matters below. The 12 * n_layers * d_model² formula ignores biases and layer norms, which are small.
Scaling laws
Researchers train many models of different sizes and plot final loss against N, D, or C. On a log-log plot the points fall close to a straight line. That is a power law:
L(N) ≈ (N_c / N)^α
Here N_c and α are constants fitted to the data. Kaplan et al. (2020) found such trends over many orders of magnitude. Each multiplication of scale buys a predictable, shrinking drop in loss. This lets teams train small models first and forecast the loss of a much larger run before paying for it.
Compute-optimal training
Kaplan et al. suggested spending extra compute mostly on bigger models. Hoffmann et al. (2022), the "Chinchilla" paper, revisited this and found that model size and token count should grow together. Their rule of thumb is about 20 training tokens per parameter. Chinchilla itself had 70B parameters and was trained on 1.4T tokens. It outperformed the 280B-parameter Gopher, which used a similar compute budget but far fewer tokens.
The GPT-3 estimate above, at about 1.7 tokens per parameter, was far from this ratio. It was undertrained by the Chinchilla standard.
Gotchas
- Compute-optimal is not deployment-optimal. Training is paid once, but inference is paid on every request. Many recent models train on far more than 20 tokens per parameter so that a smaller model reaches the same quality and is cheaper to serve.
- Scaling laws predict loss, not abilities. Loss falls smoothly, but how that maps to specific tasks varies. Some skills appear to emerge suddenly on benchmarks, partly because of how those benchmarks score answers.
- Data runs out. Quality text on the public web is finite. Repeating data gives diminishing returns, and filtering for quality matters as much as quantity.
- Fitted exponents are approximate. Different papers report different constants. Treat extrapolations far beyond the fitted range with caution.
Exercise
A team has a compute budget of 6e23 FLOPs and wants to follow the Chinchilla rule of 20 tokens per parameter (D = 20N). Using C = 6ND, roughly how many parameters should the model have, and how many tokens should it train on?
Show answer
Substitute D = 20N into C = 6ND to get C = 120 N². So N² = 6e23 / 120 = 5e21, and N ≈ 7.1e10, about 70 billion parameters. Then D = 20N ≈ 1.4e12, about 1.4 trillion tokens. This matches the Chinchilla configuration.