How Fully Sharded Data Parallel Works and What It Takes to Train Trillion-Parameter Models
This article explains the principles and engineering practices of Fully Sharded Data Parallel (FSDP/ZeRO-3) for training framework and cluster engineers. It covers why GPU memory becomes a bottleneck, how sharding reduces per-device memory, trade-offs among DP, FSDP, TP, and PP, and step-by-step guidance for configuring parallelism degree, sharding granularity, and communication buckets when scaling to trillion-parameter models.
1. Scope and Disclaimers
This article explains the principles and engineering essentials of Fully Sharded Data Parallel for training framework and cluster engineers. The model parameter counts, chip vendors, and compatibility conclusions in the original reports have not been independently verified, so this article does not cite those figures or evaluate the performance of any specific hardware. All memory calculations and configuration examples here are general estimates; actual values must be measured in your target environment.
2. Why GPU Memory Becomes the Bottleneck
In classic data parallelism, every GPU holds a complete replica of the model and only the input data is split across devices. This works fine for small models, but it breaks down once parameters reach the trillion scale. With mixed-precision Adam, each parameter typically requires about 16 bytes: 2 bytes for the bf16 parameter, 2 bytes for the bf16 gradient, 4 bytes for the fp32 master weight, 4 bytes for the momentum, and 4 bytes for the variance. A one-trillion-parameter model therefore needs roughly 16 TB of state storage, far beyond any single GPU.
Fully Sharded Data Parallel (implemented as FSDP in PyTorch and corresponding to ZeRO-3 in DeepSpeed) shards parameters, gradients, and optimizer states across N GPUs, so each device permanently holds only 1/N. With 512 GPUs, the state portion is about 16 TB / 512 ≈ 31 GB per GPU. The trade-off is that computation requires an All-Gather to temporarily reconstruct the full layer parameters, which are released right after use. Gradients are reduced back to their respective shards via Reduce-Scatter.
The following formula approximates steady-state memory:
Per-GPU steady-state memory ≈ (parameters + gradients + optimizer states) / N
This formula underestimates peak memory. Peak usage also includes three components: the temporarily gathered full layer parameters, activations (which depend mainly on batch size and sequence length and do not shrink linearly with N), and communication buffers plus memory fragmentation. Tuning decisions should be based on measured peak memory.
3. Trade-offs Among Four Parallelism Strategies
| Strategy | Memory usage | Communication pattern | Applicable range |
|---|---|---|---|
| Data Parallel (DP) | Full replica per GPU, highest usage | One gradient All-Reduce per step | Up to tens of billions of parameters |
| Fully Sharded Data Parallel (FSDP) | Sharded states, decreases with N | All-Gather and Reduce-Scatter; common paper estimates put communication volume at about 1.5× that of DP | When parameters exceed single-GPU memory |
| Tensor Parallel (TP) | Intra-layer matrix splitting, decreases with TP degree | Multiple All-Reduces per layer, bandwidth-sensitive | Within high-speed intra-node interconnects |
| Pipeline Parallel (PP) | Layers split across devices | Point-to-point activation transfers between adjacent stages, with pipeline bubbles | Cross-node scaling |
Real training runs usually combine these strategies. A common practice is tensor parallelism within a node, fully sharded data parallelism across nodes, and pipeline parallelism added when the model has many layers.
4. Implementation Steps for the Training Pipeline
Step 1: Determine the parallelism degrees. First, keep the tensor parallelism degree no larger than the number of GPUs per node—for example, 8 on an 8-GPU machine. Then use pipeline parallelism to split layers across nodes, and assign the remaining GPUs to the fully sharded group. For example, 512 GPUs can be configured as TP=8, PP=4, FSDP=16, where 8×4×16 = 512. To validate, run one full training step (forward and backward), record peak memory on each GPU, and confirm there is headroom beyond the peak for communication buffers and fragmentation; the exact margin should be determined by measurement.
Step 2: Set the sharding granularity. Wrap sharding units at the Transformer block level, and wrap heterogeneous submodules such as vision encoders separately so they can use independent sharding policies. Sharding units that are too coarse increase the temporary All-Gather peak, while units that are too fine add scheduling overhead. To validate, print the parameter count of each sharding unit and confirm the distribution is even, with no single unit consuming most of the memory.
Step 3: Tune communication buckets. Merge multiple small tensors into larger communication buckets to reduce the number of collective communication launches. Framework defaults are a reasonable starting point—for example, PyTorch DDP defaults to a 25 MB bucket size. Then use a profiler to compare single-step
