FSDP2 Sharding for Trillion-Parameter MoE Training: Key Adaptation Considerations

    This article discusses how to adapt FSDP2 sharding for training a sparse mixture-of-experts model with 2.8 trillion parameters. It covers the memory, communication, and scheduling challenges involved, the differences between FSDP1 and FSDP2, practical sharding, prefetch, loading, and checkpointing designs, and the engineering capabilities needed to validate performance in production.

    Key Challenges of Training a 2.8T-Parameter Sparse MoE Model

    An open-source community has released a sparse mixture-of-experts (MoE) model with 2.8 trillion parameters. Training it stresses memory, communication, and scheduling simultaneously. Because each token activates only a subset of experts, per-step compute is much smaller than total parameter count, but all expert parameters must still be stored somewhere.

    Rough Memory Requirement Estimate

    With BF16 mixed-precision training and the Adam optimizer, each parameter occupies about 16 bytes:

    Item Bytes per Parameter Total for 2.8T Parameters
    BF16 weights 2 About 5.6 TB
    BF16 gradients 2 About 5.6 TB
    FP32 master weights 4 About 11.2 TB
    Adam first and second moments 8 About 22.4 TB
    Total 16 About 44.8 TB

    This estimate excludes intermediate activations and communication buffers. On a cluster of 1024 accelerators, if parameters, gradients, and optimizer states are sharded uniformly, the static state per accelerator is about 43.75 GB. Activation and communication buffer space must also be reserved, so the usable memory budget is tighter in practice. This number is only for order-of-magnitude judgment; the exact value must be recalculated for your own sharding scheme and activation strategy.

    Communication Pressure from Multiple Parallel Strategies

    Large-scale training often combines data parallelism (DP) and tensor parallelism (TP). MoE models also require expert parallelism (EP). EP relies on All-to-All communication for token dispatch and result merging. If routing concentrates tokens on a few experts, those accelerators become communication and compute hot spots while others wait. With multiple parallel dimensions stacked together, process group layout and communication ordering need careful design.

    Stability Over Long Training Runs

    Training can last for weeks. Any unrecoverable GPU memory error or network hiccup can interrupt the job. The larger the model, the longer a complete checkpoint write takes. Checkpoints must therefore be saved in sharded form and support asynchronous writes.

    FSDP1 vs. FSDP2

    How FSDP1 Works

    FSDP1 (Fully Sharded Data Parallel) concatenates parameters inside a wrapping unit into a FlatParameter and shards it across processes. Before forward and backward computation, each process temporarily All-Gathers the full parameters needed for the current layer. After computation, the parameters are reshaped and freed. Gradients use Reduce-Scatter to sum and shard. Parameters, gradients, and optimizer states all remain sharded per process.

    The flat parameter approach has limitations. Parameters inside the same FlatParameter must share properties such as frozen state and data type, which complicates mixed precision and partial freezing. FlatParameter boundaries may also not align with module structure, making composition with tensor parallelism and expert parallelism more difficult.

    What FSDP2 Changes

    FSDP2 uses per-parameter sharding. Each parameter is represented as a DTensor and sharded along dimension 0. There is no FlatParameter, so each parameter retains its own shape and attributes. FSDP2 still uses All-Gather and Reduce-Scatter, so the core communication pattern is unchanged. The main benefits are:

    • It composes more naturally with DeviceMesh, making it easier to combine with tensor parallelism and expert parallelism.
    • Parameter granularity matches module structure, so prefetching and offloading can be done per expert or per layer.
    • The reshard_after_forward option lets you decide whether to release parameter shards immediately after the forward pass, trading memory for communication efficiency.

    FSDP2 does not change the fundamental idea of parameter sharding, gradient sharding, and on-demand gathering. Its value lies in finer granularity and better composability. The actual benefit depends on model structure and network conditions.

    Key Design Choices for Adaptation

    Sharded Storage and CPU-to-Accelerator Migration

    In practice, expert parameters and shared parameters are accessed at different frequencies. One approach is to track access patterns over several training steps and decide which parameters should stay in accelerator memory and which should be placed in CPU memory. The cost of swapping is dominated by PCIe bandwidth, which is much lower than NVLink bandwidth. Offloading is beneficial only when migration time can be overlapped with computation. If migration time exceeds the compute window, the safer choice is to keep parameters resident in accelerator memory. These thresholds must be measured in the actual environment.

    Overlapping Communication with Computation

    While the current block is computing gradients in the backward pass, the system can asynchronously initiate All-Gather for the next block’s parameters. Prefetch depth is a key parameter. Deeper prefetch improves communication-compute overlap but consumes more memory. Tuning should observe both peak memory usage and compute idle time.

    Partitioned Sharded Loading

    A 2.8T-parameter model cannot be fully loaded into one node and then broadcast to other nodes. A more practical approach is to pre-shard the weight files so that each compute node reads only its own shard from shared storage, then performs lightweight collective communication for verification, such as shard-level hash checks. Startup time should be recorded in separate parts: file reading, shard verification, and process group initialization, so bottlenecks can be identified.

    Multi-Modal Extension

    The model includes both text and vision encoders. The vision encoder is relatively small and can use fully sharded training. The text backbone contains more expert parameters and is better sharded by expert, with dynamic block scheduling. Gradients from the fusion layer need unified synchronization. To avoid one modality’s communication waiting on another modality’s computation, it is recommended to use separate communication groups for different modules and orchestrate their order in a unified scheduler.

    Configuration Items to Record

    This article describes an adaptation approach rather than a complete version and parameter list. To reproduce or evaluate a similar solution, at least record:

    • PyTorch, DTensor, and the underlying accelerator software stack versions.
    • Collective communication library version and topology configuration.
    • World size, per-accelerator shard size, and process group layout.
    • Prefetch depth and reshard_after_forward setting.
    • Checkpoint interval, single checkpoint size, and storage bandwidth.

    Engineering Capabilities for Production Deployment

    MoE Operators and Low-Level Compute Libraries

    Beyond the training framework, expert computation depends on efficient low-level operators. MoE routing requires sparse matrix multiplication, where tokens assigned to each expert are organized into contiguous batches and computed separately. Token permute and unpermute operations are also required. Fusing these steps into fewer kernels reduces memory access. Performance evaluation should focus on three metrics: number of tokens received per expert, load imbalance coefficient (max/mean), and single-step time before and after operator fusion. Performance data is meaningful only when numerical results match the reference implementation.

    Asynchronous Checkpointing and Failure Recovery

    Checkpoints should be saved in sharded form and written asynchronously to persistent storage during training. After a node failure, the scheduler rebuilds the process topology and recovers from the most recent complete checkpoint. Recovery time depends on checkpoint size, storage bandwidth, cluster scale, and failure type. The original solution targets reducing recovery time from hours to minutes, but no test conditions were provided. If this conclusion is cited, it should be measured through fault injection testing with a clearly defined cluster scale and checkpoint size.

    Performance Observability

    Performance observability should provide the following information:

    • Forward-pass time per shard.
    • Overlap ratio between parameter prefetch and computation.
    • Cross-node communication latency.
    • Proportion of idle bubbles between communication and computation.

    These data points are used to locate communication bottlenecks and memory peaks, and to guide tuning of prefetch depth, sharding granularity, and process group layout.

    Practical Recommendations

    First, sharding granularity determines the upper bound of training efficiency. Granularity that is too coarse wastes memory; granularity that is too fine increases communication overhead. A balance must be found.

    Second, software stack maturity directly affects migration cost. A unified compute architecture can reduce model code changes, but every key operator should be numerically compared against the reference implementation.

    Third, storage, communication, operators, and the scheduler must be designed together. Optimizing one component in isolation often creates a new bottleneck elsewhere.

    Fourth, any performance conclusion should include measurement conditions: cluster scale, model configuration, data scale, and failure type. Without those conditions, numbers are difficult to reproduce or compare.

    As model parameters continue to grow, sharding, communication, and fault tolerance designs need continuous updates. For engineering teams, building a reliable measurement and recording process first, then tuning items one by one, is usually more effective than trying to find one optimal configuration immediately.