Skip to content
tezvyn:
Menu

All-Reduce: Synchronizing Parallel Workers

Source: Wikipedia: Collective operationHardHow cards are made

All-Reduce lets parallel workers agree on a global result. Each worker contributes data, an operation (like sum) runs on all data, and every worker gets the final answer. It's the core of distributed ML training, used to average gradients across GPUs.

Why it exists

In parallel computing, workers often operate on just one slice of a problem. To make global decisions or synchronize state, they need a way to combine their local results and ensure every worker has the final, aggregated value. Without this, they can't proceed in lockstep.

The mental model

Think of a board meeting where a budget needs approval. Each department head (a worker) brings their own proposed spending (local data). An operation, 'sum,' is performed on all proposals. The final, total budget (the reduced result) is then written on the main whiteboard for every department head to see and use (the 'all' part). Every participant both contributes and receives the final result.

How it works

A naive approach sends all data to one root node for computation and broadcast, creating a bottleneck. A common, more efficient method is Ring All-Reduce. Workers are arranged in a logical ring and data is chunked. In a 'scatter-reduce' phase, chunks are passed around the ring, with each node adding its data. This continues until each node holds a fully reduced chunk. In a second 'all-gather' phase, these final chunks are circulated so every node can reassemble the complete final result, balancing network load.

When to use it

This is the workhorse of distributed data-parallel training in machine learning. Frameworks like Horovod and PyTorch's DistributedDataParallel use it to average gradients calculated on different GPUs. It is also fundamental in High-Performance Computing (HPC) for large-scale simulations requiring global state synchronization.

When not to use it

If only one process needs the final result, a simpler 'Reduce' operation is more efficient, as it omits the final broadcast-to-all step. If no aggregation is needed and you just need to send data from one node to all others, use a 'Broadcast'. All-Reduce is specifically for many-to-many aggregation and distribution.

One canonical example

Training a model on 8 GPUs. Each GPU processes a different data batch and computes a gradient vector. An All-Reduce operation sums the 8 gradient vectors. The resulting sum is delivered back to all 8 GPUs. Each GPU then divides this sum by 8 to get the average gradient and updates its local copy of the model weights identically, ensuring the model stays synchronized across all workers.

Interview question

What is a key advantage of using an All-Reduce operation over performing a separate Reduce to a single node followed by a Broadcast from that node to all workers?

  • a.All-Reduce allows workers to update their local model weights asynchronously, improving training speed.
  • b.All-Reduce ensures that the aggregation function is applied only to a subset of worker contributions, reducing computation.
  • c.All-Reduce inherently distributes the aggregation and distribution workload across all participating workers, avoiding a single bottleneck.Correct
  • d.All-Reduce can handle a wider variety of data types for aggregation than sequential Reduce/Broadcast.
Why?

The card explains that a 'naive approach sends all data to one root node for computation and broadcast, creating a bottleneck.' All-Reduce, especially efficient methods like Ring All-Reduce, is designed to distribute this workload across all workers, balancing network load. Option A is incorrect because All-Reduce is a synchronous operation, ensuring workers proceed in lockstep.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on distributed systems — each one lists the topics its interview covers.

See open roles