Evaluate the Chinchilla scaling law

Why it matters Compute budgets for LLM pretraining runs are planned with this law.

Hoffmann et al. (2022) fit pretraining loss as L(N, D) = E + A / N^alpha + B / D^beta for N parameters and D tokens.

Write chinchilla_loss(N, D, E=1.69, A=406.4, B=410.7, alpha=0.34, beta=0.28). Return L.

Signaturedef chinchilla_loss(N, D, E=1.69, A=406.4, B=410.7, alpha=0.34, beta=0.28)

Example

chinchilla_loss(1e9, 2e10) is about 2.58.

Understand the idea

The Chinchilla scaling law predicts the pretraining loss of a language model from its size N (parameters) and its data D (training tokens). The loss is a floor E that no model can beat, plus one term that shrinks as the model grows and one that shrinks as the data grows. Worked example with the default constants: N = 1e10, D = 2e11. N^0.34 = 10^3.4 = about 2512, so A / N^0.34 = 406.4 / 2512 = 0.162. D^0.28 = about 1460, so B / D^0.28 = 410.7 / 1460 = 0.281. L = 1.69 + 0.162 + 0.281 = about 2.133. Rule: L(N, D) = E + A / N^alpha + B / D^beta, with alpha used for parameters and beta for data, never swapped. Inputs can be plain floats; use float powers. Because both terms fall as power laws, doubling only one of N or D gives smaller and smaller gains, which is why the paper suggests growing them together. Used in: planning LLM training budgets, choosing model size for a fixed compute budget, and comparing training runs.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 3.

  • Sample 1: examplechinchilla_loss(1e9, 2e10)
  • Sample 2: 70Bchinchilla_loss(70e9, 1.4e12)
  • Test 3: data starvedchinchilla_loss(70e9, 1e10)