Adapting Ultra-Large Model Training: End-to-End Practices on Domestic AI Accelerators
Training ultra-large models with trillions of parameters requires distributed execution across multiple accelerators. This article explores the end-to-end pipeline for adapting such models to domestic AI hardware, covering resource estimation, four critical training stages (model loading, shard scheduling, gradient synchronization, and multimodal data paths), hardware and software stack optimization, and practical engineering validation methods.
1. Background: New Challenges Brought by Parameter Scale
According to public reports, an open-source flagship model with 2.8 trillion parameters has completed training adaptation on domestic AI computing hardware. Models of this scale exceed the capacity of a single device, requiring distributed training across a massive number of accelerator cards. This article focuses on general technical issues, outlining the critical paths of such training tasks to help readers identify missing components in their training pipelines.
Let’s estimate the resource requirements first. When storing each parameter in 2 bytes (bf16), the model weights alone require about 5.6 TB. If using a mixed-precision Adam-like optimizer, each parameter also needs an fp32 master weight, first-order momentum, second-order momentum, and gradient, totaling about 16 bytes. The overall training state reaches approximately 44.8 TB. If the model adopts a Mixture of Experts (MoE) structure, there is a significant difference between the total parameter count and the parameters actually activated during each forward pass, so memory and compute estimates should be calculated separately.
2. Four Critical Stages of the Training Pipeline
1. Model Loading
The goal is to ensure that no single process holds the complete model in memory. A common approach is to first build the model structure on a meta device (recording shapes without allocating storage), and then, according to a sharding plan, let each process instantiate and load only its assigned parameter blocks. This reduces the peak memory during startup from the total model size to the scale of a single shard.
Checkpoint reading also requires sharding. If all processes read the same large file simultaneously, the storage system becomes a bottleneck. Therefore, each process should read its corresponding data segment based on its shard.
2. Shard Scheduling
Fully Sharded Data Parallel (FSDP) shards parameters, gradients, and optimizer states across all processes. When forward computation requires the full parameters of a specific layer, processes temporarily aggregate them and immediately release them after computation, keeping only the local shard. The following points need special attention during scheduling:
- Prefetch timing: While computing the current layer, asynchronously pull the parameters required for the next layer to overlap communication with computation.
- Shard granularity: Too fine a granularity increases communication frequency, while too coarse a granularity leads to high peak memory. A trade-off is necessary.
- Module differences: Attention layers, feedforward layers, and vision encoders have different parameter shapes and access frequencies. It is advisable to set different sharding strategies based on module types.
3. Gradient Synchronization
During backpropagation, gradients fall directly onto their corresponding shards via reduce-scatter operations, so each process does not need to save the complete gradient. In practice, pay attention to the following:
- Communication bucketing: Combine multiple small gradients into larger communication blocks to reduce the startup overhead of each communication.
- Overlapping communication and backward computation: Initiate communication as soon as a segment of gradients is ready, without waiting for the entire backward pass to finish.
- Gradient accumulation: When memory is limited, accumulate over multiple steps to equivalently expand the global batch size, thereby reducing the synchronization frequency.
- Global gradient clipping: After sharding, the global norm requires cross-process reduction. The computation result must be consistent with the single-card reference implementation.
4. Multimodal Data Paths
Multimodal models include both a vision encoder and a language backbone, which differ significantly in compute density, sequence length, and memory usage. The data loading end should group samples based on their actual token count or image patch count for load balancing, preventing some processes from waiting too long to process slower samples.
3. Adaptation Focus for Accelerator Hardware and Software Stacks
As training scales up, details of the hardware and software stack directly impact throughput. The following aspects need to be verified item by item:
- Operator coverage: Attention, normalization, activation functions, and related fused operators need high-performance implementations. Missing operators will degrade into numerous small-grained calls, significantly reducing throughput.
- Collective communication mapping: Verify the mapping of collective communications on the hardware topology, including bandwidth allocation between intra-node high-speed interconnects and cross-node networks, and validate the communication latency curves at different scales.
- Memory allocation and fragmentation: Large-scale sharding generates many temporary tensors of varying sizes. Allocator fragmentation can cause falsely high memory watermarks, so the fragmentation rate should be continuously monitored.
- Numerical precision: The accumulation precision and rounding methods in mixed precision need to be checked item by item against the reference implementation to avoid hard-to-trace numerical deviations in the later stages of training.
4. Practical Engineering Validation Methods
- Numerical alignment: Use a small-scale model and a fixed random seed to compare the loss and gradient norm of the first few steps. Deviations should be controlled within an explainable range before proceeding to performance tuning.
- Phased scaling: First run on a single machine, then scale to multiple machines, and finally use the full-scale training. Keep a fallback configuration for each stage.
- Performance profiling: Separately calculate computation time, communication time, and un-overlapped waiting time to locate bottlenecks. When communication proportion remains persistently high, prioritize adjusting shard granularity and prefetch strategies.
- Checkpointing and fault tolerance: Save checkpoints in a sharded manner and record the shard plan version. Upon recovery, verify whether the shard layout matches the current topology. If inconsistent, refuse to load to prevent silent corruption.
- Memory budget regression: Record peak memory before and after each change to prevent introducing performance or memory regressions in one area while optimizing another.
The following pseudocode illustrates the main steps of sharded training. It is for flow demonstration only and omits error handling and checkpoint details:
# Pseudocode for illustrating the main steps of sharded trainingdef build_sharded_model(config, world_size, rank):# 1. Build structure on meta device without allocating actual storagemodel = build_model_structure(config, device="meta")# 2. Generate shard plan based on modules and parameter scalesshard_plan = plan_shards(model, world_size)# 3. Each process loads only its assigned parameter blocksload_local_shards(model, shard_plan, rank, checkpoint_dir=config.ckpt_dir)return model, shard_plandef train_step(model, batch, optimizer):outputs = []for layer in model.layers:full_params = gather_params(layer) # Temporarily gather full parameters of the current layeroutputs.append(layer.forward(full_params, batch))release_params(layer) # Release after computation, keeping only local shardloss = compute_loss(outputs[-1], batch.labels)loss.backward() # Gradients fall to local shard via reduce-scatteroptimizer.step()optimizer.zero_grad()return loss
5. Conclusion
The core issues in ultra-large-scale training are resource allocation and communication scheduling. Sharding strategies determine the memory ceiling, the overlap of communication and computation determines throughput, and numerical alignment is the prerequisite for all performance optimizations. Teams should first establish a baseline consistent with the reference implementation before gradually advancing scaling and tuning.
