GPUs and Model AccelerationAn interactive learning journey
On this page

    Module 5 of 6

    Multi-GPU training: share the load

    Sometimes one bag isn't enough. The model doesn't fit, or training would take months. Then we split the work, and the art is choosing what to split.

    Ben thinking

    If I give my friends part of the load, they have to talk to each other. So every strategy trades memory or time for communication.

    StrategyWhat is splitEach GPU holdsTalks whenUse it when
    DataThe batchA full copy of the modelAfter every step (gradients)The model fits; training is too slow
    ZeRO / FSDPOptimizer states, gradients, weightsA slice of the training stateEvery step, gathering slicesTraining state doesn't fit
    TensorEach layer's matricesPart of every layerInside every layerLayers are huge; GPUs share fast NVLink
    PipelineThe layersA stage of consecutive layersBetween stages (activations)The model is deep and spans machines

    1. Data parallelism

    Every GPU gets a full copy of the model and a different slice of the batch. After the backward pass, the GPUs average their gradients with an all-reduce, so every copy takes the same update.

    Ring all-reduce

    Interactive
    Gradient size (bfloat16)
    Each GPU sends and receives per step
    Time per step over NVLink (900 GB/s)
    Data per GPU=2G−1G×M
    2 reduce-scatter, then all-gatherG GPUsM gradient size in bytes

    The volume per GPU barely changes as you add GPUs: it approaches 2M. But every step must wait for it, which is why 8 GPUs rarely give 8× the speed.

    2. ZeRO and FSDP: stop storing copies

    Plain data parallelism stores the full training state on every GPU. With mixed-precision Adam that is about 16 bytes per parameter: 2 for bfloat16 weights, 2 for gradients and 12 for float32 master weights and Adam's two states. ZeRO shards this state across GPUs instead.

    Memory per GPU with ZeRO

    Interactive

    Stage 1 shards optimizer states, stage 2 adds gradients, stage 3 (like PyTorch FSDP) adds the weights. Activations are extra.

    MemoryZeRO-3≈16×ΨG
    16 bytes per parameter of training stateΨ parametersG GPUs sharing it

    3. Tensor parallelism: split each layer

    A single matrix multiplication is split across GPUs. In a transformer MLP, the first weight matrix is split by columns and the second by rows, so each GPU computes its half end to end and the GPUs only need one all-reduce at the end of the block.

    GPU 1
    × = → MLP × = partial sum
    GPU 2
    × = → MLP × = partial sum
    All-reduce: add the two partial sums → the same output as one big GPU

    The input X (grey) is copied to both GPUs. The first weight matrix is split by columns (green on GPU 1, orange on GPU 2), the second by rows, so each GPU finishes its half before one all-reduce.

    Because GPUs talk inside every layer, tensor parallelism needs very fast links. It is usually kept within one machine, where GPUs share NVLink at around 900 GB/s, rather than across machines on a network that is often 10 to 20 times slower.

    4. Pipeline parallelism: split the layers

    Consecutive layers become stages on different GPUs, like an assembly line. To keep everyone busy, the batch is cut into micro-batches. The idle gaps at the start and end are called the bubble.

    Pipeline schedule

    Interactive
    F forwardB backwardhatched: idle bubble
    Bubble fraction=p−1m+p−1
    p pipeline stagesm micro-batches

    Putting it together: 3D parallelism

    The largest models combine all three: tensor parallelism inside each machine, pipeline parallelism across machines, and data parallelism across copies of the whole setup. The design goal is always the same: keep the chattiest communication on the fastest links.

    Which strategy fits?

    Quick check

    1. A 1B model fits on one GPU, but training would take 6 months.

    2. A 70B model: you put layers 1 to 40 on GPU 1 and layers 41 to 80 on GPU 2.

    3. Each layer's matrix multiplication is split across the 8 GPUs inside one machine.

    More GPUs means more communication. Choose the strategy that splits what is too big, and keep the talking on the fastest links.