Distributed Training: 3D Parallelism and Scaling Efficiency
Discover why 1024 GPUs rarely deliver 1024× speedup, and how to minimize the gap.
NoteBackground: Why distributed training is needed
Some models are too large to fit in a single GPU’s memory, and some training jobs would take months on one GPU. Distributed training splits the work across many GPUs. This tutorial explores the three main ways to split work and the overhead each one introduces. Complete Hello, Roofline and Two Phases, One Request before this one.
Scaling a training job from 1 GPU to 1024 GPUs incurs overhead at every step. Communication, pipeline stalls, and coordination each chip away at theoretical speedup. Understanding where that efficiency goes, and how to recover it, is what separates a well-tuned distributed training job from an expensive waste of cluster time.
This tutorial explains:
How Data Parallelism, Tensor Parallelism, and Pipeline Parallelism decompose work across GPUs
Why synchronization (ring all-reduce) overhead depends on model size and network bandwidth
from mlsysim.solvers import DistributedModel# Llama-3.1-70B: the model requires distributed training — too large for a single GPUmodel = mlsysim.Models.Language.Llama3_70B# A research-scale cluster: 32 DGX A100 nodes × 8 GPUs = 256 A100s# (DGX is NVIDIA's pre-built server containing 8 GPUs connected via NVLink)cluster = mlsysim.Systems.Clusters.Research_256print(f"Model: {model.name} ({model.parameters.to('Gparam').magnitude:.1f}B params)")print(f"Cluster: {cluster.name}")print(f" Nodes: {cluster.count} × {cluster.node.accelerators_per_node} GPUs/node")print(f" Total: {cluster.total_accelerators} accelerators")print(f" Fabric: {cluster.fabric.name} @ {cluster.fabric.bandwidth.to('GB/s').magnitude:.1f} GB/s/link")
Before working through the numbers, consider how 3D parallelism decomposes a training job across a cluster (80 layers across 256 GPUs). Each dimension splits work differently and introduces a different type of overhead:
Data Parallelism (DP=4). Each GPU holds a full model copy and processes 1/4 of the batch. After the backward pass, gradients are synchronized via All-Reduce.
Pipeline Parallelism: partition layers across stages, activations flow forward.
DP uses inter-node bandwidth (network fabric), TP uses intra-node bandwidth (NVLink), and PP introduces idle time (pipeline bubbles). The optimal configuration balances all three overheads.
3. Baseline: Pure Data Parallelism
Start with the simplest configuration: no model splitting, only the full model replicated on every GPU and the batch split across them. The per-GPU compute time is determined by the same roofline model used in Hello, Roofline. The new element here is communication overhead: after each training step, all GPUs must synchronize their gradients via the network before the next step can begin.
Single-GPU compute time: 2516.5 ms/step
DP all-reduce overhead: 3287.97 ms
Pipeline bubble: 0.00 ms
Total step latency: 5804.4 ms
Scaling efficiency: 43.4%
Effective throughput: 44 samples/s
Parallelism: DP=256 TP=1 PP=1
NoteWhat scaling efficiency means
At a scaling efficiency of 43.4%, a 256-GPU cluster delivers the equivalent of about 111 fully utilized GPUs. The remaining 145 GPUs worth of compute goes to communication overhead (3288.0 ms of ring all-reduce out of every 5804.4 ms step). This is the communication tax of distributed training.
The tax is paid in ring all-reduce: after the backward pass, every GPU must synchronize gradients with every other GPU. The time to do this grows with model size and shrinks with network bandwidth.
4. Ring All-Reduce: The Network Tax
The DP all-reduce overhead comes from the ring all-reduce algorithm, which is the standard method for gradient synchronization.
Fabric BW (GB/s) Comm overhead Efficiency
----------------------------------------------------
100GbE 12.5 GB / s 3287.97 ms 43.4%
IB HDR 25.0 GB / s 1917.43 ms 56.8%
IB NDR 50.0 GB / s 1233.37 ms 67.1%
Upgrading from 100GbE (12.5 GB / s) to InfiniBand NDR (50 GB / s) increases inter-node link bandwidth by 4×. On Llama-3.1-70B (141.2 GB of FP16 gradients per step), that upgrade cuts DP communication latency from 3288 ms to 1233 ms and lifts scaling efficiency from 43.4% to 67.1%. For smaller models, it matters less, because compute time dominates.
5. Pipeline Parallelism and the Bubble
Pipeline Parallelism splits the model’s layers across multiple nodes. Node 1 runs layers 1–20, node 2 runs layers 21–40, etc. This allows a much larger model to be trained than fits on a single node.
The downside: a pipeline bubble. The first microbatch must flow through all stages before the last stage can start processing the second microbatch. During that startup phase, most GPUs are idle.
print(f"{'PP stages':>10}{'Microbatches':>13}{'Bubble %':>9}{'Comm (ms)':>10}{'Efficiency':>11}")print("-"*60)for pp_size in [1, 2, 4, 8]:for m in [1, 4, 16]:# Only show interesting combinationsif pp_size ==1and m >1:continue r = solver.solve( model=model, fleet=cluster, batch_size=256, precision="fp16", tp_size=1, pp_size=pp_size, microbatch_count=m ) bubble_pct = r.bubble_fraction *100print(f"{pp_size:>10} "f"{m:>13} "f"{bubble_pct:>9.1f}% "f"{r.pipeline_bubble_latency.to('ms'):>10.1f~} "f"{r.scaling_efficiency:>11.1%}" )
PP stages Microbatches Bubble % Comm (ms) Efficiency
------------------------------------------------------------
1 1 0.0% 0.0 ms 43.4%
2 1 50.0% 1754.4 ms 27.1%
2 4 20.0% 438.6 ms 34.0%
2 16 5.9% 109.6 ms 36.3%
4 1 75.0% 5263.1 ms 17.8%
4 4 42.9% 1315.8 ms 29.8%
4 16 15.8% 328.9 ms 35.8%
8 1 87.5% 12280.6 ms 10.5%
8 4 63.6% 3070.2 ms 23.2%
8 16 30.4% 767.5 ms 33.3%
TipRecovering bubble efficiency
Increasing the number of microbatches (\(M\)) reduces the bubble fraction. With \(M = 16\) and \(P = 8\), the bubble is only \(7/(7+16) = 30\.4%\) of the pipeline, down from \(87\.5%\) with \(M = 1\).
In practice, frameworks like Megatron-LM use interleaved pipeline schedules that further reduce the bubble. Even with the standard 1F1B schedule, however, choosing \(M \gg P\) is essential.
6. Finding the Optimal Configuration
Now combine all three parallelism strategies and find the configuration that maximizes scaling efficiency for the Research_256 cluster (256 GPUs over 100GbE).
Confining TP=8 within each 8-GPU node over NVLink (450 GB / s) and pairing PP=4 (\(M=16\)) with DP=8 raises scaling efficiency from 43.4% (44.1 samples/s) under pure DP to 57.8% (84.3 samples/s)—both fitting the model shards inside per-GPU HBM and shrinking the cross-node DP gradient payload by \(8 \times 4 = 32\times\).
Advanced: Network Topologies
The same communication equations can be used to compare topology assumptions. A ring collective is bandwidth-optimal for large gradient buffers, while tree-style collectives reduce startup latency for smaller messages. In practice, topology choice matters because the fabric determines which term dominates: link bandwidth, oversubscription, or per-hop latency.
For this release, the built-in DistributedModel exposes the core ring and hierarchical all-reduce model. Use the lower-level formulas in mlsysim.physics to compare algorithmic assumptions directly.