Key Points for Adapting Trillion-Parameter Multimodal Model Training on Domestic AI Accelerators
Training trillion-parameter multimodal models requires deep synergy between software stacks and hardware. This article explores the critical challenges and solutions for adapting large-scale model training to domestic AI accelerators, focusing on memory estimation, communication and compute bottlenecks, FSDP2 configuration, sharding granularity, and gradient synchronization.
1. Why is Adapting Ultra-Large Model Training on Domestic Compute More Challenging?
In recent years, the parameter scale of flagship multimodal models released by the open-source community has exceeded 2 trillion. Training such models requires thousand-GPU scale parallel compute, as well as deep synergy between the software stack and hardware to ensure training stability and efficiency.
Outside the mainstream GPU ecosystem, domestic AI accelerators are rapidly catching up. Recent public reports indicate that a domestic compute vendor completed the training adaptation for a 2.8 trillion-parameter open-source multimodal model using its integrated training and inference compute card and self-developed unified compute software stack, constructing an FSDP2 multimodal training path. This article references this case solely to illustrate the technical route. The performance data and details in the report have not been independently verified; readers should refer to the original source.
This case raises a universal question: How can training adaptation for an ultra-large multimodal model be completed on a non-mainstream compute platform? Below, we break down the key points across four dimensions: memory, communication, operators, and data.
2. How Much Memory is Actually Needed for Trillion-Parameter Training?
When estimating memory, the statistical scope must be defined first. Using a 2 trillion-parameter model as an example, the calculation is as follows:
- BF16 weights: 2 bytes per parameter, totaling approximately 4TB.
- BF16 gradients: 2 bytes per parameter, totaling approximately 4TB.
- FP32 master weights: 4 bytes per parameter, totaling approximately 8TB.
- Adam first and second moments: 8 bytes per parameter, totaling approximately 16TB.
Summing these up yields 16 bytes per parameter, or about 32TB. This figure does not include activations, communication buffers, or fragmentation. Results will vary significantly with different optimizers, precisions, or parallel strategies. For instance, using an 8-bit optimizer can reduce optimizer states, while enabling activation recomputation trades compute time for memory.
Therefore, there is no fixed answer to “how many extra times the optimizer states occupy.” When estimating, clearly specify the included items and calculate using the actual model configuration.
3. Which Walls Do You Hit First During Training?
Memory Wall. A single card cannot hold the complete model, necessitating sharding. After sharding, each card only stores a portion of the parameters, gradients, and optimizer states.
Communication Wall. After sharding, forward and backward passes require repeated parameter aggregation (All-Gather) and gradient reduction (Reduce-Scatter). Cross-node bandwidth is typically lower than intra-node bandwidth, easily becoming a throughput bottleneck.
Operator Compatibility Wall. The attention implementation, RoPE position encoding, normalization layers, and fused operators the model relies on must all be available on the target platform with precise accuracy. Any missing operator or large margin of error can cause training to diverge.
Multimodal Complexity. The data types, sequence lengths, and memory footprints of visual encoders, projection layers, and language backbones differ significantly. Sharding strategies and data pipelines must be considered separately.
4. How Do FSDP2 and FSDP1 Differ, and How to Start Configuration?
FSDP1 concatenates all parameters into a 1D tensor before splitting. FSDP2 shifts to per-parameter sharding via DTensor, where each parameter is managed as a distributed tensor. This allows different sharding granularities to be set per module, making mixed precision processing more straightforward.
When migrating from FSDP1, check the following:
- Ensure your PyTorch version supports
fully_shardand refer to the official documentation for that version. - Check if the optimizer relies on flattened parameter interfaces; adjustments are needed after switching to DTensor.
- Verify checkpoint save and load logic, as the sharded format has changed and must be re-validated.
- Check the reduction precision for mixed precision. FP32 reduction is more stable but incurs higher communication overhead.
Below is a minimal configuration example. It must run in a multi-process environment launched by torchrun, and the model skeleton must be constructed on the meta device:
import osimport torchimport torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy# Runtime environment: PyTorch 2.6 and above, launched by torchrun, each process binds to one GPU.# The communication backend and device_type depend on the hardware platform; here we use nccl and cuda as an example.dist.init_process_group(backend="nccl")local_rank = int(os.environ["LOCAL_RANK"])torch.cuda.set_device(local_rank)world_size = dist.get_world_size()mesh = init_device_mesh("cuda", (world_size,))mp_policy = MixedPrecisionPolicy(param_dtype=torch.bfloat16, # Precision used for forward and backward computationreduce_dtype=torch.float32, # Precision used for gradient reduction)# Shard first, then load weights block by block from checkpoint to each GPUfor block in model.transformer_blocks:fully_shard(block, mesh=mesh, mp_policy=mp_policy)fully_shard(model, mesh=mesh, mp_policy=mp_policy)
After building the model on the meta device, you should shard first, then load weights. This prevents a single card from loading the complete model first.
5. How to Choose Sharding Granularity?
Sharding granularity determines the data volume per communication and the memory peak. The following four rules serve as a starting point; specific thresholds should be adjusted based on profiler empirical data.
| Criterion | Rule | Adjustment Direction |
|---|---|---|
| Memory Peak | The sum of full parameters, gradients, and activations after a shard group is expanded exceeds 80% of single-card available memory. | Shrink the shard group, splitting large modules into multiple groups. |
| Layers & Comm Count | The data volume for a single All-Gather is very small, and launch overhead is proportionally noticeable. | Merge adjacent small layers, combining small modules like visual encoders for sharding. |
| Cross-node Bandwidth | Empirical All-Gather time exceeds the forward computation time of the corresponding layer; communication is not hidden by computation. | Increase group size, or switch to Hybrid Sharding (HSDP) to limit sharding within the node. |
| PCIe Offload Overhead | The time to move parameters back from host memory exceeds the computation time of the previous layer. | Only offload optimizer states or long-inactive layers; if it still slows training, disable offloading. |
Taking PCIe 4.0 x16 as an example, the theoretical unidirectional bandwidth is about 32GB/s, and actual transfer rates are often lower. Before offloading, estimate the single transfer time based on parameter volume and bandwidth.
6. What to Note for Gradient Synchronization and Optimizer Steps?
After backpropagation, each process retains only local sharded gradients and performs local optimizer updates. Three key points apply in practice.
First, gradient accumulation can amortize communication overhead. More accumulation steps mean fewer communications before each update, but the effective batch size increases, usually requiring learning rate readjustment.
Second, asynchronous prefetching can hide communication. Prefetch parameters for layer N+1 while computing layer N, provided there is enough memory headroom to hold the prefetched parameters.
Third,
