Mini-Batch
Splitting data into chunks and processing one chunk per step
- A mini-batch splits the training data into reasonably sized chunks, correcting the values one step for every chunk.
- Look at one example at a time and the judgment jitters wildly; look at everything at once and a single step takes forever. This lands in between.
- The results inside a chunk get averaged into one direction, so a single odd example can't drag the whole step off course.
- Chunk size tops out at whatever fits in graphics memory. Push the size up and the memory need climbs right along with it.
- Change the chunk size and the right learning rate changes too. The two aren't really separable.
Contents
1The analogy
It's canning season and you've got a hundred pounds of tomatoes to turn into sauce for the winter. No pot in the house is big enough to cook all hundred pounds at once. But cooking one tomato at a time would burn the whole day. So you load ten pounds into the big pot, cook that batch down, empty it out, and load the next ten.
At the end of every potful, you taste it. Run a little too salty this time, and you ease off the salt for the next pot. One oddly sour tomato in a batch of ten doesn't throw off your judgment much — the other nine keep it steady.
That potful is the mini-batch. Empty the pot ten times and you've worked through all hundred pounds — one full lap — and you've adjusted the seasoning ten times along the way, once per pot.
2In detail
Not one at a time, not all at once either
Correct the values after every single example and steps come fast, but the direction swings wildly each time — one odd example can single-handedly decide where things go. It's inefficient too: processing one at a time barely uses the hardware built to crunch many calculations in parallel.
Go the other way and look at all the data before correcting even once, and the direction is very accurate. But with millions of examples, a single step takes forever, and there's no way to even fit all that data in memory at once.
Chunking gets you both. Averaging within a chunk keeps the direction from swinging wildly, and finishing a chunk means finishing a step, so progress stays quick. Nearly every model trained today runs this way.
What sets the chunk size
The first limit is memory. Computing a chunk all at once means holding both the data and every intermediate result in memory simultaneously. Double the chunk size and the memory needed roughly doubles too. Run out of memory partway through training, and shrinking the chunk size is usually the first fix reached for.
The second factor is wobble. A smaller chunk means the direction shifts a little differently every time, and that wobble isn't necessarily bad — it helps shake the model loose from a mediocre spot, and it sometimes even improves the score on new data. A very large chunk smooths the steps out, but each individual step ends up wasted on less new information.
It moves together with the learning rate
Make the chunk bigger and a single step's direction becomes that much more trustworthy. So it's common to bump up the stride to match. Enlarge the chunk but leave the learning rate untouched, and the fewer steps per lap slow training down.
Training a big model across several devices splits it up the same way — each device handles one chunk and the results get combined. The effective chunk size grows with the number of devices in that setup, so without adjusting the learning rate and the warm-up period to match, training tends to break down early.
Leftover data and shuffling
When the amount of data doesn't divide evenly by the chunk size, the last chunk of the lap comes up short. Sometimes that leftover chunk gets used as-is; sometimes it gets dropped to keep every chunk the same size for the computation. Since the data gets reshuffled and rechunked at the start of every lap, whatever got left out this time lands inside a chunk the next time around.
It also matters that a chunk doesn't end up filled with just one category. A pot that's entirely one kind of tomato skews that whole step in one direction. Shuffling the data well ahead of time handles most of this on its own.
Text of different lengths or images of different sizes need extra handling to line everything in a chunk up to the same size — padding a short sentence with blanks, or cropping images to match. Only once that's done can a chunk actually get computed all together.
3More precisely
Mini-batch training performs one update using the gradient averaged across the examples in a chunk. It sits between updating after every single example and updating once after the entire dataset, and what's commonly called stochastic gradient descent today mostly refers to this chunked version. Chunk sizes are conventionally set as powers of two, a habit that traces back to the hardware's structure. When memory is too tight for a big chunk but the effect of a big chunk is still needed, results from several small chunks can be accumulated and applied as one combined update.
The comparison breaks down in places too. Ladling tomatoes into a pot really does physically divide them up, but a mini-batch isn't a copy split off from the data — it's closer to reading through the data in a set order. And a finished pot of sauce doesn't affect the next pot, while in training, whatever got corrected in one chunk feeds directly into the calculation for the next chunk. The order chunks arrive in actually shapes the outcome, which is where this differs from canning.
4Try it yourself
5Common misconceptions
It's easy to think a bigger chunk always trains better, but actually it eats more memory in exchange for fewer steps, and the score on new data can end up worse.
It's easy to think the examples in a chunk get computed one after another, but actually they get computed all at once and averaged — that's the whole point of the speed.
It's easy to think any chunk size will do, but actually it's tied to both the memory limit and the learning rate, so changing just one throws training off balance.
7One-line summary
In shortA mini-batch is data split into pot-sized chunks, one step corrected per chunk, and that size decides both how fast and how wobbly training runs.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02