Trillion-Parameter Model Training Adaptation: A Practical Guide to Fully Sharded Data Parallel (FSDP2)

    This guide explains how to adapt trillion-parameter large models for training on custom AI accelerators. It focuses on Fully Sharded Data Parallel (FSDP2) and covers memory, communication, and numerical stability challenges, software-stack adaptation, hybrid parallelism strategies, model loading, shard scheduling, gradient synchronization, mixed precision, activation recomputation, multimodal training, and practical tuning methods for scalable and reproducible training.

    Introduction: When Model Scale Reaches Trillion Parameters

    Open-source ecosystems have gradually produced flagship models with parameter counts reaching the trillion scale, such as models with 2.8 trillion parameters. These models typically combine mixture-of-experts (MoE) architectures with multimodal capabilities.

    The jump in parameter scale does not translate into a linear increase in engineering complexity. Instead, it creates systemic challenges across storage, communication, computation, and stability. For teams that want to complete training on custom AI accelerators, model adaptation is no longer simply a matter of aligning operators. It is systems engineering that requires hardware, software stacks, and distributed training strategies to work together.

    This article focuses on completing trillion-parameter large-model training adaptation on general-purpose AI training and inference accelerators. It abstracts a reusable methodology and explains how natively implemented Fully Sharded Data Parallel (FSDP2) connects the full training path, from model loading and shard scheduling to gradient synchronization.

    1. Core Challenges of Trillion-Parameter Training

    1. Memory Wall

    In mixed-precision training, every parameter occupies memory and also requires gradient and optimizer states. For a common adaptive moment estimation optimizer, a single parameter typically requires:

    • bf16/fp16 weights: 2 bytes
    • fp32 master weights: 4 bytes
    • First moment: 4 bytes
    • Second moment: 4 bytes

    The total is about 14 bytes per parameter. Multiplying this by trillions of parameters, the model states alone can reach tens of terabytes, far exceeding the capacity of any single accelerator or even a single node.

    This means parameters, gradients, and optimizer states must be sharded across hundreds or thousands of accelerators. Sharding is not optional; it is a prerequisite for feasibility.

    2. Communication Wall

    After sharding, the complete parameters that once resided on a single accelerator must be reconstructed on demand at runtime.

    During forward propagation, the full parameters of the current layer must be temporarily gathered through all-gather. During backpropagation, gradients must be reduced and scattered back to their respective shard owners through reduce-scatter after computation.

    If communication bandwidth cannot keep pace with computation, accelerators will spend substantial time waiting, severely reducing training throughput. Therefore, a core part of adaptation is to overlap computation and communication as much as possible.

    3. Stability and Numerical Consistency

    Trillion-parameter models are extremely sensitive to numerical precision. Improper handling of learning rates, gradient clipping, loss scaling, or any other link can cause loss spikes or even divergence.

    In addition, subtle numerical differences in operator implementations across different hardware can be progressively amplified at the thousand-card scale. Adaptation must not only make training runnable; it must also ensure that convergence behavior across hardware and scale is predictable and reproducible.

    2. Adaptation Logic for Compute Backends and Software Stacks

    The essence of model adaptation is to enable distributed compute graphs generated by the training framework to be executed efficiently and correctly on target hardware. This usually involves three layers:

    • Operator layer: Custom or vendor-specific software stacks need to cover many operators used by the model, including attention, normalization, activation, MoE routing, and dispatch. Missing operators can break the computation graph, while poor operator performance directly limits training efficiency.

    • Communication library layer: Collective communication primitives such as all-gather, reduce-scatter, all-reduce, and all-to-all form the backbone of distributed training. MoE expert parallelism especially relies on efficient all-to-all. Bandwidth and topology awareness directly affect scalability.

    • Framework layer: Mainstream training frameworks hide low-level hardware differences through unified device abstractions. The goal is to allow correct execution with minimal changes to upper-level code when switching to a new backend, while retaining compatibility with various parallel strategies.

    A mature adaptation approach often combines operator completion, communication optimization, and graph optimization rather than relying on a single breakthrough.

    3. Overview of Distributed Parallelism Strategies

    To understand the position of FSDP2, it is necessary to clarify mainstream parallel strategies first:

    • Data parallelism (DP): Each accelerator holds a full model replica, and gradients are synchronized through all-reduce. It is simple to implement, but memory cannot be sharded, making it unsuitable for trillion-parameter models.

    • Fully Sharded Data Parallel (FSDP): Building on data parallelism, FSDP shards parameters, gradients, and optimizer states across accelerators and temporarily aggregates them when needed. It is a key technique for training ultra-large models under memory constraints.

    • Tensor parallelism (TP): Matrix computations inside a single layer are split horizontally across multiple accelerators. Communication is frequent, so TP is usually limited to high-speed interconnect domains within a single node.

    • Pipeline parallelism (PP): The model is split vertically into different stages, and micro-batches are executed through a pipeline. Pipeline bubbles must be handled.

    • Expert parallelism (EP): Designed for MoE architectures, EP distributes different experts across accelerators and relies on all-to-all for token routing.

    When training trillion-parameter models, these strategies are often combined into multi-dimensional hybrid parallelism, such as TP×PP×FSDP×EP. Communication-intensive dimensions are placed in high-bandwidth domains, while communication-sparse dimensions are expanded across nodes.

    4. In-Depth Look at Fully Sharded Data Parallel (FSDP2)

    1. Core Idea

    FSDP shards each parameter tensor along the data-parallel dimension, with each accelerator holding only the shard it is responsible for.

    When computation arrives, full parameters are temporarily assembled through all-gather for forward or backpropagation and released immediately afterward. Gradients are directly reduced and scattered back to each shard owner through reduce-scatter.

    Its core trade-off is using communication to save memory, enabling ultra-large models to be trained under limited memory.

    2. Improvements in Second-Generation FSDP

    Compared with the first generation, which used flattened parameter blocks, FSDP2 moves to per-parameter sharding and introduces distributed tensors, or DTensor, to explicitly describe the sharding layout of each parameter.

    This brings three benefits:

    1. Clearer and less conflicting composition with tensor parallelism, pipeline parallelism, and other strategies.
    2. Easier memory lifecycle management and reduced peak-memory fluctuations.
    3. Explicit sharding semantics for easier debugging and checkpoint access.

    3. Trade-offs Between Communication and Memory

    FSDP typically triggers all-gather once for each layer during both forward and backward passes. The more layers there are and the more shards each accelerator holds, the greater the communication pressure.

    In practice, techniques such as shard-granularity grouping, overlapping forward and backward communication, and prefetching the next layer’s parameters can hide communication within computation windows and approach theoretical throughput.

    4. Illustrative Pseudocode

    1. for step in range(total_steps):
    2. activations = []
    3. # Forward: all-gather full parameters layer by layer; release aggregated shards immediately after use
    4. for layer in model.layers:
    5. full_param = all_gather(layer.sharded_param) # Communication
    6. out = layer(input) # Computation
    7. full_param.free() # Release immediately to control peak memory
    8. activations.append(save_or_recompute(out)) # Save activations or trigger activation recomputation
    9. loss = criterion(out, target)
    10. # Backward: all-gather parameters again to compute gradients, then reduce-scatter gradients
    11. loss.backward()
    12. # Each accelerator holds and updates only the shard it owns
    13. clip_grad_norm(sharded_grads) # Compute gradient norm across global shards
    14. optimizer.step() # Local shard update
    15. optimizer.zero_grad()

    This structure highlights three key points: parameters are released immediately after use, communication is overlapped with computation, and gradients are reduced by shard before local updates.

    5. Building a Complete Training Pipeline

    A reproducible training pipeline should connect the following stages:

    1. Model Loading

    Trillion-parameter models are usually stored as sharded checkpoints. During loading, checkpoints must be remapped according to the new parallel topology.

    The process should support:

    • Recovery from large-scale parallel configurations.
    • Resharding when the parallel degree changes for elastic scaling.

    Loading should also validate parameter integrity, tensor shapes, and numerical ranges to avoid starting training with an inconsistent model.

    2. Shard Scheduling

    Shard scheduling determines which accelerator holds each parameter, gradient, and optimizer state, as well as when aggregation and release occur.

    Good scheduling should:

    • Balance memory usage to avoid hotspot accelerators.
    • Preserve communication locality by aggregating consecutive layers when possible.

    Scheduling strategies must coordinate with TP, PP, and EP sharding to prevent dimension conflicts.

    3. Gradient Synchronization

    The key to gradient synchronization is the correctness of reduce-scatter: global gradients must be the reduction of gradients from all data-parallel replicas, then scattered back to their shards.

    When gradient accumulation is used, gradients from multiple forward and backward passes must be correctly accumulated before reduction.

    When gradient clipping is used, the gradient norm must be computed from global sharded statistics rather than local values on a single accelerator. Otherwise, the clipping threshold becomes inaccurate.

    4. Mixed Precision and Activation Recomputation

    Using bf16/fp16 mixed precision with fp32 master weights is a compromise between memory usage and stability.

    Activation recomputation, also known as activation checkpointing, trades a small amount of recomputation for memory and is almost always enabled in trillion-parameter training.

    Both must work with FSDP’s shard-release logic to ensure parameters can be correctly re-aggregated during recomputation.

    6. Key Considerations for Multimodal Training

    Multimodal models introduce modalities such as images and audio beyond text. Training adaptation should pay extra attention to:

    • Alignment of heterogeneous inputs: Branches for different modalities usually have different sequence lengths and tensor layouts. Data loading must use unified batching and padding strategies.

    • Data pipeline throughput: Multimodal data is large and preprocessing is heavy. High-performance object storage and prefetching are needed so that data supply keeps up with thousand-card compute and compute is not starved by I/O.

    • Loss balancing: Loss magnitudes for different modality tasks can differ. Weight scheduling or dynamic balancing is needed to prevent one modality from dominating gradients.

    • Checkpointing and recovery: Large-scale training may run for weeks and must support periodic checkpoint persistence and resuming from checkpoints.

    In cloud environments, checkpoints are commonly stored in object storage, training tasks are orchestrated through container platforms, and loss and hardware metrics are tracked with monitoring and alerting services. This helps ensure stability and operability for long-running jobs.

    7. Best Practices for Adaptation and Tuning

    1. Validate operator alignment first: On small-scale or single-accelerator setups, compare outputs against a reference implementation and target hardware to expose numerical issues early.

    2. Scale up progressively: First verify correctness with a small number of accelerators, then expand to thousands of accelerators while observing throughput and memory curves to identify communication bottlenecks.

    3. Build a performance-profiling loop: Use timeline analysis to distinguish compute, communication, and waiting time, and determine whether operators are slow or communication is slow.

    4. Parameterize parallel configurations: Make TP, PP, FSDP, and EP sharding dimensions configurable so they can be tuned quickly across different hardware topologies.

    5. Ensure reproducibility: Fix random seeds, record parallel topologies and hyperparameters, and retain checkpoints so experiments can be traced and reproduced.

    8. Conclusion

    Training adaptation for trillion-parameter large models is essentially distributed systems engineering centered on memory, communication, and stability.

    With per-parameter sharding and distributed tensor abstractions, FSDP2 provides an elegant and extensible foundation for training ultra-large models under limited memory. Coordination across model loading, shard scheduling, gradient synchronization, mixed precision, and multimodal data pipelines ultimately determines whether the training pipeline can run, remain stable, and run fast.

    For developers, mastering the methodology of sharding as the core, overlapping communication, maintaining numerical consistency, and validating progressively is more valuable than memorizing a specific set of interfaces, because the engineering core of large-model training remains consistent regardless of the underlying compute backend.