AI Compass
Compass

Distributed training

When a model does not fit one card: data, tensor and pipeline parallelism, their communication costs, and which split applies when.

·2 min read·By Fachredaktion Technik
DETAIL
3 sections

The idea

Training a large model on many cards is like a building project with many teams. The work can be split three ways: every team builds its own house to the same plan, or all build one house and share the walls, or each team takes one storey.

Each split has different coordination costs, and coordination is the bottleneck.

The three axes

AxisWhat is splitCommunication
Data parallelismDifferent examples per cardGradients after every step
Tensor parallelismOne layer across several cardsAfter every layer
Pipeline parallelismDifferent layers per cardActivations between stages

Which split when

  1. 01

    Everything fits one card

    Plain data parallelism. Simple, robust, scales to the communication limit.

  2. 02

    Optimiser states are too large

    ZeRO stages 1 to 3 or FSDP. States are sharded and gathered on demand.

  3. 03

    A single layer no longer fits

    Tensor parallelism, strictly within one node with a fast interconnect. Across node boundaries it destroys throughput.

  4. 04

    Very many layers

    Pipeline parallelism with micro-batches to keep idle time small.

Communication cost

All-reduce of the gradients

volume per card = 2 · N · b · (p − 1)/p ≈ 2 · N · b

With ring all-reduce each card sends roughly twice the parameter volume, independent of card count.

N
number of parameters
b
bytes per gradient
p
number of cards

For a 7-billion-parameter model in bfloat16 that is around 28 GB per card per step. Over a 400 GB/s link the exchange takes about 70 milliseconds. If a training step itself takes 200 milliseconds, 26 percent of the time is lost to communication, unless it is overlapped with the backward pass, which modern libraries do.

The pipeline bubble

Bubble efficiency

idle share = (s − 1) / (m + s − 1)

The share of lost time falls the more micro-batches are pushed through the pipeline.

s
number of pipeline stages
m
number of micro-batches per step

With 8 stages and 8 micro-batches, 7/15 = 46.7 percent is lost. With 64 micro-batches only 7/71 = 9.9 percent. That is why pipeline parallelism always runs with a large number of small micro-batches, and why it does not work with small overall batches.

Memory per card under ZeRO

StageWhat is shardedMemory per card with p cards
0nothing16 · N bytes
1optimiser states4 · N + 12 · N / p
2plus gradients2 · N + 14 · N / p
3plus parameters16 · N / p

At N = 7e9 and 8 cards that is 112 GB per card unsharded and 14 GB per card at stage 3: the difference between impossible and feasible. The price is extra communication, because parameters are gathered before each layer and discarded after.

Reproducibility

A distributed run is not bit-reproducible even with a fixed seed, because the order of gradient summation depends on network timing. For evidence purposes that means: the run is not what gets attested, the result is. Model checksum, dataset version, configuration and metrics belong in the log. See Logging.

Related courses and sources

CourseFreeEN

PyTorch tutorials

The official guides, from a first tensor operation to distributed training. Short, runnable and continuously updated.

For getting into the library most research is written in.

Was this page helpful?
Distributed training