Performance math: FLOPs, memory, MFU, tokens per second, costing a run

A child page of Topic: hardware: the arithmetic behind its Performance calculator, derived and checked on a real Llama 3.1 8B step counted by PyTorch. FLOPs, the roofline, memory, MFU and HFU, prefill and decode, and what a run costs. Data as of October 2026. Reading: 24 min, plus 11 in closed details.

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:

  1. A training step: FLOPs over peak. One step on an 8,192-token sequence is 492 TFLOP (60.1 GFLOP per token, counted; section 1). At 40% MFU of 989.5 TFLOP/s it takes 1.24 s. Arithmetic is the limit.
  2. What the step holds: bytes against capacity. 16.1 GB of model state (sharded over 8 GPUs) plus 57.1 GB of activations kept for backward with FlashAttention: about 73 GB at the peak against the 80 GB lid. It fits, barely (section 3).
  3. A decoded token: bytes over bandwidth. Serving at batch 1, every token reads all 16.06 GB of weights plus the conversation's 0.54 GB KV cache at 4,096 tokens: 4.95 ms at 3.35 TB/s, at most 202 tokens/s, while the die mostly waits. Bandwidth is the limit (section 6).
  4. A whole run: FLOPs over peak, times price. 6 × 8.03e9 × 15T tokens = 7.2e23 FLOPs: 507K H100-hours at 40% MFU, $2.02M at $3.99 an hour, or 783 H100s for 30 days at 90% goodput (section 7).

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.

FLOP
one floating-point add or multiply; FLOP/s is the rate.
Arithmetic intensity
FLOPs done per byte moved to or from memory.
Ridge point
peak FLOP/s over bandwidth: the intensity above which a chip is compute-bound (295 FLOPs per byte for an H100 at BF16).
MFU, HFU
model (or hardware) FLOPs per second achieved, over the dense peak; HFU also counts recomputed FLOPs.
Prefill, decode
serving's two phases: the whole prompt at once, then one token per step.
Goodput
the share of wall-clock time spent on useful training.
Meta device
PyTorch's shapes-only device: every operator runs without data, so a full 8B or 70B step can be counted for free.

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.

1. FLOPs: 6ND, and what it leaves out

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).

  1. One matrix multiply. Llama 3.1 8B's query weight W (4,096 × 4,096, drawn larger than the model's scale) meets one token's 4,096 numbers: every weight does a multiply and an add, 2 FLOPs, so 33.6 MFLOP per token; for 8,192 tokens, 2 × 8,192 × 4,096 × 4,096 = 275 GFLOP.
  2. Forward: 2N per token. Now the floor is the whole model, one square per billion weights: projections 1.34B, MLP 5.64B, output head 0.53B. Each is 2 FLOPs high, so the forward pass is 2 × 7.50B = 15.0 GFLOP per token. The input embedding (0.53B) lies flat: it looks a row up and does no arithmetic.
  3. Backward: 4N more. Every weight is used twice more going back, 2 FLOPs for the gradient of its input (to keep backpropagating) and 2 for the gradient of the weight itself: the blocks reach 6 high, 45.0 GFLOP per token. 6N with N = 8.03B gives 48.18, because it also counts the embedding (the dashed ghost): 6.5% too much at short sequences.
  4. Attention: FLOPs without weights. Each query meets every earlier key and value: 2 × 32 layers × 8,192 × 4,096 = 2.15B numbers per token, 2 FLOPs each forward and 5 backward (FlashAttention recomputes the scores, 2.5 times its forward): 15.0 GFLOP. Counted total 60.06 GFLOP per token, 1.25 × 6N; times 8,192 tokens, 492 TFLOP for the step.
  5. At 131,072 tokens. The weights do not change, but the attention floor grows 16 times, to 34.4B numbers: 240.5 GFLOP per token on its own. The step costs 285.5 GFLOP per token, 5.9 × 6N; long-context training pays for attention, not for weights.

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.

forward ≈ 2N per token    backward ≈ 4N per token    training C ≈ 6 N D
N
parameters that take part in a matrix multiply
D
training tokens

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).

The count part by part, with its formulas (under a minute)

Per token at 8,192 tokens, training (forward and backward), with the full score square counted:

