Foundations to Frontier
Tests

Compute Budgeting

Planning an LLM project means turning goals into FLOPs, GPU-hours, memory and money. Training costs about 6ND FLOPs; inference about 2N per generated token. Wall-clock time follows from the number of GPUs, their peak throughput and the model FLOPs utilisation (MFU, typically 30–50%). Memory for mixed-precision Adam training is about 16 bytes per parameter before activations, which is why large models need sharding (ZeRO/FSDP), tensor and pipeline parallelism, and activation checkpointing. When a model will serve many requests, lifetime cost (training plus inference) favours smaller models trained on more tokens than compute-optimal. This page covers FLOP and memory accounting, utilisation, parallelism choices, cost estimates and inference-aware sizing. In the exercises you estimate training days, bytes per parameter and inference FLOPs, then compute the cheapest way to reach a target loss of 2.0 under Chinchilla's law. With no inference load, the best model has 15.3B parameters (79 tokens per parameter). With 10¹³ inference tokens it has 6.5B (608 tokens per parameter), and with 10¹⁴, 3.8B. Training a 7B model needs 112 GB per GPU without sharding; ZeRO-1 cuts that to 29 GB and ZeRO-3 to 1.8 GB on 64 GPUs.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

How much will it cost, and how long will it take?

Before training a model you need to know how much computing it needs, how many GPUs for how long, whether it fits in their memory, and what it will cost. There are simple rules of thumb: training takes about 6 operations per parameter per word of text, running it about 2. And if the model will answer millions of questions, a smaller model trained longer can be cheaper overall than a big one. The demo shows the best model size for a given training budget.

LLM lab
Budget 10^21 FLOPs: best model ≈ 1.82e+9 parameters trained on 9.16e+10 tokens (50 tokens per parameter), predicted loss 2.329, using Chinchilla's parametric loss fit. The paper's headline rule of thumb, from its other estimation methods, is about 20 tokens per parameter.
Why engineers care

Ground stations, labs and companies have fixed GPU budgets. Compute budgeting decides whether an in-house aerospace model is feasible, how big it can be, and whether fine-tuning an existing model is the better deal.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Training compute is about…
  2. 2. Inference compute per generated token is about…
  3. 3. If a model will serve huge traffic, it can pay to…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • FLOPs: training C ≈ 6ND; inference ≈ 2N per token (plus attention terms for long contexts).
  • Time: days = 6ND / (GPUs × peak FLOP/s × MFU) / 86,400. Chinchilla-70B (5.9 × 10²³ FLOPs) on 1024 H100s (989 TFLOP/s bf16 dense) at 40% MFU takes about 17 days. MFU = 6N × tokens per second / (GPUs × peak).
  • Training memory: mixed-precision Adam needs 2 (bf16 weights) + 2 (gradients) + 12 (fp32 master weights, m, v) = 16 bytes per parameter, plus activations. A 7B model needs 112 GB before activations, more than one 80 GB GPU.
  • Sharding: ZeRO-1 shards optimizer states, ZeRO-2 also gradients, ZeRO-3 (FSDP) also weights: 16N/G bytes per GPU at stage 3. Tensor and pipeline parallelism split layers and depth; activation checkpointing trades about 33% more compute for much less activation memory.
  • Money: GPU-hours × price (1024 GPUs × 16 days × $2.5/h ≈ $1M).
  • Inference-aware sizing: minimise 6N·D_train + 2N·I_inference for a target quality. Large I favours smaller N and more training tokens (LLaMA-style over-training).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Bytes per parameter for mixed-precision Adam:
  2. 2. ZeRO-3 shards…
  3. 3. Activation checkpointing trades…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Budgeting in code

Exercise 1.

  • Estimate training days from 6ND, GPU count, peak FLOP/s and MFU.
  • Count bytes per parameter for Adam training.
  • Compute inference FLOPs.

Practice.

  • Measure real throughput (tokens/s) on a short run and compute MFU before extrapolating; expect 30–50% for well-tuned dense training.
  • Use FSDP or DeepSpeed ZeRO when states exceed one GPU; add tensor parallelism within a node and pipeline parallelism across nodes for very large models.
  • Budget for evaluation runs, failed runs and restarts (often 20–50% extra), data processing and storage.
  • For most domain projects, compare the cost of fine-tuning an open model (F6) with pretraining; fine-tuning is usually orders of magnitude cheaper.
