Estimate per-step communication for DP, ZeRO and TP
Why it matters Choosing between DDP, FSDP and tensor parallel on a cluster starts with this estimate.
Different parallelism strategies move different amounts of data per training step.
Write comm_bytes(params, n, mode, bytes_per=2, tokens=0, hidden=0, layers=0). For n GPUs, ring collectives send a fraction 2 (n - 1) / n of the data for all-reduce and (n - 1) / n for reduce-scatter or all-gather. Return bytes sent per GPU: mode "dp": all-reduce of params gradients; mode "zero3": reduce-scatter of gradients plus two all-gathers of params (forward and backward); mode "tp": 4 all-reduces per layer of a tokens x hidden activation.
def comm_bytes(params, n, mode, bytes_per=2, tokens=0, hidden=0, layers=0)Example
comm_bytes(1e9, 8, "dp") is 2 * 7 / 8 * 1e9 * 2 = 3.5e9.
Understand the idea
Each parallel training strategy sends different data between GPUs every step. With ring collectives over n GPUs, an all-reduce sends 2 (n - 1) / n times the data size per GPU, and a reduce-scatter or all-gather sends (n - 1) / n. Data parallel all-reduces the gradients. ZeRO-3 reduce-scatters gradients and all-gathers parameters twice (forward and backward), so it costs 1.5 times data parallel. Tensor parallel all-reduces activations, 4 times per layer. Worked example: 2e9 parameters at 2 bytes = 4e9 bytes, n = 4. DP: 2 * 3/4 * 4e9 = 6e9 bytes. ZeRO-3: 3/4 * 4e9 for the reduce-scatter plus 2 * 3/4 * 4e9 for the gathers = 3e9 + 6e9 = 9e9. TP with 4096 tokens, hidden 4096, 2 layers: one activation is 4096 * 4096 * 2 = 33,554,432 bytes; each all-reduce sends 1.5 times that; times 4 per layer and 2 layers gives 402,653,184 bytes. Rule: data = params * bytes_per for dp and zero3, tokens * hidden * bytes_per for tp; apply the ring factors above. Used in: choosing a parallelism layout for LLM training.