PartFormula 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,33633.82
Output head (vocabulary 128,256)6 × h × V3.15
Attention core forward (QKT and AV)L × 4 × T × h4.29
Attention core backward, FlashAttention2.5 × forward (recomputes the scores)10.74
Input embeddinga table lookup: 00
Total, counted by PyTorch on the real model60.06
6N, with N = 8.03B48.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:

  • The input embedding is not a multiply, it looks a row up. Its 525M parameters are 6.5% of N, so 6N over-counts by that much at short sequences. The output head is a multiply and counts.
  • Attention over the context: each query meets every earlier key, 4 × T × h forward FLOPs per layer per token, growing with the sequence while 6N does not. At 2,048 tokens the two effects nearly cancel (+1.3% over 6N); at 8,192 attention adds 24.7%, at 32,768 118%, at 131,072 it is five times 6N.
  • Causal masking: a causal kernel skips the blocks above the diagonal, about half the score square. Counting full squares (PaLM's 12LHQT, PyTorch's counter) gives the upper figure; the work done is nearer half the attention term. Say which convention you use.
  • FlashAttention's backward recomputes the scores instead of reading them back, so its attention backward is 2.5 times its forward, not 2 times (counted: 10.74 against 4.29 GFLOP per token).

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).

Predict: training Llama 3.1 8B at 131,072-token sequences. How many times 6N does one token cost?
The two attention conventions, worked at 8,192 tokens (1 min)

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.

Conventions differ: say which one you use
The parent's calculator adds attention as PaLM's 12LHQT in full (15% for 70B at 8,192), the convention published MFUs use; the causal half over matmul-only 6N is 14% for 8B at 8,192. Both are right under their own convention. Counted in full with FlashAttention's backward, the whole step is 24.7% above 6N for 8B and 16.3% for 70B.

At 8,192 tokens the real step costs 25% more than 6N; at 131,072 it costs six times as much

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.

2. Arithmetic intensity and the roofline: compute-bound or memory-bound

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.

intensity I = FLOPs / bytes    time ≥ max(FLOPs / peak, bytes / bandwidth)    ridge = peak / bandwidth
attainable
min(peak, I × bandwidth): the sloped roof below the ridge, the flat roof above it
ridge
989.5e12 / 3.35e12 = 295 FLOPs per byte for an H100 at BF16; twice that at FP8
matmul
I = mkn / (mk + kn + mn) in BF16, close to m while m is much smaller than k and n: the tokens per weight read are the intensity

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.

A weight matrix needs about 345 tokens per read before an H100 stops waiting on memory

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).

3. Memory: what one training step holds

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.

Bytes per parameter for every training and inference recipe (1 min)
What is kept per parameterBytesLlama 3.1 8BLlama 3.1 70B
Mixed-precision Adam (BF16 weight and gradient, FP32 master, m, v)16128.5 GB1,129 GB
Same, with FP32 gradients (accumulated in FP32 for stability, as Llama 3 did)18144.5 GB1,270 GB
8-bit Adam moments, FP32 master1080.3 GB705.5 GB
Everything BF16, no master copy864.2 GB564.4 GB
LoRA rank 16 on every linear (frozen BF16 base + adapters at 16 bytes)≈ 216.7 GB144.4 GB
QLoRA (NF4 base with double quantisation, 4.127 bits)≈ 0.54.8 GB39.7 GB
Inference BF16 / FP8 / NVFP4 (4.5 bits with scales) / MXFP4 (4.25)2 / 1 / 0.56 / 0.5316.1 / 8.0 / 4.5 / 4.3 GB141.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.

  1. Model state on one GPU. Five kinds per parameter: BF16 weight 2 bytes, BF16 gradient 2, FP32 master 4, Adam's m 4 and v 4. For 8.03B parameters that is 128.5 GB, well over the 80 GB lid.
  2. Sharded over 8 GPUs. ZeRO stage 3 (FSDP) gives each GPU an eighth of every kind: 16.1 GB each. The rest of each card is for activations.
  3. Forward, FlashAttention. Each layer keeps the 1.65 GB its backward rule needs (49 bytes × h per token), 52.7 GB after 32 layers; then the loss keeps the 4.47 GB of FP32 logits. The high-water mark is 73.2 GB: under the 80 GB lid with little to spare.
  4. Backward. The head's backward frees the logits; each layer's backward then uses its saved tensors and frees them, from layer 32 down to layer 1, back to the 16.1 GB of model state. The whole step is 492 TFLOP: 1.24 s at 40% MFU.
  5. Plain attention. Without FlashAttention each layer also keeps its 32 × 8,192 × 8,192 score matrix in FP32 and BF16, 13.0 GB: 14.6 GB per layer and a peak of 489 GB, six times an H100.
  6. Full recompute. Only each layer's 8,192 × 4,096 BF16 input is kept (67 MB), so the peak is 22.7 GB at the loss, most of it the logits. During backward each layer's 1.65 GB is rebuilt from its saved input, used and freed: 1.24 times the FLOPs, 1.54 s at 40% MFU (section 4).

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.

