Compute model FLOPs utilization (MFU) for a training run
Why it matters MFU is the standard way to compare training efficiency across hardware and code bases.
MFU tells you what fraction of the hardware's peak FLOPs your training job actually uses for the model's math.
Write mfu(n_params, tokens_per_sec, peak_flops, n_layers=0, seq_len=0, d_model=0). Training costs about 6 * n_params FLOPs per token (forward plus backward), plus 12 * n_layers * seq_len * d_model FLOPs per token for the attention score and value matmuls. Return (flops_per_token * tokens_per_sec) / peak_flops as a float.
def mfu(n_params, tokens_per_sec, peak_flops, n_layers=0, seq_len=0, d_model=0)Example
mfu(1e9, 10000, 1e14) is 6e9 * 1e4 / 1e14 = 0.6.
Understand the idea
Peak FLOPs is the speed printed on the GPU box. MFU asks how much of that speed goes into useful model math, like asking how much of a car's top speed you actually average on a trip.
A dense model with N parameters does about 2N FLOPs per token in the forward pass (one multiply and one add per weight) and about 4N in the backward pass, so 6N per token for training. Attention over a context of T tokens adds about 12 * L * T * d more.
Example: a 1 billion parameter model processing 10,000 tokens per second needs 6e9 * 1e4 = 6e13 FLOPs per second. On hardware with a 1e14 peak, MFU = 0.6, which is 60%.
Rule: MFU = (6N + 12 L T d) * tokens_per_sec / peak_flops.
Large training runs usually report MFU somewhere between 30% and 60%; the rest is lost to communication, memory traffic and idle time.