The problem
Before a training run starts, a few lines of arithmetic tell you how much compute it needs, how long it will take, and whether the model size fits the budget. You will write four of them, with plain Python floats. All of them are built on one rule from the theory page: training a model with parameters on tokens costs
FLOPs (floating-point operations), where 2 per parameter per token are for the forward pass and 4 for the backward pass.
1. Compute of a run
, with = n_params and = n_tokens.
Example. and : FLOPs.
2. The best model size for a budget
Hoffmann et al. (Chinchilla) found that, for a fixed budget, about 20 training tokens per parameter gives the lowest loss: . Put it into :
so
Example. : parameters, and tokens.
3. Days of training
Each of the n_gpus GPUs (graphics processing units) can do at most peak_flops FLOPs per second, and a real run uses a fraction mfu of that peak, the MFU (model FLOPs utilization), for example 0.4. So the run does n_gpus * peak_flops * mfu useful FLOPs per second, and lasts divided by that, in seconds. A day has 86,400 seconds.
Example. The run of part 1 ( FLOPs) on 8 GPUs with a peak of FLOPs per second and an MFU of 0.4: FLOPs per second, so seconds, about days.
4. The MFU of a running job
The other way round: from the measured speed of a run, in tokens per second for the whole cluster, compute its MFU. The model needs FLOPs per token, so it uses tokens per second; divide by the peak of the whole cluster, n_gpus * peak_flops.
Example. A model of processing tokens per second on the same 8 GPUs: FLOPs per second, out of a peak of : an MFU of .
What to implement
train_flops(n_params, n_tokens): part 1.chinchilla_optimal(compute): part 2, the tuple(n_params, n_tokens).training_days(n_params, n_tokens, n_gpus, peak_flops, mfu): part 3.model_flops_utilization(n_params, tokens_per_second, n_gpus, peak_flops): part 4.
Requirements
- Return floats (for
chinchilla_optimal, a tuple of two floats).