Skip to main content

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:

Tip3D Parallelism at a Glance

Modern distributed training uses three orthogonal strategies simultaneously:

Strategy What it splits Main overhead
Data Parallelism (DP) Batch across GPUs All-reduce gradients after backward pass
Tensor Parallelism (TP) Individual matrix ops within a layer All-gather within each forward/backward
Pipeline Parallelism (PP) Layer groups across nodes Pipeline bubble at start/end of batch

The product \(\text{DP} \times \text{TP} \times \text{PP} = \text{total GPUs}\).


1. Setup

import mlsysim
from mlsysim.solvers import DistributedModel
from mlsysim.solvers import DistributedModel

# Llama-3.1-70B: the model requires distributed training — too large for a single GPU
model = 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_256

print(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")
Model:   Llama-3.1-70B  (70.6B params)
Cluster: Research Cluster (256 GPUs)
  Nodes: 32  ×  8 GPUs/node
  Total: 256 accelerators
  Fabric: 100GbE @ 12.5 GB/s/link

2. Visualizing 3D Parallelism

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.

flowchart LR
    R1["Replica 1<br/>Batch 1/4"] <-.->|"All-Reduce"| R2["Replica 2<br/>Batch 2/4"]
    R2 <-.->|"All-Reduce"| R3["Replica 3<br/>Batch 3/4"]
    R3 <-.->|"All-Reduce"| R4["Replica 4<br/>Batch 4/4"]

Data Parallelism: replicate the model, split the batch, synchronize gradients.

Tensor Parallelism (TP=2). Each layer is split across GPUs, which requires a fast interconnect (NVLink).

flowchart LR
    G1["GPU 0<br/>Left half of each layer"] <-->|"All-Gather<br/>(NVLink)"| G2["GPU 1<br/>Right half of each layer"]

Tensor Parallelism: split each layer across GPUs, communicate via NVLink.

Pipeline Parallelism (PP=4). Model layers are partitioned across stages. Activations flow forward; gradients flow backward.

flowchart LR
    S1["Stage 1<br/>Layers 1–20"] --> S2["Stage 2<br/>Layers 21–40"]
    S2 --> S3["Stage 3<br/>Layers 41–60"]
    S3 --> S4["Stage 4<br/>Layers 61–80"]

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.

solver = DistributedModel()

result_dp = solver.solve(
    model=model,
    fleet=cluster,
    batch_size=256,
    precision="fp16",
    tp_size=1,   # no tensor parallelism
    pp_size=1,   # no pipeline parallelism
)

node_perf = result_dp.node_profile
print(f"Single-GPU compute time:     {node_perf.latency.to('ms'):~.1f}/step")
print(f"DP all-reduce overhead:      {result_dp.dp_communication_latency.to('ms'):~.2f}")
print(f"Pipeline bubble:             {result_dp.pipeline_bubble_latency.to('ms'):~.2f}")
print(f"")
print(f"Total step latency:          {result_dp.step_latency_total.to('ms'):~.1f}")
print(f"Scaling efficiency:          {result_dp.scaling_efficiency:.1%}")
print(f"Effective throughput:        {result_dp.effective_throughput.magnitude:.0f} samples/s")
print(f"Parallelism:                 DP={result_dp.parallelism['dp']}  TP={result_dp.parallelism['tp']}  PP={result_dp.parallelism['pp']}")
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.

Note🧮 See the Math

For the full equation deriving All-Reduce overhead from model size, node count, and fabric bandwidth, see the Mathematical Foundations: Ring All-Reduce.

The following sweep shows how fabric bandwidth affects overhead:

from mlsysim import Systems
from mlsysim.systems.types import Fleet, NetworkFabric

fabrics = [
    ("100GbE",      Systems.Fabrics.Ethernet_100G),
    ("IB HDR",      Systems.Fabrics.InfiniBand_HDR),
    ("IB NDR",      Systems.Fabrics.InfiniBand_NDR),
]

print(f"{'Fabric':>10}  {'BW (GB/s)':>10}  {'Comm overhead':>14}  {'Efficiency':>11}")
print("-" * 52)

for fab_name, fabric in fabrics:
    custom_cluster = Fleet(
        name="Custom",
        node=Systems.Nodes.DGX_H100,
        count=32,
        fabric=fabric
    )
    r = solver.solve(
        model=model,
        fleet=custom_cluster,
        batch_size=256,
        precision="fp16"
    )
    print(
        f"{fab_name:>10}  "
        f"{fabric.bandwidth.to('GB/s'):>10.1f~}  "
        f"{r.dp_communication_latency.to('ms'):>14.2f~}  "
        f"{r.scaling_efficiency:>11.1%}"
    )
    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%
WarningFabric choice determines scaling efficiency

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.

Note🧮 See the Math

For the full equation governing pipeline bubbles and interleaved 1F1B schedules, see the Mathematical Foundations: Pipeline Parallelism Bubble.

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 combinations
        if pp_size == 1 and 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 * 100
        print(
            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).

configs = [
    # (description,             tp, pp, m)
    ("DP only",                  1,  1,  1),
    ("DP + TP=2",                2,  1,  1),
    ("DP + PP=4, M=16",          1,  4, 16),
    ("DP + TP=2 + PP=4, M=16",   2,  4, 16),
    ("DP + TP=8 + PP=4, M=16",   8,  4, 16),
]

print(f"{'Config':<26}  {'DP':>4} {'TP':>4} {'PP':>4}  {'Fits HBM':>8}  {'Efficiency':>11}  {'Throughput':>14}")
print("-" * 82)

for desc, tp, pp, m in configs:
    r = solver.solve(
        model=model,
        fleet=cluster,
        batch_size=256,
        precision="fp16",
        tp_size=tp,
        pp_size=pp,
        microbatch_count=m
    )
    fits = "YES" if r.node_profile.feasible else "Spill"
    print(
        f"{desc:<26}  "
        f"{r.parallelism['dp']:>4}  "
        f"{r.parallelism['tp']:>4}  "
        f"{r.parallelism['pp']:>4}  "
        f"{fits:>8}  "
        f"{r.scaling_efficiency:>11.1%}  "
        f"{r.effective_throughput.magnitude:>14.1f}"
    )
Config                        DP   TP   PP  Fits HBM   Efficiency      Throughput
----------------------------------------------------------------------------------
DP only                      256     1     1     Spill        43.4%            44.1
DP + TP=2                    128     2     1     Spill        36.7%            53.6
DP + PP=4, M=16               64     1     4     Spill        35.8%            52.2
DP + TP=2 + PP=4, M=16        32     2     4     Spill        36.0%            52.6
DP + TP=8 + PP=4, M=16         8     8     4       YES        57.8%            84.3

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.


Where This Clicks in the Textbook

Vol II · Ch 5Collectives

Derives alpha-beta latency and bandwidth bounds for Ring AllReduce, Tree AllReduce, ReduceScatter, and All-to-All.

Vol II · Ch 64D Parallelism

Composes DP, TP, PP (1F1B bubbles), ZeRO sharding, and Expert Parallelism across cluster hierarchies.

Vol II · Ch 3Fabrics

Explains NVLink vs. InfiniBand/RoCE hierarchies, fat-tree bisection bandwidth, and oversubscription.

Next Steps

  • Two Phases, One Request: After training, learn how to model the serving cost of the same model
  • Math Foundations: Full derivations for ring all-reduce, pipeline bubble, and MFU
  • Fleet Zoo: Browse the available cluster configurations and their network specs
Back to top