activations per layer ≈ 49 × s × b × h bytes (Llama, reference code)    sbh (34 + 5as/h) (GPT-3)
s, b, h, a
sequence length, micro-batch, hidden size, attention heads; the 5as/h term is the stored score matrix, which FlashAttention removes
Correction to the old page, and to the parent's calculator
The old notes wrote activations as "sbh × L × c (batch s × seq b ...)": in Korthikanti et al. s is the sequence length and b the micro-batch, and the per-layer constant is 34 + 5as/h (about 34 with FlashAttention, 2 with full recomputation). The parent calculator's "store all, FlashAttention" option used 34sbh, about 1.4 times low for Llama-style models in the Transformers code (49h counted) and without the FP32 logits; since 2026-10-24 it uses this page's count.

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.

Where 49 comes from: the GPT-3 count, and every tensor one Llama layer saves (3 min)

Korthikanti et al. listed what one GPT-style layer stores, in bytes, in 16-bit precision (Reducing Activation Recomputation, section 4.1):

BlockWhat is storedBytes
Attentioninput 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 normstheir inputs4sbh
Per layersbh (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:

  • SwiGLU. Llama's MLP has three matrices and an intermediate width of 14,336 = 3.5h, and four 3.5h-wide tensors are saved (gate output, up output, SiLU output, their product): 28h against GPT's 18h.
  • RMSNorm in FP32. The reference code upcasts to FP32 before normalising, so each norm saves a 4h FP32 copy plus 2h BF16 copies: 16h for two norms against 4h. A fused norm kernel saves only its input and the per-token scale.
  • Grouped-query attention saves K and V at 8 heads instead of 32 (0.5h each), and there is no dropout.

Fused RMSNorm and SwiGLU kernels bring the real figure down; the counted number is for the reference code.

4. Utilisation: MFU, HFU, and what real runs reach

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:

MFU = tokens per second × model FLOPs per token / (chips × peak FLOP/s per chip)
peak
the dense datasheet peak in the format the matmuls run in (BF16 for most runs; never the sparse figure)
FLOPs per token
6N, plus 12LHQT if you count attention (PaLM's definition); say which

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.

  • Matmuls below peak. Even a large BF16 GEMM reaches about 73% of an H100's peak; that ceiling is reached before anything else goes wrong.
  • Memory-bound operators (norms, activations, residual adds, the loss): no matmul, so no MFU, and on an H100 each byte costs as much time as 295 FLOPs (section 2; section 5 counts them).
  • Communication that does not overlap (section 8), pipeline bubbles (idle stages at the start and end of each step), stragglers, data loading.
  • Failures and restarts, which MFU measured in steady state leaves out: Llama 3.1 8B's model card lists 1.46M H100-hours for about 15T tokens, an implied 13.9% if every hour were training.

Large runs keep 30 to 46% of peak; one GPU on big matmuls reaches 75%; the hours on a model card imply far less

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.

Recomputation, and why HFU flatters

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).

MFU counts model FLOPs     HFU counts hardware FLOPs
model FLOPs
what the model needs for one forward and one backward pass, however it is implemented (6N plus attention)
hardware FLOPs
what the chips actually executed, including recomputation

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".

The arithmetic behind each bar, PaLM's HFU rebuilt, and Llama 3's step time (4 min)
RunMFUArithmetic
Megatron-Turing NLG 530B29.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 540B46.2%No pipeline parallelism, 6,144 TPU v4 in two pods; 45.7% without the attention term; 57.8% HFU (below).
Llama 3 405B43.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 MoE35.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 Pro72 to 75%Measured here (section 5).
Llama 3.1 8B, model card hours13.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):

StepArithmeticResult
Model FLOPs per token6 × 540e9 + 12 × 118 layers × 48 heads × 256 head size × 2,048 tokens3.276 TFLOP (paper: 3.28)
MFU238.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)/30.822 TFLOP
HFU238.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

5. Measuring MFU yourself, and predicting it operator by operator

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.

The same operators on an H100: why fusion matters more on faster chips

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.

The M1 runs, step by step (1 min)

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.

The M1 Pro runs 72 to 75% MFU, and the step takes 14 to 22% longer than its roofline sum

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.

6. Serving: prefill, decode, and tokens per second

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.

