How Do Thousands of GPUs Add Up Their Work? All-Reduce, Explained

6 min read

How Do Thousands of GPUs Add Up Their Work? All-Reduce, Explained

The problem

When a model trains on many GPUs at once, each GPU looks at different data and works out its own gradient: its own opinion of how every weight should change. Before anyone takes a step, those opinions have to be added together so every GPU applies the same update. With a model of billions of weights and hundreds of GPUs, "just send everything to everyone" would drown the network.

The trick that solves this has a dull name, All-Reduce, and it is one of the most important pieces of plumbing in modern AI. This piece explains it with a ring of four GPUs and small numbers you can check by hand. It draws on Aleksa Gordic's long technical post on TPU and GPU cluster communication, which goes much further into the hardware.

Four operations do most of the talking

Gordic points out that the main ways of splitting a model across a cluster sit on top of a short list of "collective operations", where a group of chips all take part in one exchange:

  • All-Gather: every chip starts with one piece and ends with every piece.
  • Reduce-Scatter: every chip starts with partial values for every piece. They add them up as they pass them around, and each chip ends up owning one fully added piece.
  • All-Reduce: every chip ends with the full added result. It is a Reduce-Scatter followed by an All-Gather.
  • All-to-All: every chip sends a different piece to each other chip. This is what Mixture-of-Experts models use to route tokens to the chip that holds their expert.

Plain data-parallel training, where each GPU holds the whole model and sees different data, uses All-Reduce to sync gradients. Splitting the weights themselves across chips (tensor parallelism, FSDP) leans on All-Gather and Reduce-Scatter.

Reduce-Scatter: add while you pass

Picture four GPUs in a ring. Each one splits its gradient into four chunks. To keep the numbers tiny, here is what each holds:

chunk 0chunk 1chunk 2chunk 3
GPU 010111213
GPU 120212223
GPU 230313233
GPU 340414243

The answer we want is the column sums: 100, 104, 108, 112.

In each step, every GPU sends one chunk to its right-hand neighbour, and the neighbour adds it to its own copy of that chunk. Every GPU sends a different chunk, so all four links are busy at once. After three steps (N − 1 for N GPUs), each GPU holds one chunk that contains everyone's contribution.

Animation: Reduce-Scatter on a ring of 4 GPUs. After 3 steps each GPU owns one fully summed chunk.

All-Gather: copy while you pass

Now each GPU has one finished chunk and three unfinished ones. All-Gather runs the same ring schedule again, except each GPU now copies the finished chunk it receives instead of adding to it. After three more steps, every GPU has 100, 104, 108, 112.

Animation: All-Gather spreads the finished chunks so every GPU ends with the full sum.

That is All-Reduce: Reduce-Scatter, then All-Gather. Here is the whole thing as runnable Python, which is how we checked the numbers above:

python
N = 4
data = [[10*(w+1) + c for c in range(N)] for w in range(N)]
target = [sum(data[w][c] for w in range(N)) for c in range(N)]
buf = [row[:] for row in data]
for s in range(N - 1):                      # reduce-scatter: add
    for w, c, v in [(w, (w-s) % N, buf[w][(w-s) % N]) for w in range(N)]:
        buf[(w+1) % N][c] += v
for s in range(N - 1):                      # all-gather: copy
    for w, c, v in [(w, (w+1-s) % N, buf[w][(w+1-s) % N]) for w in range(N)]:
        buf[(w+1) % N][c] = v
assert all(buf[w] == target for w in range(N))
print(buf[0])   # [100, 104, 108, 112]

Why bother with two phases instead of one big shuffle? Because each GPU only ever sends one chunk per step, every link carries a small, even load. Nobody becomes the bottleneck.

The mirror trick

Gordic notes a useful duality: for many ways of splitting a model, if the forward pass uses All-Gather, the backward pass uses Reduce-Scatter, and the other way round. Forward, you gather the pieces of a weight you need. Backward, the gradients for those pieces have to be added and handed back to whoever owns each piece. Once you see that, a lot of distributed training code stops looking like magic.

Rings, trees and the shape of the machine

A ring needs N − 1 steps per phase. A tree-style algorithm, which pairs chips and doubles what each one holds every round, needs only log2(N). For 8 GPUs that is 7 rounds versus 3.

Animation: For 8 GPUs a ring takes 7 rounds and a tree takes 3. Which one wins depends on message size.

Fewer rounds sounds strictly better, but Gordic explains that rings are easier to pipeline: you can stream many chunks around continuously and keep every link busy. So for big messages rings often get higher real bandwidth, and for small messages, where the fixed cost per round dominates, trees win. Libraries like NVIDIA's NCCL pick between ring, tree and hybrid algorithms based on message size and topology.

The hardware shape matters too:

  • TPUs are wired to their nearest neighbours in a grid that wraps around at the edges (a torus). Each chip has 4 or 6 neighbours depending on the generation. If you rent a slice too small to keep the wraparound links, the ring turns into a line, and Gordic says collectives along that axis pay roughly a 2x time penalty.
  • NVIDIA GPU nodes connect 8 GPUs (in a DGX H100) through a switch, so any GPU reaches any other in one hop. The ring there is a logical order chosen in software, not a physical cable loop.
  • Some NVIDIA switches can do the adding themselves, a feature called SHARP. In theory that makes All-Reduce close to 2x faster. Gordic cites measurements showing the real gain is closer to 30%, and his advice is to always benchmark on your own cluster.

He also shows a quick way to tell whether latency or bandwidth is your problem. TPU links have roughly 1 microsecond of delay per hop and about 45 GB/s in one direction, so about 45 KB fits through a link in the time of one hop. If your chunks are around that size or smaller, the per-hop delay matters as much as the bandwidth.

Why this is worth knowing

If you only ever call a training library, All-Reduce is invisible. But it explains real decisions: why some clusters scale well and others stall, why a slice shape can halve your speed, why big gradient messages are better than many small ones, and why Mixture-of-Experts models stress networks differently. When a training job is slower than the maths says it should be, the answer is very often in how the data moves between chips, not in the chips themselves.

For more of the vocabulary, see our GPU and PCIe glossary and how big clusters spot dying GPUs.

Sources

  • Aleksa Gordic, "Inside TPU and GPU Clusters: The Anatomy of Collective Communication", aleksagordic.com/blog/collective-operations
  • NVIDIA Collective Communications Library (NCCL) documentation
  • The ring example and code above were written and run by BlogLLM.