Every performance question about a model is three counts divided by three numbers of the chip: FLOPs over peak FLOP/s gives the time when arithmetic is the limit, bytes moved over memory bandwidth gives the time when memory is the limit, and bytes held against memory capacity says whether it fits. MFU is the share of the peak a real run reaches, and the price per hour turns the time into money.
The running example is Llama 3.1 8B (8.03 billion parameters, 32 layers, hidden size 4,096) on one H100 SXM (989.5 TFLOP/s dense BF16, 3.35 TB/s, 80 GB; vendor specifications from the parent's Chip atlas). Fig. 1 walks it through the four divisions the page derives:
Notice which chip number each step divides by: peak FLOP/s for the training step and the run, capacity for what the step holds, bandwidth for the decoded token. The tray's heights are to scale (80 GB is the dashed lid); the work block, positions and the layout of the GPU field are illustrative.
You need: what a training step and a decoder layer are, and the chip numbers of the parent Topic: hardware (its Chip atlas and Roofline lab). Why backward costs twice forward is derived on Matrix calculus and backprop; here it is used.
How the numbers were obtained. counted: PyTorch 2.14.1 ran the real Llama 3.1 8B (Transformers 5.18.0, config from Hugging Face) on the meta device, recording PyTorch's own FLOP formulas and every tensor autograd saved. measured: timed on this laptop's Apple M1 Pro GPU. derived: arithmetic on sourced inputs, formula shown. No NVIDIA GPU was available: nothing here ran on one.
One matrix multiply. Llama 3.1 8B's query projection is a 4,096 × 4,096 weight. Applied to 8,192 tokens it makes 8,192 × 4,096 outputs, each a sum of 4,096 products: 4,096 multiplies and 4,096 adds, so 2 × 8,192 × 4,096 × 4,096 = 275 GFLOP. In general an (m × k) by (k × n) multiply is 2mkn FLOPs, and almost all of a transformer's work is of this kind: tokens (m) times a weight matrix (k × n).
Floor areas and heights are to scale (volume is FLOPs per token); positions are illustrative. Parameter counts from the config; GFLOP per token are PyTorch's count of the real model on the meta device, with the full score square counted (the convention of PaLM's formula and of PyTorch's counter) counted.
The rule is Kaplan et al.'s (Scaling Laws, section 2.1; Kaplan's Table 1 is recounted on the Scaling Laws paper page), and PaLM's Appendix B made it the basis of MFU (PaLM). The Matrix calculus and backprop page derives the factor 2 for backward and measures it on a small model (exactly 2.00 for the matrix products).
Per token at 8,192 tokens, training (forward and backward), with the full score square counted:
| Part | Formula per token (training, forward + backward) | GFLOP |
|---|---|---|
| Attention projections (q, k, v, o) | 6 × L × (2 h·h + 2 h·1,024) | 8.05 |
| MLP (gate, up, down) | 6 × L × 3 h·14,336 | 33.82 |
| Output head (vocabulary 128,256) | 6 × h × V | 3.15 |
| Attention core forward (QKT and AV) | L × 4 × T × h | 4.29 |
| Attention core backward, FlashAttention | 2.5 × forward (recomputes the scores) | 10.74 |
| Input embedding | a table lookup: 0 | 0 |
| Total, counted by PyTorch on the real model | 60.06 | |
| 6N, with N = 8.03B | 48.18 |
L = 32 layers, h = 4,096, T = 8,192, V = 128,256. The formula column equals the traced count to within 128 FLOPs per token (the RoPE frequency table) at 2,048, 8,192, 32,768 and 131,072 tokens, and for Llama 3.1 70B at 8,192 counted. Script: src/code/trace_llama.py.
Four things move the count away from 6N:
Mixture of experts. Each token passes through only k of E experts, so FLOPs follow the active parameters and memory follows the total: DeepSeek-V3 is 671.0B total and 37.55B active, 17.9 times fewer FLOPs per token than a dense model of the same size (parameter counts recounted from its config by the parent's calculator). The router's own FLOPs are tiny; the cost moves to the network (section 8).
At 8,192 tokens the attention term is 26.7% of 6N counted in full, 14.3% of the matmul-only 6N counted causally: both conventions are in use.
Training FLOPs per token of Llama 3.1 8B by part, against 6N (dashed). The bars are PyTorch's count on the real model at each sequence length counted. The FLOP and memory ledger tab draws it for any length and for 70B and 405B.
The same weight, two ways. The 4,096 × 4,096 BF16 query weight is 33.6 MB. Used by one token (decoding at batch 1) it does 33.6 MFLOP for 33.6 MB moved, about 1 FLOP per byte: an H100 finishes the arithmetic in 0.034 µs and then waits 10.0 µs for the bytes. Used by 8,192 tokens (a training sequence or a long prompt) it does 275 GFLOP for 167.8 MB moved, 1,638 FLOPs per byte: 277.8 µs of arithmetic against 50.1 µs of reading. Same weight, same chip; the first is limited by memory, the second by arithmetic.
Three consequences run through the rest of the page. Decode at small batch sits near 1 FLOP per byte, so its speed is bytes over bandwidth (section 6), and batching is how serving climbs the slope. Training and prefill run thousands of tokens per weight read, so they are compute-bound and their time is FLOPs over peak (sections 4 and 7). Elementwise operators (norms, activations, residual adds, casts) do about one FLOP per several bytes whatever the batch, so they are always memory-bound: on an H100 a BF16 add reaches 0.56 TFLOP/s, and the only cure is to fuse it into a neighbouring kernel (section 5). The parent's Roofline lab measures these ceilings on a real GPU; the CUDA and serving pages apply the model to kernels and to batching.
Predict, then drag: how many tokens must share one read of this weight before the H100 reaches its peak? 10, 100, 1,000?
One 4,096 × 4,096 BF16 matmul: FLOPs 2mkn, bytes 2(mk + kn + mn) for reading both inputs and writing the output. Roofs: H100 SXM, 989.5 TFLOP/s dense BF16 and 3.35 TB/s (vendor), ridge 295 FLOPs per byte; Apple M1 Pro, 5.06 TFLOP/s and 165 GB/s measured in the parent's Roofline lab, ridge 31. The fixed point is a BF16 elementwise add (1 FLOP per 6 bytes) derived. A roofline is a ceiling: real kernels sit below it (section 5).
The model state. Mixed-precision training with Adam keeps, for every parameter, the BF16 weight used in the matmuls (2 bytes), its BF16 gradient (2), and the optimizer's state in FP32: a master copy of the weight (4, because tiny updates vanish when added in BF16) and Adam's two moments m and v (4 + 4). That is 2 + 2 + 12 = 16 bytes per parameter, the ZeRO paper's 2Ψ + 2Ψ + KΨ with K = 12 (ZeRO, section 3 "Where did all the memory go?"; paper page): 128.5 GB for Llama 3.1 8B. That does not fit one 80 GB H100, nor two 32 GB RTX 5090s; sharded over an 8-GPU server (ZeRO stage 3, FSDP) the 128.5 GB is 16.1 GB per GPU. 70B's 1.13 TB does not fit an 8-GPU H100 server (640 GB) even sharded: it needs more servers or the optimizer offloaded to CPU memory.
| What is kept per parameter | Bytes | Llama 3.1 8B | Llama 3.1 70B |
|---|---|---|---|
| Mixed-precision Adam (BF16 weight and gradient, FP32 master, m, v) | 16 | 128.5 GB | 1,129 GB |
| Same, with FP32 gradients (accumulated in FP32 for stability, as Llama 3 did) | 18 | 144.5 GB | 1,270 GB |
| 8-bit Adam moments, FP32 master | 10 | 80.3 GB | 705.5 GB |
| Everything BF16, no master copy | 8 | 64.2 GB | 564.4 GB |
| LoRA rank 16 on every linear (frozen BF16 base + adapters at 16 bytes) | ≈ 2 | 16.7 GB | 144.4 GB |
| QLoRA (NF4 base with double quantisation, 4.127 bits) | ≈ 0.5 | 4.8 GB | 39.7 GB |
| Inference BF16 / FP8 / NVFP4 (4.5 bits with scales) / MXFP4 (4.25) | 2 / 1 / 0.56 / 0.53 | 16.1 / 8.0 / 4.5 / 4.3 GB | 141.1 / 70.6 / 39.7 / 37.5 GB |
Parameter counts from the configs (8,030,261,248 and 70,553,706,496); LoRA adapters 41.9M and 207.1M; recipes as in the parent's calculator derived. The FP32-gradient row follows Llama 3, section 3.3.2 ("FP32 gradient accumulation"). Sharding divides every row. The formats themselves are Quantization and Precision's; the hardware these bytes live in is the sibling Memory technology.
Activations. Every backward rule needs something from the forward pass (a linear layer's weight gradient needs its input, SiLU needs its input, softmax its output), so those tensors stay alive from the moment they are made until backward uses them; they grow with tokens per GPU. Counting every tensor autograd saves in the real model gives 49 bytes per token per hidden unit per layer: 52.7 GB for the 32 layers at 8,192 tokens and micro-batch 1, plus 4.47 GB for the output, because the loss needs the logits in FP32 (128,256 × 4 bytes per token, more than two whole layers). Total 57.1 GB, against the 36.5 GB that the GPT-3 count (34sbh) predicts counted. With plain ("eager") attention each layer also keeps its scores, 32 heads × 8,192 × 8,192 in FP32 and again in BF16: 13.0 GB per layer, 473 GB in all. With full recomputation only each layer's 2h input is kept: 6.6 GB, most of it the logits.
Fig. 3 stacks what one GPU holds, by kind, for one 8,192-token sequence at micro-batch 1 with the model state sharded over 8 H100s (16.1 GB per GPU). The step runs forward through 32 layers, computes the loss, then backward from layer 32 to layer 1; the last two steps replay it with the other two ways of keeping activations: the same step, same scale.
Per-layer bytes, logits and FLOPs are the counted values of section 1 and this section counted; time is FLOPs at 40% MFU on one H100 (989.5 TFLOP/s dense BF16) derived. Transient buffers (gathered weights, gradients being reduced, allocator slack) are left out, so real peaks are higher. With plain attention the step needs about 490 GB, six times an H100; FlashAttention brings it to about 73 GB, which fits with little to spare; full recomputation holds about 23 GB but does more arithmetic (section 4). Heights are to scale (the glass lid is 80 GB); positions are illustrative.
Real runs choose per layer. Megatron's selective recomputation recomputes only the attention-score part, cheap in FLOPs and expensive in memory (Korthikanti et al., section 5); with FlashAttention there is nothing quadratic left, so the choice is between keeping the 49h and recomputing layers. Tensor parallelism with sequence parallelism divides the per-layer figure by the TP degree. How checkpointing and sharding work is Distributed Training's subject; activation memory for any model, length and choice is the FLOP and memory ledger tab.
Korthikanti et al. listed what one GPT-style layer stores, in bytes, in 16-bit precision (Reducing Activation Recomputation, section 4.1):
| Block | What is stored | Bytes |
|---|---|---|
| Attention | input to Q, K, V (2sbh); Q and K for QKT (4sbh); softmax output (2as²b); dropout mask (as²b); dropout output and V (2as²b + 2sbh); input to the output projection (2sbh); its dropout mask (sbh) | 11sbh + 5as²b |
| MLP (4h wide) | inputs to the two linears (2sbh, 8sbh); GeLU input (8sbh); dropout mask (sbh) | 19sbh |
| Two layer norms | their inputs | 4sbh |
| Per layer | sbh (34 + 5as/h) |
For GPT-3 at 2,048 tokens the 5as/h term is 80, more than the 34 for everything else (the paper's own example). For Llama 3.1 8B, running the real model on the meta device and catching every tensor autograd saves (torch.autograd.graph.saved_tensors_hooks, each underlying tensor counted once, parameters excluded) gives, for one layer:
Bytes per token in units of h = 4,096 (BF16 is 2 bytes per number, so "2h" is one hidden-sized vector). The source line is where the tensor was saved in Transformers' modeling_llama.py; attention uses PyTorch's flash kernels and saves what the flash-attn library saves (q, k, v at their own 8 KV heads, the output and the log-sum-exp) counted.
Three differences from GPT-3's 34 explain the 49:
Fused RMSNorm and SwiGLU kernels bring the real figure down; the counted number is for the reference code.
A real run. Llama 3 405B trained at 430 TFLOP/s per GPU on 8,192 H100s (Llama 3, Table 4). The H100's dense BF16 peak is 989.5 TFLOP/s, so the run kept 430 / 989.5 = 43.5% of the arithmetic the chips could do: its MFU. The other big runs that published enough to check land in the same band:
Rearranged, the same formula answers every planning question: time = total FLOPs / (chips × peak × MFU). The parent's calculator checks it against 27 published figures (its "Checks against published figures" table).
Where the other 55 to 60% goes.
Bars: MFU against each chip's dense peak in the format the matmuls ran in; the hatched extension is PaLM's HFU; the dashed line is the best large BF16 GEMM on an H100 (about 720 of 989.5 TFLOP/s, 73%, in SemiAnalysis's independent measurement, Dec 2024). DeepSeek-V3 is shown against the BF16 peak; against the FP8 peak it trained in, 17.6%. Each bar's arithmetic is in the closed block below.
Section 3's full recomputation (Fig. 3, step 6) holds 23 GB instead of 73 GB by running each layer's forward again during backward. The textbook cost is 8N instead of 6N, 1.33 times the work; the counted cost for Llama 3.1 8B at 8,192 tokens is 1.24 times counted, for three reasons: the output head is not recomputed (only the transformer layers are checkpointed); PyTorch's non-reentrant checkpoint stops recomputing as soon as every saved tensor exists again, so each layer's last matmul (the MLP's down projection, which produces nothing backward needs) is not rerun (PyTorch 2.14 docs: "Non-reentrant checkpoint stops recomputation as soon as all needed intermediate activations have been recomputed"); and FlashAttention's backward already costs 2.5 times its forward, so the recompute is a smaller share. The recompute is 118.7 TFLOP, not the layers' full 149.5 TFLOP forward (30.8 TFLOP of down projections skipped).
Korthikanti et al. define them this way: "model FLOPs are hardware and implementation independent and only depend on the underlying model", while "if an implementation requires activation recomputation ... the hardware FLOPs are going to be larger" (section 6.3). A run that recomputes everything can show high HFU while training no faster: PaLM reported 46.2% MFU and 57.8% HFU. Compare runs by MFU. Recomputation can still make training faster: it frees memory for a larger micro-batch or less model parallelism, which is why PaLM chose it "because this results in higher training throughput at larger batch sizes".
| Run | MFU | Arithmetic |
|---|---|---|
| Megatron-Turing NLG 530B | 29.8% | 65.43K tokens/s (1,920 × 2,048 tokens per 60.1 s step) × 6 × 530e9 / (2,240 A100 × 312 TFLOP/s). PaLM printed 29.7%: truncation. Pipeline parallel across servers. |
| PaLM 540B | 46.2% | No pipeline parallelism, 6,144 TPU v4 in two pods; 45.7% without the attention term; 57.8% HFU (below). |
| Llama 3 405B | 43.5% | 430 / 989.5 on 8,192 H100s. Meta prints 43%; 41% on 16,384 GPUs, 38% at 131,072-token sequences. |
| DeepSeek-V3 671B MoE | 35.1% | 180K H800 GPU-hours per trillion tokens: 6 × 37.55e9 active × 1e12 / (180e3 × 3,600 s × 989.5e12). Against the FP8 peak: 17.6%. |
| Two Llama 3.1 8B layers, M1 Pro | 72 to 75% | Measured here (section 5). |
| Llama 3.1 8B, model card hours | 13.9% | 6 × 8.03e9 × 15e12 / (1.46e6 h × 3,600 × 989.5e12): every hour counted as training. |
Sources: PaLM Appendix B (MT-NLG step time from Smith et al. 2022, as PaLM quotes it), Llama 3, Table 4, DeepSeek-V3, section 1, Llama 3.1 8B model card. DeepSeek does not state the H800's peak; assumed equal to the H100 SXM's (the H800 differs in interconnect) derived.
Rebuilding PaLM's 57.8% HFU. PaLM 540B recomputed during backward and reported both numbers; its Appendix B gives everything needed (PaLM, Appendix B and Table 22):
| Step | Arithmetic | Result |
|---|---|---|
| Model FLOPs per token | 6 × 540e9 + 12 × 118 layers × 48 heads × 256 head size × 2,048 tokens | 3.276 TFLOP (paper: 3.28) |
| MFU | 238.3K tokens/s × 3.276e12 / (6,144 TPU v4 × 275 TFLOP/s) | 46.2% (paper: 46.2%) |
| Recompute | "75% of non-attention forward pass FLOPs are recomputed while all attention forward pass FLOPs are recomputed": 0.75 × 2N + (12LHQT)/3 | 0.822 TFLOP |
| HFU | 238.3K × (3.276 + 0.822) TFLOP / (6,144 × 275 TFLOP/s) | 57.8% (paper: 57.8%) |
Reproduced independently from the paper's own description derived: our hardware FLOPs per token, 4.098 TFLOP, against Table 22's 4.10.
Selective recomputation's ratio. Korthikanti et al. give the hardware-to-model ratio as about 1 + s/6h: for their 530B model (s = 2,048, h = 20,480) that is 1.017, and their Table 5 lists 56.0% MFU against 57.0% HFU (56.0 × 1.017 = 56.9) derived. Cheap recomputation is the point of the method: with sequence parallelism, a 29 to 32% throughput gain over full recomputation in their runs (Table 5).
Turning Llama 3's MFU back into a step time. Table 4's first row: 8,192 GPUs, data parallel 64, batch 32 sequences of 8,192 tokens per data-parallel group, so 64 × 32 × 8,192 = 16,777,216 tokens per step. At 430 TFLOP/s per GPU and 6N FLOPs per token, one step takes 16.78e6 × 6 × 405.85e9 / (8,192 × 430e12) = 11.6 s; counting attention in full (8.3% more FLOPs), 12.6 s. Meta does not say which FLOP count its 430 uses, so the step time is known only to within that 8%. Per GPU that is 177 tokens per second. derived
How to measure. Warm up (the first iterations compile kernels and fill allocator caches), then time many steps; synchronise before reading the clock, because GPU calls return before the work finishes (torch.cuda.synchronize(), here torch.mps.synchronize()); take the median, repeat the whole run, and report the spread and what else was running. MFU = model FLOPs of the step / time / dense peak, with the FLOPs from torch.utils.flop_counter.FlopCounterMode or from section 1's formulas; they agree.
Measured here: two decoder layers with the real 8B shapes (436M parameters; the 128K-vocabulary embedding and head left out to fit the shared laptop's memory), FP16, forward and backward, batch 1, PyTorch 2.14.1 on the M1 Pro GPU (MPS backend) measured.
72 to 75% MFU on one GPU. With large matrices, no communication and no tensor cores (the M1's FP16 runs at the same rate as FP32 through ordinary ALUs, so its ridge point is only about 31 FLOPs per byte), almost every operator is compute-bound and the GPU runs near its own matmul speed. A single GPU on big matmuls reaches high MFU; the losses of section 4 come from elsewhere.
Predicting the step from its operators. The same step was run once more with a TorchDispatchMode recording every operator PyTorch launched (447 per step, 315 of which compute or move data): its FLOPs and the bytes it reads and writes. Each operator gets a roofline time, max(FLOPs / peak, bytes / bandwidth), and the step's prediction is the sum. The measurement takes 14 to 22% longer than the prediction: the overhead of launching each kernel and of matmuls that do not quite reach the FMA peak.
That projection is a roofline estimate, not a run. torch.compile and hand-written fused kernels (FlashAttention, fused norms, fused cross-entropy) exist to remove exactly this traffic, and it matters wherever the ridge is high: 295 FLOPs per byte for an H100 at BF16, twice that at FP8. Writing such kernels is the Topic: cuda-and-gpu-programming root's subject; timing them honestly is its Profiling, benchmarking and correctness child's.
Each run is the median of 8 timed steps after 3 warm-up steps; 3 runs, 20 s apart, with the 1-minute load average of the shared machine recorded. At 2,048 tokens the first run hit memory swapping (41.7 s) and is excluded by taking the median of the three runs.
Peak 5.06 TFLOP/s (FP16 fused multiply-add) and bandwidth 165 GB/s are the parent's Roofline lab measurements on this GPU. Script: src/code/m1_step.py.
A served request has two phases on opposite sides of section 2's ridge. Prefill runs the whole prompt through the model at once: thousands of tokens per weight read, compute-bound. Decode then produces one token per step, and each step must read every weight it uses plus the conversation's KV cache (the keys and values of every earlier token, which attention needs): one token per weight read, memory-bound.
| Llama 3.1 8B, BF16, one H100 | Value | Arithmetic |
|---|---|---|
| Prefill of a 4,096-token prompt | 70.9 ms | at 100% of 989.5 TFLOP/s; 141.9 ms at 50% |
| KV cache of one 4,096-token conversation | 0.54 GB | 2 (K and V) × 32 layers × 8 heads × 128 × 2 bytes = 128 KiB per token |
| Decode step, batch 1 | 4.95 ms | (16.06 GB weights + 0.54 GB cache) / 3.35 TB/s: 202 tokens/s at most |
| Decode step, batch 64 | 15.1 ms | weights read once, 64 caches read: 4,252 tokens/s in total, 66 per user; memory 50.4 GB |
| Cost per million output tokens at $3.99 per GPU-hour | $5.49 / $0.26 | batch 1 / batch 64: price / (tokens/s × 3,600) × 106 |
The parent's calculator functions (decode, prefill), copied unchanged; ceilings at full bandwidth or full peak, real serving reaches less derived. Lambda on-demand H100 price fetched 2026-10-05.
Batching is the whole economics of serving. Each step reads the weights once whatever the batch, so 64 users share the 16 GB read and cost 21 times less per token, at the price of each user waiting 3 times longer per token. The cache does not share: at long contexts each conversation's KV reads dominate and batching stops helping, the reason grouped-query attention, latent attention and FP8 caches exist. Cache sizing is Long context's subject, and what one decode step reads is drawn in 3D on the sibling Memory technology (its Fig. 3); the step at batch 1 and 64 is animated in the parent's Performance calculator, and tokens per second against cost for any model, chip and batch is the Run and serving planner tab.
Mixture of experts. At batch 1 a decode step reads only the routed experts: DeepSeek-V3 in FP8 reads 37.6 GB of its 671 GB. But 64 tokens with 8 of 256 experts each touch about 222 experts per layer (uniform routing, 256 × (1 − (1 − 8/256)64)), so the step reads 585 GB: an MoE's bandwidth advantage disappears at the batch sizes that make serving cheap, while its FLOP advantage stays derived.
Llama 3.1 70B with a 32,768-token prompt on 8 H100s at 50% of peak: 1.52 s before the first token, and attention is 23% of those FLOPs (causal count). Prefill time grows faster than linearly with the prompt. Scheduling, paged caches and speculative decoding are Topic: inference-and-serving's.
Llama 3 405B. 6 × 405.85e9 parameters × 15.6e12 tokens = 3.80 × 1025 FLOPs, the figure the paper states (3.8 × 1025). At Table 4's 400 TFLOP/s per GPU on 16,384 H100s (40.4% MFU; the table prints 41%) that is 26.4M GPU-hours: 67 days on 16,384 GPUs, $105M at the $3.99 list price. The model card lists 30.84M H100-hours, 1.17 times the estimate.
Headline GPU-hours are a budget, not a measurement of efficiency. Llama 3.1 8B on 15T tokens is 7.2 × 1023 FLOPs, 507K H100-hours at 40% MFU; its model card lists 1.46M H100-hours, 2.9 times our 507K: at list price $5.8M. Either the steady-state MFU was far below 40%, or (more likely) the hours include more than one clean pass: experiments, restarts, other stages (model card). DeepSeek-V3's $5.576M is 2.788M H800-hours at the $2 per hour DeepSeek assumes, and excludes "prior research and ablation experiments" by its own statement (the DeepSeek-V3 paper page checks the bill).
Smaller jobs and serving. Fine-tuning the 8B on 1 billion tokens with FSDP on one 8-GPU H100 server takes 4.2 hours at 40% MFU: about $135 at list price (the parent's worked example). To produce one million output tokens per minute (16,667 per second) from Llama 3.1 8B at 4,096 tokens of context takes about 4 H100s at batch 64, or 83 at batch 1, at the bandwidth ceiling; real deployments reach a fraction of it and must also run prefill, so plan from measured throughput once you have it. Chips for a deadline and the serving frontier for any model are the Run and serving planner tab; failures and checkpoint intervals are the sibling Power, cooling and reliability's.
| At 40% MFU, 90% goodput | GPU-hours | Cost (list) | GPUs for 30 days |
|---|---|---|---|
| H100 SXM (989.5 TFLOP/s, $3.99/h) | 507K | $2.02M; $2.25M with goodput | 783 |
| B200 (2,250 TFLOP/s, $6.69/h) | 223K | $1.49M; $1.66M with goodput | 344 |
GPU-hours before goodput; GPUs for 30 days include it. Lambda on-demand 8-GPU instance prices fetched 2026-10-05 (Lambda pricing) derived. The B200 costs more per hour and less per run, if the software reaches the same MFU on it. Prices and peaks for every chip: the parent's Chip atlas.
Predict, then drag: what MFU would make the estimate equal the 405B's published 30.84M hours?
GPU-hours = 6 × N × D / (989.5 TFLOP/s × MFU) / 3,600; cost at the stated hourly price derived. Llama 3 405B: defaults reproduce the paper's 3.8 × 1025 FLOPs, independently (N from the config, D = 15.6T); MFU from Table 4 (Llama 3); hours from the Llama 3.1 model card, which counts the total GPU time of training, while the estimate is steady-state pretraining only (the 131,072-token stage ran at 380 TFLOP/s, and Meta reports more than 90% effective training time). Llama 3.1 8B: about 15T tokens, 40% MFU illustrative, card 1.46M hours. DeepSeek-V3: 37.55B active parameters, 14.8T tokens, the H800 assumed at the H100's peak; its 35.1% MFU is back-solved from "180K H800 GPU hours" per trillion tokens, so landing on the 2.664M pretraining hours ($5.328M at DeepSeek's $2 per hour) is by construction (DeepSeek-V3, Table 1).
On many GPUs every step also moves data, and the arithmetic is section 2's again: count the bytes each GPU sends, divide by the bandwidth of the link it crosses, and ask whether it overlaps with compute. For Llama 3.1 8B on 8 GPUs, data parallelism all-reduces 28.1 GB of BF16 gradients per step (62.5 ms over NVLink 4), once per step and overlapped with backward, so it can cross the slower network between servers; tensor parallelism moves 0.47 GB per layer on the critical path, so it stays inside the NVLink domain. The layouts are Distributed Training's subject and the links and collectives Interconnects and scaling's; the parent calculator's "Why tensor parallelism stays inside the NVLink domain" chart puts numbers on the placement.
| Parallelism | What moves, per GPU | Formula | Llama 3.1 8B, 8 GPUs |
|---|---|---|---|
| Data parallel (DDP) | all-reduce of the BF16 gradients, once per step | 2(n−1)/n × 2N | 28.1 GB; 62.5 ms over NVLink 4 |
| Fully sharded (FSDP, ZeRO-3) | gather weights forward, gather again backward, reduce-scatter gradients | 3 × (n−1)/n × 2N | 42.2 GB (1.5 × DDP) |
| Tensor parallel (Megatron) | 4 all-reduces of the layer's activations per layer and micro-batch, on the critical path | 4 × 2(t−1)/t × s b h × 2 | 0.47 GB per layer, 15.0 GB per 8,192-token micro-batch |
| Pipeline parallel | activations forward and gradients back at each stage boundary | s b h × 2 each way | 67 MB per micro-batch |
| Expert parallel (MoE) | each token's hidden vector to its k experts and back (all-to-all) | ≤ 2 × k × h × 2 per token per MoE layer | DeepSeek-V3: ≤ 229 KB per token per layer |
n data-parallel GPUs, t tensor-parallel GPUs, s sequence length, b micro-batch, h hidden size, k experts per token; 2 bytes per BF16 value derived. Ring collectives follow NCCL's bus-bandwidth model (nccl-tests PERFORMANCE.md). The MoE row is an upper bound: tokens whose experts sit on the same GPU do not move, and DeepSeek-V3 limits each token to 4 nodes. Expert parallelism's all-to-all is per layer, like tensor parallelism's.
Mistakes worth knowing and questions to answer before revealing; every answer is computed in the sections above. The parent's Performance calculator has ten more drills.
Every FLOP and every saved byte of one training step of a Llama-family model, part by part, for any sequence length. The formulas are the Reading tab's sections 1 and 3; for Llama 3.1 8B at 2,048, 8,192, 32,768 and 131,072 tokens, and Llama 3.1 70B at 8,192, they equal PyTorch's own count of the real model (the green badge says when the point you chose is one of them).
Try: slide the sequence length up and watch attention overtake the MLP; switch the attention convention to see what causal masking saves; switch checkpointing and the GPU to see what fits.
Solid: the exact count (with the convention chosen above); dashed: 6N; dotted: the MLP alone. Log scale on both axes.
Model state is not included here (the Reading tab's section 3 and the parent's calculator add it). Per-layer bytes per token: 16h (two RMSNorms in FP32 and their outputs) + 4 × heads × head size (Q and the output) + 4 × KV heads × head size (K and V) + 8 × MLP width + small terms; plain attention adds 6 × heads × sequence length; full recompute keeps 2h. Logits: 4 bytes × vocabulary per token. Tensor parallel with sequence parallel divides the layers' share by the TP degree (the logits are left whole, a simplification). Counted on Transformers' reference code; fused kernels save less.
Two planning questions the parent's Performance calculator leaves open, built on its functions (copied unchanged, so the two pages agree): how many accelerators and how much money a training run needs to finish by a date, and what serving costs per million tokens as the batch grows. Every result is a ceiling or an estimate at the efficiency you set; prices are on-demand list prices fetched 2026-10-05 (Lambda for GPUs, Google Cloud for TPUs), and only chips with a published price show a cost.
Try: Llama 3.1 8B on 15,000B tokens finishes in 30 days on about 780 H100s; drop MFU to 25% or goodput to 70% and watch the count and the bill; switch to DeepSeek-V3 to see active parameters set the compute.
Try: start at batch 1 and follow the curve: total throughput rises almost linearly while each user's speed barely falls, until the KV cache or compute takes over. Raise the context and watch the knee move left.
Decode only (prefill adds its own compute); each step reads the weights in use (for a mixture of experts, the experts the batch touches under uniform routing) plus every sequence's cache at the given context; the step time is the larger of bytes over bandwidth and FLOPs over peak, both scaled by the efficiency. Cost per million output tokens = price × chips / (tokens per second × 3,600) × 106 derived.
Every FLOP and saved byte of a Llama training step, part by part, for any sequence length, attention convention and checkpointing choice. 10 min
Chips and money to finish a run by a date; tokens per second against cost per million tokens as the batch grows. 10 min
The root: the map of the topic. Its "Performance calculator" tab is the calculator this page derives (training, inference, communication, 27 checks, 10 drills); "Roofline lab" measures this laptop's GPU; "Chip atlas" holds every peak and price. 28 min, plus 3
Where the peaks come from: SMs, tensor cores, Ampere to Rubin. 34 min, plus 9
HBM, GDDR and SRAM, CXL and offload, and why bandwidth bounds decode. 27 min, plus 9
Systolic arrays, TPU pods, AMD, Trainium, Groq, Cerebras: the same arithmetic on other machines. 39 min, plus 7
The links behind section 8: PCIe, NVLink, InfiniBand and RoCE, collectives. 34 min, plus 14
Failures, goodput and checkpoint intervals: the other side of section 7. 28 min, plus 3
Why backward is twice forward, derived and measured; checkpointing from first principles. 32 min
Data, tensor, pipeline, expert and context parallelism; its Layout calculator chooses a layout at scale. 32 min, plus 5
Failures, checkpointing and recovery in practice, and how to account for the time lost. 41 min
The formats behind the bytes per parameter. 34 min, plus 11
Writing the fused kernels section 5 argues for, and applying the roofline to kernels. 28 min, plus 4
Batching schedulers, paged KV caches, speculative decoding. 34 min, plus 3
Where C = 6ND was written down; its Table 1 recounted. 21 min
The 16 bytes per parameter of section 3 and how sharding divides them, stepped through. 24 min
Tensor parallelism: the four all-reduces per layer of section 8. 23 min
Why the score matrix need not be stored, run as a kernel. 26 min
The 16K-GPU job, its MFU table and its 419 interruptions. 31 min
An FP8 mixture of experts and its $5.576M bill, checked. 32 min
Training FLOPs and memory budgets in one page. 35 min
The serving counterpart: KV cache, latency, batching. 40 min
Rooflines for compute, memory and the network; its later chapters do this page's arithmetic for TPUs. 45 min
Compute-bound, bandwidth-bound and overhead-bound, with intuition. 25 min
The original MFU definition and the HFU accounting rebuilt in section 4. 15 min
The 34 + 5as/h count, sequence parallelism and selective recomputation. 40 min
Memory, parallelism and communication for training at scale, with measured runs and calculators. 3 h
Algorithm and bus bandwidth: the communication model of section 8. 10 min
Reentrant against non-reentrant checkpointing, and the early stop counted in section 4. 10 min