Training a 2.8 Trillion-Parameter Multimodal Model on a Domestic AI Accelerator: FSDP Adaptation Challenges and Engineering Practices
This article examines how a domestic integrated AI training and inference accelerator adapted to a 2.8 trillion-parameter multimodal model. It explains the hardware, software, and algorithmic barriers, how native Fully Sharded Data Parallel (FSDP) shards parameters and gradients, the full training pipeline, software-stack adaptation, numerical validation, performance tuning, and long-running stability practices.
1. Why training adaptation is hard
A company recently open-sourced a flagship multimodal large model with 2.8 trillion parameters. After the announcement, a domestic integrated AI training and inference accelerator completed training adaptation for the model using its self-developed software stack. The work established a native fully sharded data parallel (FSDP) training path and connected the complete pipeline from model loading, parameter shard scheduling, and gradient synchronization.
For developers, the important point is not simply that another model was adapted, but the technical difficulty of the adaptation itself. Training adaptation must satisfy three requirements at the same time: the model can run (functionality), training produces correct results (numerics), and training is efficient enough (performance). Meeting each requirement requires passing through three barriers: hardware, software, and algorithms.
1.1 Hardware barrier: memory and bandwidth pressure
Using mixed-precision training as an example, the memory requirements of a model in this trillion-parameter class on a single node are roughly:
- Parameters (BF16/FP16): about 2 TB
- Gradients: about 2 TB
- Optimizer states (Adam-like, including an FP32 parameter copy and two momentum terms): about 12 TB
- Activations, communication buffers, and other overheads: additional
The total is about 16 TB, before activations are fully accounted for. Current mainstream single-node accelerator memory capacity is usually only a few TB, leaving a gap of more than 10x.
Bandwidth is also tight. Every training step repeatedly exchanges parameters and gradients. The larger the model and the more accelerators involved, the larger the total collective communication volume. If interconnect bandwidth is insufficient, even strong compute can only wait for data.
1.2 Software barrier: operators, compiler, and framework support
- Operator coverage: Trillion-parameter models involve many operators, such as matrix multiplication, attention, normalization, and activation. Hardware provides compute, but an operator can be used only after the software stack compiles, optimizes, and exposes it in a form that the framework can call.
- Compiler adaptation: If the compilation flow is not adapted, the computation graph may not generate efficient executable code for the target hardware. Training may degrade or even fail to start.
1.2.1 Additional operator and memory pressure from multimodality
Multimodal models also need to process non-text inputs such as images, audio, and video:
- Vision encoders contain operators such as convolution and window attention, which differ substantially from the Transformer backbone.
- High-resolution images or long videos are often expanded into a large number of visual tokens after visual encoding, increasing the sequence length on the input side.
- Multimodal data loading, decoding, and preprocessing also create additional pressure on the host side.
These are new workloads beyond basic adaptation.
1.3 Algorithm barrier: three forms of instability in large models
- Loss spikes: The larger the parameters in a single layer, the more easily a bad batch can amplify the perturbation.
- Normalization statistic drift: This is especially noticeable when there are many layers and complex parallel splitting schemes.
- Gradient clipping failure: After parallel splitting, gradients are distributed across accelerators. If clipping is handled incorrectly, the norm that is actually applied will deviate from expectations.
2. Core mechanism: how FSDP breaks a model into shards
Data parallelism is straightforward: each accelerator holds a complete copy of the model, reads a portion of the data, and aggregates gradients during backpropagation. However, when the model is too large to fit on a single accelerator, standard data parallelism no longer works.
Fully Sharded Data Parallel (FSDP) takes a different approach. Instead of storing a complete model on every accelerator, it splits parameters across accelerators so that each accelerator stores only about 1/N of the parameters. During computation, full parameters are temporarily assembled on demand.
2.1 Two basic assumptions
- All accelerators participate in computation graphs of the same shape, so the set of parameters needed at the same time is basically the same.
- Parameters can be assembled on demand and released after use.
Under these assumptions, FSDP reduces the memory requirement per accelerator from “the complete model” to “local shard plus currently used parameters.” The memory advantage grows as the number of accelerators increases.
2.2 Data flow in a single training step
Forward propagation (layer by layer)1. AllGather: collect the full parameters of the current layer from all accelerators2. Compute the output of the current layer3. Release: restore parameters to shardsBackward propagation (layer by layer)1. AllGather: assemble the full parameters of the current layer again for gradient computation2. Compute gradients3. ReduceScatter: sum gradients and scatter them so that each accelerator keeps only local shard gradients4. ReleaseOptimizer update- Update parameters and optimizer states on local shards
Key points:
- Gradient summation and sharding are completed in one step: sum plus scatter. The communication volume is about half of the gradient AllReduce used in traditional data parallelism, and the result is mathematically equivalent to using a complete model with data parallelism.
- Cost: Parameters are reassembled once for every backward layer, doubling the AllGather communication volume compared with the forward pass.
- Mitigation: Increasing shard granularity, prefetching the next layer’s parameters to overlap communication with computation, and enabling activation recomputation can all reduce this cost.
2.3 What “native” means
Implementations of FSDP differ significantly across frameworks. Early implementations flattened all or part of a layer, or even the whole model, into one large buffer for unified management. This made sharding simple and reduced communication calls, but it had three costs:
- It was difficult to combine with other partitioning methods, such as tensor parallelism.
- The semantics of operations such as mixed precision and parameter freezing became complex.
- It was difficult to perform finer-grained scheduling on demand.
Newer native implementations shard parameters individually. Each parameter carries its own shard metadata, and communication is performed at the tensor level. This allows FSDP to be composed like building blocks with tensor parallelism, sequence parallelism, and other strategies. It is also the foundation for building a native multimodal training path.
3. Full-pipeline breakdown: from model loading to gradient synchronization
A complete training pipeline can be divided into five stages, each with its own adaptation challenges.
3.1 Model loading and meta-device initialization
Weight files for a trillion-parameter model can be several TB. If they are first loaded into a single accelerator and then split, the loading stage will fail immediately because of insufficient memory. In practice, this is usually handled in two steps:
- Instantiate the model structure on a “meta device”: create the computation graph and parameter shapes without allocating real storage.
- Load weights into the corresponding shard positions on each accelerator according to the sharding rules.
import torchfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy# 1. Build the model skeleton on the meta device: keep only structure and shapes, without allocating real accelerator memorywith torch.device("meta"):model = build_multimodal_model(config)# Layers will create real parameters later, ready for sharded weight loading# 2. Create a 2D device mesh:# dp = data parallel group, tp = tensor parallel groupmesh = init_device_mesh("cuda", (dp_size, tp_size), mesh_dim_names=("dp", "tp"))# 3. Set the mixed precision policy:# Parameters and computation use BF16, while gradient reduction uses FP32 to reduce accumulation errormp_policy = MixedPrecisionPolicy(param_dtype=torch.bfloat16, reduce_dtype=torch.float32)# 4. Shard the language model Transformer layers first, then shard the vision encoderfor block in model.language.blocks:fully_shard(block, mesh=mesh["dp"], mp_policy=mp_policy)for block in model.vision.blocks:fully_shard(block, mesh=mesh["dp"], mp_policy=mp_policy)# 5. Finally shard the top-level module and enable parameter and gradient prefetch to overlap communicationfully_shard(model, mesh=mesh["dp"], mp_policy=mp_policy)# 6. Load the sharded weights (illustrative)load_sharded_checkpoint(model, ckpt_path)
Shard loading itself must avoid a single-point bottleneck. When multiple processes read the same file from the same storage at the same time, network and disk congestion can easily occur. Common practices include:
- Each shard is read only by the process responsible for it.
- Data is stored in parallel file systems or object storage, with caching.
- Process groups load in a staggered manner.
3.2 Shard scheduling: granularity, networking, and recomputation
Shard granularity has a major impact on performance:
- Too fine: many communication calls, each with small data volume, making it difficult to saturate bandwidth.
- Too coarse: peak memory usage rises, and it becomes harder to keep the communication and computation pipeline full.
A common practice is to use a Transformer layer, including attention and feed-forward network, as the sharding unit, then adjust it based on measured memory headroom. Three additional points matter:
- 2D mesh: In large-scale training, devices are often organized as a 2D mesh of data parallelism and tensor parallelism. The data parallel dimension handles parameter sharding and gradient scattering, while the tensor parallel dimension splits matrix multiplications within a layer across accelerators.
- Device affinity: Collective communications such as AllGather and ReduceScatter should preferentially use high-speed intra-node interconnects, leaving only necessary traffic to cross nodes.
- Activation recomputation: Instead of storing all intermediate activations during the forward pass, recompute them during the backward pass. This trades compute for memory and is especially effective for very long sequences.
3.3 Forward and backward passes: overlapping communication with computation
Forward and backward passes are layer-by-layer pipelines, but whether they can be overlapped depends on the communication capabilities of the hardware:
- Whether computation and communication can run in parallel through different execution channels.
- Whether collective communication can be split into subtasks internally and started in segments as needed.
- Whether the hardware supports related synchronization and queue mechanisms.
Adaptation means correctly mapping the framework’s communication semantics onto hardware capabilities. If the mapping is done well, a pipeline such as “compute layer i while prefetching layer i+1” can work. Otherwise, AllGather and computation will run serially, and accelerator utilization will drop significantly.
# Gradient accumulation (illustrative)accum_steps = 8optimizer.zero_grad(set_to_none=True)for step, batch in enumerate(loader):# Build inputs for text, image, audio, and other modalities separatelywith torch.autocast("cuda", dtype=torch.bfloat16):out = model(input_ids=batch["text"],pixel_values=batch["image"],audio_values=batch["audio"],)loss = out.loss / accum_steps # Scale by the number of accumulation steps# Gradients still remain on local shards; FSDP schedules shards during backwardloss.backward()if (step + 1) % accum_steps == 0:# A safer approach in distributed environments:# First sum gradient norms globally across shards, then clip locally in a unified waytorch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)optimizer.step() # Update only local shardsoptimizer.zero_grad(set_to_none=True)
3.4 Gradient synchronization and numerical consistency
Gradient synchronization has two baseline requirements:
- Mathematical equivalence: Regardless of the number of accelerators, parallel strategy, or whether recomputation is enabled, the parameter update result of a single training step should match the reference implementation, at least within the same floating-point error range.
- Correct norm calculation: Gradient clipping must compute the global norm across all data parallel accelerators. If only the local norm is calculated, the effective clipping threshold is amplified by a factor of sqrt(N). A common failure pattern in large-model training, where the gradient norm slowly increases and then suddenly diverges, is often caused by this issue.
3.5 Optimizer update and checkpointing
Optimizer states are about 8 times the parameter size, for example BF16 parameters plus Adam, and they represent the largest memory overhead. Under FSDP, each accelerator updates only its local shard, so optimizer states are naturally sharded with the parameters and do not require additional splitting.
Checkpointing must balance size and speed:
- Sharded saving: Each accelerator writes its local shard in parallel, avoiding a single process serializing TB-scale data.
- Portable format: Record shard information in a standard format so that loading remains possible after changing the parallel configuration.
- Asynchronous flushing: Overlap computation with writing to storage.
- Hot and cold tiering: Store frequent small-step checkpoints in local high-speed storage, and store infrequent full snapshots in object storage for long-term retention.
4. Software-stack adaptation: four key focus areas
4.1 Operator coverage and automatic fallback
Take matrix multiplication as an example. Mathematically, FP16 and BF16 tensors can be multiplied with FP32 weights, and the framework will perform internal type promotion. However, some operators have stricter constraints on input precision and will raise errors when run directly.
During adaptation, it is necessary to confirm that the software stack provides implementations for these operators, or provides a fallback mechanism that is observable, configurable, and logged. Silent fallback to a low-efficiency path should be avoided; otherwise, performance loss becomes difficult to locate.
4.2 Compilation and execution
Before training starts, the computation graph needs compilation and optimization, such as operator fusion, memory reuse, and scheduling generation, before it can run efficiently on the target hardware. Adaptation should at least verify:
- Compilation succeeds, and dynamic control flow does not repeatedly trigger recompilation.
- The generated executable code is semantically consistent with the original computation graph.
4.3 Collective communication library
Primitives such as AllGather, ReduceScatter, AllReduce, and AllToAll are the “road system” of distributed training. Adaptation needs to confirm:
- Primitives are complete and topology-aware.
- Multi-channel execution is supported to overlap communication with computation.
- Communication timeouts can be diagnosed and recovered.
4.4 Mixed precision and numerical strategy
- Store and compute parameters in BF16, and keep the FP32 master copy in the optimizer.
- Use FP32 accumulation for gradient reduction.
- Keep normalization layers in FP32.
- Loss scaling: BF16 has a large dynamic range, so loss scaling is usually unnecessary; if falling back to FP16, it must be enabled.
5. Verification methods: how to prove that training is correct
Whether an adaptation is trustworthy cannot be judged only by whether it can run. Verification can proceed in four levels:
| Level | Verification target | Passing criterion |
|---|---|---|
| L1 Operator level | Output of a single operator | Maximum error versus reference implementation is within floating-point range |
| L2 Single layer or single step | Forward output and backward gradients | Element-wise comparison with single-accelerator baseline meets relative error target |
| L3 Small-scale convergence | Training a small model on a small dataset | Loss curve trend matches the baseline curve |
| L4 Full-pipeline stability | Long-running training | Training for several days or more without crashes or abnormal spikes |
Illustrative comparison code:
ref_out = ref_model(batch) # Reference implementation (single accelerator)par_out = model(batch) # Sharded training implementationrel_err = (par_out - ref_out).norm() / ref_out.norm().clamp_min(1e-12)assert rel_err < 2e-2, f"Forward output mismatch: {rel_err}"# The threshold should be set according to data type and layer depth:# BF16 single layers are usually around 1e-2, while deeper models should be relaxed appropriately
6. Performance tuning: from “running” to “running efficiently”
- Bottleneck identification: First check accelerator utilization and communication ratio. If communication accounts for a large share, increase shard granularity and enable prefetching. If memory is tight, enable activation recomputation or offload part of the optimizer states.
- Batching and sequence packing: Dynamic sequence lengths can cause accelerators to wait for the slowest one. Length bucketing or sequence packing can reduce padding waste.
- Multimodal data pipeline: Decoding and preprocessing high-resolution images and long videos can be expensive. Use multi-process or multi-threaded loading, local caching, and format conversion preprocessing so that the data side does not become the bottleneck.
- Parallel strategy selection: Parameter sharding plus tensor parallelism is suitable when the model itself does not fit. Expert parallelism, as used in MoE structures, requires additional expert routing and AllToAll communication. Pipeline parallelism splits layers but introduces bubbles. Real training usually combines multiple dimensions. The principles are minimal communication volume, sufficient memory capacity, and a pipeline that can be kept full.
7. Long-running training: necessary engineering conditions
- Elastic fault tolerance: Hardware failures are hard to avoid in large-scale training. The training framework needs to support automatically removing failed nodes and resuming training from the latest checkpoint.
- Observability: Centrally record metrics such as loss, gradient norm, throughput, memory usage, temperature, and power consumption in log services. Monitoring and alerts should provide timely warnings for sudden loss spikes and abnormal gradient norm growth.
- Experiment management: Version hyperparameters, code versions, and parallel configurations so that problems can be reproduced.
- Cost accounting: Allocate resources by accelerator-hours and storage volume. Teams with limited resources can first request on-demand accelerator instances through cloud container platforms for small-scale validation, then expand to large-scale training. Data and checkpoints can be stored in object storage.
8. Developer takeaways: methodology for compute adaptation
This adaptation of a trillion-parameter model training workload offers three lessons:
- Training adaptation is fundamentally hardware-software co-engineering. Model structure, parallel strategy, communication scheduling, and numerical strategy must be designed together. Any weak link becomes a bottleneck.
- “Getting it running” is only the starting point. The L1 to L4 verification levels and long-running stability are the real threshold for training usability.
- Native parallelism is the key foundation. Native FSDP can reduce memory pressure on each accelerator while flexibly combining with tensor parallelism, sequence parallelism, and other strategies. It is an important foundation path for deploying trillion-parameter models.
As model sizes continue to grow, the software ecosystem of domestic AI accelerators is moving from “individual operators work” to “the full training pipeline is usable.” For development teams, understanding this adaptation logic has more long-term value than remembering any single adaptation announcement.
