Training Trillion-Parameter Multimodal Models with FSDP2: Memory Budgeting, Sharding, and Parallel Strategies

    A practical guide to training trillion-parameter multimodal models with FSDP2 in PyTorch. This article covers how to estimate GPU memory requirements, the key differences between FSDP2 and FSDP1, how to shard heterogeneous multimodal components, how to overlap gradient communication with computation, and how to combine FSDP2 with tensor parallelism and pipeline parallelism, along with a minimal runnable code skeleton.

    1. First, Calculate the Memory Budget

    Before training a trillion-parameter model, you need to estimate GPU memory usage. Take a 2.8 trillion-parameter model as an example: storing the weights in BF16 alone requires roughly 5.6 TB (decimal). This figure covers only the weights — it excludes optimizer states, gradients, and activations.

    In a typical mixed-precision AdamW setup, each parameter consumes about 16 bytes: 2 bytes for the BF16 weight, 4 bytes for the FP32 master weight, 4 bytes for the FP32 first momentum, 4 bytes for the FP32 second momentum, and 2 bytes for the BF16 gradient. By this estimate, the total training state amounts to about 44.8 TB. If you use 1,024 accelerators with 64 GB of memory per card, fully sharded training states take up roughly 43.75 GB per card, and the remaining memory must be reserved for activations, communication buffers, and memory fragmentation. Activations typically need to be further compressed with activation checkpointing.

    2. FSDP2 vs. FSDP1

    FSDP2 is built on DTensor and shards parameters individually. Each parameter is split along dimension 0 across the ranks of a device mesh; full parameters are gathered on demand during the forward and backward passes and released immediately afterward. FSDP1, by contrast, flattens module parameters into a FlatParameter and relies on module wrapping.

    Dimension FSDP1 FSDP2
    Entry API FullyShardedDataParallel(model) wraps the whole model fully_shard(module) acts on submodules in place
    Sharding representation Flattened FlatParameter Per-parameter sharding based on DTensor
    Parameter access Requires the summon_full_params context Parameters are DTensors and can be accessed directly
    Mixed precision config MixedPrecision MixedPrecisionPolicy
    Device specification device_id device_mesh

    Use PyTorch 2.6 or later. For exact API details, refer to the official documentation of the version you are using.

    3. Loading and Sharding Multimodal Models

    The vision encoder, audio module, and LLM backbone differ in parameter counts and computation patterns. Therefore, you should define sharding strategies per module group rather than applying a single configuration to the entire model. The typical approach is to call fully_shard on each Transformer layer first, then call it once on the root module, so that the remaining parameters — such as embeddings and projection layers — are grouped into the root shard group. Calling bottom-up ensures each layer’s parameters are released promptly after the forward pass.

    Very large models should not be fully instantiated on every rank. The recommended approach is to build the model structure on the meta device, complete the sharding, and then load the weights shard-by-shard using torch.distributed.checkpoint.

    4. Gradient Synchronization and Compute-Communication Overlap

    During backpropagation, once the gradient computation for a shard group finishes, FSDP2 distributes the gradients to the corresponding ranks via Reduce-Scatter. The communication runs on an asynchronous stream and can overlap with computation in subsequent layers. This requires the underlying communication library to support non-blocking collective operations.

    Two configurations involve trade-offs. The first is reduce_dtype. Using FP32 for gradient reduction is more stable, but doubles the communication volume compared with BF16. The second is reshard_after_forward. When set to False, parameters stay in memory after the forward pass and do not need to be re-gathered in the backward pass, saving communication at the cost of higher memory usage. In practice, it is common to disable resharding for later layers while keeping it enabled for earlier layers.

    5. Choosing a Parallelism Strategy

    FSDP2 can be used on its own. At extreme scale, it is usually combined with tensor parallelism (TP) and pipeline parallelism (PP). A common way to divide responsibilities is:

    • Place TP within a single node to leverage high-speed intra-node interconnects, reducing per-layer activation memory and matrix multiplication sizes.
    • Use PP to split layers across nodes, reducing cross-node communication, but be aware of pipeline bubbles that require enough micro-batches to hide.
    • Use FSDP2 to shard parameters and optimizer states along the data-parallel dimension.

    The vision encoder has relatively few parameters and usually works fine with FSDP2 alone. The LLM backbone is better suited to 3D hybrid parallelism. Ultimately, the choice should be based on measured peak memory and communication share, not on rules of thumb alone.

    6. Minimal Runnable Skeleton

    The environment requires PyTorch 2.6 or later. To launch on a single node with 8 GPUs, run torchrun --nproc_per_node=8 train.py. The following code assumes the model has two attributes: llm.layers and vision_tower.

    ```python
    import os
    import torch
    import torch.dist