Training Trillion-Parameter Large Language Models on Domestic AI Accelerators: FSDP/FSDP2 Adaptation Practices
This article examines the engineering challenges of training trillion-parameter large language models on domestic AI accelerators. It explains what training adaptation means across the hardware, software stack, and model layers, then focuses on Fully Sharded Data Parallel (FSDP/FSDP2) as a core approach for overcoming memory limits. It also covers sharding, parameter gathering, gradient synchronization, mixed precision, multimodal training considerations, practical tuning advice, and the role of cloud training platforms.
1. Background: The Training Barrier of Trillion-Parameter Models
The rise of ultra-large parameter models, with parameter counts reaching the trillion scale, has pushed model training from something that can be handled on a single machine to a workload that requires large-scale distributed clusters. For a trillion-parameter model, the parameters alone can occupy several terabytes of memory when stored in half precision. Once gradients, optimizer states, and activations are included, the memory demand per accelerator far exceeds the capacity of any single device. As a result, training such a model is fundamentally an engineering problem: how to partition and schedule workloads across many accelerators and machines.
Historically, this kind of adaptation relied heavily on a small number of mature software ecosystems. In recent years, however, domestic AI accelerators have advanced rapidly, making it a practical proposition to run full-chain large-model training on these platforms. This matters because diversified compute supply is closely tied to the sustainability, cost, and supply-chain security of large-model training. The core of adaptation is not simply making the model run, but completing the full training loop: model loading, partitioning and scheduling, and gradient synchronization. On top of that, the goal is to balance throughput, memory efficiency, and training stability.
2. What “Training Adaptation” Really Means
A common misunderstanding is that training adaptation is completed automatically once a new hardware backend is supported. In practice, it usually requires coordination across three layers:
- Hardware layer: the compute capability, memory bandwidth, and inter-accelerator high-speed interconnect of the accelerator itself.
- Software stack layer: adaptation of the compiler, operator libraries, communication libraries, and distributed training frameworks for that hardware.
- Model layer: tuning the model structure, parallelism strategy, and numerical precision to match the hardware characteristics.
Only when all three layers work together can the training pipeline not only run, but run stably and efficiently. Among these, operator completeness in the software stack is often the biggest bottleneck. Every operator used by the model needs an equivalent implementation on the target hardware. Otherwise, training may fail midway or fall back to a very slow compatibility path.
3. Core Principles of Fully Sharded Data Parallel (FSDP/FSDP2)
One of the mainstream approaches to addressing the memory wall of trillion-parameter models is Fully Sharded Data Parallel (FSDP). The idea can be summarized as “shard storage, aggregate on demand, and release immediately after use”:
Sharded storage: Model parameters, gradients, and optimizer states are partitioned along the data-parallel dimension across all participating processes, or ranks. Each rank only keeps a shard of the full model resident in memory. This reduces the resident memory footprint on each accelerator to roughly 1/N of the original, where N is the degree of parallelism.
On-demand aggregation: Before the forward computation of a given layer, all-gather temporarily aggregates the required shards into the full parameters for that layer. The same applies during backward propagation. Once computation for that layer is complete, the temporary aggregated parameters are released immediately, and the model returns to its sharded state.
Gradient synchronization: During backward propagation, gradients from each rank are reduced and re-sharded through reduce-scatter. Each rank retains only the gradient shard it is responsible for, and the local optimizer updates the corresponding parameter shard.
FSDP2 introduces further modernization at the framework-design level, mainly in the following areas:
- It replaces the earlier flattened packing approach with per-parameter sharding, making the sharding granularity for parameters and gradients finer and the semantics clearer.
- It uses distributed tensor abstractions to express how shards are laid out, making FSDP easier to combine with other parallelism dimensions such as tensor parallelism and pipeline parallelism.
- It provides a simpler and more predictable API, reducing the complexity of orchestrating advanced parallel strategies.
From the perspective of parallelism dimensions, data parallelism partitions the batch, while FSDP also partitions model state on top of that. In other words, FSDP combines data parallelism with sharding of model state. When a model still cannot fit after sharding, or when communication becomes the bottleneck, FSDP needs to be combined with intra-layer tensor parallelism and inter-layer pipeline parallelism to form a more complex multi-dimensional parallel strategy. This also explains why adaptation work emphasizes “native support”: the framework must natively enable collaboration across parallelism dimensions, rather than stitching things together with external patches.
4. Building the Training Pipeline: From Loading to Synchronization
A complete training pipeline targeting a native FSDP2 multimodal training path usually includes the following stages.
1. Model Loading and Structural Conversion
When training starts, weights are first loaded into memory, and the model structure is logically divided into several “shardable units,” or wrap units, according to the target parallel strategy. For Transformer-style models, a single Transformer Block is typically used as one sharding unit, followed by one additional sharding wrapper around the outermost model. This “per-layer wrapping plus root-module wrapping” approach is key to balancing memory usage and communication efficiency.
2. Sharding and Scheduling Strategy
Sharding granularity directly affects performance. If the shards are too coarse, peak memory reduction per accelerator is limited. If the shards are too fine, the number of all-gather and reduce-scatter communications and the scheduling overhead increase. In engineering practice, coarse-grained partitioning aligned with the model structure is usually preferred, combined with the following optimizations:
- Communication-computation overlap: While computing the current layer, asynchronously prefetch the parameters needed for the next layer, hiding all-gather communication time behind computation.
- Timely release: Release aggregated shard results as soon as they are no longer needed to keep peak memory usage low.
- Bucketed communication: Combine communications from multiple small tensors into larger buckets to reduce launch overhead and improve bandwidth utilization.
The following code is illustrative and only shows the basic flow of FSDP-style sharding:
# Pseudocode: illustrating FSDP2-style sharding and training flowfor block in model.transformer_blocks:fully_shard(block) # Shard each Block as a sharding unitfully_shard(model) # Shard the root moduleoptimizer = AdamW(model.parameters(), lr=1e-4) # Generic optimizer algorithmscaler = GradScaler() # Loss scaling under mixed precisionfor step, batch in enumerate(dataloader):with autocast(dtype="bfloat16"): # Forward pass uses low precisionloss = compute_loss(model, batch)scaler.scale(loss).backward() # Backward triggers all-gather and reduce-scatterscaler.step(optimizer) # Each rank updates its local shardoptimizer.zero_grad()
3. Gradient Synchronization and Optimizer State
During backward propagation, the communication library automatically handles gradient reduction and re-sharding. The optimizer is responsible only for the local shard, so optimizer states such as momentum and variance are also distributed across ranks. This step is critical for turning “fits in memory” into “can actually train.”
4. Mixed Precision and Numerical Stability
Trillion-parameter models almost inevitably rely on mixed precision, such as bf16 or fp16. Because bf16 has a larger dynamic range, it is generally more stable and easier to manage than fp16. In practice, loss scaling is also used in fp16 scenarios, together with fp32 accumulation on critical paths, to maintain numerical stability. The key is to balance throughput and stability while avoiding issues such as gradient overflow or abnormal convergence caused by low precision.
5. Special Considerations for Multimodal Training
When the model is multimodal, adaptation becomes significantly more complex. Encoders for text, images, audio, and other modalities can differ greatly in operator composition, tensor shapes, and computational intensity:
- Heterogeneous operator coverage: Multimodal models introduce more types of operators, such as convolutions, attention variants, and image preprocessing operators. Each of these must have a correct and efficient implementation on the target hardware.
- Dynamic shapes: Visual input resolutions and sequence lengths may vary, leading to changing tensor shapes. This places higher demands on memory planning and operator compatibility.
- Data pipeline: Multimodal training requires supplying multiple modalities of data simultaneously. Data loading, decoding, and preprocessing can easily become bottlenecks, so techniques such as prefetching, parallel decoding, and caching are needed to overlap data supply with computation.
Therefore, “completing the full training pipeline” in multimodal scenarios especially means three things happening at the same time: full operator coverage, full shape compatibility, and uninterrupted data supply.
6. Engineering Practices and Tuning Suggestions
- Start with small-scale validation: First run convergence tests on a small number of accelerators, then gradually scale up to the target scale to avoid wasting resources on large clusters.
- Identify communication bottlenecks: Use the framework’s built-in profiling capabilities to observe the proportion of all-gather and reduce-scatter operations, and determine whether the workload is compute-bound or communication-bound. Then adjust sharding granularity and parallel combinations accordingly.
- Manage memory budgets: Evaluate four major memory consumers: parameter shards, activations, optimizer states, and communication buffers. If necessary, enable activation checkpointing to trade compute for memory.
- Ensure training stability and fault tolerance: Long-running training must consider regular checkpointing, fault rescheduling, and resuming from checkpoints. The larger the scale, the more important automation becomes.
- Maintain full-pipeline observability: Connect training logs, throughput metrics, hardware utilization, and fault alerts into a unified monitoring and logging system so that anomalies can be detected early and issues can be traced later.
7. The Role of Cloud Compute Platforms
In real production environments, large-model training is rarely a bare-metal, single-machine job. It usually runs on top of a cloud compute platform. A mature training platform typically provides general capabilities that support the entire process described above:
- Compute scheduling and containerized orchestration: Accelerators can be requested and allocated on demand, enabling elastic scaling for multi-machine, multi-accelerator jobs.
- Object storage and high-speed data loading: Object storage can hold massive training datasets and checkpoints, while caching helps improve data throughput.
- Monitoring, alerting, and logging services: These services collect training and hardware metrics in real time, trigger alerts when anomalies occur, and support post-event analysis.
For example, Baidu AI Cloud’s general cloud capabilities in compute scheduling, object storage, monitoring and alerting, and logging services are common supporting elements for such training platforms. They help free developers from low-level operations so they can focus on the model and algorithms themselves.
8. Conclusion
Adapting trillion-parameter models for training on domestic AI accelerators is essentially a systems-engineering effort that requires deep collaboration between software and hardware. With Fully Sharded Data Parallel as the core mechanism, the full training loop—from model loading and sharding scheduling to gradient synchronization—is achieved through “sharded storage, on-demand aggregation, and gradient re-sharding.” In multimodal scenarios, additional challenges must be addressed, including heterogeneous operator coverage, dynamic shape compatibility, and continuous data supply. Understanding and mastering every stage of this pipeline is essential for stable and scalable large-model training on diverse compute platforms.
