Sharded Scheduling and Gradient Synchronization for Multimodal Training of Extremely Large Models

    This article outlines a practical training pipeline for multimodal models at trillion-parameter scale, where parameters, gradients, and optimizer states must be sharded across many processes. It covers weight loading, on-demand parameter aggregation, sharded gradient synchronization, optimizer state management, multimodal-specific packaging, and communication optimization for gradient synchronization.

    Sharded Scheduling and Gradient Synchronization for Multimodal Training of Extremely Large Models

    1. Problem Background

    Recently, the industry has seen public cases of very large open-source models completing multimodal training adaptation. Such models reach trillion-parameter scale and process multiple input types such as images and text at the same time. The memory of a single accelerator card cannot hold the full parameters, gradients, and optimizer states, so training must rely on multi-GPU and even multi-node collaboration.

    This creates three engineering challenges. First, how should model weights be split across multiple cards and loaded correctly? Second, during each training step, how should parameters be aggregated on demand, computed, and released promptly? Third, how should gradients produced on different cards be synchronized efficiently while ensuring numerical results match single-card training? The following sections address these three questions and describe a complete training pipeline.

    2. Training Pipeline Overview

    A usable training pipeline for extremely large models usually contains four stages:

    1. Model construction and weight loading: Allocate weights to each process according to sharding rules without exhausting single-card memory.
    2. Sharded scheduling: Before forward computation, temporarily aggregate the parameters required by the current module; after computation, release non-local shards.
    3. Backward computation and gradient synchronization: Reduce gradients produced by backpropagation according to shards, and keep only the portion owned by each process.
    4. Optimizer update and state management: Each process updates only the parameters and optimizer states of its local shard, and saves checkpoints when needed.

    The four stages depend on one another. If the sharding rules are inconsistent in any part, the result can be shape errors, numerical deviations, or out-of-memory failures. Therefore, engineering teams should first validate the entire pipeline on a small-scale model before scaling it to the target size.

    3. Core Mechanism of Fully Sharded Data Parallelism

    The idea of fully sharded data parallelism is to shard parameters, gradients, and optimizer states across processes, so that each process permanently holds only 1/N of the data, where N is the number of parallel processes.

    Taking common mixed-precision training as an example, if an adaptive moment estimation optimizer is used, each parameter occupies roughly the following memory excluding activations:

    • Low-precision parameters: 2 bytes
    • Low-precision gradients: 2 bytes
    • High-precision master weights, first-order momentum, and second-order momentum: about 12 bytes

    The total is about 16 bytes. If the model has Φ parameters, each card needs about 16Φ bytes without sharding. With full sharding, the persistent footprint per card drops to about 16Φ/N bytes. With N=64, for example, the memory footprint of persistent states drops to about 1/64 of the original.

    This estimate does not include activations, communication buffers, or temporarily aggregated parameters, so the actual peak is usually higher. Planning therefore needs to reserve headroom and determine batch size and shard granularity through measurement.

    3.1 On-Demand Parameter Aggregation

    During forward computation, each sharded module first needs to assemble the full parameters through collective communication. The pseudocode for the core flow is as follows:

    1. for block in model.blocks:
    2. full_params = all_gather(block.local_shard) # Gather full parameters for the current module
    3. output = block.forward(x, full_params)
    4. free(full_params) # Release immediately after computation
    5. x = output

    The backward computation flow is similar, but parameters need to be aggregated again. After gradients are computed, reduce-scatter semantics are also required so that each process keeps only the gradient of its local shard.

    3.2 Choosing Grouping Granularity

    Grouping granularity determines the trade-off between communication count and peak memory. With finer grouping, the amount of data aggregated at one time is smaller and peak memory is lower, but the number of communication operations increases and latency accumulates noticeably. With coarser grouping, communication count decreases, but peak memory rises. A common practice is to group by Transformer layer or module boundary, and to compare throughput and memory usage under different granularities through benchmarking.

    4. Special Handling for Multimodal Models

    A multimodal model usually consists of a vision encoder, a connector module, and a language model. These parts differ significantly in parameter scale, compute density, and numerical sensitivity. Applying a single sharding strategy to all of them often does not produce optimal results.

    In practice, the following approaches can be considered:

    • Module-wise wrapping: Wrap the vision encoder and language model separately, and let each independently determine its sharding scope and aggregation timing.
    • Differentiated handling of frozen parts: If the vision encoder is frozen at a certain stage, it can be excluded from gradient synchronization, thereby reducing communication volume.
    • Data types by module: Keep higher precision for numerically sensitive normalization layers and output layers, and use lower precision for the rest.
    • Input shape alignment: Sequence lengths differ greatly across modalities, so padding or bucketing needs to be unified to avoid some processes waiting for others and slowing down the overall speed.

    These approaches all need to be validated experimentally for their impact on convergence curves; throughput metrics alone are not sufficient.

    5. Gradient Synchronization and Communication Optimization

    Gradient synchronization is the most likely bottleneck in distributed training. There are three main optimization directions.

    First, overlap communication and computation. While backpropagating through one layer, asynchronously launch the gradient reduction for the previous layer. As long as communication time does not exceed computation time, most communication overhead can be hidden.

    Second, gradient accumulation. When memory is tight, parameters can be updated after multiple forward and backward passes. This effectively increases the global batch size, so the learning rate needs to be adjusted accordingly, and convergence stability should be monitored.

    Third, correct implementation of gradient clipping. In a fully sharded setup, the global gradient norm must be aggregated across processes. If each process computes the norm using only its local shard, …