Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

AllReduce Algorithm Analysis: Bandwidth, Latency, and Message Size

Introduction

In our previous lesson, we established that the AllReduce operation is the cornerstone of data-parallel training, responsible for synchronizing gradients across all GPUs to maintain model consistency. We took a first look at the Ring-AllReduce algorithm, one of the primary methods NCCL uses to implement this collective efficiently.

This lesson advances our analysis from what AllReduce does to how it performs. Our learning outcome is to analyze the Ring-AllReduce and Tree-based algorithms in terms of their bandwidth usage, latency, and message size sensitivity.

We will deconstruct these two fundamental algorithmic families and model their performance. This analysis is critical for your goal of designing and optimizing AI systems, as the choice of algorithm—often made automatically by libraries like NCCL—has a profound impact on training throughput, especially at scale. Understanding these trade-offs will allow you to reason about performance bottlenecks in distributed workloads.

Ring-AllReduce: A Deeper Analysis

As we saw previously, Ring-AllReduce organizes processors in a logical ring and operates in two phases: a reduce-scatter and an all-gather.

Ring-AllReduce Algorithm Visualization
This diagram provides a step-by-step visualization of the Ring-AllReduce algorithm across four nodes. The **Reduce-Scatter** phase (top) results in each node holding a unique, fully-reduced chunk of the total sum. The **AllGather** phase (bottom) circulates these chunks so that every node reconstructs the final, complete result.

To build a solid foundation, let's start with a textual resource that provides a clear analysis of the algorithm's performance characteristics.

Distributed Data Parallel Training

The following article, 'Distributed Data Parallel Training', clearly breaks down the Ring-AllReduce algorithm. It provides the formula for data transfer and discusses its latency profile.

Please read the sections 'Ring All-Reduce Algorithm' and 'Latency of Ring All-Reduce'. Focus on understanding the two phases (scatter-reduce and all-gather) and the reasoning behind its bandwidth and latency costs.

Let's formalize the insights from that reading. Consider GPUs and a total data size of .

Bandwidth Usage

The algorithm consists of steps. In each step, a chunk of data of size is transferred between adjacent GPUs. The total amount of data a single GPU sends and receives over the entire operation is:

The key insight here is that the total data volume transferred per GPU is approximately , regardless of the number of GPUs, . This makes the algorithm bandwidth-optimal, as it effectively uses the available link bandwidth without creating hotspots.

Latency

While bandwidth usage is excellent, the algorithm's latency is its primary weakness. The operation proceeds in sequential communication steps. The total time () can be modeled as the sum of a latency component (cost per step) and a bandwidth component (time to transfer the data):

Here, is the per-message latency (a fixed cost for initiating communication) and is the bandwidth of the links.

The latency cost, , scales linearly with the number of GPUs, . For training at a very large scale (e.g., thousands of GPUs), this linear scaling becomes a significant bottleneck.

Message Size Sensitivity

The performance of Ring-AllReduce is highly dependent on the size of the message :

  • Large Messages: When is large (e.g., gradients for a large model), the bandwidth term dominates the total time. Since the algorithm is bandwidth-optimal, it performs exceptionally well in this regime.
  • Small Messages: When is small, the latency term dominates. The large number of sequential steps makes the algorithm inefficient for small data transfers.

Tree-Based AllReduce Algorithms

The linear latency scaling of the ring algorithm motivates the search for an alternative. Tree-based algorithms provide a powerful solution.

Distributed Data Parallel Training

The same article also provides an excellent introduction to Tree-AllReduce, explaining its logarithmic latency and its primary limitation.

Now, read the section 'Tree All-Reduce'. Focus on the reduce and broadcast phases and understand why its latency is logarithmic but its bandwidth usage is not optimal.

Let's analyze the simple tree algorithm's performance.

Latency

The tree structure allows for logarithmic scaling. Data is aggregated up the tree to a root node and then broadcast back down.

  • Reduce Phase: Takes steps.
  • Broadcast Phase: Takes steps.

The total time () is:

The latency cost, , scales logarithmically with . This is a dramatic improvement over the ring's linear scaling and is the primary advantage of tree-based approaches, making them ideal for systems with a large number of nodes.

Bandwidth Usage

The simple tree algorithm's weakness is its inefficient use of bandwidth. As the article notes, leaf nodes (which constitute half of all nodes) are idle during one of the two phases—they only send during the reduce phase and only receive during the broadcast phase. This means they only use their network links in a half-duplex manner, leaving half the available bandwidth on the table. The root node also becomes a bottleneck.

