Trillion-Parameter Large Model Training: End-to-End Distributed Adaptation from FSDP to FSDP2
This article explains why trillion-parameter models require distributed training and how full-parameter sharding strategies make them feasible. It compares tensor, pipeline, data, and FSDP-based parallelism, then focuses on the evolution from FSDP to FSDP2, including per-parameter sharding and Distributed Tensor abstractions. It also walks through the end-to-end training pipeline—metadata-based loading, device mesh mapping, forward all-gather, backward reduce-scatter, checkpointing, and fault tolerance—along with hardware-software co-design, multimodal considerations, and practical engineering guidance.
Trillion-Parameter Large Model Training: End-to-End Distributed Adaptation from FSDP to FSDP2
1. Why Trillion-Parameter Models Are Hard to Train
When model size grows from tens of billions to trillions of parameters, the main bottleneck is no longer compute alone. The challenge is how to fit the model into limited accelerator memory and keep hundreds or thousands of accelerators working efficiently.
For example, a dense model with about one trillion (10^12) parameters, trained with mixed precision, can require tens of terabytes of memory for parameters, gradients, and optimizer states alone. This far exceeds the memory capacity of a single accelerator or even a single node. Therefore, the core problem of very-large-scale training can be summarized as follows: how to shard model state across enough devices while keeping communication overhead acceptable and compute utilization high.
Several major technical routes have evolved around this problem:
- Tensor Parallelism (TP): splits individual matrix operations within a layer across multiple devices. It relies on frequent communication and is best suited to high-bandwidth intra-node interconnects.
- Pipeline Parallelism (PP): splits the model by layers. It introduces pipeline bubbles, which can leave compute resources idle.
- Data Parallelism (DP): each device keeps a complete model replica, and only the data batch is sharded.
- Fully Sharded Data Parallel (FSDP): builds on data parallelism by sharding parameters, gradients, and optimizer states across all devices and gathering them on demand.
For trillion-scale models, a single strategy is usually not enough. In practice, multiple parallel strategies must be combined. Within the data-parallel dimension, FSDP’s fully sharded approach is an important option for large-scale adaptation because it requires relatively few changes to model code and is generally applicable.
2. From FSDP to FSDP2: Evolving Sharding Granularity
The core idea of FSDP is: each device normally keeps only the parameter shard for which it is responsible. When a forward or backward pass needs a layer, the full parameters are temporarily gathered through collective communication, and then released after computation.
This brings two direct benefits:
- Memory usage drops significantly because optimizer states, gradients, and parameters are sharded instead of redundantly stored.
- Through block-pipeline-style prefetching, communication for gathering parameters can overlap with computation, hiding communication latency.
The key evolution of FSDP2 over earlier versions is finer sharding granularity and a standardized abstraction layer:
- Per-parameter sharding: FSDP2 uses individual parameters as the sharding unit instead of flattening an entire layer into a one-dimensional tensor. This makes shard boundaries clearer and makes it easier to correctly shard and reconstruct models with sparse structures such as Mixture-of-Experts (MoE) or irregular parameter shapes.
- Distributed Tensor (DTensor) abstraction: FSDP2 introduces DTensor, which turns information such as “which dimensions of this tensor are sharded across which devices” into describable and composable type information. Sharding layout becomes a first-class concept, reducing the complexity of manual sharding management.
- Better composability: FSDP2 works more easily with quantization, activation recomputation, CPU offload, and other capabilities, leaving more room for deploying very large models under limited memory.
The following pseudo-code illustrates the basic FSDP2 usage idea. It is only an example and does not represent a specific implementation:
import torchfrom torch.distributed.fsdp import fully_shard # Example: fully sharded wrapping# 1. Build the model layer by layer according to Transformer decoder blocksmodel = build_transformer(num_layers=80)# 2. Apply fully sharded wrapping to each decoder block to form shard unitsfor block in model.layers:fully_shard(block)# 3. Wrap the top-level module again to coordinate schedulingfully_shard(model)# 4. Run forward / backward as usual; parameters are gathered on demand and released after useloss = model(batch)loss.backward()optimizer.step()
The core behavior is: when entering forward for a shard unit, its parameters are gathered; when exiting, the gathered result is immediately released. This balances memory usage and the number of communication operations.
3. Breaking Down the Full Training Pipeline
Whether a training adaptation can run successfully depends on how tightly each stage of the end-to-end pipeline connects. The following sections describe the process in practical execution order.
3.1 Model Loading and Metadata Preparation
Very large models usually cannot be instantiated and then loaded with weights directly, because full instantiation can immediately exhaust accelerator memory. A common approach is metadata-first loading (meta device / lazy initialization): first build the model structure logically and record each layer’s shapes and data types, but do not allocate real accelerator memory yet. Then, combined with sharded checkpoint loading, pretrained weights are streamed into the corresponding device locations according to the sharding layout. This stage also needs to handle weight format conversion, alignment of tensor-parallel split dimensions, and mapping of data types (such as BF16/FP16) and optimizer states.
3.2 Parameter Sharding and Device Mapping
After construction, model parameters must be mapped onto a device mesh. A device mesh describes how physical accelerators are organized into a logical multi-dimensional topology, such as a 2D mesh of (data-parallel dimension, tensor-parallel dimension). The sharding strategy determines which shards each device holds based on mesh dimensions. The following points are especially important:
- Choice of split dimensions: For weights in attention and feed-forward modules, the split dimensions must align with subsequent tensor parallelism to avoid redundant communication.
- Load balancing: Sharding should keep per-device memory usage as balanced as possible and avoid out-of-memory errors on individual devices.
- Combination with parallel strategies: When FSDP is combined with tensor parallelism and pipeline parallelism, it is important to clarify which dimension is responsible for sharding and which dimension is responsible for splitting matrices, to avoid dimension conflicts.
3.3 Forward Computation and On-Demand Gathering
Forward propagation proceeds layer by layer. When reaching a shard unit, the communication group performs an all-gather to temporarily reconstruct the layer’s full parameters on participating devices for local computation. The gathered result is released immediately after computation, leaving only each device’s local shard. To hide communication latency, prefetching is usually enabled: while computing the current layer, parameters for the next layer are gathered in advance. If the prefetch depth is too large, it consumes memory; if too small, it cannot hide communication. It needs to be tuned according to bandwidth and memory budget.
3.4 Backward Propagation and Gradient Synchronization
During backward propagation, parameters must also be gathered by shard unit to compute gradients. Unlike standard data parallelism, FSDP gradient synchronization uses reduce-scatter: each device reduces its locally computed full gradient, and the result is scattered back to each device according to the sharding layout, so that each device keeps only its own gradient shard. This completes global gradient aggregation while avoiding redundant gradient storage on every device. During optimizer updates, each device updates only the parameter shards it holds, further reducing peak memory usage.
3.5 Checkpoints and Fault Tolerance
The cost of failure in trillion-parameter training is extremely high, so training must rely on sharded checkpoints: save state according to the sharding layout to avoid a single extremely large file, and support resuming from the latest checkpoint after interruption. Combined with asynchronous saving and periodic validation, this can significantly reduce rerun losses for long-running jobs.
4. Key Aspects of Hardware-Software Co-Design
Whether a model runs efficiently depends on deep coordination between the software stack and hardware capabilities. The following are general engineering principles:
- Operator and library adaptation: Ensure that collective communication operators and mixed-precision operators required by the parallelism framework have efficient implementations on the target hardware. Otherwise, fallback to generic paths can cause significant slowdown.
- Collective communication topology optimization: all-gather and reduce-scatter are high-frequency communications in FSDP. They require high-speed interconnects and carefully configured communication groups to prevent cross-node communication from becoming a bottleneck.
- Fine-grained memory budgeting: Use techniques such as activation checkpointing, CPU/NVMe offload, and shard granularity adjustment to trade memory for trainability when memory is limited.
- Monitoring and observability: Combine common capabilities such as logging, monitoring, and alerting to continuously track metrics such as memory usage, communication time, per-step latency, and throughput (tokens/s), and to detect load imbalance or communication hotspots early.
5. Additional Considerations for Multimodal Training
Multimodal models include vision, audio, and other encoders in addition to language backbones. Their structures are more heterogeneous, their parameter shapes are more irregular, and they impose additional requirements on training adaptation:
- Different sharding strategies for heterogeneous modules: Vision encoders and language backbones may need different sharding or parallel configurations.
- Data pipeline complexity: Sampling, alignment, and packing for multimodal inputs such as image-text and audio-text require independent and efficient loading pipelines.
- Loss and gradient balancing: Loss scales can differ significantly across modality branches, so consistency of gradient scales and learning rates needs attention.
FSDP2’s per-parameter sharding and its use of distributed tensor abstractions to describe layouts make it well suited to the sharding and reconstruction needs of these structurally irregular models.
6. Engineering Practice Recommendations
- Validate convergence at small scale first: Use smaller models or fewer devices to validate parallel strategies and hyperparameters. Confirm that the loss curve behaves normally before scaling up.
- Prioritize communication-computation overlap: Prefetching and asynchronous communication are key to improving efficiency, but they must be tuned within the memory budget.
- Tune shard granularity and memory together: When OOM occurs, prioritize adjusting recomputation scope and offload strategies rather than blindly increasing the number of devices.
- Build a complete fault-tolerance path: Sharded checkpoints + fast failure localization + automatic resume are essential safeguards for long-running training.
- Use metrics to drive tuning: Optimize iteratively around core metrics such as throughput, per-step latency, peak memory, and communication ratio, rather than relying on intuition.
7. Summary
Adapting trillion-parameter models for training is essentially about finding a sustainable engineering balance among memory, communication, and scheduling. Fully sharded data parallelism—especially FSDP2 with per-parameter sharding and distributed tensor abstractions—uses the mechanism of “gather on demand, release after use” to turn an otherwise infeasible full-model task into a shardable, streaming task. Combined with metadata-first loading, reduce-scatter gradient synchronization, and sharded checkpoints, it forms a complete pipeline from model loading to gradient updates. Mastering these general principles and engineering trade-offs is key to quickly designing stable and efficient training solutions for very large-scale models across different hardware and model structures.
