Learn the MachineDansk

Explained with an interactive demo

What are scaling laws?

Scaling laws describe how a language model’s loss falls as you give it more parameters, more data and more compute. They are used to decide how large a model to train, and on how many tokens, before spending millions on it. Split a compute budget yourself and see why Chinchilla, with 70 billion parameters, beat Gopher with 280.

The demo needs JavaScript. The text below explains what it shows.

Embed this demo on your site

Copy the code into your page. The demo loads from learnthemachine.com, so it stays up to date, and the link under it shows where it comes from.

What a scaling law says

Kaplan et al. (2020) at OpenAI showed that language models’ test loss falls smoothly as a power law when you increase the number of parameters, the amount of data or the compute, with trends spanning more than seven orders of magnitude. A power law L ∝ N−α becomes a straight line when both axes are logarithmic. That makes it possible to train many small models, draw the line and predict how a much larger model will do before spending the money on it.

The formula behind the demo

Hoffmann et al. (2022) trained over 400 models from 70 million to over 16 billion parameters on 5 to 500 billion tokens and fitted the formula L(N, D) = E + A/Nα + B/Dβ. E is the loss no model can get below on that data, corresponding to the text’s own unpredictability. The other two terms are what too small a model and too little data cost. Training costs about 6 · N · D operations: two per parameter and token in the forward pass and four in backpropagation.

Chinchilla: a smaller model, more tokens

With a fixed budget there is a trade-off: a larger model means fewer tokens. The curve in the demo is U-shaped, and the bottom is the best split. Hoffmann et al. concluded that parameters and tokens should be scaled equally: twice the model, twice the tokens. They trained Chinchilla, with 70 billion parameters, on 1.4 trillion tokens with the same budget as Gopher, which has 280 billion parameters and was trained on 300 billion tokens, and Chinchilla did better on a wide range of tasks. That is 20 tokens per parameter. GPT-3 got 1.7 tokens per parameter and was, by that measure, heavily undertrained.

Even the formula is uncertain

Besiroglu et al. (2024) re-estimated the formula from the same experiments and found that the published constants fitted the data poorly and would recommend far more tokens per parameter than the 20 Chinchilla was actually trained with. Their own fit gives about 20. Switch between the two in the demo: at Chinchilla’s budget the original fit gives 40 billion parameters and 59 tokens per parameter, the re-estimate 72 billion and 18 tokens per parameter, close to Chinchilla itself. A scaling law is a fitted curve, not a law of nature, and the constants are uncertain.

Why train “too long”?

Chinchilla-optimal means cheapest to train to a given loss. But a model also has to be run, and a smaller model is cheaper for every answer. Meta trained Llama 3 8B on over 15 trillion tokens, almost 1,900 tokens per parameter, and wrote that the model kept improving far beyond the roughly 200 billion tokens that would be Chinchilla-optimal for 8 billion parameters. When a model will be used by many people, it can pay to spend more compute on training to get a small model that is cheap to run. See What is quantization? for what model size means for memory and speed.

Limits

The formula describes test loss on the data it was fitted to, not abilities on particular tasks. Some abilities seem to appear suddenly even while the loss falls smoothly, and how much of that comes from the way they are measured is debated. The numbers in the demo apply to Chinchilla’s training data and setup and do not transfer directly to other models: data quality, architecture and repeated data change the constants. The table therefore shows only tokens per parameter, not an expected loss for the other models.

Train your own language model

In the Train a text model lab you go from next-token prediction to a small transformer language model that you train and investigate yourself. It is the same loss per token that scaling laws describe, at a much smaller scale. The lab requires full access.

See the Train a text model labOr watch a model learn with gradient descent, free

More explainers