The Solution: Double Binary Trees

To overcome the bandwidth limitation of a single tree, high-performance libraries like NCCL implement a Double Binary Tree (or Two-Tree) algorithm.

Tree-based Communication Patterns for Collective Operations
This image from NVIDIA illustrates the construction of two complementary binary trees. A rank that is a leaf in one tree is an internal node in the other. By splitting the data and processing it on both trees simultaneously, the algorithm achieves both logarithmic latency and full bandwidth utilization.

The core idea is to use two trees where the data is split in half. Each half is processed on one of the trees. This design ensures that nearly all nodes are simultaneously sending data on one tree while receiving data on the other, thus utilizing the full-duplex network capacity.

Massively Scale Your Deep Learning Training with NCCL 2.4

This NVIDIA developer blog post introduced the Double Binary Tree algorithm in NCCL 2.4. It explains how this approach achieves the best of both worlds.

Read the introduction and the section 'Double binary trees'. Pay close attention to the statement 'each rank will at most receive half of the data twice and send half of the data twice, which is as optimal as rings'.

The double binary tree algorithm effectively combines:

  • Logarithmic Latency: steps, like the simple tree.
  • Bandwidth Optimality: Total data transfer per GPU is , just like the ring.

This makes it an extremely powerful and versatile algorithm.

Performance in Practice: A Synthesis

We now have a theoretical model for Ring vs. (Double) Tree algorithms.

  • Ring:
  • Tree (Double):

The choice between them hinges on the trade-off between the latency term (dependent on ) and the bandwidth term (dependent on ).

  • For small messages, the term dominates. Since is much smaller than for large , Tree-based algorithms are superior.
  • For large messages, the term dominates. Both algorithms have similar bandwidth costs, so performance is comparable. In practice, the simpler data flow of the Ring algorithm can sometimes give it a slight edge on certain hardware topologies.

This theoretical trade-off is confirmed by empirical benchmarks. The following video from the HOTI symposium presents performance results comparing different NCCL protocols, which are built on these underlying algorithms.

Demystifying NCCL An In depth Analysis of GPU Communication Protocols and Algorithms - Zhiyi Hu

This presentation from the HOTI symposium provides an in-depth analysis of NCCL's performance. The speaker presents benchmark results that directly compare protocols optimized for latency (tree-like) versus those optimized for bandwidth (ring-like).

Watch the section from 16:11 to 17:59. Observe the performance charts. Note how the 'LL' and 'LL128' protocols (which are tree-based and optimized for low latency) excel at small message sizes, while the 'Simple' protocol (which is ring-based) performs best for large messages.

As the video shows, for small messages, tree-based protocols are faster. As message size increases, the bandwidth-optimized ring protocol catches up and eventually surpasses them. This perfectly illustrates the message size sensitivity we analyzed.

Modern libraries like NCCL are aware of these trade-offs and will often dynamically select the optimal algorithm at runtime based on the number of GPUs, the message size, and the network topology it discovers.

Conclusion

In this lesson, we moved beyond the functional role of AllReduce to analyze the performance of its core implementations. You are now equipped to reason about the trade-offs between Ring and Tree-based algorithms, a crucial skill for understanding and optimizing distributed AI systems.

Key Takeaways:

  • Ring-AllReduce: Offers optimal bandwidth utilization ( data transfer per GPU), making it ideal for large messages. However, its latency scales linearly (), limiting its performance at large scale with small messages.
  • Tree-AllReduce: Provides excellent logarithmic latency scaling (), making it superior for workloads with many GPUs and small messages. The simple version underutilizes bandwidth.
  • Double Binary Tree: An advanced algorithm used by NCCL that combines the best of both: logarithmic latency and optimal bandwidth utilization.
  • Message Size is Key: The optimal algorithm choice is a function of message size. Trees excel with small messages where latency dominates, while Rings are competitive or superior for large messages where bandwidth is the bottleneck.

Preview of the Next Lesson:

Having analyzed the primary communication primitive, AllReduce, we will now zoom out to see how it fits into a complete training paradigm. In the first lesson of the next module, "Paradigms of Distributed Training," we will formally describe data parallelism, covering how data is partitioned, how models are replicated, and how frameworks like PyTorch's DistributedDataParallel (DDP) orchestrate the entire process.

Can't find a good explanation? Sign up and we'll make it for you

Sign up