TL;DR
The linear scaling rule is a recipe for training with a bigger batch of examples. If the batch becomes times larger, multiply the learning rate by as well. A single step on the big batch then moves the parameters about as far as steps on the small batches would have, so the run needs about as many steps. It works up to a limit, and it is usually paired with a warm-up period at the start of training.
Builds on: Stochastic Gradient Descent · Leads to: Learning Rate Warmup, Critical Batch Size, and the large-batch training recipes in Goyal and colleagues' ImageNet paper
Where it's used
Image classification at scale. In 2017 Goyal and colleagues trained ResNet-50 on ImageNet in about one hour. They used a batch of 8,192 images spread over 256 GPUs. Their baseline batch was 256 with learning rate 0.1, so the batch was 32 times larger, and they set the learning rate to 0.1 times 32, which is 3.2. The rule let the same number of epochs finish in far fewer wall-clock steps.
Data-parallel training. When a model is trained on many machines, each machine computes gradients on its own slice of the batch, and the gradients are averaged across machines (Data Parallelism). Adding machines enlarges the effective batch. The rule tells the engineer how to change the learning rate when the number of machines changes, so the training curve stays similar.
Hyperparameter planning. A team tuned a learning rate on a small cluster and now wants to train on a cluster eight times larger. The rule gives a first guess for the new rate, which saves a sweep of many expensive runs. The guess is a starting point, not a final answer.
How it works
Think of the learning rate in gradient descent as the length of each stride. A small batch gives a noisy direction, so the strides are short. A bigger batch gives a steadier direction, so each stride can be longer. The rule says: if the batch is times bigger and the direction is steady over those small batches, a stride times longer covers the same ground.
Let us trace one tiny case. A single parameter starts at 0. Suppose the gradient is about for every batch in the next few steps, so each step is roughly the same. The learning rate at the small batch size is .
- Take the small-batch path. Each small-batch step moves by . Check: each step is in the same direction, so moves per step.
- Take small steps. After four steps, . Check: the total move is , which is four times the single-step move.
- Make the batch 4 times bigger. The batch now holds four times as many examples, so the gradient estimate is steadier. The rule sets the new learning rate to . Check: the rate grew by the same factor as the batch.
- Take one big step. The big step moves by . Check: the big step lands at , the same place as the four small steps.
- Read the result. One big step covers the ground of four small steps. The number of parameter updates falls by a factor of four, and the work per update grows by about the same factor, so the number of examples processed stays the same.
flowchart LR A["batch 256, rate 0.1"] -->|"4 steps"| B["w moves 0.8"] C["batch 1024, rate 0.4"] -->|"1 step"| D["w moves 0.8"]
The math
Let the batch size be and the learning rate be . If the batch is changed to for some factor , the linear scaling rule sets the new learning rate to
The rule is derived from SGD and is intended for it. It is a rule of thumb, not a theorem.
Step 1 in symbols: the small-batch path
Write the SGD update on a batch of size as , where is the average gradient over that batch and is the vector of parameters. Over small steps starting at ,
The sum symbol means "add up the terms for from 0 to ". Each term is one batch's average gradient.
Step 2 in symbols: the big step
One big step on a batch of size with rate gives
where is the average gradient over the big batch. The big batch contains the small batches, so is the average of the small-batch averages, , when the examples are split evenly.
Step 3 in symbols: matching the two paths
Assume the gradient changes little over the steps, so for every . Then the small-batch path gives
Setting the big-step move equal to the small-batch move, , gives . This is the linear scaling rule. The derivation shows exactly where it can fail: it needs the gradient to stay roughly constant over the steps.
Step 4 in symbols: the count of updates
The number of updates needed to process a fixed number of examples is at batch size and at batch size . The second is times the first, which is the saving in wall-clock steps.
Worked examples
Start with batch 256 and learning rate 0.1. Double the batch to 512, so .
- The new learning rate is .
- Check the move: at the small batch, two steps with gradient move the parameter by .
- At the big batch, one step with gradient moves it by .
- Interpretation: the two paths match. The run has half as many updates, and each update uses twice the examples.
The baseline batch is 256 with learning rate 0.1. The target batch is 8,192, so .
- The scaled learning rate is .
- Check the size: a rate of 3.2 is 32 times the baseline, the same factor as the batch.
- Count steps per epoch. ImageNet has about 1.28 million training images, and steps per epoch.
- Compare with the baseline: at batch 256 an epoch is about steps. The big batch cuts the number of steps per epoch by the factor 32.
- Interpretation: the big batch needs far fewer steps, and the scaled rate keeps each step's size in proportion to the batch. Applied directly, rate 3.2 at the start of training is unstable, which is why the paper adds a warm-up (see below).
Try it: a team trains with batch 1,024 and learning rate 0.4. They move to batch 4,096. What is the new learning rate by the rule? Answer: , so .
A team trains a model on 8 machines. Each machine processes 32 examples per step, so the global batch is , and the tuned learning rate is 0.1. The numbers below are invented for illustration.
- The team adds machines until there are 64 of them, each still processing 32 examples per step. The global batch is .
- Find : .
- Scale the rate: .
- Warm up before using the full rate. Start at 0.1 and raise the rate linearly to 0.8 over the first few epochs. Without the warm-up, the first large steps can push the parameters into a region where training is unstable.
- Interpretation: the global batch grew 8 times, so the team expects about 8 times fewer steps per epoch. The rule gives a first guess for the rate, and the team should check the training curve before trusting it.
Try it: the same team adds machines until there are 128 of them, each still on 32 examples. What is the global batch, and what learning rate does the rule give before warm-up? Answer: the global batch is , so , and .
Common mistakes and tradeoffs
It is tempting to think that the learning rate should stay fixed when the batch changes, since the update rule looks the same. In fact a larger batch gives a less noisy gradient, so each step can and should be longer. Keeping the rate fixed wastes the bigger batch, because the run takes many more steps to cover the same ground.
It is tempting to think that the rule works at any batch size. In fact it holds only up to a point. Beyond the Critical Batch Size, a larger batch stops cutting the number of steps by much, and the linear rate can overshoot. Past that point, more examples per step are mostly wasted.
It is tempting to think that the rule can be applied on the first step. In fact large rates at the start of training cause instability, because the parameters are still far from a good region and the gradients change quickly. A warm-up, a period where the rate rises from its small starting value, is the standard fix (Learning Rate Warmup). Clipping the size of each gradient (gradient clipping) is another safeguard against the first large steps.
It is tempting to apply the rule to every optimiser. In fact the rule was derived and tested for SGD and momentum-based SGD. Adaptive optimisers, such as Adam, normalise the step by running statistics, so the link between batch size and the right rate is less direct.
When to use it. Use the rule as a first guess when you change the batch size of SGD-style training, especially when adding machines. Pair it with a warm-up and check the training curve.
When not to use it. Do not use it for batches far beyond the critical batch size, for very short runs where warm-up takes most of the budget, or as a substitute for tuning when the result matters a lot.
Alternatives. Square-root scaling, which multiplies the rate by , is a more conservative choice that some teams use with adaptive optimisers. Tuning the rate directly at the new batch size is the most reliable choice when compute allows it.
History
Before 2017, training deep networks on large datasets was slow, and making the batch larger was not an obvious way to speed it up. Engineers who wanted to use more machines needed a way to keep the training curve the same as the batch grew, and the learning rate was the obvious knob to change.
In 2017 Priya Goyal and colleagues at Facebook AI Research trained ResNet-50 on ImageNet with a batch of 8,192 images across 256 GPUs, and reported the result in about one hour. They stated the linear scaling rule as a recipe and paired it with a gradual warm-up, which made the large-batch run stable. Their paper made the rule widely used.
The rule caught on because it is simple and matches the first-order behaviour of SGD. Practitioners still treat it as a starting point, and research since then has mapped the limits, including the critical batch size, where the rule stops paying off.
Recap
- Stochastic gradient descent uses the average gradient over a batch, and a bigger batch gives a steadier gradient.
- If the batch grows times, the linear scaling rule multiplies the learning rate by , so one big step covers the ground of small ones.
- The derivation assumes the gradient changes little over those steps, which is why the rule needs care.
- A warm-up is usually needed so that the large rate does not destabilise the start of training.
- Read next: Learning Rate Warmup for the warm-up, Critical Batch Size for the limit of the rule, and the Goyal and colleagues paper, which applies the rule at ImageNet scale.