What is distributed training in deep learning?
Distributed training is training one neural network on many GPUs at once by splitting the work between them. Data parallelism splits the batch, tensor parallelism splits each matrix multiply, and pipeline parallelism splits the stack of layers. Sharding methods such as ZeRO split the training state itself, so no single GPU has to hold all of it.
Every large language model is trained this way, because both the memory and the compute exceed one accelerator. Llama 2, GPT-3, and similar models ran on thousands of GPUs at once, usually with tensor parallelism inside each 8-GPU server, pipeline parallelism across servers, and data parallelism on top. The same tools, such as PyTorch FSDP, DeepSpeed, and Megatron-LM, also make fine-tuning a 7B model practical on a handful of GPUs.
Key ideas
- Training a 7B model with Adam in mixed precision needs about 108 GB of weights, gradients, and optimizer state, more than one 80 GB GPU.
- Data parallelism copies the model to every GPU and all-reduces the gradients, which speeds up compute but saves no memory.
- ZeRO shards optimizer states, then gradients, then weights across data-parallel GPUs, cutting per-GPU memory by up to N times.
- Tensor parallelism splits each layer's matrices and needs all-reduces inside every layer, so it stays within one fast-linked node.
- Pipeline parallelism assigns layers to stages and leaves an idle bubble of (p − 1)/(m + p − 1) of each step.
- Large runs combine all three, with the total GPU count equal to the tensor, pipeline, and data-parallel degrees multiplied together.
Common questions
What is the difference between data parallelism and model parallelism?
Data parallelism gives every GPU the whole model and a different slice of the batch. Model parallelism splits the model itself, either within layers (tensor parallelism) or between layers (pipeline parallelism), so each GPU holds only part of the weights. Data parallelism is simpler and is tried first, and model parallelism is added when the model or its state no longer fits.
Is FSDP the same as ZeRO?
PyTorch Fully Sharded Data Parallel implements the same idea as ZeRO stage 3. Each GPU keeps a shard of the weights, gradients, and optimizer state and gathers full layers just before using them. Its sharding strategies also include a mode that matches ZeRO-2, keeping full weights but sharding gradients and optimizer state.
Does a larger global batch change training results?
Yes, it can. More data-parallel GPUs at the same per-GPU batch raise the global batch, which lowers gradient noise and usually needs a retuned learning rate and warmup. Past a model-dependent critical batch size, extra data per step gives little extra progress, so adding GPUs stops shortening training.
How many GPUs does it take to fine-tune a 7B model?
Full fine-tuning with Adam needs about 108 GB of state plus activations, so it typically runs on 2 to 8 80 GB GPUs with ZeRO or FSDP sharding. Parameter-efficient methods such as LoRA freeze the base weights and train small adapters, which brings the memory close to the 13.5 GB of fp16 weights. With 4-bit base weights (QLoRA), a single 24 GB GPU is often enough.
Related explainers
- Epochs & Batching — How data is fed to the model in epochs, batches, and shuffles
- Optimizers — SGD, momentum, and Adam — smarter gradient descent
- The Transformer Architecture — A visual guide to 'Attention Is All You Need'
- LoRA & Parameter-Efficient Fine-Tuning — Adapt large models by training tiny low-rank matrices instead of all the weights
- Quantization — Shrinking model weights to 8 and 4 bits
- Mixture of Experts — Routing each token to a few experts in a much larger model
- Mixed Precision Training — Training in 16-bit without losing small gradients
References
- Rajbhandari et al. (2019), "ZeRO: Memory Optimizations Toward Training Trillion Parameter Models"
- Shoeybi et al. (2019), "Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism"
- Huang et al. (2018), "GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism"
- Narayanan et al. (2021), "Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LM"
Last updated