Compute-optimal model and data size with a Chinchilla-style rule of thumb
The Chinchilla paper (Hoffmann et al., 2022) argued that many large models were undertrained and that parameters and training tokens should grow together. A commonly cited approximation of its result is about 20 training tokens per parameter, combined with the standard estimate that training costs C = 6 * N * D FLOPs for N parameters and D tokens.
Write compute_optimal(C, tokens_per_param) for a FLOP budget C. Use D = tokens_per_param * N and C = 6 * N * D, and solve for N. Return (N, D) as floats, N in parameters and D in tokens.
def compute_optimal(C, tokens_per_param)Example
compute_optimal(1.2e21, 20) gives N = 1e9 and D = 2e10.
Understand the idea
The compute-optimal idea says that for a fixed training budget, model size and data size should grow together rather than making the model huge and training it briefly. Two rules of thumb make this concrete: training costs about 6 FLOPs per parameter per token, so C = 6 * N * D, and a good ratio is about 20 tokens per parameter, so D = 20 * N. Put them together: C = 6 * N * 20 * N = 120 * N^2. Worked example: C = 1.2e23 FLOPs. N^2 = 1.2e23 / 120 = 1e21, so N = sqrt(1e21) = 3.16e10, about 31.6 billion parameters, and D = 20 * N = 6.32e11, about 632 billion tokens. Rule: N = sqrt(C / (6 * tokens_per_param)), D = tokens_per_param * N, both returned as floats. Because N grows with the square root of C, doubling compute raises both N and D by about 1.41 times. Forgetting the factor 6 makes N about 2.45 times too large. Labs use this kind of estimate when planning a training run's size.