Topic 4 of 6 · 6 min read
Data, tensor and pipeline parallelism
Goal: Choose a parallelism strategy for a stated model size and GPU count and explain its communication cost.
Pick the simplest parallelism that makes the model fit, because every extra form of splitting adds communication between GPUs.
Check yourself · 1 of 3
When does plain data parallel (DDP) work as the parallelism choice?
Why it matters
Adding GPUs does not automatically make a run faster. GPUs must exchange gradients, weights or activations, and the link between them (NVLink inside a server, Ethernet or InfiniBand between servers) can become the bottleneck. A wrong strategy leaves expensive GPUs waiting.
The options
- Data parallel (DDP). Every GPU holds a full copy of the model, trains on different data, and averages gradients. Simple and fast. It only works if the whole model, gradients and optimizer state fit on one GPU.
- Sharded data parallel (FSDP, ZeRO). Still data parallel, but parameters, gradients and optimizer state are split across GPUs and gathered when a layer needs them. The ZeRO paper describes stages 1, 2 and 3 that shard optimizer state, then gradients, then parameters. Memory per GPU falls roughly with the GPU count, at the cost of more communication.
- Tensor parallel. Each layer's matrices are split across GPUs, which must exchange results several times per layer. It needs fast links, so it normally stays inside one server.
- Pipeline parallel. Groups of layers sit on different GPUs and micro-batches flow through. Communication is light, but GPUs sit idle in "bubbles" unless many micro-batches are in flight.
How to choose
- Model, gradients and optimizer state fit on one GPU: use DDP.
- They do not fit, but the weights do: use FSDP or ZeRO-2 or 3 within one server.
- Weights alone do not fit on a server, or sequences are very long: combine tensor parallel inside a server with pipeline or data parallel across servers.
accelerate launch --num_processes 8 --use_fsdp train.py
Before and after
Weak: "We have 8 GPUs, so we will use pipeline parallel for a 7B LoRA run." The model already fits on one card, so splitting it only adds idle time. Fixed: DDP across the 8 GPUs, which adds almost no memory pressure and scales near-linearly on a single server.
What goes wrong
- Sharding when you do not need to. FSDP on a model that fits adds communication for no gain.
- Tensor parallel across slow links. Spanning servers over Ethernet can make throughput worse than using fewer GPUs.
- Mismatched world size. Batch size, accumulation and learning rate all depend on the GPU count, so changing it changes the recipe.
Examples
Choosing for three setups
| Model and hardware | Choice | Why |
|---|---|---|
| 7B LoRA, 8 GPUs, one server | DDP | Base weights and adapters fit on each GPU |
| 13B full fine-tune, 8 x 80 GB, one server | FSDP | About 208 GB of state is sharded to about 26 GB per GPU |
| 70B+ pretraining, many servers | Tensor inside servers, data or pipeline across | Weights alone exceed a server's memory |
Throughput drops at 16 GPUs
A run scales well to 8 GPUs, then slows when it spans two servers on Ethernet. The sharded all-gather per layer now crosses a slow link. Options: keep sharding inside each server and use plain data parallel across servers (hybrid sharding), or use a faster network.
Key points
- Use DDP when the full model and optimizer state fit on each GPU, because it has the least overhead.
- FSDP and ZeRO shard parameters, gradients and optimizer state so memory per GPU shrinks as GPUs are added.
- Tensor parallelism splits each layer and needs fast links, so it normally stays inside one server.
- Pipeline parallelism needs many micro-batches in flight to avoid idle bubbles.
- Changing the GPU count changes the effective batch size, so recheck the recipe.
Common mistakes
- Reaching for FSDP or tensor parallelism when a model already fits with DDP.
- Running tensor parallelism across servers on a slow network.
- Assuming throughput scales linearly with GPUs without measuring tokens per second at each size.
- Forgetting that more GPUs raises the effective batch size and needs a recipe adjustment.
Check yourself · 2 of 3
What does FSDP or ZeRO stage 3 shard across GPUs?
Check yourself · 3 of 3
Why is tensor parallelism usually kept inside a single server?
Practice items, not counted towards your mastery.
Start here
- The Ultra-Scale Playbook: Training LLMs on GPU Clusters (opens in a new tab)BookFree
An interactive guide to data, tensor, pipeline and ZeRO parallelism with measured trade-offs.
- Getting Started with Fully Sharded Data Parallel (FSDP) (opens in a new tab)DocsFree
A runnable FSDP setup that shows how parameters, gradients and optimizer state are sharded.
- ZeRO: Memory Optimizations Toward Training Trillion Parameter Models (opens in a new tab)PaperFree
Breaks down the bytes per parameter for weights, gradients and Adam states, and how sharding removes the copies.
More for this topic
- PyTorch Distributed Data Parallel notes (opens in a new tab)DocsFree
How DDP replicates the model and averages gradients across processes.