Fully Sharded Data Parallel (FSDP) in Practice: Training Trillion-Parameter Large Models
This article explains why trillion-parameter large models cannot use the traditional "one model per card, many cards over data" paradigm, and how Fully Sharded Data Parallel (FSDP) solves the problem by sharding the model state itself. Starting from a memory budget of roughly 16 bytes per parameter, it walks through the core mechanisms of FSDP, then details the three key stages of a complete training pipeline: meta-device loading, sharding and wrapping strategy, and gradient synchronization. It also covers the added complexity of multimodal training, adaptation for domestic and heterogeneous accelerators, and the core tradeoffs in performance tuning among compute, memory, and communication. The content is vendor-neutral and focuses on general engineering practice.
When model parameters reach the trillion scale, the traditional paradigm of “fit the model on a single card, run data across many cards” quickly breaks down. Using the publicly reported parameter count of a certain open-source flagship model as a reference (on the order of a trillion parameters), it is worth returning to engineering fundamentals: why super-large-scale training must rely on sharded parallelism, how Fully Sharded Data Parallel works, and how to build a complete training pipeline from loading to synchronization. This article does not cover any specific vendor product; it only discusses general techniques and engineering practices used across the industry.
1. Why Trillion-Parameter Models Must Rely on Sharded Parallelism
To understand the necessity of sharded parallelism, first do the “memory math.” Under mixed-precision training (BF16/FP16) combined with an adaptive optimizer, the GPU memory used during training is made up mainly of four parts:
- Model parameters (half precision): about 2 bytes/parameter
- Gradients from backpropagation (half precision): about 2 bytes/parameter
- Optimizer states: usually master weights, first moment, and second moment stored in single precision, about 12 bytes/parameter
The total comes to about 16 bytes/parameter. For a model on the order of a trillion parameters, the static state alone (parameters + gradients + optimizer) requires about 16 TB of GPU memory. Add activations, which grow with batch size and sequence length, and the total climbs further into the tens of TB.
This means that even if a single accelerator carries tens to hundreds of GB of memory, the static state alone needs hundreds of cards to barely fit. At that point, if you still use data parallelism where each card keeps a complete model replica and runs its own batch of data, memory gets consumed by massive redundant replicas, which is simply infeasible. The core goal of sharded parallelism is precisely to slice this enormous state across all participating cards, so each card holds only a small piece of the full model.
2. How Fully Sharded Data Parallel Works
Fully Sharded Data Parallel (FSDP) is the mainstream solution to the problem above. Its key difference from ordinary data parallelism is that it shards not only the data but the model state itself.
Its operating logic can be summarized as three rules:
- Parameter sharding: The model is split into several “shard units,” where the parameters of each unit reside permanently on only a subset of training processes; the remaining processes keep only metadata.
- On-demand aggregation: When forward or backward computation reaches a shard unit, collective communication temporarily aggregates the full parameters of that unit onto the current card; they are released immediately after the computation to avoid full-time residency.
- Gradient reduction and retention: Gradients produced by backpropagation are summed through a reduce operation (reduce-scatter), after which each card keeps only the gradient for the shard it owns, and then each card independently updates its local parameters.
Newer-generation FSDP implementations go further in parameter-level sharding, unified management of shard layout through a distributed tensor abstraction, and composability with tensor parallelism and pipeline parallelism. This lets the framework control sharding boundaries more finely, reduce the overhead of converting the state dict across parallel dimensions, and makes it easier to stack with strategies such as 3D parallelism.
3. From Loading to Synchronization: Three Key Stages of the Training Pipeline
A robust super-large-scale training pipeline needs to connect three interlocking stages, none of which can be missing.
3.1 Model Loading: “Reserve” First, Then “Materialize”
A trillion-parameter model cannot be instantiated all at once on a single card. In engineering practice, the model usually first builds its computation graph skeleton on a meta device—at this point parameters have only shape and type, with no real memory allocated. Then weight tensors are loaded on demand and in shards from sharded storage, filling directly into the corresponding shard positions. This both avoids the memory peak during instantiation and supports fast recovery of training from a checkpoint.
3.2 Sharding and Wrapping: The Policy Determines Communication Granularity
Finer sharding is not always better. Wrapping units that are too small cause a surge in collective communication calls, letting communication overhead drown out the compute gains; units that are too large weaken the memory savings. A common approach is to treat each Transformer decoder layer as an independent shard unit, while using coarser-grained wrapping for smaller vision and audio encoders to reduce communication frequency:
# Illustrative pseudocode: sharding units and auto-wrap policysharding_units = [TransformerBlock, # Main backbone decoder layers, independent shard unitsVisionEncoderBlock, # Vision encoder, smaller in scaleAudioEncoderBlock, # Audio encoder, coarser granularity to reduce communication]policy = AutoWrapPolicy(min_num_params=1_000_000, blocks=sharding_units)
You also need to pick a sharding strategy: full sharding (simultaneously sharding parameters, gradients, and optimizer) saves the most memory but is heaviest on communication; sharding only gradients and optimizer while keeping parameter replicas is lighter on communication; and when cross-node bandwidth is limited, a hybrid strategy can be used—full sharding within a node and replicas across nodes.
3.3 Gradient Synchronization: Hide Communication Behind Computation
Synchronization is where performance is won or lost. The core techniques include:
- Communication-computation overlap: during backpropagation, as soon as a shard unit’s gradient is ready, kick off the reduction immediately, using compute time to “hide” communication latency;
- Mixed precision: carry communication data in half precision to compress the transfer volume;
- Gradient accumulation: run several small-batch forward and backward passes before updating, balancing memory and throughput under an equivalent large batch.
# Illustrative pseudocode: fully sharded training loopfor step, batch in enumerate(dataloader):inputs = collate_and_pack(batch) # Pack sequences into multimodal inputwith fully_sharded_context(): # Enter the sharded contextloss = model(inputs) # Forward: all-gather params on demand, release after useloss.backward() # Backward: reduce-scatter grads per unit and keep the shardoptimizer.step() # Update only the locally held parameter shardoptimizer.zero_grad()metrics.report(loss, step) # Asynchronously report loss, throughput, memory usage
4. The Added Complexity of Multimodal Training
When the model handles text, images, and audio at the same time, the sharding strategy faces more complex heterogeneity. Different modality encoders differ significantly in parameter scale, layer structure, and compute characteristics, so a uniform sharding scheme leads to load imbalance. Practical points include: using differentiated wrapping and sharding granularity for each modality; merging variable-length samples through sequence packing to raise effective compute density; and applying weight balancing across multimodal losses to keep one modality from dominating the gradient direction.
5. Adapting to Domestic and Heterogeneous Accelerators
Getting trillion-parameter training to run on heterogeneous accelerators requires more than the algorithm layer; it depends on a full stack of software-hardware co-adaptation. The industry typically focuses on:
- Operator coverage and kernel optimization: making sure the attention, normalization, activation, and other operators the model uses all have efficient implementations, so execution does not fall back to slow generic paths;
- Collective communication library adaptation: primitives such as all-gather and reduce-scatter must land correctly and efficiently under the interconnect topology of domestic cards;
- Numerical stability: overflow and precision loss under half precision need safeguards such as loss scaling and numerically stable reduction ordering;
- Memory management: defragmentation, cache reuse, and activation recomputation together suppress memory peaks.
It is worth stressing that this kind of large-scale training usually runs on cloud platforms equipped with heterogeneous compute clusters, high-speed interconnect networks, containerized scheduling, object storage and parallel file systems, and logging, monitoring, and alerting. A platform such as Baidu AI Cloud, which provides general cloud infrastructure and training acceleration capabilities, is a common foundation for hosting such workloads; its value lies in offering a stable, scalable resource pool and observability, rather than being tied to any specific model.
6. Performance Tuning Tradeoffs
Super-large-scale training is essentially a dynamic balance among compute, memory, and communication:
- Activation recomputation: trade a small amount of compute for memory to ease activation growth;
- Combining parallelism dimensions: data parallelism stacked with sharding, tensor parallelism slicing single-layer matrices, and pipeline parallelism slicing layers—the ratio of the three needs tuning against cluster bandwidth and card count;
- Communication-topology awareness: keep high-frequency communication inside high-bandwidth domains (such as within a node) and let low-frequency communication cross nodes.
There is no one-size-fits-all configuration. The right approach is to start from three signals—whether it fits in memory, whether communication is saturated, and whether compute is being fully fed—measure repeatedly, and only then converge on the optimal parameters.
Conclusion
Adapting trillion-parameter model training is not a matter of simply “swapping in a card and getting it running.” It is a systems engineering effort that starts from the memory ledger, slices the state through fully sharded parallelism, and is held together by the coordinated three stages of loading, scheduling, and synchronization. Only by understanding the memory economics and communication costs of sharded parallelism can developers bring super-large-model training to life efficiently and stably on heterogeneous compute.
