Tokenwerk · The LLM textbook

Chapter 27 · VI · Thinking bigger · 5 minutes

Scaling up without calculating blindly

Bigger is better? Only if model, data and computing time fit together. Here you calculate what a bigger model costs before you start it.

Three ingredients that have to fit

A bigger model can store more patterns, but only if it gets enough data to learn from. And more data only helps if there is enough computing time to actually work through it. Model size, amount of data and compute budget are like flour, water and baking time: too much of one and too little of another doesn't make a good cake.

And careful: more training steps on the same small text don't mean more knowledge. The model just reads the same pages more often.

How much computing work is that?

Computing work is measured in FLOPs, the number of individual operations on decimal numbers (additions, multiplications). There is a handy rule of thumb for training a transformer:

Computing work ≈ 6 × number of parameters × number of training tokens.

The 6 comes roughly from about 2 operations forward and 4 backward per parameter and token (Kaplan et al., 2020). An example: 15 million parameters and 300 million tokens give 6 × 15 million × 300 million = 27 quadrillion operations. Sounds like a lot? A modern graphics card manages trillions of them per second.

This is an approximation, not a law; attention on long texts, for instance, isn't exactly included. For a first plan it is enough.

The rule of thumb as a formula

With N parameters and D processed training tokens (D exceptionally does not mean the embedding width here!): computing work ≈ 6ND6ND FLOPs. For our example: 6⋅15 000 000⋅300 000 000=2.7⋅10166\cdot15\,000\,000\cdot300\,000\,000=2.7\cdot10^{16} FLOPs, i.e. 27 PFLOP. PFLOP is an amount of operations; PFLOP/s would be a speed.

From computing work to time

To turn computing work into time, divide by the speed of your computer. But please by the actually measured speed, not by the number on the box. Manufacturer specs hold under ideal conditions that real training rarely reaches.

Even simpler for your project: measure directly how many tokens per second your training manages. If it is 2,000, then 10 million tokens take about 5,000 seconds, a little under an hour and a half, plus breaks for checks and saving.

How much data per parameter?

A famous study called Chinchilla investigated: if you have a fixed compute budget, how do you best split it between model size and amount of data? The result: grow both together. That is where the often-quoted rule of thumb of about 20 training tokens per parameter comes from.

But: this rule only optimizes the training cost. If a model is then used millions of times, it often pays off to train a smaller model much longer, because a small model is cheaper every time it is used. That is why small models today are trained far beyond 20 tokens per parameter: Llama 3 8B saw over 15 trillion tokens, almost 2000 per parameter. Training Compute-Optimal Large Language Models.

Memory is a bottleneck of its own

A model can fit into memory and still be far too slow. Or it would be fast enough but doesn't fit with the desired batch size and text length. The parameter count alone tells you neither.

So: only ever enlarge one thing: width, depth or context length. Then measure speed, memory and validation loss. That way you find out where things really get stuck.

Several graphics cards: an overview

When one computer isn't enough, the work is distributed:

  • Data parallelism: every card has a copy of the model and computes different examples. The gradients are synchronized.
  • Tensor parallelism: individual large calculations are split across several cards.
  • Pipeline parallelism: different layers sit on different cards, like on an assembly line.
  • Sharding: optimizer states and weights are distributed so each card needs less memory.

All of this brings coordination effort and new sources of error. A model with millions of parameters on one computer is therefore the right first step. Distribution solves a measured problem; it isn't an end in itself.

Data preparation has to grow too

Our teaching tokenizer is easy to understand but far too slow for large amounts of data. When scaling up, you keep the format and the tests and only swap the trainer for a fast implementation. Pre-tokenized files and parallel data readers help in the same way. Important: don't secretly change the tokenizer or the evaluation method along the way; otherwise you are comparing apples and oranges.

Calculate first, test small, then go big

Estimate in advance: amount of data, parameter count, memory and time, the last from a short measurement run. Then a small pilot run. If the loss doesn't respond sensibly, you do not start the run that is ten times longer. The most expensive experiment is a long training run with a bug you could have seen in the first batch.

Three sensible milestones

  1. A tiny model can memorize a small batch: the system works.
  2. A small model beats the bigram baseline on new texts: it learns real patterns.
  3. A larger corpus plus SFT delivers readable, partly reliable answers to new questions.

Each step builds ability and evidence together.

Key points

  • Model size, amount of data and computing time must fit together. Rule of thumb for computing work: 6 × parameters × tokens.
  • Chinchilla: about 20 tokens per parameter is training-optimal. For frequently used models, small models are trained much longer.
  • Estimate first, then test briefly, then start big. Only ever enlarge one thing at a time.