FSDP › Worked Example: Memory Savings on a 7B Model
Language AI HandbookAll chapters FSDP › Worked Example: Memory Savings on a 7B ModelOne section · Sections in this chapter8 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To build intuition for the magnitudes involved, let's trace through the memory accounting for a concrete scenario: training a 7 billion parameter model on 8 A100-40GB GPUs.
Without FSDP (DDP Baseline)
With standard DDP, every GPU holds the complete model state:
- Parameters: GB
- Gradients: GB
- Optimizer states (Adam): GB
- Total model state: GB
This already exceeds the 40 GB GPU capacity by . DDP cannot run this configuration at all.
With FSDP FULL_SHARD on 8 GPUs
With FULL_SHARD, each GPU holds of each component:
- Parameters (shard): GB
- Gradients (shard): GB
- Optimizer states (shard): GB
- Total steady-state: GB
During the forward and backward passes, a single FSDP unit's all-gather buffer temporarily consumes an additional GB where is the number of FSDP units. For a 32-layer model wrapped at the layer level, each all-gather buffer is GB, bringing peak memory to about GB per GPU, well within the 40 GB limit.
The remaining memory budget of approximately 25 GB can accommodate activations from long sequence lengths and larger batch sizes. Activations for a typical transformer layer scale as where is batch size, is sequence length, and is hidden dimension. For a 7B model (), a batch of 4 sequences of length 2048 in bfloat16 generates roughly MB per layer before considering the activations needed for attention score computation. With activation checkpointing (recomputing rather than storing activations), this budget extends further.
The Practical Significance
This example illustrates why FSDP enabled more open-source large model training in 2023 and 2024. Before FSDP became widely available and well-documented, training 7B models required either expensive 80 GB GPUs (A100-80GB or H100), proprietary systems like Google's TPU pods, or careful hand-engineering with DeepSpeed. With FSDP on standard 40 GB A100 GPUs, which were broadly available through cloud providers, the research community could train and fine-tune these models on accessible hardware.