All courses

Compute-optimal training (Chinchilla)

Given C ≈ 6ND, find the split of compute between N and D that minimizes loss. Arrive at roughly 20 tokens per parameter, and size a compute-optimal model for a given FLOP budget.

Builds on: Scaling laws: loss vs parameters, data, compute

▶ Watch this lesson Start the whole course

What the animation says

One budget, two appetites

You have a fixed compute budget for training. Call it C, counted in floating point operations. Training costs about six times the number of parameters times the number of tokens. So every parameter you add leaves fewer tokens you can afford. A huge model that reads little text stays undertrained. A small model fed endless text runs out of capacity. Warm-up: keep the budget fixed and make the model one percent bigger. What happens to the tokens?

Shift until the gains cancel

About one percent fewer tokens. The six never changes, so parameters and tokens trade percent for percent. Is that trade worth it? The bigger model lowers the loss. The smaller dataset raises it. The fitted loss has three parts: a floor E, a parameter term, and a data term. A, B, alpha and beta are just fitted constants. Keep shifting budget toward whichever side saves more loss, until a one percent step either way saves the same. That balance point: alpha times the parameter term equals beta times the data term.

Twenty tokens per parameter

Both terms are power laws, so the balance point moves predictably as the budget grows. Optimal size grows as C to the power beta over alpha plus beta. Tokens grow as C to alpha over alpha plus beta. Chinchilla's fits found alpha and beta nearly equal, so both exponents are about one half. Parameters and tokens then grow by the same factor, at about twenty tokens per parameter. Now quadruple the compute. How much bigger should the optimal model be?

Which plan is balanced?

Two times bigger. Size is the square root of C over one hundred twenty, so four times compute doubles both parameters and tokens. Now a real budget: five point eight eight times ten to the twenty-three FLOPs. Here are three plans. Every one spends exactly this budget. Only one sits near twenty tokens per parameter. Divide tokens by parameters, then tap it.

Sizing it, and the wrong turn

Let's derive that plan. Divide the budget by one hundred twenty: four point nine times ten to the twenty-one. Its square root is seven times ten to the ten: seventy billion parameters. Tokens are twenty times that: one point four trillion. Six times both gives the budget back. Spend the same budget on two hundred eighty billion parameters, and only three hundred fifty billion tokens remain. That's one and a quarter tokens per parameter. Badly undertrained, with a clearly higher loss.

Remember

At fixed compute, loss is lowest when the parameter term and the data term are balanced. In practice, grow parameters and tokens together, at about twenty tokens per parameter. For ten to the twenty-four FLOPs, that's about ninety-one billion parameters on one point eight trillion tokens. One caveat: this minimizes training compute only. It ignores the cost of running the model afterwards.

Bigger model, or more data?

You have a fixed budget of $C$ FLOPs. Training costs $C \approx 6ND$, so every parameter you add leaves fewer tokens you can afford. A huge model that sees little text stays undertrained. A small model fed endless text runs out of capacity. Where between these two extremes is the lowest loss? And how big should the model be for, say, $10^{24}$ FLOPs?

Shift budget until the gains cancel

Keep $C$ fixed but make the model 1% bigger. Because $C=6ND$, $N$ goes up 1% and $D$ must drop about 1%. The move pays off if the loss saved by the bigger model beats the loss added by having less data. Keep shifting until the two effects cancel. Both loss terms are power laws, so this balance point moves predictably as $C$ grows. The best split therefore follows a simple rule.

The optimum from the fitted scaling law

Take the fitted law $\mathcal{L}(N,D)=E+\frac{A}{N^\alpha}+\frac{B}{D^\beta}$. Here $E$, $A$, $B$, $\alpha$, $\beta$ are fitted constants, so $A$ and $B$ are not the attention pattern or the batch size. $E$ is the irreducible floor. Substitute $D=C/(6N)$ and set $d\mathcal{L}/dN=0$. This gives the balance condition $$\alpha\frac{A}{N^\alpha}=\beta\frac{B}{D^\beta}.$$ A 1% increase in $N$ lowers the loss by about $0.01\cdot\alpha A/N^\alpha$, and a 1% increase in $D$ lowers it by about $0.01\cdot\beta B/D^\beta$. At the optimum these two drops are equal. Solving: $$N_{opt}\propto C^{\frac{\beta}{\alpha+\beta}},\qquad D_{opt}\propto C^{\frac{\alpha}{\alpha+\beta}}$$

The ~20 tokens per parameter rule

The Chinchilla fits found $\alpha\approx\beta$, so both exponents are about $0.5$. That means $N$ and $D$ grow by the same factor, and $D/N$ stays constant. The measured constant is about 20 tokens per parameter. Plug $D=20N$ into $C=6ND$: $$C=120N^2\;\Rightarrow\;N_{opt}=\sqrt{C/120},\quad D_{opt}=20N_{opt}$$ Consequence: 4× the compute buys 2× the parameters and 2× the tokens.

Sizing a model for 5.88×10²³ FLOPs

1. $N^2 = 5.88\times10^{23}/120 = 4.9\times10^{21}$, so $N = 7\times10^{10}$ (70B). 2. $D = 20N = 1.4\times10^{12}$ (1.4T tokens). 3. Check: $6\cdot7\times10^{10}\cdot1.4\times10^{12}=5.88\times10^{23}$ ✓ Now spend the same budget on 280B parameters instead: $D = 5.88\times10^{23}/(6\cdot2.8\times10^{11}) = 3.5\times10^{11}$. That is only 1.25 tokens per parameter. The model is badly undertrained and reaches a clearly higher loss than the 70B one.

Remember

At fixed compute, loss is lowest when the parameter term and the data term are balanced. In practice $N$ and $D$ grow by the same factor as $C$ grows, at about 20 tokens per parameter, so $N\approx\sqrt{C/120}$ and $D\approx20N$. For $10^{24}$ FLOPs that gives $N\approx\sqrt{8.3\times10^{21}}\approx9.1\times10^{10}$ (about 91B) and $D\approx1.8$T tokens. This minimizes training compute only. It ignores the later cost of running the model.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.