How to Build the Training Pipeline for a 2.8-Trillion-Parameter Multimodal Model

    This article explains how to construct the training pipeline for a 2.8-trillion-parameter multimodal model. It covers three core problems: using sharding to keep memory usage within the capacity of a single GPU, overlapping parameter loading, scheduling, and communication, and recording performance metrics with their measurement conditions. It also analyzes the differences between FSDP1 and FSDP2 and provides a code example based on FSDP2.

    How to Build the Training Pipeline for a Large-Scale Multimodal Model

    1. The Conclusion First

    Training a 2.8-trillion-parameter multimodal model requires solving three problems: using sharding to reduce memory consumption to a level a single GPU can handle, overlapping parameter loading, scheduling, and communication as much as possible, and recording the performance numbers and measurement conditions of every stage. The following sections expand on these three points, and a checklist is provided at the end.

    2. The Real Pressure on Memory and Communication

    If 2.8 trillion parameters are stored in FP16 or BF16, the model weights alone take about 5.6 TB (2.8 × 10^12 parameters at 2 bytes each). This figure only accounts for the weights themselves. Training also requires gradients, optimizer states, and forward activations. Under a common mixed-precision setup with Adam, each parameter requires an FP32 master weight, a first-order momentum, and a second-order momentum — about 12 bytes in total, six times the size of an FP16 weight. As a result, the memory needed for full training far exceeds the size of the weights, and neither a single GPU nor a single node can hold the entire model.

    Communication pressure grows with parameter count as well. Every training step requires exchanging parameters and gradients across GPUs. If the communication strategy is poorly designed, communication time can exceed computation time, and GPU utilization will drop noticeably.

    Multimodal models also introduce structural heterogeneity. The typical characteristics of each module are as follows:

    Module Typical Characteristics Impact on Memory Impact on Communication
    Vision encoder High input resolution, large activations Activations dominate Relatively few parameters, frequent synchronization
    Language decoder Largest parameter count, regular layer structure Parameters and optimizer states dominate Highest communication volume from inter-layer parameter aggregation
    Modality alignment layers Few in number, varied structure Small footprint Requires separate sharding granularity; prone to becoming a small-operator bottleneck

    3. Differences Between FSDP1 and FSDP2

    FSDP1 shards at the granularity of wrapped units. All parameters within the same wrapped unit are first flattened into a single FlatParameter and then partitioned across GPUs as a whole. This approach delivers high communication efficiency, but the boundaries between parameters are merged, which makes handling frozen parameters, mixed precision, and state dictionaries cumbersome.

    FSDP2 instead represents sharding per parameter using DTensor. Parameters are still partitioned along a dimension, but each parameter retains its own shape and metadata rather than being merged into one large flat tensor. This brings two direct benefits. First, frozen layers and trainable layers can coexist in the same wrapped unit. Second, when saving and loading checkpoints, parameters can be read and written directly by name. For multimodal models — where the vision encoder, language decoder, and alignment layers have very different parameter shapes — per-parameter management is much easier to work with.

    Note that FSDP2 is a PyTorch interface, and its API and version requirements change across releases. If you use a vendor-specific software stack, the device type and communication backend must be replaced, but the sharding semantics remain consistent with the example below.

    4. A Wrapping Example Based on FSDP2

    The example requires PyTorch 2.6 or later, launched with torchrun, with each process bound to one GPU and NCCL as the communication backend.

    1. import os
    2. import torch
    3. import torch.distributed as dist
    4. from torch.distributed.device_mesh import init_device_mesh
    5. from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy
    6. # torchrun injects environment variables such as LOCAL_RANK and WORLD_SIZE
    7. dist.init_process_group(backend="nccl")
    8. local_rank = int(os.environ["LOCAL_RANK"])
    9. torch.cuda.set_device(local_rank)
    10. # 1D device mesh: all GPUs participate in the same sharding group
    11. mesh = init_device_mesh("cuda", (dist.get_world_size(),))
    12. # Build the model on the meta device without consuming actual memory
    13. # MultiModalModel and config are placeholders; attribute names must be
    14. # replaced with the actual model structure
    15. with torch.device("meta"):
    16. model = MultiModalModel(config)
    17. mp_policy = MixedPrecisionPolicy(
    18. param_dtype=torch.bfloat16, # Parameter precision for forward and backward
    19. reduce_dtype=torch.float32, # Precision for gradient reduction
    20. )
    21. # Wrap repeated sublayers first, then the outermost module, so communication
    22. # can overlap layer by layer
    23. for block in model.language_decoder.layers:
    24. fully_shard(block, mesh=mesh, mp_policy=mp_policy, reshard_after_forward=True)
    25. fully_shard(model, mesh=mesh, mp_policy=mp_policy)
    26. # Allocate actual memory, then load parameters from a sharded checkpoint
    27. model.to_empty(device="cuda")

    A few points in the example need clarification. First, sublayers must be wrapped before the outer module; otherwise, the outer module will absorb the sublayer parameters into a single sharding unit, and you lose the benefit of per-layer prefetching. Second, a 1D mesh is sufficient on a single node. When inter-node bandwidth is weak, you can switch to a 2D mesh, placing the replication dimension across nodes and the sharding dimension within nodes — that is, Hybrid Sharded Data Parallel (HSDP). Third, if you need to shard the optimizer states