Practical Guidelines for Training a Trillion-Parameter Multimodal Model with FSDP2

    This article shares practical experience on training a 2.8-trillion-parameter multimodal model with PyTorch FSDP2. It covers how to estimate GPU memory feasibility before training, how FSDP2 shards parameters, how to load models on meta devices, and how to tune communication bucket sizes and compute-communication overlap, helping engineers plan large-scale distributed training efficiently.

    1. Estimating GPU Memory Feasibility Before Training

    Data parallelism requires each GPU to hold a full copy of the model. For 2.8 trillion parameters, BF16 weights alone take up 5.6 TB, which no single GPU can hold, so parameters must be sharded.

    Under mixed-precision training, each parameter takes roughly 16 bytes: 2 bytes for BF16 weights, 2 bytes for BF16 gradients, 4 bytes for FP32 master weights, and 4 bytes each for Adam’s first momentum and second variance.

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

    Activations are not included in the table above; they depend on batch size, sequence length, and whether gradient checkpointing is used. With an even shard across 1,024 GPUs, model states take about 44 GB per GPU (44.8 TB divided by 1,024, in decimal units). If each GPU has 80 GB of memory, the remaining space must accommodate activations, communication buffers, and memory fragmentation. With only 128 GPUs, model states alone would require about 350 GB per GPU, far exceeding single-GPU capacity. In that case, you need to add more GPUs or offload to CPU and NVMe. Offloading reduces throughput and must be evaluated separately.

    The estimate above only provides a lower bound. Real training must also reserve room for peak activation memory, and length fluctuations in multimodal inputs can push that peak even higher.

    2. How FSDP2 Shards Parameters

    FSDP2 wraps modules through the fully_shard API. It shards at the tensor level: each parameter is stored as a DTensor, split along dimension 0 across ranks. FSDP1 flattens all parameters within a module into a single FlatParameter, while FSDP2 preserves the independent shape of each parameter. As a result, saving and loading state dictionaries and mapping optimizer states become more straightforward.

    The process group used for sharding is determined by the DeviceMesh. The simplest configuration is when the data-parallel dimension matches the sharding dimension. If you need to shard within a node and replicate across nodes, use a two-dimensional mesh (i.e., HSDP).

    Version and dependency checks come first. This article uses the FSDP2 API in PyTorch 2.x as an example. Parameter names and behavior may differ across versions, so always refer to the official documentation for the version you are using.

    The reshard_after_forward option controls whether full parameters are released after the forward pass. Enabling it lowers peak memory, but requires another AllGather during the backward pass, which increases communication volume.

    3. Loading the Model on a Meta Device

    A meta device only records tensor shapes and data types without allocating actual GPU memory. The loading workflow can be divided into the following steps:

    1. Build the model on torch.device("meta"), which consumes no GPU memory at this stage.
    2. Call fully_shard in bottom-up order, from child modules to the root module, to complete the sharding plan.
    3. Call to_empty(device="cuda") to allocate memory for each rank’s local shard.
    4. Use Distributed Checkpoint (DCP) so that each rank reads only the shard it is responsible for. The checkpoint must record parameter shapes, data types, sharding dimensions, and the original world size.
    5. Reinitialize buffers that are not in the state_dict, such as cached rotary position embeddings. These tensors hold no real values on a meta device, and skipping this step will produce incorrect results.
    6. Run a forward pass with a small batch to verify that output shapes and values are correct before starting full training.

    Checkpoints can be stored on a high-performance parallel file system or in object storage. When many nodes read concurrently, you should limit concurrency to prevent the metadata service or network bandwidth from becoming a bottleneck. In this project, the team used a parallel file storage service from a cloud provider. Readers can substitute any storage on their local cluster that supports parallel reads; the key selection criteria are read throughput and concurrent metadata capability.

    4. Tuning Communication Bucket Size and Compute Overlap

    FSDP2 performs an AllGather for parameters before the forward and backward pass of every layer. If communication takes longer than computation, the compute units sit idle. The goal of tuning is to hide communication behind computation as much as possible.

    If you use custom bucketing, multiple parameters can be merged into a single communication bucket. When tuning, pay attention to the following:

    • The AllGather time for a single bucket should not exceed the compute time of the preceding layer.
    • If buckets are too small, the startup overhead of each collective communication takes a larger share, and bandwidth utilization for small messages drops.
    • If buckets are too large, peak memory increases, and the time window available for overlap also