N, D, gpus, peak, mfu = 7e9, 2e12, 256, 989e12, 0.4
days = 6 * N * D / (gpus * peak * mfu) / 86400
mem_per_gpu = 16 * N / gpus / 1e9                     # GB with ZeRO-3, before activations
print(f"{days:.1f} days, {mem_per_gpu:.1f} GB/GPU of states, ${gpus * days * 24 * 2.5:,.0f}")
🐍 Exercise 1: time, memory and inference compute
Estimate training days, optimizer memory per parameter and inference FLOPs.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Typical MFU for well-tuned dense training:
  2. 2. PyTorch's built-in sharded data parallelism:
  3. 3. Budgets should include a margin for…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Lifetime cost. If a model must reach loss L* and serve I inference tokens, its total compute is 6N·D(N) + 2N·I, where D(N) is the training data a model of size N needs to reach L*. Smaller N needs disproportionately more D (the data term of the law), so training cost rises. But inference cost falls linearly in N. The optimum moves to smaller N as I grows (Sardana and Frankle, 2023).

Why memory dominates design. Optimizer states (12 bytes per parameter in fp32) dwarf the bf16 weights. Sharding them is pure communication overhead but removes the redundancy of data parallelism, which is why ZeRO enables models far larger than one GPU’s memory.

Utilisation. Peak FLOP/s are rarely reached. Communication, memory bandwidth, small matrix shapes, pipeline bubbles and data loading all reduce MFU. Budgets built on peak numbers are optimistic by 2–3×.

📝 Quick check (Level 3)
0/3 answered
  1. 1. As expected inference grows, the cost-optimal model gets…
  2. 2. Adam's optimizer states in fp32 take…
  3. 3. Budgets based on peak FLOP/s are…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How does expected inference demand change the best model to train?

History.

  • S. Rajbhandari et al., “ZeRO: memory optimizations toward training trillion parameter models” (SC 2020).
  • D. Narayanan et al., “Efficient large-scale language model training on GPU clusters using Megatron-LM” (SC 2021).
  • N. Sardana and J. Frankle, “Beyond Chinchilla-optimal: accounting for inference in language model scaling laws” (2023).

Exercise 2.

  • Part 1: for a target loss of 2.0 under Chinchilla’s parametric law, find the model size N minimising lifetime compute 6N·D(N) + 2N·I for lifetime inference I of 0 to 10¹⁴ tokens. D(N) is the training data needed to reach the target.
  • Part 2: per-GPU memory for training states (mixed-precision Adam, 16 bytes per parameter) of 7B and 70B models on 64 GPUs under ZeRO stages 0–3, activations excluded.
lifetime inference tokens best N training tokens tokens per parameter training FLOPs lifetime FLOPs
0 15.3B 1.21T 79 1.11 × 10²³ 1.11 × 10²³
10¹² 11.5B 1.66T 144 1.14 × 10²³ 1.37 × 10²³
10¹³ 6.5B 3.92T 608 1.52 × 10²³ 2.81 × 10²³
10¹⁴ 3.8B 14.78T 3932 3.33 × 10²³ 1.08 × 10²⁴
model ZeRO-0 ZeRO-1 ZeRO-2 ZeRO-3
7B 112 GB 29.3 GB 15.5 GB 1.8 GB
70B 1120 GB 293.1 GB 155.3 GB 17.5 GB
  • Inference demand shrinks the best model: with 10¹³ inference tokens, the best model is 6.5B instead of 15.3B. It costs 37% more to train but cuts lifetime compute by a third relative to serving the training-optimal model (2.81 × 10²³ against 1.11 × 10²³ + 2 × 15.3B × 10¹³ = 4.17 × 10²³), and repays its extra training after about 2.3T inference tokens.
  • Heavy inference justifies extreme over-training: thousands of tokens per parameter, as in recent small open models.
  • Memory decides parallelism: a 7B model does not fit one 80 GB GPU for training without sharding; with ZeRO-1 it does. A 70B model needs ZeRO-3 (17.5 GB per GPU on 64 GPUs) plus activation management.
  • Caveat: the parametric Chinchilla fit is uncertain at high tokens per parameter, and real data may run out (F5-2); treat the numbers as a planning guide.
🐍 Exercise 2 (research): how does expected inference demand change the best model to train?
Find the lifetime-compute-optimal model size for a target loss as expected inference grows, and compute per-GPU training memory under ZeRO stages.

Compute budgeting in AI, robotics and aerospace

  • Project feasibility: deciding between pretraining, continued pretraining and fine-tuning for a domain assistant.
  • Edge deployment: small, heavily trained models minimise lifetime cost for onboard or high-volume use.
  • Design lesson: budget the whole lifecycle (training, evaluation, failures and inference), not just one training run.

References

  1. S. Rajbhandari, J. Rasley, O. Ruwase and Y. He (2020). “ZeRO: memory optimizations toward training trillion parameter models.” Proc. SC.
  2. D. Narayanan et al. (2021). “Efficient large-scale language model training on GPU clusters using Megatron-LM.” Proc. SC.
  3. N. Sardana and J. Frankle (2023). “Beyond Chinchilla-optimal: accounting for inference in language model scaling laws.” arXiv:2401.00448.
  4. J. Hoffmann et al. (2022). “Training compute-optimal large language models.” NeurIPS.