time to first token ≈ prefill FLOPs / (peak × efficiency)     time per output token ≈ bytes read per step / bandwidth
prefill FLOPs
2N per prompt token, plus attention over the prompt (causal: about half the score square)
bytes per step
weights used (all of them for a dense model) plus every sequence's KV cache
Llama 3.1 8B, BF16, one H100ValueArithmetic
Prefill of a 4,096-token prompt70.9 msat 100% of 989.5 TFLOP/s; 141.9 ms at 50%
KV cache of one 4,096-token conversation0.54 GB2 (K and V) × 32 layers × 8 heads × 128 × 2 bytes = 128 KiB per token
Decode step, batch 14.95 ms(16.06 GB weights + 0.54 GB cache) / 3.35 TB/s: 202 tokens/s at most
Decode step, batch 6415.1 msweights 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.26batch 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.

Long prompts: prefill grows faster than the prompt (under a minute)

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.

7. Costing a run, and planning capacity

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.

GPU-hours = total FLOPs / (peak × MFU) / 3,600    cost = GPU-hours / goodput × price
goodput
the share of wall-clock time spent on useful training; Llama 3 reports "higher than 90% effective training time" despite 419 unexpected interruptions in 54 days (Llama 3, section 3.3.4)
price
dated, with its terms (on-demand list prices here; reserved and committed prices are lower)

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.

The 8B run on H100 against B200, with goodput and a 30-day deadline (under a minute)
At 40% MFU, 90% goodputGPU-hoursCost (list)GPUs for 30 days
H100 SXM (989.5 TFLOP/s, $3.99/h)507K$2.02M; $2.25M with goodput783
B200 (2,250 TFLOP/s, $6.69/h)223K$1.49M; $1.66M with goodput344

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.

Estimate from 6ND and MFU, against the hours each lab published

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).

8. Communication: the same division, for bytes on the wire

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.

Bytes per step for every kind of parallelism (1 min)
ParallelismWhat moves, per GPUFormulaLlama 3.1 8B, 8 GPUs
Data parallel (DDP)all-reduce of the BF16 gradients, once per step2(n−1)/n × 2N28.1 GB; 62.5 ms over NVLink 4
Fully sharded (FSDP, ZeRO-3)gather weights forward, gather again backward, reduce-scatter gradients3 × (n−1)/n × 2N42.2 GB (1.5 × DDP)
Tensor parallel (Megatron)4 all-reduces of the layer's activations per layer and micro-batch, on the critical path4 × 2(t−1)/t × s b h × 20.47 GB per layer, 15.0 GB per 8,192-token micro-batch
Pipeline parallelactivations forward and gradients back at each stage boundarys b h × 2 each way67 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 layerDeepSeek-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.

Rehearsal (optional)

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.

Common mistakes the sections do not already show (1 min)
Dividing by the sparse peak
Datasheets print 2:4 structured-sparsity figures, twice the dense ones (H100 BF16: 1,979 sparse, 989.5 dense). Training never uses them; MFU against a sparse peak is half what it should be. The parent's Chip atlas marks which is which.
Using 6N at long context
At 32,768 tokens the attention core more than doubles the per-token cost of Llama 3.1 8B (105 against 48 GFLOP, full-square count). State the convention (full or causal) whenever you add it.
Counting the input embedding as compute
It is a lookup: 6.5% of Llama 3.1 8B's parameters do no FLOPs. Labs differ on whether "N" includes it (gpt-oss-120b's card leaves it out of the active count).
Forgetting the logits
With a 128K vocabulary the FP32 logits kept for the loss cost 4.47 GB per 8,192-token sequence. Chunked or fused cross-entropy kernels exist for this reason.
Leaving out goodput and price terms
A cost estimate without failures, restarts and the price's date and terms is a lower bound. Say which.
Drills: commit to an answer, then reveal (4 min)
1. One training step of Llama 3.1 8B on one 8,192-token sequence. How many FLOPs, counting attention?
2. With FlashAttention and no recomputation, how much activation memory does that step keep?
3. Why can plain (non-flash) attention not train this model at 8,192 tokens on an H100?
4. Full activation checkpointing in PyTorch: by how much does the hardware's work exceed the model's?
5. Llama 3 405B ran at 430 TFLOP/s per GPU on 8,192 H100s with 16.8M tokens per step. How long was a step?
6. How many H100s pretrain Llama 3.1 8B on 15T tokens in 30 days at 40% MFU and 90% goodput?
7. Serving Llama 3.1 8B on one H100 at 4,096 tokens of context: how much cheaper per token is batch 64 than batch 1, at the ceilings?
8. DeepSeek-V3 in FP8 decoding a batch of 64: what share of its 671 GB of weights does one step read?
10. Your 8B run reaches 25% MFU on 64 H100s. Where do you look, in order?