Topic 37 of 62 · Training at scale
Collectives and their communication cost
HardWhich collective does each parallelism strategy use, and how do you estimate its time?
1 · Start with the intuition
Distributed training is a few communication patterns repeated millions of times. Data parallelism averages gradients with all-reduce. Sharded training splits that into reduce-scatter and all-gather. Tensor parallelism all-reduces or all-gathers activations inside every layer. Mixture-of-experts shuffles tokens with all-to-all. Estimating time means counting bytes and dividing by the bandwidth of the slowest link they cross.
2 · How the mechanism works
Mechanism step 1 of 3 · no question to answer
Name the collective
all-reduce, reduce-scatter, all-gather, all-to-all, broadcast, or point-to-point send/recv.
Next, we will look at: Count the bytes. Move on when this operation makes sense.
Visualizing the behavior
What each collective leaves on 4 ranks
Same 2 GB all-reduce, different link speeds (bandwidth term only)
Derived3 · The governing equation
T ≈ steps · α + bytes_per_rank / β Ring all-reduce: 2(N − 1)/N · S per rank Reduce-scatter or all-gather: (N − 1)/N · S per rank
Notation: α is per-message latency, β the achievable per-rank bandwidth, S the buffer size, N ranks. NCCL reports "bus bandwidth" normalized so it can be compared with link speed.
Bandwidth cost per rank for all-reduce is almost independent of N, but latency terms grow with N and real clusters have hierarchy, so crossing nodes is what hurts. That is why tensor parallelism, which communicates in every layer on the critical path, is kept inside a node, while data-parallel gradient traffic can cross nodes and overlap with backward. All-to-all for MoE is harder: every rank sends different data to every other rank, the volumes depend on routing, and imbalance makes the slowest rank set the pace.
4 · Put concrete numbers on it
Worked numbers (from stated assumptions)5 · Common misconception to avoid
“All-reduce time grows linearly with the number of GPUs.” Ring bandwidth cost per rank approaches 2S; what grows is latency and the chance of crossing slower links or stragglers.
In practice · implementation & engineering rule of thumb
Run nccl-tests (all_reduce_perf) on your cluster before training to measure real bus bandwidth; a single degraded NIC or bad cable will bottleneck the entire ring collective.
# Estimate ring all-reduce time from payload S (bytes) and effective bus bandwidth:
def ring_allreduce_sec(payload_bytes, num_ranks, bus_bw_bytes_per_sec):
bytes_per_rank = 2.0 * ((num_ranks - 1) / num_ranks) * payload_bytes
return bytes_per_rank / bus_bw_bytes_per_secGo one level deeper
Follow-ups that often come after a correct first answer.
- Why tensor parallelism stays inside a node
- Megatron-style TP needs two all-reduces per layer in forward (attention and MLP) and two in backward, on the critical path with activation-sized buffers. Over slower inter-node links those stalls cannot be hidden, so TP degree is usually capped at the GPUs in one NVLink domain.
- Overlapping communication with compute
- DDP buckets gradients and all-reduces each bucket during backward; FSDP prefetches the next layer’s all-gather during the current layer’s compute. Overlap only works if there is enough compute per byte, which is one reason tiny per-GPU batches scale poorly.
6 · Self-check & interview synthesis
Explain it in your own words first
Before revealing the reference answer, try answering the opening question aloud in four beats: what it is → how the math works → what trade-off it makes → a concrete number or failure mode.
Follow-up question interviewers often ask next
MediumHow do large MoE systems keep all-to-all from crossing too many nodes?
Show follow-up reasoning
They constrain routing by topology. DeepSeek-V3, for example, limits each token to experts on at most 4 nodes, and systems often place expert parallelism within fast domains and overlap dispatch with computation.