Topic 2 of 6 · 5 min read
Estimating training FLOPs and cost
Goal: Estimate the GPU-hours and cost of a training run from model size, token count and GPU throughput.
Training a dense transformer costs about 6 x N x D floating-point operations, where N is the number of parameters and D is the number of training tokens.
Check yourself · 1 of 3
What is the usual rule of thumb for training FLOPs of a dense transformer?
Why it matters
Before you rent a cluster you need an order-of-magnitude answer: will this take a weekend on one GPU or three months on a thousand? The 6ND rule gives it in a few lines. It comes from the accounting in Kaplan et al. (2020): about 2N FLOPs per token for the forward pass and about 4N for the backward pass.
How to estimate a run
- FLOPs.
C = 6 * N * D. - Real throughput. A GPU's datasheet peak is not what you get. Memory traffic, communication and data loading mean a real run sustains a fraction of peak. That fraction is called model FLOPs utilisation (MFU). Measure it on a short real run; do not copy it from a brochure.
- Seconds.
seconds = C / (sustained FLOP/s per GPU * number of GPUs). - GPU-hours and money. Divide seconds by 3600, multiply by the hourly price.
- Add slack. Failed runs, restarts, evaluation, and the small experiments that came first often add a large share to the bill.
Before and after
Weak: "7B model, 1T tokens, so about 7 times 10 to the 21." This drops the factor 6 and mixes up the units.
Better, with stated assumptions (a GPU sustaining 400 TFLOP/s as measured, a price of 2.50 per GPU-hour):
N = 7e9 # parameters
D = 1e12 # tokens
C = 6 * N * D # 4.2e22 FLOPs
sustained = 4e14 # FLOP/s per GPU, measured
gpu_hours = C / sustained / 3600
print(round(gpu_hours)) # about 29,000
print(round(gpu_hours * 2.5)) # about 73,000 in currency units
On 256 GPUs that is roughly 114 hours, close to five days of wall-clock time.
What goes wrong
- Using datasheet peak FLOP/s instead of measured sustained throughput, which understates time by a large factor.
- Forgetting the 6: counting only the forward pass.
- Using the rule for a sparse mixture-of-experts model with total parameters; use the active parameters per token instead.
- Ignoring the cost of experiments, failures and evaluation.
Examples
Weekend on one GPU?
A 125M model on 2.5B tokens needs 6 x 1.25e8 x 2.5e9, about 1.9e18 FLOPs. At a sustained 1e14 FLOP/s that is about 19,000 seconds, near 5 hours. Yes, a single GPU can do it in an evening.
Same model, double the data
Doubling tokens from 1T to 2T doubles C and the bill, so the 7B run above becomes about 58,000 GPU-hours. Cost scales linearly in tokens; doubling parameters and tokens together quadruples it.
Key points
- Training FLOPs for a dense transformer are about 6 x parameters x tokens.
- Use measured sustained throughput, not the datasheet peak, because real runs reach only a fraction of peak.
- GPU-hours equal FLOPs divided by sustained FLOP/s per GPU divided by 3600, and cost is GPU-hours times price.
- For mixture-of-experts models, use the parameters active per token in the formula.
- Budget extra for failed runs, restarts, evaluation and the experiments that came before the main run.
Common mistakes
- Using peak datasheet throughput as if the run would sustain it.
- Dropping the factor 6 or counting only the forward pass.
- Plugging total parameters of a mixture-of-experts model into 6ND.
- Quoting the cost of one clean run and ignoring failures and experiments.
Check yourself · 2 of 3
A 3B model trains on 300B tokens. About how many FLOPs is that?
Check yourself · 3 of 3
Your run needs 3e21 FLOPs. The GPU's datasheet says 1e15 FLOP/s, but a short test run sustains 3e14. How many GPU-hours should you budget?
Practice items, not counted towards your mastery.
Start here
- Scaling Laws for Neural Language Models (opens in a new tab)PaperFree
Shows test loss following power laws in parameters, data and compute, with the fitted exponents and the 6ND compute estimate.
- Training Compute-Optimal Large Language Models (Chinchilla) (opens in a new tab)PaperFree
The 70B model trained on 1.4T tokens that beat a 280B model at equal compute, and the rule of about 20 tokens per parameter.
- How to Scale Your Model (Google DeepMind scaling book) (opens in a new tab)BookFree
A free, practical text on FLOPs, memory and communication limits when training and serving large models.