FSDP2 for Training Trillion-Parameter Multimodal Models: A Practical Adaptation Guide

    This article explains how to adapt trillion-parameter multimodal models for training with FSDP2. It starts with why the memory footprint of parameters, gradients, and optimizer states rules out single-machine training and why FSDP2's per-parameter sharding improves on earlier FSDP implementations. It then covers four key areas of adaptation: per-device parallel loading and initialization, compute-communication overlap and prefetch tuning, bf16 compute with fp32 gradient reduction, and gradient synchronization through reduce-scatter and all-gather. It also outlines considerations specific to multimodal models, such as sharding heterogeneous sub-networks and loss calibration, and a stepwise adaptation path for emerging AI accelerator platforms.

    Introduction: The Training Engineering Challenge of Trillion-Parameter Models

    Once foundation models crossed into the trillion-parameter range, the core challenge of training shifted. It is no longer just about whether an algorithm can converge, but about how to keep a model far larger than a single accelerator’s memory running stably across a heterogeneous set of accelerators. For a trillion-parameter multimodal model, the combined memory footprint of parameters, gradients, and optimizer states under mixed-precision training is often more than ten times the size of the parameters alone. Take Adam-style optimizers as an example. Beyond the bf16 parameters and gradients, they must also retain fp32 master weights and first- and second-order momentum states, which a single device simply cannot hold. No single-machine solution is therefore viable. A distributed training framework is required to shard the model state across many devices and schedule them in coordination.

    Why FSDP2: From Full Replication to Full Sharding

    The most basic form of data parallelism gives every accelerator a complete copy of the model, so memory cannot scale with model size. Fully Sharded Data Parallel (FSDP) takes a different approach: parameters are gathered on demand during the forward and backward passes and released once they are no longer needed. As a result, each accelerator permanently holds only a portion of the parameters, gradients, and optimizer states.

    The key improvement in FSDP2 over earlier implementations is its sharding granularity. FSDP2 shards at the granularity of individual parameters and uses a distributed tensor abstraction to express the sharded view, rather than flattening an entire layer into a single one-dimensional parameter. This design delivers three main benefits:

    • Finer control over communication and memory, which makes it easier to combine FSDP2 with activation recomputation and mixed-precision policies.
    • Easier orthogonal composition with other parallelism dimensions, such as pipeline parallelism and tensor parallelism, avoiding the tight coupling that flat parameters create.
    • Fewer redundant copies when parameters are repeatedly gathered and released, which helps keep long-tail memory peaks down.

    The following is illustrative pseudocode that shows how FSDP2 is used. It does not represent the API of any specific framework:

    1. # Define the mixed precision policy: compute in bf16, reduce gradients in fp32 for numerical stability
    2. policy = MixedPrecisionPolicy(param_dtype="bf16", reduce_dtype="fp32")
    3. for block in model.blocks: # apply sharding to each submodule individually
    4. shard_module(block, policy)
    5. shard_module(model, policy) # shard at the top level as well, forming a layered structure where the outer module is wrapped and the inner modules are sharded
    6. loss = model(batch)
    7. loss.backward() # the backward pass triggers the gradient reduce-scatter

    Four Key Areas of Training Adaptation

    1. Model Loading and Parallel Initialization

    For a trillion-parameter model, you cannot build the full set of weights on one device and then distribute them. Instead, use per-device parallel loading: each rank reads and initializes only the weights it is responsible for, while the remaining shards are described by metadata such as global shapes and shard offsets. This keeps peak memory during loading within what a single device can handle and avoids out-of-memory (OOM) errors. When weights already exist, a checkpoint format with sharding support can split the large weights into multiple shard files that are written and read in parallel, shortening cold-start times.

    2. Sharding Strategy and Compute-Communication Scheduling

    FSDP hides communication overhead through compute-communication overlap. While the parameters of one layer are being gathered with all-gather, the operators of the preceding layer are computed at the same time, so communication time and computation time mask each other.

    The scheduler needs a well-tuned prefetch depth. If prefetching is too shallow, communication is exposed; if it is too deep, the memory peak rises. Prefetch depth therefore has to be balanced between throughput and memory. In a hierarchical sharding structure, the order in which modules are wrapped and sharded also affects gather granularity and overlap efficiency, so it should be tuned empirically against the model’s structure.

    3. Mixed Precision and Numerical Stability

    Large-scale training commonly uses bf16 for computation and fp32 for gradient reduction. bf16 has a wide dynamic range and is relatively insensitive to overflow, which suits the stability requirements of trillion-parameter models. Accumulating gradient reductions in fp32, meanwhile, reduces the precision loss that comes from summing large numbers of small gradients.

    One caveat: optimizer master weights usually keep an fp32 copy. This portion of memory cannot be eliminated and is a significant item in the memory budget.

    4. Gradient Synchronization and the Backward Path

    During the backward pass, FSDP performs a reduce-scatter on the gradients of each shard in reverse order along the computation graph. Each accelerator ends up holding only the summed gradients for the parameter shards it owns. These gradients are then passed to the corresponding optimizer shards to perform the updates, after which an all-gather produces the new parameters for the next step. This “gather, reduce, update, and gather again” cycle must be strictly aligned with the scheduling order. Otherwise, gradients may be mismatched or collective communication may deadlock.

    Special Considerations for Multimodal Models

    Multimodal models typically contain multiple modality encoders along with unified modules for feature alignment and fusion. Adapting them requires additional attention:

    • Sharding heterogeneous structures: Sub-networks can differ greatly in parameter count, so they should use separately defined sharding granularities. Otherwise, small modules may be over-sharded, which inflates the share of communication.
    • Data-side construction: Samples such as text, images, and audio vary in length, so reasonable batch construction and packing strategies are needed to make better use of available compute.
    • Precision and loss calibration: Loss scales differ across modalities, so loss weights and gradient clipping thresholds need to be calibrated for each modality. This prevents any one modality from dominating the overall optimization direction.

    Stepwise Adaptation Recommendations for Emerging AI Accelerator Platforms

    When carrying out this kind of adaptation on AI accelerator platforms outside the established GPU ecosystem, along with their software stacks, a typical path is as follows:

    1. Operator coverage and precision verification: First get forward and backward passes running for a single layer, then check each operator’s numerical results against a reference implementation.
    2. Communication primitive alignment: Confirm that the semantics and performance of collective communication primitives such as all-gather and reduce-scatter meet expectations on the target platform.
    3. Scale up incrementally: Move from a single device to multiple devices on one node, then to multiple nodes, scaling up step by step and validating the convergence curve and memory usage at each stage.
    4. Observability: Use general-purpose cloud capabilities such as logging services and monitoring and alerting (for example, those offered by platforms like Baidu AI Cloud) to continuously track memory peaks, the share of communication, and throughput changes so that bottlenecks can be located quickly.

    Conclusion

    Adapting trillion-parameter multimodal models for training is ultimately a systems engineering problem: sharding a massive model state and coordinating it efficiently within limited memory and bandwidth. With its fine-grained parameter-level sharding and distributed tensor abstraction, FSDP2 provides good composability and scalability for cross-device training. The actual results, however, depend on how well sharding and scheduling, mixed precision, gradient synchronization, and platform operator adaptation work together. A shortcoming in any one of these areas can become the overall performance ceiling.