Training Adaptation of Trillion-Parameter Large Models on Domestic Compute: Engineering Practices and FSDP2
As open-source trillion-parameter multimodal models proliferate, training them across diverse compute platforms is shifting from "can it run" to "can it run stably, fast, and cost-effectively." This article examines the engineering challenges of training adaptation for ultra-large models—the memory wall, communication overhead, and long-run stability—and walks through the core work: operator and computation-graph adaptation, distributed parallelism strategy, software-stack coordination, and the role of FSDP2 full sharding. It also covers building a complete training pipeline (model loading and conversion, sharding and scheduling, gradient synchronization), the extra demands introduced by multimodal training, and practical hardware-software co-design recommendations for running trillion-parameter training on domestic accelerators.
As the open-source ecosystem matures, flagship large models with trillion-parameter scale and integrated multimodal capabilities spanning text and images have been released one after another. The question of how to complete training adaptation across diverse compute platforms is shifting from “can it run” to “can it run stably, fast, and cost-effectively.” This article addresses the general technical problem of training adaptation for ultra-large-scale models, analyzing the engineering challenges and the approaches to solving them.
1. Why Training Adaptation for Trillion-Parameter Models Is So Difficult
Training models at the trillion-parameter scale is fundamentally about approaching physical limits along three dimensions simultaneously: memory, compute, and communication.
First, the memory wall. Take a trillion-parameter model in mixed precision as an example. Simply stacking model weights, optimizer states, and gradients, the memory footprint far exceeds the capacity of a single card, let alone a single machine. By the common rule of thumb for memory estimation, when using an Adam-class optimizer each parameter requires storing additional first- and second-order moments, so the actual memory requirement is often more than ten times the parameter count. This means any training scheme must first solve the problem of “parameters not fitting.”
Second, communication overhead. The larger the parameter scale, the more data devices must exchange during training. When the model is sharded across tens of thousands of accelerators, whether communication is efficient and whether it overlaps with computation directly determines overall throughput.
Third, stability. Ultra-large-scale training can run for weeks at a time. A single card dropping offline, a numerical overflow, or a communication timeout can all render the entire job’s progress worthless. So the core of adaptation work is not just “being able to compute,” but “being able to compute stably over the long term.”
2. From Hardware to Training: Core Aspects of Adaptation
“Training adaptation” refers to making a given model architecture run correctly and efficiently on a specific accelerator and its software stack. This is a systems engineering effort that typically involves the following key aspects.
Operator and computation-graph adaptation. A model is composed of a large number of operators, and the accelerator’s software stack needs to provide complete support for these operators or map missing ones to equivalent implementations. Operator compatibility directly determines whether the model can run through.
Distributed parallelism strategy adaptation. When a single card cannot hold the model, you must rely on data parallelism, tensor parallelism, pipeline parallelism, and other strategies to split it. How to combine these strategies is key to training efficiency.
Software-stack coordination. Hardware needs a complete underlying software stack, including compute libraries, communication libraries, compilation/optimization layers, and so on. The maturity and degree of optimization of the software stack often determine the actual training experience more than the hardware’s peak compute.
For domestic accelerators, the first two aspects are especially critical: on one hand, you must ensure that the various operators in the model architecture can be executed correctly; on the other hand, you must adjust parallelism and communication strategies for the hardware’s interconnect topology to prevent communication from becoming a bottleneck.
3. FSDP2: How Fully Sharded Data Parallel Evolves
Among the many data parallelism schemes, Fully Sharded Data Parallel (FSDP) has become one of the mainstream choices in the industry for training ultra-large models. Its core idea: during training, shard the model parameters, gradients, and optimizer states across each data parallel replica, and only temporarily aggregate the complete parameters of a layer when computing that layer, releasing them immediately after use. This way each card only needs to store one shard of the model, significantly reducing memory usage.
Compared with earlier versions, FSDP2 has been optimized and evolved in several respects, making it more suitable for large-scale, multimodal training scenarios:
- More unified parameter representation: parameters are organized in the form of per-device shards, making the relationship between shards and computation clearer and facilitating fine-grained memory management.
- More thorough overlap of communication and computation: parameter all-gather and gradient reduce-scatter are better overlapped with forward and backward computation to hide communication latency.
- Better coordination with mixed precision, activation recomputation, and other features: it reduces the complexity of manual tuning while remaining easy to use.
The illustrative pseudocode below describes the core rhythm of FSDP2 training—“aggregate before use, release after use”:
# Illustrative pseudocode: demonstrates only the sharding and aggregation rhythmfor layer in model.layers:# Before computing this layer, aggregate sharded parameters into full parametersfull_param = all_gather(layer.sharded_param)# Forward/backward pass uses the layer's full parametersoutput = layer.forward(input, full_param)# Release the full parameters immediately after use to reclaim memoryrelease(full_param)# After the backward pass, reduce the gradient shards across devicesreduce_scatter_gradients(model)
This “aggregate when needed, release when done” pattern allows trillion-parameter models to train within limited memory.
4. Building a Complete Training Pipeline
The value of training adaptation ultimately lies in whether it can connect the entire path from model to convergence. A complete training path should cover at least the following three aspects.
1. Model loading and conversion. First, load the model architecture definition and weight files, then convert them into a representation the accelerator’s software stack can recognize. This step handles details such as weight format alignment, precision conversion, and naming mapping. For new architectures, you often need to supplement missing operator implementations or equivalent mappings to ensure the model can be instantiated correctly.
2. Sharding and scheduling. Once the parallelism strategy is determined, shard the model parameters across devices in the FSDP manner and plan the execution order of computation and communication. Choosing the sharding granularity involves a trade-off: too coarse, and memory savings are insufficient; too fine, and communication frequency and scheduling overhead increase. In engineering practice, this is usually determined by combining the hardware interconnect bandwidth, single-card memory capacity, and model structure characteristics.
3. Gradient synchronization and update. After backpropagation computes the gradients of each shard, they are synchronized across devices via collective communication, and the optimizer then updates each parameter shard, completing one iteration. The correctness of gradient synchronization directly determines whether training converges, while the efficiency of synchronization determines overall throughput.
# Illustrative pseudocode: main loop of a single training stepoptimizer.zero_grad()# Forward: aggregate sharded parameters layer by layer and computeloss = forward(model, batch)# Backward: compute gradients and trigger gradient-shard reduce communicationloss.backward()# After reduction completes, each device updates parameters based on its local shardoptimizer.step()
5. Additional Challenges from Multimodal Training
Contemporary flagship models are often not pure text models but simultaneously process multiple modalities such as text and images. Multimodal training introduces several additional engineering considerations on top of the general training pipeline:
- Data mixing ratios across modalities: data of different modalities varies greatly in quantity and length distribution, and sampling and concatenation strategies affect both load balancing and convergence.
- Memory layout of heterogeneous structures: the vision encoding module and the language backbone have different structures, so sharding and aggregation strategies must account for the characteristics of both subnetworks, avoiding a situation where one module becomes a memory or communication hotspot.
- Numerical stability: multimodal feature fusion involves concatenating and normalizing features of different scales, and under mixed precision training, particular attention must be paid to numerical overflow and precision loss.
These factors together require the training path to be flexible enough to accommodate heterogeneous subnetworks within a unified parallelism framework and to support targeted memory and communication optimization.
6. Hardware-Software Co-Design: Engineering Recommendations for Adaptation
Based on the above analysis, completing training adaptation for ultra-large models on domestic compute platforms can follow these engineering practices:
- Run it first, then optimize. First ensure complete operators, a correct pipeline, and a normally decreasing loss, then gradually introduce throughput optimizations, avoiding premature optimization that masks correctness defects.
- Make good use of activation recomputation. Using gradient checkpointing (activation checkpointing) to trade compute for memory is one of the most direct and effective ways to alleviate the memory wall, at the cost of roughly 20%–30% additional compute.
- Hide communication. Try to overlap parameter aggregation and gradient reduction with computation to reduce device idle waiting; make targeted adjustments to the interconnect topology to lower the proportion of cross-node communication.
- Prioritize observability. Integrating common capabilities such as logging services and monitoring/alerting, and continuously collecting metrics like throughput, memory usage, and communication time, is the foundation for locating performance bottlenecks and stability issues.
- Strengthen fault tolerance. Ultra-large-scale, long-cycle training must support checkpoint resume, faulty-node isolation, and rapid recovery to minimize the impact of incidental failures.
From the practice perspective of platforms such as Baidu AI Cloud, large-scale distributed training is never the victory of a single piece of hardware or a single framework, but a systematic achievement of hardware compute, software stack, parallelism strategy, and engineering operations working together. Understanding how a full-sharding parallelism mechanism like FSDP2 works, and accordingly completing end-to-end adaptation of model loading, sharding scheduling, and gradient synchronization, is the core methodology for efficiently training trillion-parameter models on domestic compute.
