Batch size

Batch size is the number of training examples a model processes before each update to its weights, a setting that affects training speed, stability, memory use and results.

Batch size is one of the main settings, or hyperparameters, chosen before training starts. Google's machine learning glossary gives the plain definition: the number of examples in a batch, so a batch size of 100 means the model processes 100 examples per training step. At one extreme, a batch size of one is classic stochastic gradient descent; at the other, the whole training set forms a single batch. Most training sits in between.

The choice is a trade-off. Larger batches give a steadier estimate of which way to move the weights and make fuller use of parallel chips. But they need more memory, and past a point each extra example adds little. A 2018 study led by Sam McCandlish found that a measurable quantity called the gradient noise scale predicts the largest useful batch size, and that this limit varies widely by task, from tens of thousands of examples for ImageNet image classification to millions for agents playing the game Dota 2.

Batch size also interacts with other settings. In a 2017 paper, a research team trained the ResNet-50 image model with batches of 8,192 images across 256 graphics chips in one hour while matching the accuracy of small-batch training, by scaling the learning rate in proportion to the batch size and warming it up gradually. A 2016 paper had documented the risk: very large batches tended to settle on solutions that generalised worse to new data.

For language models, batch size is usually counted in tokens rather than documents. DeepMind's Chinchilla, for example, was trained with batches that started at 1.5 million tokens and rose to 3 million. Big batches are part of what makes it possible to spread one training run across thousands of chips, which is why the setting comes up in stories about very large training clusters.

Common questions

What is batch size in machine learning?

Batch size is the number of training examples the model processes before updating its weights. With a batch size of 32, the model looks at 32 examples, averages what it learned from them and makes one adjustment.

Is a bigger batch size better?

Not automatically. Bigger batches use parallel hardware efficiently and give steadier updates, but they need more memory and, beyond a certain size, each extra example adds little. Very large batches can also hurt how well the model generalises unless the learning rate and other settings are adjusted.

How does batch size relate to learning rate?

They are linked. A widely used rule from 2017 research is to scale the learning rate up in proportion when the batch size grows, with a gradual warm-up at the start of training. Changing one without the other can make training unstable or slow.

Why is batch size measured in tokens for language models?

Language model training data is a stream of tokens cut into sequences, so the natural unit is the total number of tokens per update. Reported figures such as 3 million tokens per batch reflect that.

Finding more

Search for "batch size learning rate scaling", "large batch training" or "gradient noise scale" for the research on choosing batch sizes. Papers on arXiv, the machine learning courses of major providers and the tuning guides published with training frameworks are reliable. Advice tuned for one model type does not always carry over to another, so check what kind of model a recommendation was tested on.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.