19.2 Pretraining compute and scaling
This part of Choosing Training and Adaptation Methods develops the mechanisms below. Work the numerical examples or trace the code before checking the answer.
Concepts from other sections (8)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Entropy: , the average surprise of a distribution. Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator in Mathematics
- Perplexity: , the geometric mean of ; the effective number of choices per token. Read more: 17.2 Perplexity, bits per byte, NLL accumulator in Mathematics
- FLOPs per token: for the matmul parameters touched plus the parameter-free attention term; three times that for a training step. Read more: 11.1 Counting: parameters, FLOPs, KV bytes, and memory plans in Mathematics
- Compute budget: the training FLOP available, , which fixes the trade between parameters and tokens . Read more: A.1 Capstone: TinyStories, owned end to end
- token budget: the maximum number of tokens, prompt and generated, the scheduler puts into one step. Read more: 20.6 Inside an Inference Engine: How vLLM and SGLang Run a Model
- Chinchilla-optimal: the compute-optimal split that minimizes loss for a fixed training budget. Read more: 19.7 The training step and validation
- MFU: model FLOPs utilization, useful model FLOPs per second divided by the hardware’s peak. Read more: 19.7 The training step and validation
- activation checkpointing: discarding a segment’s activations in the forward pass and recomputing them during backward. Read more: 17.1 Mixed precision, loss scaling, gradient accumulation, and activation checkpointing
Learning objectives
- Estimate training compute and distinguish a cost model from a measurement.
The mathematics of pretraining
Section titled “The mathematics of pretraining”The pretraining objective is the cross entropy between the data and the model, in nats per token:
Its exponential, , is the perplexity. In code the whole objective is a shift by one: inputs = x[:, :-1] and targets = x[:, 1:], as in train_step_torch.py.
Why training costs 6ND
Section titled “Why training costs 6ND”The number to carry everywhere is that training costs about FLOPs for a model with parameters trained on tokens. The forward pass costs FLOPs per token, one multiply-add per parameter. The backward pass costs , because it computes two sets of gradients, with respect to the activations and with respect to the weights, at each. Attention adds about FLOPs per token for layers of width at sequence length , which stays small until the context gets long.
Chinchilla, and why everyone overtrains anyway
Section titled “Chinchilla, and why everyone overtrains anyway”Given a fixed compute budget , how should you split it between model size and data? Kaplan et al. gave the first answer; Chinchilla gave the one that stuck. In the Chinchilla study, compute-optimal parameter and token budgets scaled approximately together, motivating a rule of thumb near within that experimental setting. It is an empirical fit, not a universal token requirement for every architecture, data mixture, or serving budget. The fitted loss is
Yet modern models are trained far past that point on purpose. Chinchilla minimizes training cost, but a model’s lifetime cost is , and for a popular model dwarfs (Beyond Chinchilla-Optimal). A smaller model trained well past reaches the same quality at a much lower serving cost. Llama 3 8B saw about 15T tokens, roughly 93 times its Chinchilla-optimal budget.
Utilization: MFU and HFU
Section titled “Utilization: MFU and HFU”Hardware never runs at its peak. Model FLOPs utilization measures how close you get:
MFU depends on shapes, precision, parallelism, topology, attention accounting, and the chosen hardware peak. Treat any assumed percentage as a scoping input and report the measured result separately. Hardware FLOPs utilization (HFU) also counts FLOPs that are recomputed, so under activation checkpointing HFU is greater than MFU.
Working it by hand: an 8B model on 15T tokens
Section titled “Working it by hand: an 8B model on 15T tokens”These formulas are enough to cost a real pretraining run. Take the Llama 3 8B shape on H100s, as computed by memory_calc.py:
N = 8.03e9 (Llama 3 8B shape) D = 15e12C = 6 N D = 6 × 8.03e9 × 15e12 = 7.23e23 FLOPsH100 dense BF16 peak = 989 TFLOP/sat 40% MFU = 3.96e14 FLOP/s per GPUGPU-seconds = 7.23e23 / 3.96e14 = 1.83e9 s → ~507,000 GPU-hourson 1,024 GPUs ≈ 20.6 daysassuming $2-3 per H100-hour ≈ $1.0-1.5M of pure computeThis is an analytical scenario using a fixed MFU and an illustrative GPU-hour price, not a current quote or a reconstructed training bill. Actual wall time also depends on attention work, achieved utilization, data loading, evaluations, checkpointing, failures, and the scope of the reported run. A difference from a published GPU-hour figure does not identify which of those causes dominated.
Summary
Section titled “Summary”Estimate training compute and distinguish a cost model from a measurement. State the assumptions before applying the result to a different workload.
Review questions
Section titled “Review questions”-
Does doubling parameter count always double total run time?
Answer
Only with fixed tokens, throughput efficiency, communication, and memory assumptions. A change that forces a different layout changes those assumptions.