Training a 2.8 Trillion Parameter Model: FSDP2 Sharding and Gradient Synchronization

    This article explores the infrastructure and software stack adaptations required to train a 2.8 trillion parameter multimodal model. It delves into the mechanics of FSDP2 for parameter, gradient, and optimizer state sharding, detailing parallel strategy selection, model loading, forward and backward scheduling, and gradient synchronization. Additionally, it covers multimodal sub-network configurations, numerical stability, fault tolerance, and performance tuning to provide a comprehensive checklist for large-scale model training.

    1. Why a 2.8 Trillion Parameter Model Requires a Redesigned Training Plan

    Recently, an institution open-sourced a flagship multimodal model with 2.8 trillion parameters. This scale far exceeds the hundred-billion-level models, placing immense pressure on the training infrastructure:

    • VRAM Capacity: FP16 weights alone require about 5.6TB (2.8×10^12 parameters × 2 bytes). Calculating with mixed-precision training, weights, gradients, and optimizer states combined require about 16 bytes per parameter, totaling roughly 44.8TB. A single card typically has 80GB to 192GB of VRAM, which is far from enough to hold the complete model.
    • Communication Volume: The data volume for parameter synchronization and gradient aggregation grows with the model size, making cross-node bandwidth a likely bottleneck.
    • Load Imbalance: The computational density differences among vision, language, and fusion modules mean a uniform splitting approach will leave some GPUs idle.
    • Fault Tolerance and Recovery: Node failures during long training runs are inevitable, requiring specialized designs for state saving and recovery.

    Therefore, the focus of training adaptation is the co-design of the software stack and hardware. Simply adding more GPUs cannot solve the above issues.

    2. Hardware and Software Stack

    The adaptation discussed in this article was completed by a domestic GPU vendor. Their integrated training and inference compute cards are equipped with high-bandwidth memory (HBM2e or HBM3) and high-speed interconnects, achieving full interconnection within a single node. The accompanying MUSA software stack is a general-purpose parallel computing architecture that provides PyTorch-compatible APIs, a built-in collective communication library similar to NCCL, and supports RDMA and GPU direct communication.

    The original text did not disclose the specific card model, driver version, or PyTorch version. Readers attempting to reproduce the setup must verify these dependencies with the vendor and check for differences between the interfaces and upstream PyTorch.

    3. How to Choose FSDP2 Sharding Granularity

    FSDP (Fully Sharded Data Parallel) distributes parameters, gradients, and optimizer states across all GPUs. Each card only holds a portion of the parameters. During forward and backward passes, the framework temporarily aggregates the full parameters of the current layer via all-gather and releases them once used.

    FSDP2 is the next-generation implementation in PyTorch, corresponding to the fully_shard interface. Its key changes include:

    • Per-Parameter Sharding: Each parameter is individually sharded, and the shard state is represented by a DTensor. FSDP1, by contrast, concatenates multiple parameters into a FlatParameter before sharding. Per-parameter sharding results in less memory fragmentation and more straightforward state dict handling.
    • Easier Composition with Other Parallel Methods: The sharded parameters remain DTensors, allowing them to be combined with methods like tensor parallelism.
    • Computation-Communication Overlap: The all-gather prefetching for the next layer can execute in parallel with the current layer’s computation.

    Sharding granularity requires a trade-off. If the granularity is too fine, such as wrapping each small module individually, the number of collective communication calls increases, raising the overhead of small messages. If the granularity is too coarse, such as aggregating an entire large module at once, peak memory usage may exceed the single-card capacity. In practice, it is common to wrap by Transformer blocks or similar sub-modules, and then adjust using peak memory and communication ratio metrics.

    4. How to Choose Parallel Strategies

    The table below compares several common parallel methods. ‘P’ in the table represents the amount of parameter data that needs to be synchronized per card.

    Strategy Sharding Target Per-Card VRAM Benefit Communication Characteristics Applicable Scenarios Main Limitations
    Data Parallel (DP) Data batch None, each card holds the full model One AllReduce per step, communication ~2P Model fits on a single card Cannot train ultra-large models
    Tensor Parallel (TP) Intra-layer matrices Corresponding layer weights reduced by parallelism degree Multiple collective communications per layer, sensitive to bandwidth Intra-node high-bandwidth interconnect Noticeable latency increase across nodes
    Pipeline Parallel (PP) Layer segments Only segment layers are saved Passes activations between segments, low communication volume Cross-node scaling Pipeline bubbles exist, requires micro-batch scheduling
    Fully Sharded Data Parallel (FSDP2) Parameters, gradients, optimizer states Three states reduced to ~1/N All-gather and reduce-scatter per layer, total volume ~1.5x of DP Multi-node large models Relies on prefetch overlap, complex scheduling
    Sequence Parallel Sequence length dimension Reduces activation memory for long sequences Requires extra collective communications Long text or long video inputs Requires attention implementation adaptation

    The benefits listed are theoretical. Actual benefits also depend on activations, communication buffers, and framework implementation.

    5. Model Loading and Sharding Planning

    Let’s use 512 cards with 192GB of VRAM as an estimation example. This is just a calculation sample and does not represent the actual deployment configuration of the original text.

    • Total training states are about 44.8TB, averaging about 87.5GB per card.
    • Each card has roughly 100GB remaining for activations, communication buffers, and memory fragmentation.

    The loading process is divided into four steps:

    1. Metadata Parsing: Read the configuration file, record the name, shape, and data type of each layer, and distinguish between the vision tower, language tower, and fusion projection layers.
    2. Sharding Planning: Determine the sharding method for each layer based on the number of cards and per-card VRAM. In manual sharding scenarios (like tensor parallelism), linear layer weights shaped [out_features, in_features] can be split into N parts along the output dimension, and Embedding layers are suitable for row-wise splitting. FSDP2 will automatically generate sharding information, but the location of each shard should still be recorded.
    3. Streaming Loading: Read shards one by one and place them directly into the corresponding card’s VRAM, without saving the complete model in host memory.
    4. Integrity Check: Perform a SHA256 check on each shard. If the hash does not match, re-read the shard, retrying up to 3 times by default. If it still fails, terminate loading and report the shard name. Failed shards cannot be skipped to continue training.

    6. Sharding Scheduling in Forward and Backward Passes

    The pseudo-code below only illustrates the scheduling order and is not a real interface:

    1. # Illustrative pseudo-code, not a real interface
    2. for i, layer in enumerate(layers):
    3. handle = prefetch_all_gather(layers[i + 1]) # Asynchronously prefetch the full parameters of the next layer
    4. full_weight = wait_all_gather(layer) # Wait for the current layer's parameters to be ready
    5. out = layer.forward(out, full_weight)
    6. release(full_weight) # After the forward pass, only keep the shard

    During backpropagation, parameters need to be all-gathered again because the full parameters were released after the forward pass. This is a trade-off between memory and communication. If the full parameters are retained, backpropagation can skip an all-gather, but it will consume more memory. The corresponding setting in FSDP2 is reshard_after_forward; refer to the documentation of your specific version for exact semantics.

    Prefetching allows communication to overlap with computation, reducing GPU idle time. The original text mentioned a 20% to 30% utilization improvement, but did not specify the baseline, number of cards, or measurement method, so this figure is not adopted here.

    7. Gradient Synchronization and Optimizer Updates

    Traditional data parallelism performs an AllReduce every step, with a per-card communication volume of about 2P. The per-card communication volume of Reduce-Scatter is about P, which is of the same order as AllReduce and roughly half of it. It does not reduce the communication volume to 1/N.

    FSDP2 requires reduce-scatter for gradients during backpropagation, and all-gather for both forward and backward passes. Therefore, the total communication volume per step is about 3P, which is 1.5 times that of data parallelism. FSDP2 trades communication for memory; the communication volume is not reduced. This estimation ignores implementation details, and actual values need to be confirmed through communication counting or profiling tools.

    Regarding the optimizer, AdamW saves FP32 momentum and variance for each parameter during mixed-precision training, totaling 8 bytes, which is 4 times the size of FP16 weights (2 bytes). After sharding, each card only saves about 1/N of the optimizer states, and the FP32 master weights are also sharded. The savings ratio depends on the number of cards N; the larger the N, the smaller the per-card burden.

    Gradient clipping also requires attention. The global gradient norm must first reduce the sum of squares across all shards before taking the square root. The clipping threshold of 1.0 in the original text is just a common starting point and should be adjusted based on the training curve.

    8. Differentiated Configuration for Multimodal Sub-networks

    The computational characteristics of different modules vary significantly and can be configured separately:

    • Vision Encoder: High computation, relatively few parameters. Data parallelism combined with intra-layer sharding helps balance the load across cards.
    • Language Decoder: Parameter-dense, suitable for deep sharding.
    • Cross-modal Fusion Layer: Heavily influenced by sequence length. Sequence parallelism can be used to split the sequence dimension and control activation memory.

    FSDP2 allows setting separate sharding ranges and precision for each sub-network. The vision part commonly uses BF16. For the language part, FP8 can be attempted if both hardware and framework support it, but the numerical effects must be verified and it should not be enabled by default. Numerically sensitive parts like attention probability calculations should retain FP32.

    9. Numerical Stability and Gradient Monitoring

    BF16 has the same exponent bits as FP32, providing a sufficient dynamic range, and usually does not require loss scaling. The original text listed dynamic loss scaling alongside BF16, which is inaccurate. If training with FP16 or FP8, loss scaling is required.

    The following signals should be recorded during training: the trend of the global gradient norm, the occurrence of NaN or Inf, and the skip ratio of loss scaling updates. A consistently increasing skip ratio usually indicates that the numerical range or learning rate needs adjustment.

    10. Fault Tolerance, Monitoring, and Performance Tuning

    1. Checkpointing and Elastic Recovery

    Asynchronous checkpointing saves parameter shards, optimizer states, and random number seeds every K steps. When a failure occurs, the average lost computation is about half a checkpoint interval. Therefore, K should be determined jointly by the single-step latency and the failure frequency. A longer interval means lower per-save overhead, but greater loss in the event of a failure.

    After a node failure, the framework needs to re-shard according to the new number of cards, so the checkpoint format should support loading according to the new topology. After recovery, verify that the loss curve is continuous.

    The original text stated that a single step could take more than 30 seconds. Actual latency depends on the model structure, parallel strategy, network, and batch size, so you should use your own baseline.

    2. Performance Monitoring

    • Communication Time Ratio: Compare with the baseline. If the ratio continuously and significantly increases, check the sharding granularity and the overlap of communication and computation.
    • Memory Fragmentation: When the gap between allocated memory and reserved memory continues to widen, check the patterns of frequent aggregation and release.
    • GPU Utilization and Bubbles: Identify idle periods and verify whether prefetching is actually effective.

    11. Implementation Checklist

    • Loading: Each shard has a hash check, with retries and clear error reporting on failure.
    • Sharding: Record the sharding method for each layer, estimate usage based on per-card VRAM, and reserve margin for activations and communication buffers.
    • Scheduling: Confirm that prefetch and computation overlap is effective, and record the communication ratio.
    • Gradient: Monitor the global gradient norm, NaN and Inf counts, and loss scaling skip ratio.
    • Fault Tolerance: Match checkpoint intervals with failure rates, and verify loss continuity after recovery.
    • Performance: Compare throughput and convergence curves with a small-scale baseline.

    The difficulty of training a 2.8 trillion parameter model lies in balancing sharding, communication, and fault tolerance. Readers should first verify each of the above items using a small-scale model before scaling up to the full size.