Technical Paths for Adapting Ultra-Large Multimodal Model Training
When parameter scales reach the trillions, training bottlenecks shift from compute power to memory and communication. This article analyzes the technical paths for adapting ultra-large multimodal model training. It explores the Fully Sharded Data Parallel (FSDP) approach to manage memory constraints, breaks down the training pipeline including model loading, sharding scheduling, and gradient synchronization, and highlights key engineering practices and troubleshooting steps specific to multimodal scenarios.
I. Background: New Requirements of Ultra-Large Parameter Models on Training Systems
When parameter scales reach the trillion level, training bottlenecks shift from compute power to memory and communication. For instance, a model with 2.8 trillion parameters cannot fit entirely on a single accelerator card. Training also requires saving gradients and optimizer states, which typically consume several times the space of the parameters themselves. Multimodal models introduce image, video, or audio encoding modules, whose input shapes and computational patterns differ significantly from the language backbone, requiring separate processing during training.
Therefore, a viable training solution must simultaneously solve three problems: fitting the model, reading parameters on demand, and correctly aggregating gradients.
II. Core Approach: Fully Sharded Data Parallel
Fully Sharded Data Parallel (FSDP) shards parameters, gradients, and optimizer states across all participating training devices. Each card only holds the segment it is responsible for. Before forward computation, devices gather the full parameters required for the current layer on demand; after backward computation, gradients are scattered and written back to their respective shards. This approach makes single-card memory usage roughly inversely proportional to the number of devices, at the cost of increased communication overhead for parameter gathering and gradient reduction.
In mixed-precision training, a common adaptive optimizer requires about 16 bytes of state space per parameter: 2 bytes each for bf16 parameters and gradients, and 12 bytes total for the fp32 master weights and two momentum terms. Based on this estimate, we can compare the differences before and after sharding:
| Configuration | Number of Devices | Per-Card State Usage (Estimated) |
|---|---|---|
| Unsharded | 1 | ~44.8 TB, far exceeding any single-card capacity |
| Fully Sharded | 1024 | ~44 GB, plus required activation values and communication buffers |
Calculation: 2.8×10¹² parameters × 16 bytes ÷ 1024 devices ≈ 43.75 GB. This figure only reflects parameter-related states; actual memory must also include activations and temporary buffers, so the practical budget needs to be more generous.
An illustrative construction process is as follows (pseudo-code, omitting exception handling):
def build_sharded_model(config, device_mesh, ckpt_dir):with init_on_meta_device(): # Build structure only, no memory allocationmodel = build_model(config)for block in model.transformer_blocks:shard_module(block, device_mesh) # Shard block by blockshard_module(model, device_mesh) # Shard the remaining partsload_shards_from_checkpoint(model, ckpt_dir, device_mesh)return model
III. Training Pipeline Breakdown
3.1 Model Loading
The goal of the loading phase is to ensure each process only reads the data it is responsible for, avoiding full reads followed by broadcasts. Recommended practices include:
- Meta Device Initialization: Build the model structure without allocating actual memory, verifying the structure before populating parameters.
- On-Demand Reading: Each process locates its assigned shards via an index file and reads only those specific files. If a single process reads the full weights and then broadcasts, it will cause an instantaneous spike in host memory.
- Tensor-by-Tensor Validation: After loading, check the shape, data type, and name of each tensor. Report any missing or misplaced tensors immediately to prevent numerical anomalies after training has started.
3.2 Sharding Scheduling
Sharding scheduling determines how communication and computation are arranged, with the core being the choice of wrapping granularity.
- Too Coarse Granularity: Gathering large amounts of parameters at once causes memory spikes.
- Too Fine Granularity: Frequent communication leads to high latency for small messages, eating up most of the gains.
- Layer-Level Wrapping: Using a Transformer block as the unit is typically a balanced approach.
Scheduling also requires overlapping communication and computation. Prefetching parameters for the next layer while computing the current layer can hide communication time within computation time.
In multimodal scenarios, encoding modules and the language backbone should be wrapped separately. If a vision encoder is frozen during training, its parameters do not require gradient synchronization, and the corresponding communication can be directly omitted. This is a typical example of tailoring scheduling based on module characteristics.
3.3 Gradient Synchronization
During backpropagation, the gradients for each block are written to their corresponding shards via a reduce-scatter operation, with each device retaining only the gradient portion it is responsible for.
Gradient clipping is an error-prone area. The global gradient norm must be obtained by aggregating the local sum of squares across all shards; a single card’s local norm cannot represent the global situation. The correct process is: each device computes its local sum of squares, performs a global reduction, takes the square root, and then scales the gradients using the same coefficient.
During gradient accumulation, intermediate steps can skip gradient reduction, synchronizing only at the final step to reduce communication frequency. Regarding numerical precision, the reduction process typically retains fp32 precision to minimize accumulation errors.
An illustrative training step is as follows:
for batch in loader:loss = model(batch).loss / accum_stepsloss.backward()if (step + 1) % accum_steps == 0:clip_grad_norm_sharded(model, max_norm) # Global norm clippingoptimizer.step()optimizer.zero_grad()
IV. Engineering Essentials for Multimodal Paths
Multimodal training requires attention to three additional points:
- Module Grouping: Different modules have varying parameter scales and computational densities, so their wrapping granularity and sharding strategies should be determined separately rather than applying a one-size-fits-all approach.
- Load Balancing: Image or audio samples vary greatly in length, causing uneven computational loads across devices. Bucketing by sample length or using dynamic batching can reduce idle wait times.
- Data Pipeline: Data preprocessing and model computation should be asynchronous to prevent data loading from becoming a bottleneck.
V. Common Issues and Troubleshooting
- Out of Memory (OOM): First, check if the wrapping granularity is too coarse, then confirm if activation recomputation is enabled, and finally verify the prefetch window size. Prefetching too much will simultaneously occupy a large amount of memory.
- Training Hangs: This is mostly caused by inconsistent collective communication call sequences across different processes, such as a conditional branch executing only in some processes. The solution is to ensure all processes execute the exact same communication sequence.
- Abnormal Gradient Norms: Check if the global reduction is completed before clipping. If only local shards are considered, the norm will be artificially small, and the clipping effect will be distorted.
- Loss Spikes After Resuming Training: Verify the mapping between optimizer states and parameter shards, and ensure that random seeds and data reading positions are consistent with those before the interruption.
VI. Pre-Deployment Checklist
- Single-step forward and backward propagation results are reproducible on a small-scale device setup.
- Shape and data type validations pass for every shard after loading.
- Gradient clipping uses the global norm, and the results are consistent across all processes.
- The loss curve remains continuous after saving and restoring checkpoints.
- The memory budget includes sufficient margins for activation values and communication buffers.
