Tree and recursive-doubling collectives
Compare logarithmic step counts with transferred bytes and local reductions under explicit power-of-two and operator assumptions.
On this page
The question for today
What you’ll understand
- Derive a full-array recursive-doubling step count for power-of-two ranks.
- Distinguish full-array exchange from bandwidth-efficient halving/doubling.
- Calculate a small-message comparison without declaring one universal best algorithm.
Not every collective should circulate chunks through a linear number of stages. Tree and recursive algorithms can combine information across exponentially growing participant groups, reducing startup depth. Some do so by exchanging the full tensor repeatedly; others vary message size to control total bytes. Comparing only the number of rounds hides that distinction and can predict the wrong winner for a large training bucket.
Doubling the covered group needs logarithmic rounds
Take p equal to a power of two. In a simple recursive-doubling AllReduce, each rank exchanges its current full-array partial result with a partner whose rank differs in one successive bit. After one round it covers two ranks, after two it covers four, and after log2(p) rounds it covers all participants. Assume a compatible associative and commutative reduction for this simple schedule. Each exchange can reduce received values locally. The protocol's valid ordering for a noncommutative operation needs additional care rather than relying on a rank-bit diagram.
A full-array exchange sends n bytes each round, so logarithmic startup does not imply a single-tensor byte volume. A simple tree reduce followed by broadcast has a different two-phase critical path, with its own fan-in, fan-out, and contention assumptions. Real libraries can use double trees, pipelining, multiple channels, and hardware assistance. The teaching equations compare specific idealized algorithms. They are not a statement that every operation named tree has the same traffic or that one generic tree formula describes current NCCL on every architecture.
Halving and doubling can reduce total bytes
A recursive-halving reduce-scatter exchanges successively smaller relevant portions, leaving each rank with its reduced shard. A reverse allgather doubles the available reduced data until every rank has the full result. For equal datatype-aligned partitions and a power-of-two group, each phase has logarithmic steps and aggregate per-rank send volume n(1−1/p). This achieves a different latency-bandwidth balance from full-array recursive doubling. It requires suitable element partitioning and operator support; non-power-of-two sizes need an explicitly described extension or another algorithm.
Local reduction work still matters and can be represented by an additional seconds-per-byte or seconds-per-element term in a richer model. GPU kernels can also contend for memory bandwidth while network transfers occur. Keeping those terms separate helps identify when an apparently better network schedule loses in practice. The original collective-optimization literature analyzes multiple message sizes and participant counts precisely because the best choice changes with the regime. Record what assumptions hold before using a model crossover to tune a real job.
Small messages reveal startup differences
For a small tensor, the transfer term may be much smaller than a few additional startup rounds. A scalar synchronization can therefore behave differently from a hundred-megabyte gradient bucket. For a large tensor, repeated full-array exchanges can dominate despite a low round count. Validate several representative payloads and datatype choices instead of carrying a single microbenchmark result into every layer of a model. An autotuned implementation may already choose different algorithms across those sizes, so a manual override can improve one point and worsen the rest.
The modular lab illustrates the rank-bit partner progression as a separate arithmetic exercise. Reset, set both m=8 and a=1, predict all eight residues appear in one additive orbit, then Play or Step. Separately Reset, set both m=8 and a=4, predict period two, then Play or Step. This is addition modulo eight, not the XOR partner schedule used by recursive doubling and not a tree simulation. State that difference explicitly: arithmetic coverage can be inspected here, but the logarithmic communication argument must come from the actual partner protocol described above.
Work it through
A small tensor favors fewer modeled startups
Use eight power-of-two ranks, a 4 KiB full input tensor per rank, alpha=5 μs, and hypothetical bandwidth B=10 GiB/s with beta=1/B. Ignore reduction, protocol, and topology costs.
The transfer time for one full array is 4,096/(10×1,073,741,824) s≈0.38147 μs. Recursive doubling has three rounds, giving 3×(5+0.38147)≈16.1444 μs.
The simple ring has fourteen startup steps and a transfer factor of 1.75. Its model gives 14×5+1.75×0.38147≈70.6676 μs.
The halving/doubling model has six startups and the same 1.75 transfer factor, giving 30+0.6676≈30.6676 μs. These hypothetical results compare the specified schedules; actual implementation selection and local costs can change the measured ranking.
A logarithmic-round algorithm can win for small messages without being the best full-array schedule for every larger payload or rank topology.
The living notebook
Explore the model
Interactive lab · modular
Do not confuse additive orbits with XOR partners
Reset, set both m=8 and a=1, predict period eight, then Play or Step. Separately Reset, set both m=8 and a=4, predict period two, then Play or Step. This additive modular orbit is explicitly not recursive doubling's XOR schedule, a tree, or a collective-cost simulator.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA useful analogy must preserve its boundary; logarithmic collective rounds require the actual partner-exchange argument.
Pause & reason
Check your understanding
Your turn
Try it yourself
With sixteen ranks, how many full-array recursive-doubling rounds are required under the power-of-two model? For an 8 MiB tensor, how many MiB does each rank send across those rounds?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute log2(16), then multiply by the full-array size.
Compare with the solution
There are four rounds and each rank sends 4×8=32 MiB in the stated full-array exchange model. This is send-only endpoint volume, not send-plus-receive or physical link-hop bytes. A bandwidth-efficient halving/doubling implementation has a different volume, and actual reduction or protocol costs remain outside this count.
Keep the idea
Take it with you
- Logarithmic rounds and bandwidth efficiency are distinct properties.
- State power-of-two, partitioning, and reduction-operator assumptions.
- Compare a payload range and actual selected algorithms rather than one universal operator name.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.