[Paper Review] PyTorch FSDP: Experiences on Scaling Fully Sharded Data Parallel
The paper presents PyTorch Fully Sharded Data Parallel (FSDP), a native, industry-grade solution for training large models by parameter sharding, with deferred initialization, configurable sharding, and extensive optimizations, achieving comparable performance to DDP on small models and near-linear TFLOPS scalability for much larger models (tested up to 512x80GB A100 GPUs).
It is widely acknowledged that large models have the potential to deliver superior performance across a broad range of domains. Despite the remarkable progress made in the field of machine learning systems research, which has enabled the development and exploration of large models, such abilities remain confined to a small group of advanced users and industry leaders, resulting in an implicit technical barrier for the wider community to access and leverage these technologies. In this paper, we introduce PyTorch Fully Sharded Data Parallel (FSDP) as an industry-grade solution for large model training. FSDP has been closely co-designed with several key PyTorch core components including Tensor implementation, dispatcher system, and CUDA memory caching allocator, to provide non-intrusive user experiences and high training efficiency. Additionally, FSDP natively incorporates a range of techniques and settings to optimize resource utilization across a variety of hardware configurations. The experimental results demonstrate that FSDP is capable of achieving comparable performance to Distributed Data Parallel while providing support for significantly larger models with near-linear scalability in terms of TFLOPS.
Motivation & Objective
- Motivate the need for an industry-grade, framework-native solution to train extremely large models beyond single-GPU memory.
- Introduce PyTorch FSDP and its co-design with PyTorch core components to provide non-intrusive, efficient training.
- Develop and evaluate sharding strategies, initialization methods, and memory/communication optimizations to handle hardware heterogeneity and large memory footprints.
- Demonstrate FSDP’s effectiveness and scalability across language and recommender models on large GPU clusters.
Proposed method
- Decompose models into FSDP units and shard parameters so that only one unit is fully materialized at a time.
- Implement deferred initialization to allow model construction on fake devices and replay initializations when materializing on real GPUs.
- Provide multiple sharding strategies (full and hybrid) with a sharding factor F to trade memory footprint against communication.
- Use a FlatParameter to coalesce parameters for efficient AllGather/ReduceScatter without extra copies.
- Integrate tightly with PyTorch autograd through views and gradient hooks for correct, automatic gradient flow and reduction.
- Apply communication optimizations (overlapping, forward/backward prefetching, gradient accumulation) and memory management (CUDA caching allocator, rate limiter).
Experimental results
Research questions
- RQ1How can a native PyTorch solution for large-model training be designed to minimize memory while maximizing throughput across heterogeneous hardware?
- RQ2Can FSDP achieve comparable performance to DDP on small models and provide near-linear TFLOPS scalability for much larger models?
- RQ3What initialization, sharding, and memory-management techniques are required to support training models that exceed a single GPU’s memory?
- RQ4How should communication be organized to maximize overlap with computation in a fully sharded setup?
- RQ5What are the trade-offs between full and hybrid sharding in real datacenter topologies?
Key findings
- FSDP can match DDP performance on small models while enabling significantly larger models with near-linear TFLOPS scalability.
- A FlatParameter-based sharding approach enables parameter-level memory efficiency with minimal copy overhead during gather/scatter operations.
- Deferred initialization and unit-by-unit materialization allow constructing very large models without full upfront memory allocation.
- Hybrid sharding reduces cross-host traffic and can exploit datacenter locality, offering a tunable memory-throughput trade-off for medium-sized models.
- FSDP is beta in PyTorch 2.0 and has been battle-tested in industry and research settings, with artifacts available for reuse.
- Experiments demonstrate scalability on large-scale GPU clusters, up to 512 x 80GB A100 GPUs.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.