epoch.training← the field guide

Field Guide · Part I — The machine · 06

// mpi and collectives

MPI and collectives, in one page

A supercomputer has thousands of nodes, but a single calculation needs all of them working on one problem. They coordinate by passing messages. Learn the handful of patterns those messages fall into and you understand how distributed AI training actually moves data. The pattern that trains every large model is called all-reduce.

Each node on a cluster has its own memory. There is no shared array everyone can read. So when a job spans 4,000 nodes, the only way they cooperate is by explicitly sending data to each other — message passing. The standard for this, since the mid-1990s, is MPI, the Message Passing Interface: a specification (not a product) that defines how independent processes name each other, send and receive buffers, and — crucially — perform group operations together.

Ranks, and the two kinds of message

An MPI program launches the same executable as many ranks — say 32,000 copies, each with a unique integer ID from 0 to 31,999. Every rank runs the same code but branches on its rank number, so rank 0 might read the input file and hand pieces to the rest. Communication comes in two flavours:

Collectives matter because the naive way to do a group operation — have everyone send to rank 0, let it compute, then send back — makes rank 0 a bottleneck that gets worse as you add nodes. The whole art is doing these operations so their cost grows slowly, ideally like the logarithm of the number of ranks, not linearly.

The collectives you actually need to know

How these are implemented is not obvious. Thakur, Rabenseifner and Gropp showed that the best algorithm depends on message size: for a short all-reduce you want a latency-optimal recursive-doubling scheme; for a long one you switch to a bandwidth-optimal reduce-scatter followed by all-gather, which moves far less data over the wire. Same MPI call, completely different machinery underneath, chosen at runtime.

// every rank contributes its local gradient sum;
// every rank gets back the global sum, in place.
MPI_Allreduce(MPI_IN_PLACE, grad, n,
              MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
// divide by world size → the averaged gradient
One line of MPI hides a tree-structured, size-adaptive communication pattern across every node in the job.

Why all-reduce is the heart of AI training

Data-parallel training puts a copy of the model on every GPU and feeds each a different slice of the batch. Each GPU computes gradients on its slice — but to take one coherent optimizer step, every GPU must apply the average gradient across all of them. That average is exactly an all-reduce with a sum, divided by the number of workers. It happens every single training step, on tensors that can be gigabytes.

Because those tensors live in GPU memory and the links are NVLink and InfiniBand rather than a switched Ethernet cluster, NVIDIA built NCCL (and AMD its API-compatible RCCL) — GPU-native collective libraries that speak the same broadcast/reduce/all-reduce vocabulary as MPI but are tuned for GPU topology. NCCL's default all-reduce is a ring: a scatter-reduce phase then an all-gather phase, sized so each GPU sends the same volume regardless of ring length. Every distributed PyTorch and JAX job you have ever run leans on this. The forty-year-old idea of a collective did not get replaced by AI — it got a GPU back-end and became load-bearing infrastructure for the whole field.

Why it matters: when a training run stalls, "the GPUs are slow" is usually wrong — the GPUs are waiting on an all-reduce. Communication, not computation, is what caps the scaling of large models, which is why overlapping all-reduce with backprop, picking the right collective algorithm, and getting the network topology right are among the highest-leverage things an infrastructure engineer can do. The MPI collective is the abstraction the entire industry is quietly optimizing around.

Sources & where to go deeper

R. Thakur, R. Rabenseifner & W. Gropp, "Optimization of Collective Communication Operations in MPICH", Int. J. High Performance Computing Applications 19(1):49–66, 2005 (DOI 10.1177/1094342005051521) — the size-adaptive algorithms behind broadcast, reduce and all-reduce. Open PDF.
MPI Forum, "MPI: A Message-Passing Interface Standard, Version 4.1", MPI Forum, 2023 — the collective-communication chapter is the authoritative definition of these operations.
NVIDIA, "Collective Operations — NCCL Documentation", NVIDIA Developer Docs — AllReduce, Broadcast, ReduceScatter and AllGather as implemented for GPUs.

This is one page of twenty.

The workshops go deep on the real thing — scheduling, storage, interconnect, GPUs — hands-on, on real infrastructure, from someone who's run these machines at national scale.

See the trainings →