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.

A mini-batch of 256 samples is cut into four shards of 64. Each shard goes to one of four GPUs, and each GPU holds the same weights w. Each GPU produces its own gradient g0 to g3. An all-reduce box averages them, and the same average comes back to all four GPUs, which apply the same update and keep the same w.
Each GPU sees a quarter of the batch, but after the all-reduce all four apply the same averaged gradient, so the copies never disagree.

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 pageMeaning
coloured cella chunk of the local gradient, or a chunk that is complete (summed over all GPUs)
white cella partial sum during the all-reduce
blue arrowsthe ring: GPU 0 → 1 → 2 → 3 → 0
grey linesthe links to the parameter server; red while they are the bottleneck
time barscompute, 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.
A grid with one row per GPU (0 to 3) and one column per chunk (c0 to c3), drawn three times: at the start every cell holds a local value; after reduce-scatter each row has one complete chunk on a diagonal (GPU 0 c1, GPU 1 c2, GPU 2 c3, GPU 3 c0) and the other cells are partial; after all-gather every cell is complete and every row is the same.
Reduce-scatter leaves one finished chunk on each GPU; all-gather copies the finished chunks round the ring until every GPU has all of them.

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.

Left: a star, four GPUs connected to one server; the server's link is red and labelled 400 MB in and 400 MB out, 80 ms. Right: a ring of four GPUs; every link carries 150 MB, 15 ms. Below, two time bars of a step: 60 ms compute plus 80 ms exchange is 140 ms for the server, 60 plus 15 is 75 ms for the ring.
The server's one link carries everything, so it is busy 80 ms; in the ring the same work is spread over every link and takes 15 ms.

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:

GPUscomputering stepefficiencyserver stepefficiency
1240 ms240 ms100 %240 ms100 %
2120 ms130 ms92.3 %160 ms75 %
460 ms75 ms80 %140 ms42.9 %
830 ms47.5 ms63.2 %190 ms15.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.

On the mind map

Open the Computer Architecture mind mapComputerArchitectureAbstraction and numbers: layers and bit patternsAbstraction and numbersCombinational logic: output depends only on inputsCombinational logicSequential logic: state held by a clockSequential logicMIPS software: how C becomes machine wordsMIPS softwareThe processor: datapath plus controlThe processorPipelines and parallelism: more instructions at oncePipelines and parallelismMemory and I/O: small fast near, big slow farMemory and I/OMIPS pipelineMIPS pipelineforward data, stall on load-useBranch predictionBranch prediction2-bit counters guess, flush if wrongOut-of-order executionOut-of-order executionrenaming removes WAR and WAW hazardsSIMD, threads, multicoreSIMD, threads, multicoreAmdahl's law caps the speedupAmdahl vs GustafsonAmdahl vs Gustafsonfixed job caps at 1/s; scaled growsMPI Send/Recv & CollectivesMPI Send/Recv & CollectivesTrees: log₂ p rounds; Send may blockData-Parallel TrainingRing all-reduce keeps every copy equalJacobi halo exchangeJacobi halo exchangeGhost rows refreshed before every sweepInterconnect topologiesInterconnect topologiesHypercube: hops = bits that differParallel Prefix SumParallel Prefix SumBlelloch: 2(n−1) work, 2 log n spanOpenMP loop schedulesOpenMP loop schedulesUneven costs: dynamic beats static blocksGPU and SIMT warpsGPU and SIMT warps32 lanes, one instruction; branches splitOpen the Computer Architecture mind mapComputer Architecturemore instructions at oncePipelines and parallelismMIPS pipelineMIPS pipelineforward data, stall on load-useBranch predictionBranch prediction2-bit counters guess, flush if wrongOut-of-order executionOut-of-order executionrenaming removes WAR and WAW hazardsSIMD, threads, multicoreSIMD, threads, multicoreAmdahl's law caps the speedupAmdahl vs GustafsonAmdahl vs Gustafsonfixed job caps at 1/s; scaled growsMPI Send/Recv & CollectivesMPI Send/Recv & CollectivesTrees: log₂ p rounds; Send may blockData-Parallel TrainingRing all-reduce keeps every copy equalJacobi halo exchangeJacobi halo exchangeGhost rows refreshed before every sweepInterconnect topologiesInterconnect topologiesHypercube: hops = bits that differParallel Prefix SumParallel Prefix SumBlelloch: 2(n−1) work, 2 log n spanOpenMP loop schedulesOpenMP loop schedulesUneven costs: dynamic beats static blocksGPU and SIMT warpsGPU and SIMT warps32 lanes, one instruction; branches split
This page on the Computer Architecture mind map · 76 pages in 7 branches · open it to see the whole map and test yourself in recall mode.