Shard Scheduling and Gradient Synchronization in Large Multimodal Model Training
This article covers how to adapt large multimodal model training to distributed hardware. It explains the four stages of the training pipeline, the memory and communication trade-offs of fully sharded data parallelism, and common issues in multimodal training. It also covers numerical correctness, checkpoint recovery, and a validation checklist for new hardware platforms.
1. Background: Why Training Adaptation Is a Separate Problem
When model parameters reach the trillion scale, the memory of a single accelerator cannot hold the full weights, gradients, and optimizer states at once. Multimodal models also include heterogeneous modules, such as a vision encoder, a language model, and projection layers. These modules differ clearly in their computation patterns and parameter structures. Training adaptation therefore has three goals: the numerical results must match the baseline, throughput must stay within an acceptable range, and training must be able to resume after an interruption. Getting the program to run is only the starting point.
2. The Four Stages of the Training Pipeline
A complete training pipeline has four stages, and each stage has different constraints.
- Model loading: Build the model structure on a meta device first, which stores no actual data. Then read the weights shard by shard. This avoids loading the full model in every process, which lowers the peak memory during startup.
- Shard scheduling: Split parameters by layer or by functional module. Decide which parameters each compute unit must gather before its forward computation. A coarse granularity raises peak memory. A fine granularity increases the number of communication operations.
- Gradient synchronization: After backpropagation, the accelerators must reduce their gradients. After sharding, each accelerator keeps only the gradient segment it owns, which lowers the communication volume.
- Optimizer update: Each accelerator updates only the parameter shard it holds. Optimizer states are also stored by shard.
The pseudocode below shows only the execution order. It does not correspond to any specific API.
# Illustrative pseudocode, shows execution order onlyForward pass:for each shard unit in the model layer sequence:full_params = all_gather(parameter shards of this unit) # gather on demand before computeoutput = forward_compute(full_params, input)release(full_params) # free right after compute to control peak memoryinput = outputBackward pass:for each shard unit in reversed(model layer sequence):full_params = all_gather(parameter shards of this unit)local_grad = backward_compute(full_params, upstream_grad)release(full_params)shard_grad = reduce_scatter(local_grad) # each accelerator keeps only its gradient shardOptimizer stage:optimizer_update(local_param_shard, shard_grad)
3. Core Mechanisms of Fully Sharded Data Parallelism
Fully sharded data parallelism splits parameters, gradients, and optimizer states across all processes. Each process holds only a portion of this state over the long term. When it computes a layer, it temporarily gathers the full parameters for that layer and releases them immediately after the computation finishes.
This approach relies on two types of communication operations:
- All-gather: Before the forward or backward computation of a layer, collect the parameter fragments spread across accelerators and combine them into the full parameters.
- Reduce-scatter: After the backward computation, sum the local gradients on all accelerators and send each result only to the accelerator that owns it.
Static memory estimation is the first step in capacity planning. Take mixed-precision Adam training as an example. Each parameter takes roughly 16 bytes: 2 bytes for the bf16 parameter, 2 bytes for the bf16 gradient, 4 bytes for the fp32 master weight, and 8 bytes for two fp32 optimizer momentum terms. For a model with 1 trillion parameters, the static states total about 16 TB. Splitting them evenly across 256 accelerators leaves about 62.5 GB per accelerator. This figure excludes activations, communication buffers, and fragmentation overhead, so extra memory must be reserved.
More shards do not always help. More shards lower the static memory per accelerator, but each compute unit then needs more frequent gather communication. In practice, estimate the memory headroom first, then choose the smallest shard count that meets the capacity requirement. This keeps communication overhead low.
4. Issues Specific to Multimodal Training
Multimodal training is more prone to problems than single-modality text training. The main issues are:
- Shard granularity for heterogeneous modules: The vision encoder and the language model have different layer structures. A single sharding strategy can over-fragment some modules. A common approach is to define a separate shard unit for each module.
- Variation in input length: Image token counts and text lengths vary widely, so the compute load across accelerators in the same batch can be uneven. Faster accelerators must wait for slower ones, which reduces overall throughput. Possible solutions include bucketing by length or balancing the load at the data level.
- Mixed frozen and trainable parameters: When some modules are frozen, their parameters should not produce gradients or enter the optimizer states. If freezing logic is applied only after sharding, it can waste memory or misalign gradients.
- Consistent randomness: The random seeds for operations such as data augmentation and dropout must be set explicitly on each accelerator. Inconsistent seeds make repeated runs of the same configuration hard to reproduce.
5. Gradient Synchronization and Numerical Correctness
In distributed training, numerical problems are often harder to debug than performance problems. The following steps need particular attention.
- Reduction precision: Communicating in low precision, such as bf16, saves bandwidth. However, if accumulation also runs in low precision, the error grows as the number of accelerators increases. A common practice is to accumulate in fp32 during reduction and use low precision only for transmission.
- Gradient clipping: After sharding, each accelerator holds only part of the gradients. The global norm must first be computed as a local sum of squares on each accelerator. Then one global reduction combines these sums, and the square root is taken last. If each accelerator computes the norm independently, the clipping result will differ from single-accelerator training.
- Baseline alignment: When adapting to new hardware, first compare outputs and gradients between a single accelerator and multiple accelerators using a small model. Compare relative errors layer by layer, and set tolerances based on the accuracy requirements of the task. No universal standard exists for tolerance thresholds. The team should set them based on the model and task.
6. Checkpointing and Fault Tolerance
Long training runs will eventually be interrupted, and checkpoint design directly affects recovery cost.
- Sharded saving: Each process saves the parameter and optimizer shards it holds. This avoids gathering the full model, which would create memory and network pressure.
- Resharded loading: The number of accelerators at restore time may differ from the number at save time. The loading logic must re-split the data according to the new sharding rules. Otherwise, recovery is possible only at the same scale.
- Recovery validation: After recovery, check whether the training loss continues smoothly from its value before the interruption. If there is a clear jump, first check whether the optimizer state or the random number generator state was loaded correctly.
7. Validation Checklist for New Hardware Platforms
When adapting training to a new computing platform, confirm each item in the following checklist.
- Core operators: Forward and backward passes, normalization, attention, and other core operators produce numerical behavior at the target precision that matches the baseline.
- Collective communication: Primitives such as all-gather and reduce-scatter are correct and show the expected latency across different message sizes.
- Peak memory: The gap between actual peak memory and the estimate is explainable, and enough safety margin remains.
- Throughput and scalability: From a single machine to multiple machines, throughput scales with the accelerator count as expected.
- Long-run stability: Run for a sufficiently long time and monitor the loss curve, memory usage, and process status for stability.
8. Practical Recommendations
Adapt training in the order of “start small and scale up, align first and then optimize.” First, run the full pipeline end to end on a small model and establish a numerical baseline. Second, gradually increase the number of accelerators and the model size, and repeat baseline alignment at each step. Third, after training is stable, tune performance, for example by overlapping communication with computation and adjusting shard granularity.
Throughout the process, record the memory, throughput, and loss for each configuration. These records help troubleshoot problems later and provide an objective reference when comparing approaches across platforms.
