FSDP2 Training for Ultra-Large Multimodal Models: A Practical Guide
This article examines the memory and communication bottlenecks in training trillion-parameter multimodal models, reviews the hardware and software prerequisites, explains how FSDP2 shards parameters and performs All-Gather and Reduce-Scatter during forward and backward passes, and provides a minimal runnable example for PyTorch 2.6 or later.
1. Where Do Training Bottlenecks Come From?
Training memory for trillion-parameter models is mainly composed of weights, gradients, and optimizer states. Using mixed-precision training with AdamW as an example, each parameter takes about 16 bytes: 2 bytes for the BF16 weight, 2 bytes for the BF16 gradient, and 12 bytes for the FP32 master weight plus two FP32 momentum states. At 1 trillion parameters, this state alone requires about 16 TB, far exceeding the memory capacity of a single accelerator or a single machine. Activations also take additional space; longer sequences and larger batches increase usage.
Communication is the second bottleneck. Multimodal models include a vision encoder, a language model, and fusion modules. Their parameter scales and compute patterns differ substantially, and after sharding it is difficult to align each module’s communication time with its compute time. Once communication time exceeds compute time, accelerators sit idle. Inter-node bandwidth is usually lower than intra-node interconnect, so cross-node collective communication is most likely to become the bottleneck.
2. What the Hardware and Software Foundation Must Provide
At the hardware level, three types of metrics matter: high-bandwidth memory capacity and bandwidth, intra-node inter-accelerator interconnect bandwidth, and inter-node network bandwidth. Inter-accelerator bandwidth determines the speed of intra-node All-Gather, while the inter-node network determines the latency of cross-machine Reduce-Scatter. The larger the gap between the two, the more the sharding strategy must account for topology, for example by restricting the most communication-intensive groups to the same node.
At the software level, confirm that native framework operators and communication libraries have available implementations on the target hardware. Fused operators such as FlashAttention can reduce memory read/write traffic and shorten attention-layer compute time. The communication library must support primitives such as All-Gather and Reduce-Scatter and be able to select appropriate algorithms in multi-machine environments. The memory allocator must also handle fragmentation; over long training runs, accumulated fragmentation gradually reduces available memory.
Before deployment, it is recommended to use vendor-provided collective communication benchmark tools such as nccl-tests to measure intra-node and inter-node communication bandwidth separately, and record the measured values. These values serve as the basis for choosing shard granularity and communication groups later.
3. How FSDP2 Works
FSDP2 is PyTorch’s fully sharded data parallel solution, invoked through the fully_shard interface. FSDP1 shards flattened large parameter blocks, while FSDP2 shards each parameter within a module. Sharded parameters are stored as DTensors. This makes it more straightforward to inspect, freeze, and configure mixed precision for parameters, and easier to combine with methods such as tensor parallelism.
A training iteration roughly works as follows. When forward computation reaches a module, the system performs All-Gather on that module’s parameters, obtains the full weights, and completes computation. After computation, if reshard_after_forward is enabled, the full weights are released and only the shard handled by the local accelerator is retained. During backward propagation, the module’s parameters are All-Gathered again; after gradients are computed, Reduce-Scatter is performed, and each accelerator keeps only its own gradient shard.
The trade-off around reshard_after_forward is clear. Enabling it lowers peak memory at the cost of an extra parameter gather before backward propagation. If memory is sufficient and communication is already the bottleneck, it can be disabled. The final choice should be based on measured peak memory and per-step time.
The benefits of FSDP2 over FSDP1 depend on model architecture, shard granularity, and network topology. Ratios from blogs or papers should not be directly applied to your own workload.
4. Minimal Runnable Example
The following example applies to PyTorch 2.6 or later, where fully_shard is located in torch.distributed.fsdp. Launch it with torchrun, with each process bound to one accelerator. Replace build_model and dataloader in the code with your actual implementations. The model should consist of several shardable submodules; here it is assumed that the submodules are stored in model.transformer_blocks.
import osimport torchimport torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicylocal_rank = int(os.environ["LOCAL_RANK"])torch.cuda.set_device(local_rank)
