Sixteen GPUs can share work without talking after every step. Train in big batches first, then let each GPU walk alone: 93% test accuracy with about half the syncs.
Learn why more GPUs often means worse learning, and how one change to the schedule, called post-local SGD, fixes it while it cuts the talking.
Press the five recipes in turn, from A1 to A5. Watch the purple ticks, which are the moments the GPUs stop and talk, and the bar for test accuracy. Then we build every piece from zero: the averaging, the local steps, the noise, the schedule and the tables.
You need a rough idea of a neural network that learns by small steps. We explain gradients, batches, workers and syncs from zero, and the lesson Local SGD and Model Averaging teaches the background.
Paper: Tao Lin, Sebastian U. Stich, Kumar Kshitij Patel and Martin Jaggi (EPFL, and IIT Kanpur), ICLR 2020. arXiv 1808.07217. Re-taught here in our own words and devices; every result comes from the paper.
Read as one of the linked papers of Rohan Anil’s post The Hitchhiker’s Guide to Training on Compute Islands (Core Automation, 2 November 2026).
Accuracies are the paper’s Figure 1 table for ResNet-20 on CIFAR-10 with 16 GPUs: test top-1 93%, 92%, 89%, 92%, 93%. The bar axis starts at 85% so the gaps show. The ticks are our drawing of how often each recipe syncs, read from that table (1, 1, 4, 4, then 1 and 16 batches between syncs); A5 switches at epoch 150, the first learning rate drop.
Chapter 0
See why sixteen GPUs that talk after every step wait a lot, and why a bigger batch can still learn worse
You have sixteen GPUs and one model to train. Each GPU is a very fast calculator. You hope the job now takes a sixteenth of the time. It does not. Most of the clock goes to something else: the GPUs stop and talk.
To see why, we need a few plain words. Training means repeating one small act. Show the model a few examples. Measure how wrong it is. Nudge its numbers so it is a little less wrong. The numbers it holds are its weights, written w. The measure of wrongness is the loss.
The nudge comes from the gradient: for every weight, it says which way to move to lower the loss. The learning rate, written γ, says how far to move. A mini-batch is the small handful of examples (B of them) that one gradient is measured on. Stochastic gradient descent (SGD) is the loop: draw a random mini-batch, compute its gradient, move the weights a little against it.
Now add more machines. A worker is one GPU, and the paper calls the number of workers K. In the standard recipe, each worker holds a full copy of the model. Each worker measures a gradient on its own mini-batch. Then all K workers must agree on one average gradient before anyone moves.
That agreement is a synchronization, or sync: every worker stops, and they swap numbers over the network. The usual operation is an all-reduce, which leaves every worker holding the same average. The lesson Data Parallel and All-Reduce builds it from zero. The speed of the wire is the bandwidth, counted in bits per second; Bandwidth Arithmetic explains the units.
Inside one machine the wire is fast. The paper draws a data center in its Figure 17: about 200 Gb/s per GPU inside a node (NVLink), about 40 Gb/s from a node to its rack switch, and slower links beyond. Its own experiments ran on a 10 Gbps network. Across sites, the wire is slower again. That is why a sync is the expensive moment.
Look at a GPU's day. It computes for a while, then waits for the sync, then computes again. If the sync costs as much as three steps of compute, a GPU that syncs after every step spends three quarters of its time waiting. Drag the cost and compare three habits: sync every step, every 4 steps, every 16 steps.
Each row is one GPU over the same 40 time units. Warm blocks are compute steps. Purple blocks are syncs. Drag the cost of a sync and watch the warm share change.
Toy numbers: the sync cost is yours to set, counted in steps of compute. The share computing is H divided by (H plus the cost), which is exact for this picture. The paper’s own measured speedups on a 10 Gbps cluster come in Chapter 6.
The fix looks easy: sync less often. But the paper adds a second problem that stops the easy fix.
Suppose you use the sixteen GPUs to make each step bigger. Each worker keeps its mini-batch of 128. The combined batch is now 16 × 128 = 2,048. Big steps mean fewer steps and fewer syncs per pass over the data. Throughput goes up.
The model that comes out is often worse on new data. The paper calls this the generalization gap: the model fits the training examples as well as before, yet scores lower on test data, the held-out examples it never saw. In the paper's Figure 1, big-batch SGD scores 92% on test images where one GPU scores 93%. A one point gap sounds small. At the batch sizes that really save time, it grows: 76.3% at a batch of 16,384 (Chapter 3).
Lin, Stich, Patel and Jaggi say: do not make the batch huge. Let each worker take several small steps on its own before any sync. This is local SGD. Better, switch it on only in the second half of training. This is post-local SGD. They report that it keeps the one-GPU accuracy, and syncs far less than the big-batch baseline.
The idea sits in the Core Automation post as one row of its history table: “2018 Local SGD (Stich); Lin et al.: Convergence analysis and the empirical case for infrequent averaging”. The post builds on that row to train across clusters that sit far apart. This lesson reads the Lin et al. paper in full. The lesson Local SGD and Model Averaging teaches the background, and the post shows where it ends up.
The paper names two situations. In Scenario 1, the network is the bottleneck: a sync takes much longer than a gradient. In Scenario 2, the batch is so large that accuracy suffers. Local SGD helps with the first. Post-local SGD is the answer to the second.
Chapter 1
Follow one synchronous step on four workers, with real numbers
Four friends each hold a few numbers. They want to find the average of all the numbers together, but they may only take small steps and compare notes. This is standard distributed training in miniature. Before we change it, we need to see exactly how it works.
The paper starts from a sum. The training set has N examples. Example i has a loss fi(w), the error of weights w on that one example. The goal is to find the w with the lowest average loss across all N examples. Mini-batch SGD with K workers does this one synchronous step at a time.
Read it from the inside out. Each worker averages the gradients of its B examples. The workers average those K results. The weights move against that final average by γ. The paper uses the same B on every worker, so one step uses K × B examples in all.
Make the model as small as it can be: one weight w. Let each example be a number x. Its loss is half the squared distance, ½(w − x)2, so its gradient is w − x. Now split eight numbers across four workers, two each. Worker 1 holds 2 and 4. Worker 2 holds 6 and 8. Worker 3 holds 1 and 3. Worker 4 holds 5 and 9. Start at w = 0 with γ = 0.5.
Each worker averages its two gradients. The average of (w − x) over a worker’s numbers is w minus the average of those numbers. At w = 0 the four local gradients are −3, −7, −2 and −7. The all-reduce averages them: (−3 − 7 − 2 − 7) / 4 = −4.75. The update is w = 0 − 0.5 × (−4.75) = 2.375.
Check it another way. A single machine with all eight numbers has the average 38 / 8 = 4.75, and its gradient at w = 0 is −4.75 too. So four workers with a batch of 2 each take exactly the step of one machine with a batch of 8. This is the key fact for what follows: synchronous mini-batch SGD with K workers is just SGD with a batch K times larger. Step through it yourself.
The line is the value of the weight w. Each warm arrow is what one worker wants (minus its gradient). The purple arrow is their average, the step the group takes. Press Step, then try a different learning rate.
Toy numbers made up for this lesson (workers hold {2,4}, {6,8}, {1,3}, {5,9}); the update rule is the paper’s equation (1). The target 4.75 is the average of all eight numbers.
With γ = 0.5 the gap to 4.75 halves every step: 4.75, then 2.375, then 1.19. With γ = 1 the weight lands on 4.75 in one step, because the toy loss is a perfect bowl. Real losses are not bowls, so a rate that big would overshoot. The learning rate is a trust slider: how much to believe one averaged gradient.
On a real model, w is a long list. ResNet-20, the paper’s base model, has about 0.27 million weights (He et al., 2016), so each gradient is a list of 0.27 million numbers, about 1 MB in 32-bit floats. At each step, every worker sends and receives a gradient list of that size, once. The input shapes are (B, 3, 32, 32) images for CIFAR-10. The output of the all-reduce is a (d) vector, the same on all K workers. An epoch is one full pass over the training set. With 300 epochs on 50,000 images, one GPU at B = 128 takes about 117,000 steps; sixteen GPUs at a combined batch of 2,048 take about 7,300. Fewer steps means fewer syncs, but each step is bigger.
A bigger combined batch has a less noisy gradient, so you may take a bigger step. The paper follows Goyal et al. (2017): scale the learning rate linearly with the global batch size, so 16 times the batch gets 16 times the rate. ResNet-20’s single-GPU rate of 0.2 becomes 3.2 at a batch of 2,048. Then warm up: ramp the rate from 0.2 to 3.2 over the first 5 epochs, about 122 steps, adding roughly 0.025 each step. A huge rate on the first step would throw the weights far from where a good run starts.
The paper also computes batch normalization statistics (the running averages of layer outputs that keep activations in range) separately on each worker, as in Goyal et al. That means no extra sync for them.
The symptom is a speedup far below K. The paper measures it on 16 GPUs (8 machines with 2 GPUs each, 10 Gbps network), in its Table 9, for the plain recipe H = 1. ResNet-20 on CIFAR-10 speeds up by 9.45 times, which is 59% of the ideal 16. DenseNet-40-12 gets 8.31 times (52%), and WideResNet-28-12 only 5.33 times (33%). The bigger the model, the longer each sync, so the worse the efficiency. The fix is to talk less, and that is the next chapter.
Chapter 2
Let each worker take H steps by itself, then merge the models
The four friends are tired of comparing notes after every step. So they agree on a new rule. Each walks alone for a few steps, using only the numbers in their own hands. Then they meet, average where they ended up, and all start again from that average. This is local SGD.
Local SGD (also called local-update SGD, parallel SGD, or federated averaging) lets every worker run H ordinary SGD steps on its own copy of the model. H is the number of local steps. After H steps, the workers average their models, not their gradients. Every worker restarts from the shared average. Between two syncs there is no talking at all.
The paper writes it as two lines. The first line is one local step. The second line is the merge.
Two special cases anchor it. If H = 1 and Bloc = B, local SGD is exactly mini-batch SGD from the last chapter. And if the mini-batch run uses B = H × Bloc, both methods compute the same number of gradients between syncs and talk equally often. That is the fair comparison the paper uses all through. The updates still differ for any H larger than 1, so the test accuracy is expected to differ.
Take the toy from Chapter 1: four workers, targets 3, 7, 2 and 7 (the average of each worker’s two numbers), γ = 0.5, start at w = 0. Use H = 2. Worker 1 steps to 0 − 0.5 × (0 − 3) = 1.5, then to 1.5 − 0.5 × (1.5 − 3) = 2.25. In general a worker ends at 0.75 times its own target: 2.25, 5.25, 1.5 and 5.25. The merge averages them: (2.25 + 5.25 + 1.5 + 5.25) / 4 = 3.5625.
Now run two synchronous steps instead. Chapter 1 gave 2.375 after the first. The second step gives 2.375 − 0.5 × (2.375 − 4.75) = 3.5625. The numbers are identical. This is not luck. When the gradient is a straight line in w, as in a perfect bowl with exact gradients, averaging after the steps is the same as averaging during them.
Real training breaks both conditions. The loss surface curves, and each gradient is noisy because it comes from a small random batch. Then the K local models wander along different paths, and their average differs from the synchronous result. Whether that difference hurts or helps is the whole question of this paper. The device lets you watch it on a curved valley with noisy gradients.
Warm paths are the four workers. Purple dots are merged models, where the workers meet. Pick H, then press Play. Compare H = 1 with H = 16: the same 48 steps each, but 48 meetings against 3.
Toy, made up for this lesson: loss ½(u² + 4(v − ½u²)²), four workers, 48 steps each at γ = 0.08, Gaussian gradient noise of 0.8 per worker (seeded). The mean over 20 seeded runs is computed on the page. Nothing here is from the paper’s experiments.
In this toy the ending loss barely moves. Across 20 seeded runs it is about 0.02 for every H from 1 to 16, yet the workers talk 16 times less at H = 16. The toy is gentle, with only 48 steps. It shows the promise: the walk apart costs little when H is small compared with the length of the run.
On a real network each round sends one list of d weights per worker, then waits. With H local steps, the number of rounds falls by a factor of H. The paper’s Algorithm 1 phrases the merge as an average of the differences Δk = w − wk, the distance each worker moved. With an outer step of 1 that equals averaging the models, so we use equation 2. For momentum (a running average of gradients that smooths the path), the paper runs a Nesterov momentum (a version that looks one step ahead) of 0.9 independently inside each local model, with no extra talking.
The symptom is a model that trains worse after a merge than before. The cause is drift: workers that walk long enough along different noisy paths end up far apart, and their average is not a good model. The paper measures it. At 4 workers, local SGD with H = 16 reaches 92.5% test accuracy, against 89.5% for mini-batch SGD at the same effective batch of 8,192 (Table 2). At 16 workers and H = 8, it reaches 92.0% against 76.3% for mini-batch SGD at a batch of 16,384. So local SGD beats a big batch with the same number of gradients between syncs.
But the paper also reports that local SGD with both H and K large (H = 16, K = 16) “can encounter optimization issues during initial training”. The fix is the schedule of Chapter 5: keep H at 1 at the start. As for speed, the paper reports a 2.59 times time-to-accuracy speedup for 91.2% test accuracy at H = 8, and 1.76 times for 92.57% at H = 2.
Chapter 3
Measure how a big batch fits the training set and still loses on new data
Two students study the same textbook for the same number of hours. Both score full marks on the practice questions. On the real exam, one scores 93 and the other 92. Nothing in the practice scores tells you why. This is the puzzle of large-batch training.
The training set is the data the model learns from. The test set is data it never sees while learning. A model generalizes when it does well on the test set, not just the training set. The top-1 accuracy is the share of images where the model’s first guess is right. The paper uses ResNet-20, a small image network, on CIFAR-10, 60,000 tiny pictures in 10 classes (50,000 for training).
Now run the same job five ways. The paper’s Figure 1 does exactly that, with one local batch Bloc = 128, and reports everything in one table.
| Recipe | Training loss | Train acc. | Test acc. | GPUs | Local batches of work per sync |
|---|---|---|---|---|---|
| A1: small batch, 1 GPU | 0.01 | 100% | 93% | 1 | none |
| A2: big batch (K = 16, B = Bloc) | 0.01 | 100% | 92% | 16 | 1 |
| A3: huge batch (K = 16, B = 4Bloc) | 0.10 | 81% | 89% | 16 | 4 |
| A4: local SGD (K = 16, H = 4) | 0.01 | 95% | 92% | 16 | 4 |
| A5: post-local SGD (K = 16, H = 16) | 0.01 | 99% | 93% | 16 | 1, then 16 |
The last column is our reading of the paper’s “communication” column, which prints ~1, ~4, ~4 and ~1 then ~16. It matches the text: A4 and A3 have equal communication, and A5 switches from H = 1 to H = 16.
Read the table in pairs. A1 and A2 have the same training loss and the same 100% training accuracy. The big-batch run did not fail to learn. It simply scores one point lower on new images. That is the generalization gap. A3 is different: with the batch pushed even further it also fits the training data worse (81%), an optimization problem. And A4 beats A3 at the same communication: local SGD with H = 4 scores 92% where one huge batch scores 89%.
The point of the big batch is to use many GPUs. So the batch must grow with the number of workers. The paper's Table 2 shows what happens as it grows. Pick the number of workers and compare how each recipe scores.
Pick 4 or 16 workers. Each bar is a recipe from the paper’s Table 2. Notice how far the plain big batch falls, and which bars stay level.
All numbers are the paper’s Table 2 (ResNet-20, CIFAR-10, mean of three runs, fine-tuned mini-batch baselines). The bar axis starts at 70% so the gaps show. An arrow in a label (512 to 8192) means the batch switched at the first learning rate drop.
With 4 workers, a plain mini-batch run at a combined batch of 512 scores 92.6%. Make the batch 8,192 and it drops to 89.5%. With 16 workers it is worse: 92.5% at a batch of 2,048, but only 76.3% at 16,384. The gap is 16 points. Local SGD at the same big batch (H = 16 for K = 4, H = 8 for K = 16) scores 92.5% and 92.0%. Post-local SGD scores 92.7% and 92.9%.
People tried the obvious fixes. Goyal et al. said the gap comes from optimization, and used the warm-up of Chapter 1. The paper uses it too, and the gap stays. Hoffer et al. closed the gap by training for more iterations as the batch grows, which throws the speed gain away. You et al.'s LARS (a rate scaled per layer) reaches larger batches, but the gap does not vanish. Noise-injection ideas needed costly extra computation. The paper says that, to its knowledge, none of these gave small-batch accuracy on both CIFAR and ImageNet at low cost.
The other obvious fix is to keep the batch small on each GPU. But GPUs are built for big batches. The paper's Table 7 times a ResNet-20 pass on a Tesla V100. Processing 4,096 images in batches of 32 takes 9.03 times longer than one batch of 4,096. At batches of 128 it still takes 2.74 times longer. On the older Titan XP the penalty is mild (1.12 times at 128). So small batches waste the chip, and you cannot buy back accuracy that way.
The symptom: test accuracy falls while the training curve looks perfect. The measurement: 76.3% against 92.5%, with the same 300 epochs and the same data. The reading the paper offers is that the cause is not only optimization (A2 fits the training set perfectly) but something about how the weights are found. The next chapter gives its candidate: the path of the weights is less noisy with a big batch, and noise turns out to matter.
Chapter 4
Trace why local steps add useful noise and why flatter valleys follow
Shake a tray with a marble on it. The marble rolls out of the small dents and settles in the wide dip, where shaking cannot throw it out. A model being trained is that marble. This chapter explains the paper’s idea that the tiny random errors in each gradient are a feature, and that a big batch removes too many of them.
A gradient measured on a mini-batch is only an estimate of the true gradient on all N examples. The paper splits the estimate into the truth plus an error. Call the estimate ĝ, the truth g, and the error ε.
In words: the noise gets smaller as the batch gets bigger, and it points in the directions in which examples disagree. That is useful structure, not plain static.
Treat training as a continuous process. The paper cites work (Jastrzębski et al.) showing that, when B is much smaller than N, the learning rate and batch size enter only through the ratio ρ = γ/B. That explains the linear scaling rule of Chapter 1: raise B by 16 and raise γ by 16, and ρ, the noise level, stays put. The rule worked well for ImageNet batches up to a point.
But the explanation fails for big batches. The exact factor is γ(N − B)/(BN), which is ρ times (1 − B/N). For CIFAR-10 (N = 50,000) at a fixed ρ, the noise level is 99.7% of its small-batch value at B = 128, 95.9% at B = 2,048 and only 67.2% at B = 16,384. The batch is a big fraction of the data, and there is less left to be noisy about. That is a possible reason the gap stays. The paper only says this could be a reason, not that it is proven.
Now the key step. In local SGD each worker takes steps with a local batch Bloc, which is K times smaller than the combined batch. Each local step is as noisy as a step of a single small-batch run. The paper says the noise ε is approximately sampled with covariance KΣ(w) instead of Σ(w). Our numbers: at Bloc = 128 the factor (1/B − 1/N) is 0.00779, against 0.000468 for a combined batch of 2,048. The ratio is 16.6, close to K = 16.
The paper calls this a natural and computation-free way to inject well-structured stochastic noise. Other noise methods add random numbers by hand or build the expensive Fisher matrix. Local SGD uses noise that the data already carries, and saves communication at the same time. See the effect on a marble.
All 60 walkers start in the narrow, deep valley on the left. The noise multiple is how much louder their steps are than a big-batch run. Pick it, press Play, and count who ends in the wide valley on the right.
Toy, made up for this lesson: a one-dimensional loss with a narrow well and a wide well, 3,000 noisy steps per walker (seeded). Noise multiples of 1, 2, 4, 8 and 16 stand for K = 1 to 16. The paper does not run this picture; it measures curvature on real networks, below.
A minimum is a place where the loss stops falling. A sharp minimum is a narrow dent: nudge the weights a little and the loss shoots up. A flat minimum is a wide dip. The belief, from Hochreiter and Schmidhuber and from Keskar et al., is that flat minima generalize better, because the test data is a slightly shifted version of the training data. The idea is debated (Dinh et al. 2017), and the paper says only that its evidence supports it.
The paper measures sharpness two ways on ResNet-20 with 16 GPUs and a combined batch of 2,048. First, it computes the dominant eigenvalue of the Hessian: the Hessian is the matrix of second derivatives (how the loss curves), and its largest eigenvalue is the curvature in the sharpest direction. Mini-batch SGD, and post-local SGD with a small H such as 2 or 4, end with a noticeably larger eigenvalue; post-local SGD with larger H ends lower (Figure 4a). Second, it draws a line between the two final models and measures the loss along it (Figure 4b), and perturbs each model along ten random directions (Figure 13). The test accuracy of the two compared models is 92.25% for mini-batch SGD and 92.61% for post-local SGD with H = 16.
The symptom of too much noise is an unstable run. Starting local SGD at epoch 0 with large H and K can hurt early training, and the paper tests a gentler start: raise H slowly from 1 (linear, exponential or constant warm-up). Its verdict in Appendix B.4.2 is that “none of the investigated strategies show convincing performance”: the noise from local steps soon degrades the run even after a 50-epoch warm-up. Starting too late fails too: if local steps begin only at the second learning rate drop, the run costs more communication and risks sharper minima (Appendix C.2). The right moment is the subject of Chapter 5.
Chapter 5
Switch on local steps after the first learning rate drop
A team of sixteen hikers starts up a fog-covered mountain. At first they stay in a tight group and pick the trail together, because the early trail is steep and a wrong turn is costly. Once they reach the high meadow and the fog lifts, each hiker wanders off to explore for a while, and they regroup now and then. The first half is careful. The second half explores. That is post-local SGD.
Post-local SGD runs ordinary mini-batch SGD for the first part of training, then switches to local SGD for the rest. In the paper’s words, local SGD “is only started in the second phase of training, after t1 initial steps with standard mini-batch SGD”. The number of local steps H changes with time:
The switch point t1 is not tuned separately. For ResNet-20 on CIFAR-10 the learning rate drops by a factor of 10 when the model has seen 50% and 75% of its training samples. So the first drop falls at epoch 150 of 300, and t1 sits there. The paper adds that t1 could be tuned to catch the moment when the weights enter “the influence basin of a local minimum”.
There are three reasons, and the paper gives each one.
The paper stresses one more point. Using local SGD in the second phase is crucial. Simply switching to a large batch in the second phase scores worse. In Table 2, with 16 workers, the run that grows the plain batch from 2,048 to 16,384 at the switch gets 92.0%. Post-local SGD at the same moment gets 92.9%.
Take the paper’s setup: 16 workers, local batch 128, so a combined batch of 2,048. CIFAR-10 has 50,000 training images, so one epoch is 50,000 / 2,048 = 24.41 synchronous steps. Training runs 300 epochs.
Plain mini-batch SGD syncs every step: 300 × 24.41 = 7,324 syncs. Post-local SGD with H = 16 and t1 at epoch 150 does the first half the same way: 150 × 24.41 = 3,662 syncs. In the second half each round covers 16 steps, so it needs 3,662 / 16 = 229 syncs. The total is 3,662 + 229 = 3,891 syncs, which is 0.53 of 7,324. That is the 0.53 you saw in the hero. Both runs compute the same number of gradients; only the talking differs.
Build your own schedule and watch the count move. Try switching at epoch 0, then at epoch 225, and compare with the paper’s choice.
Top: the learning rate, which drops at epochs 150 and 225. Middle: local steps H(t). Bottom: purple ticks are syncs. Pick when local steps start and how many.
The schedule is the paper’s setup for ResNet-20 on CIFAR-10 (300 epochs, drops at 50% and 75%, K = 16, Bloc = 128, N = 50,000). The sync counts are our arithmetic from it. Which start is best comes from the paper’s Figure 12, not from this drawing.
The data flow is simple. Before t1, a (d) vector of gradients crosses the network every step. After t1, a (d) vector of weights crosses it once every H steps. Batch normalization statistics are kept per worker in both phases.
Figure 3 of the paper shows two things. Any number of local steps on top of a large batch of 2,048 improves test accuracy over mini-batch SGD. And post-local SGD with H = 16 or 32 is better than mini-batch SGD in general, for 2 to 16 workers. The cost is a new hyperparameter, H, and one more way to fail: a value that is too large, or a switch that is too early. The next chapters read the tables, then the limits.
Chapter 6
Read each main table and figure and say what it proves
You have the method. Now ask the fair question: what did the authors measure, and how big is the win? This chapter reads the main tables one at a time and says what each one proves, and what it does not.
The paper trains three image networks on CIFAR-10 and CIFAR-100: ResNet-20, DenseNet-40-12 and WideResNet-28-10. Each cell is a mean of three runs with its spread (the ± number is the standard deviation, a measure of how much the three runs differ). The small-batch baseline uses 2 workers and a combined batch of 256. The large-batch baseline uses 16 workers and a combined batch of 2,048. Both have a fine-tuned learning rate. Post-local SGD runs on 16 workers at the large batch, with default settings and H = 16 or 32.
The device shows the result as a change from the small-batch baseline, so the networks line up. A marker to the left of zero is worse than the small batch.
Zero is the small-batch baseline. Each row is a network. Circles are the large batch, squares and diamonds are post-local SGD. Whiskers are the spread over three runs. Switch tables.
Numbers are the paper’s Table 3 (batch 2,048, 16 GPUs) and Table 11 (batch 4,096, 32 GPUs, CIFAR-100), means of three runs. Each marker is the table value minus the small-batch baseline; the whisker is that method’s own standard deviation, and does not include the baseline’s.
On CIFAR-10 the large batch loses 0.15, 0.05 and 0.46 points. Post-local SGD brings every network back to the baseline or above it, with one exception: WideResNet at H = 32 is 0.13 points below, well inside the spread. Treat the CIFAR-10 gains (about 0.2 to 0.4 points on ResNet-20) as small: the standard deviations are about 0.2. On CIFAR-100 the large batch loses 0.5 to 0.8 points, and post-local SGD at H = 32 ends 0.2 to 0.9 above the baseline.
In Table 11 the batch is 4,096 on 32 GPUs. The large batch now loses about 1.5 to 2 points (67.34 against 68.84 for ResNet-20). Post-local SGD recovers most of it, but it does not always pass the baseline. For ResNet-20 it scores 68.38 and 68.30, still below 68.84. For DenseNet-40-12 at H = 16 it scores 74.96 against 74.85, and for WideResNet-28-10 79.80 against 79.78: level with the baseline, not above it. The claim of the paper holds with that caveat.
Table 12 adds a fair control: train the large batch longer. At 400 epochs the large-batch ResNet-20 scores 67.55 against post-local SGD’s 69.06, so more steps do not close this gap. The abstract says exactly this: post-local SGD “significantly improves the generalization performance compared to large-batch training”.
The cluster has 8 machines with 2 GPUs each on a 10 Gbps network. The speedup is the time on one GPU divided by the time on 16. The table gives whole-training speedups, with H = 1 meaning plain mini-batch SGD.
| Network, dataset | H = 1 | H = 16 | H = 32 | Efficiency at H = 1 and 32 |
|---|---|---|---|---|
| ResNet-20, CIFAR-10 | 9.45 | 12.24 | 13.00 | 59% and 81% |
| DenseNet-40-12, CIFAR-10 | 8.31 | 10.80 | 11.37 | 52% and 71% |
| WideResNet-28-12, CIFAR-10 | 5.33 | 7.94 | 8.19 | 33% and 51% |
These are the paper’s Table 9 values for CIFAR-10; the efficiency column is our division by 16. The speedup grows with H but flattens: the first half of the run is still synchronous, so the whole-run gain at H = 32 is 1.38 times for ResNet-20 (13.00 over 9.45). Table 10 counts only the second phase: for ResNet-20 it reports 17.33 at H = 16 and 20.80 at H = 32. Those exceed 16, and the main text does not explain why. The paper’s text summarizes the CIFAR gain as “at least 1.3× speedup” over the whole training.
Figure 2(a) plots test accuracy against workers K for several H. Local SGD with H = 8 reaches 91.2% test accuracy with a 2.59 times time-to-accuracy speedup, and with H = 2 it reaches 92.57% with 1.76 times, while the best mini-batch run on 16 GPUs reaches 92.48%. Local SGD on 8 GPUs even reaches the target in half the time of mini-batch SGD on 16 GPUs. On ImageNet with ResNet-50 on a 16 × 2-GPU cluster it is at least 1.5 times faster to 75% top-1. Figure 3(a) shows any H on top of a large batch of 2,048 improves accuracy over mini-batch SGD.
Post-local SGD stacks with other tricks. With sign-based compression (each gradient entry sent as one bit), ResNet-20 on CIFAR-10 goes from 92.45% (error-feedback signSGD at H = 1) to 92.63%, 92.72% and 92.76% at H = 16, 32 and 64. On ImageNet with LARS (a per-layer learning rate rule) and K = 32, H = 4, the top-1 goes from 75.99 to 76.13 at a batch of 8,192, and from 74.52 to 75.23 at 16,384. At a batch of 4,096 on ImageNet, post-local SGD reaches 76.18 against 75.87 for mini-batch, but at 8,192 only 75.65 against 75.64: a tie.
A last honest number is the language task. A three-layer LSTM on WikiText-2, with batch 1,024 on 16 workers, gets validation perplexity (lower is better) 86.50 for the small batch, 86.90 for the large batch, 86.61 at H = 8 and 86.85 at H = 16. The paper calls it a “proof of concept”. The gain at H = 8 is 0.29 perplexity, with a spread of about 0.3.
Chapter 7
Find where more local steps stop paying and start to hurt
Back to the hikers. They explore alone between meetings. How long can they wander before the group is worse off? A walk of 8 steps feels safe. A walk of 1,024 steps feels reckless. The paper measures where that line is, on time and on accuracy, and tests several ways to stretch it.
The paper's Table 16 trains ResNet-20 on CIFAR-10 on the 8-machine, 2-GPU-per-machine cluster, with local batch 128, and varies H from 1 to 1,024. Every run does the work of 300 epochs. The device plots the minutes it took.
Dots are the paper’s measured minutes. The dashed line is a two-number model we fitted: a fixed compute time plus a sync time divided by H. Drag H and see where the model stops matching.
Measured times are the paper’s Table 16 (minutes, mean of three runs, no tuning, 8 × 2 GPUs). The dashed model, time = C + S/H with C = 7.83 and S = 12.24 minutes, is our fit through the H = 1 and H = 2 points; the paper does not give it.
The times are, in minutes, for H = 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1,024: 20.07, 13.95, 10.48, 9.20, 8.57, 8.32, 9.22, 9.23, 9.50, 10.30 and 10.65. Time falls fast, bottoms out at H = 32, and then climbs again. The fastest run is 2.4 times faster than plain mini-batch SGD.
Why a floor? Think of each run as compute plus waiting. Compute is the same for all H. Waiting is one sync per H steps. So time should be C + S/H. Fit it through the first two points: S = 2 × (20.07 − 13.95) = 12.24 minutes and C = 20.07 − 12.24 = 7.83 minutes. That says 61% of the plain run is spent in syncs. The model predicts 10.89, 9.36, 8.59 and 8.21 for H = 4, 8, 16 and 32, within about 0.4 minutes of the measurements. It then keeps falling to 7.84 at H = 1,024, while the real run climbs to 10.65.
The paper says only that more local steps “cannot infinitely improve the communication performance, or would even reduce” its benefits. It does not name the cause. The gap between the model and the dots, 2.8 minutes at H = 1,024, is cost the model does not count. Whatever it is, past H = 32 on this cluster there is nothing left to gain from the network.
Time is only half of it. In Figure 2 the authors raise H and K together. The test accuracy of plain local SGD falls at the largest settings. They note that it “still encounters difficulties when scaling to very large mini-batches”, though far less than mini-batch SGD. Post-local SGD softens the problem, because the first phase has already stabilized the weights. Figure 3(a) shows that H from 2 up to 128 on top of a large batch of 2,048 keeps the gain, although the paper's headline numbers use H = 16 and 32.
A natural fix is a ramp: start with H = 1 and raise it slowly to the target. The paper tests three ramps (linear, exponential, constant), with a warm-up as long as 50 epochs. It reports that none shows convincing results, because the noise from local steps later degrades the run anyway. That is why the plain two-phase switch stays.
Momentum keeps a running average of past gradients, so a step has inertia. In local SGD there are two places to put it. Local momentum lives inside each worker, as in the main experiments (0.9, with Nesterov). Global momentum is applied once per sync to the average distance the workers moved. That average, (1/K) ∑ (w − wk) / γ, works like a gradient the group produced over H steps. Later work calls it a pseudo-gradient and the step that uses it the outer optimizer. Here it is, already, in this paper's Appendix B.4.1.
Table 8 tries it on a 5 × 2-GPU cluster (local batch 128, H = 1):
| Local momentum | Global momentum | Test top-1 | What it shows |
|---|---|---|---|
| 0.0 | 0.0 | 90.57 | No momentum at all is clearly worse. |
| 0.9 | 0.0 | 92.41 | Local momentum alone is the main experiments’ setting. |
| 0.9 | 0.3 | 92.54 | A little global momentum helps a tiny bit. |
| 0.9 | 0.6 | 91.32 | Too much starts to hurt. |
| 0.9 | 0.7 | 18.76 | Training breaks down. |
The paper calls it a toy example and decides to use only local momentum. It notes that how the two momenta combine is not understood, which makes H and K harder to tune. The lesson DiLoCo and Low-Communication Pretraining picks up exactly this thread, and the post lists SlowMo and FedAvgM as the next steps.
Chapter 8
Nest the idea once per network level, from one machine to many sites
A company has desks in one office, offices in one city, and branches in many countries. Colleagues at the next desk talk all day. Branches in other countries exchange a short report once a week, because each call is slow and costly. Nobody runs the company with one rule for every pair of people. The paper's last idea does the same for GPUs.
The paper's Figure 17 draws a real data center. GPUs inside one machine talk over NVLink at about 200 Gb/s each. Machines in a rack connect to a top-of-rack switch at about 40 Gb/s. A cluster switch ties many racks together. Beyond the building, “edge switches face the external network at even lower bandwidth”. Each step up the tiers is slower, and the paper adds that the same shape holds for “several data-centers” and even for phones.
A flat rule, such as “all GPUs average every H steps”, treats the slowest wire as the price of every sync. The paper's answer is to nest the rule.
Hierarchical local SGD runs local SGD as an inner loop at each level of the hierarchy, matched to that level's wire. Take two levels. A GPU block is a group of GPUs on a fast wire, such as one machine. Each GPU takes H local steps, then the GPUs in its block average their models (fast). After Hb such block steps, all blocks average with each other (slow). Hb is the number of block steps. Figure 18 draws the small case: local batch 2, H = 3 and Hb = 2.
Count the syncs. In Table 17, with H · Hb = 16, there is one sync over the slow wire per 16 steps in every column. The number of fast syncs inside the node is Hb − 1: 15, 7, 3, 1 and 0 for Hb = 16, 8, 4, 2 and 1. With Hb = 1 the scheme is plain local SGD with H = 16. The paper's cost formula (equation 6) counts each kind of sync times its price, C1 within a server and C2 across servers, with C1 much smaller than C2. It concludes that Hb matters more than H for cutting communication.
Each row does the same work: H × Hb steps of compute (warm). Purple blocks are syncs: thin ones are cheap block syncs, wide ones are the slow wire. Set the schedule and the cost of the slow wire.
Toy costs, our own: a block sync costs 1 step of compute and the slow wire costs what you set. A round has H × Hb steps and Hb − 1 block syncs plus one slow sync, as in the paper’s Table 17. The paper’s timing runs (Figure 19) use real delays of 1 and 50 seconds.
The first test is delay. The paper uses 2 blocks of 2 GPUs, fixes H = 2, and varies Hb from 1 to 32 in Figure 19. It adds an artificial delay to each global sync: none, then 1 second, then 50 seconds. Its conclusion is that hierarchical local SGD “shows high tolerance to network delays”. Even with a 50-second delay per global round, “a large number of block steps (e.g. Hb = 16) still manages to fully overcome the communication bottleneck with no/trivial performance damage”.
The second test is accuracy, in Table 17, on a 16-GPU cluster split into different shapes. With 8 nodes of 2 GPUs, the test accuracy (mean of three runs) is 90.02% at H = 1, Hb = 16, then 90.25%, 89.95%, 91.41% and 91.18% at H = 16, Hb = 1. The best is H = 8, Hb = 2. On this shape, though, the paper notes that the 8 × 2 topology “fails to further improve the performance of local SGD by using more frequent inner node synchronizations”. A sufficiently large GPU block, it says, benefits more. The design space “should be further investigated”.
The post by Rohan Anil puts it plainly: “Within an island of compute, use the fast interconnect aggressively. Across islands of compute, exchange updates on a slower schedule.” That sentence is hierarchical local SGD with the tiers set to islands. The post's own run uses two sites, 160 GPUs each, about 9,000 miles apart on a 25 Gbps link, with a sync every 50 steps. Inside each island, the post uses the fast interconnect aggressively, with the parallelism layout tuned to that site.
Here is what the 2018 paper has, and what the post adds.
Chapter 9
Review the numbers, the checklist and the core code, then go onward
You can now reproduce the paper from memory: what mini-batch SGD does, why a big batch loses accuracy, what local steps add, when to switch them on, what the tables say, and where the idea stops. This page keeps the numbers, a checklist, the core code, and the way onward.
Synchronous mini-batch SGD on K workers is SGD with a K times larger batch. It waits on the network after every step, and at large batches it loses test accuracy even though the training curve looks perfect. Local SGD lets each worker take H steps alone, then averages the models, so it talks H times less and injects more gradient noise. Post-local SGD runs ordinary mini-batch SGD until the first learning rate drop and local SGD after it. On ResNet-20 with 16 GPUs it matches the one-GPU accuracy (93%), where the large batch reaches 92% and a still larger batch 76.3%, and it syncs about half as often. Hierarchical local SGD nests the same idea once per network tier.
| What | Number | Source |
|---|---|---|
| Test accuracy, ResNet-20, CIFAR-10, 16 GPUs | A1 93%, A2 92%, A3 89%, A4 92%, A5 93% | Figure 1 table |
| Large batch collapse, K = 16 | 92.5% at 2,048; 76.3% at 16,384 | Table 2 |
| Same big batch with local steps | local SGD 92.0%; post-local SGD 92.9% | Table 2 |
| Three networks, CIFAR-100 | ResNet-20: 68.17 large batch vs 69.24 and 69.38 post-local | Table 3 |
| Batch 4,096, ResNet-20, CIFAR-100 | 67.34 large batch vs 68.38 and 68.30 post-local; small batch 68.84 | Table 11 |
| Syncs over 300 epochs (our count) | 7,324 vs 3,891 (0.53) | K = 16, Bloc = 128, H = 16, t1 = 150 |
| Speedup on 16 GPUs, ResNet-20 | 9.45 (H = 1), 12.24 (H = 16), 13.00 (H = 32) | Table 9 |
| Training time against H | 20.07 min (H = 1), 8.32 min (H = 32), 10.65 min (H = 1,024) | Table 16 |
| ImageNet, ResNet-50 | 76.18 vs 75.87 at 4,096; 75.65 vs 75.64 at 8,192 | Appendix C.5.3 |
| ImageNet with LARS, K = 32, H = 4 | 76.13 vs 75.99 at 8,192; 75.23 vs 74.52 at 16,384 | Table 5 |
| Global momentum 0.3 and 0.7 | 92.54% and 18.76% | Table 8 |
| Bandwidth tiers | NVLink about 200 Gb/s per GPU; rack switch about 40 Gb/s | Figure 17 |
| Term | Plain meaning |
|---|---|
| Worker, K | One GPU holding a model copy. K is how many. |
| Mini-batch, B and Bloc | The few examples one gradient is measured on. Bloc is the size on one worker. |
| Sync, all-reduce | The stop where workers swap numbers so all hold the same average. |
| Local steps, H | Steps a worker takes alone between two syncs. |
| Generalization gap | Same training score, lower test score. |
| Post-local SGD, t1 | Mini-batch SGD up to time t1, local SGD after it. The paper sets t1 at the first learning rate drop. |
| Global momentum, pseudo-gradient, outer optimizer | Momentum applied once per sync to the average distance the workers moved. Later work names that distance the pseudo-gradient. |
| GPU block, block steps Hb | A group of GPUs on a fast wire, and the number of block averages between two global ones. |
| Time-to-accuracy | How long a run takes to reach a target test accuracy. |
pythonimport torch, torch.distributed as dist import torch.nn.functional as F K = dist.get_world_size() # number of workers (GPUs) def average_models(model): # the merge: one all-reduce of d numbers for p in model.parameters(): dist.all_reduce(p.data, op=dist.ReduceOp.SUM) p.data /= K def train(model, opt, sched, loader, epochs=300, t1=150, H=16): step = 0 for epoch in range(epochs): loader.sampler.set_epoch(epoch) # disjoint shards, reshuffled globally each epoch h = 1 if epoch < t1 else H # H(t): 1 before the first LR drop, H after for x, y in loader: # x: (B_loc, 3, 32, 32), B_loc = 128 loss = F.cross_entropy(model(x), y) opt.zero_grad(); loss.backward() if h == 1: # phase 1: mini-batch SGD, average gradients for p in model.parameters(): dist.all_reduce(p.grad); p.grad /= K opt.step() # Nesterov momentum 0.9, kept on each worker step += 1 if h > 1 and step % h == 0: # phase 2: H local steps, then average models average_models(model) sched.step() # LR /10 at 50% and 75% of the samples
This is our sketch of the recipe, not the authors’ code. Theirs is at github.com/epfml/LocalSGD-Code. Note one detail: with plain SGD, averaging gradients every step and averaging models every step give the same result; with momentum they differ, and the paper keeps momentum local in the second phase.
Local SGD is older than this paper. The post dates averaging of independently trained models to 2010 (Parallelized SGD) and local steps with averaging to 2016 (Federated Averaging), and lists “2018 Local SGD (Stich); Lin et al.” as the empirical case for infrequent averaging. This paper adds the large-batch generalization story, the two-phase schedule, and the hierarchy. Its blind spots are the ones the post attacks: asynchrony, hardware mixes, failures, compression, and models that are billions of weights wide.
Credit: Tao Lin, Sebastian U. Stich, Kumar Kshitij Patel and Martin Jaggi, “Don’t Use Large Mini-Batches, Use Local SGD”, ICLR 2020, arXiv 1808.07217. Every result here is theirs; the toys, the sync counts and the time-model fit are ours and are labelled as such. Read as part of Rohan Anil’s post for Core Automation.
Now press Present or Teach and explain from memory why 16 GPUs with a bigger batch score lower, what H and t1 do, and why 0.53 of the syncs is enough. Then go back to the five recipes at the top and say, for each, why it lands where it does.