The idea: one model, many copies, a slice of the batch each
Training a neural network repeats one step many times: take a mini-batch of samples, compute the gradient of the loss, and move the weights a little against it (see Gradient Descent). With one GPU a mini-batch of 256 samples might take 240 ms. Data parallelism splits that work. Every GPU keeps a full copy of the same model. The mini-batch is cut into shards, 64 samples for each of 4 GPUs. Each GPU computes a gradient on its own shard, the GPUs combine their gradients, and every GPU applies the same update.
The canvas uses a tiny model so that every number fits on screen: a linear model ŷ = w · x with 4 weights, 8 samples (standing for the 256) and 2 samples per GPU. The 4 numbers of a gradient are also the 4 chunks c0–c3 that the GPUs exchange; each stands for 25 MB of a real 100 MB gradient. The times on the right are those of the real job: 60 ms of compute per shard and links of 10 GB/s, so 100 MB take 10 ms.
| On the page | Meaning |
|---|---|
| coloured cell | a chunk of the local gradient, or a chunk that is complete (summed over all GPUs) |
| white cell | a partial sum during the all-reduce |
| blue arrows | the ring: GPU 0 → 1 → 2 → 3 → 0 |
| grey lines | the links to the parameter server; red while they are the bottleneck |
| time bars | compute, wait, exchange; the bottom bar is one GPU doing the whole batch |
Why 4 GPUs get exactly what 1 GPU gets
The loss of a mini-batch is the mean of the per-sample losses, so its gradient is the mean of the per-sample gradients. With 4 shards of the same size, the mean of the 4 shard gradients is the mean over all samples. In Demo 1 the local gradients of GPU 0 and GPU 3 are [−9.5, −3, −7, −6.5] and [−8.5, −10, −7, −5]. Their sum with the other two is [−28.5, −19.5, −25.5, −21], and the average is [−7.125, −4.875, −6.375, −5.25]: exactly the gradient that one GPU computes on all 8 samples. With η = 1/8 every GPU gets w = [0.891, 0.609, 0.797, 0.656], and so does the single GPU. After the second step (Demo 4) they still agree, now at w = [1.282, 0.746, 1.104, 0.907], and the loss has fallen from 15.75 to 3.46 to 1.59.
This is synchronous SGD: no GPU starts the next step before the average is in. If you skip the exchange (Demo 2), each GPU steps on its own shard's gradient and the four copies end up at four different w, none of them the right one. Shards must also be the same size, or the plain average weights some samples more than others.
Ring all-reduce: reduce-scatter, then all-gather
Combining the gradients so that every GPU ends with the sum is an all-reduce, the same collective as MPI_Allreduce on the MPI page. That page sends whole values along a tree. For a 100 MB gradient the cost is the bytes, not the number of rounds, and the ring all-reduce is the standard answer. The GPUs form a ring, and the gradient is cut into N chunks.
- Reduce-scatter, N − 1 steps: in step s, GPU i sends chunk (i − s) mod N to GPU i + 1, which adds it to its own. After 3 steps GPU i holds the full sum of chunk i + 1: GPU 0 has c1 = −19.5, GPU 3 has c0 = −28.5.
- All-gather, N − 1 steps: each GPU passes a finished chunk on, and the receiver overwrites its partial one. After 3 more steps every GPU has all 4 sums.
That is 2(N − 1) = 6 steps. In each step every GPU sends one chunk of S/N = 25 MB and receives one, and all 4 links work at the same time. Each GPU sends 2(N − 1)/N × S = 150 MB, which takes 15 ms on a 10 GB/s link. The amount hardly grows with N: it stays under 2S however many GPUs join.
The parameter server and its one link
The older design puts one parameter server in the middle. Each GPU pushes its whole gradient to it, the server sums and averages, and each GPU pulls the result. (In the classic version the server also keeps the weights and applies the update; the traffic is the same.) The trouble is the server's link: it must take in N × 100 MB = 400 MB and send out another 400 MB. At 10 GB/s that is 80 ms against the ring's 15 ms (Demo 3), and it grows with every GPU added.
Real systems with parameter servers split the weights over several servers (sharding), which spreads the load. The ring needs no extra machines at all.
A straggler sets the pace
Synchronous SGD waits for the slowest GPU. In Demo 5 GPU 3 needs 120 ms instead of 60 ms (a hotter chip, a busier host). GPUs 0–2 finish at 60 ms and sit idle for 60 ms, the ring starts at 120 ms, and the step takes 120 + 15 = 135 ms. Efficiency drops from 80 % to 44.4 %. One slow worker slows them all, which is why large jobs watch for stragglers and why some systems use backup workers or asynchronous updates.
Compute, communication and scaling efficiency
The time of a step is the compute time plus the exchange time. The speedup is T₁ / TN and the scaling efficiency is speedup / N. Keeping the mini-batch at 256 and adding GPUs (Demo 6) gives:
| GPUs | compute | ring step | efficiency | server step | efficiency |
|---|---|---|---|---|---|
| 1 | 240 ms | 240 ms | 100 % | 240 ms | 100 % |
| 2 | 120 ms | 130 ms | 92.3 % | 160 ms | 75 % |
| 4 | 60 ms | 75 ms | 80 % | 140 ms | 42.9 % |
| 8 | 30 ms | 47.5 ms | 63.2 % | 190 ms | 15.8 % |
Even the ring loses efficiency, because the compute shrinks while the exchange does not. This is the communication part of Amdahl's law. Two common answers: give each GPU a bigger share (weak scaling, a larger global batch), and start sending the gradients of the last layers while the backward pass is still working on the first ones. Fast links matter too: GPUs in one server talk over NVLink at hundreds of GB/s, servers over InfiniBand or RoCE. Cloud providers rent such GPU machines by the hour, as the cloud service models page describes for ordinary servers, and inside each chip the same bandwidth question shows up again in the on-chip interconnect. For shared versus distributed memory in general, see Parallel Hardware.
What the page leaves out
The model is a 4-weight linear model, the same 8 samples are used every step, and a real mini-batch would be drawn fresh each time. Times ignore latency, the start-up cost of each message, which makes many small chunks expensive; libraries such as NCCL also use trees and two-level rings across servers. Left out: overlapping the exchange with the backward pass (gradient buckets), mixed precision and gradient compression, asynchronous SGD and stale gradients, larger learning rates for larger batches, and model, pipeline and tensor parallelism, where the model itself is split because it does not fit on one GPU. Floating-point sums can differ in the last bits with the order of the additions; the page uses numbers that are exact in binary, so its copies agree bit for bit.