Training Trillion-Parameter Multimodal LLMs on Domestic AI Accelerators: An FSDP2-Based Adaptation Practice
As model sizes scale from tens of billions to trillions of parameters, traditional data parallelism quickly hits physical memory limits, shifting the core challenge from raw speed to sharding the model across thousands of accelerators without sacrificing convergence. This article explains why FSDP2—with its DTensor-based per-parameter sharding—is the foundation for such workloads, walks through its core mechanics (all-gather during forward and backward passes, reduce-scatter for gradients), and covers the three critical stages of the full training pipeline: model loading and shard initialization, shard scheduling, and gradient synchronization. It also addresses multimodal-specific considerations, the key software-stack adaptation points for domestic AI accelerators (operators, collective communication, framework compatibility, and numerical consistency), and engineering optimizations such as mixed precision, activation recomputation, gradient accumulation, and multi-dimensional parallelism.
Training Challenges in the Trillion-Parameter Era
As model parameters scale from tens of billions to trillions, traditional data parallelism quickly reaches physical limits. A trillion-parameter model requires roughly 2TB of memory for the weights alone, even when stored in BF16 half precision. Add gradients, optimizer states (such as Adam’s first and second moments), and forward activations, and neither a single GPU nor a single node can hold it all. This means the central problem of large-scale training is no longer “how to run faster” but “how to slice the model finely enough that thousands of accelerators can work together without compromising convergence quality.”
From Data Parallelism to FSDP2: Why It Matters
Distributed training has evolved through several generations:
- Data parallelism (DP/DDP): Every GPU holds a full copy of the model and only all-reduces gradients. Simple to implement, but the memory redundancy is severe, making it unsuitable for very large models.
- Tensor parallelism (TP): Splits a single operator (such as matrix multiplication) across GPUs, with frequent communication, usually limited to the high-speed interconnect within a single node.
- Pipeline parallelism (PP): Partitions layers across devices and hides bubbles using micro-batches, but suffers from pipeline bubbles and scheduling complexity.
- Fully Sharded Data Parallelism (FSDP): Shards parameters, gradients, and optimizer states by rank, aggregating them on demand.
FSDP2 is the second-generation rewrite of fully sharded data parallelism. Its core change is using DTensor (distributed tensor) as the underlying abstraction to achieve per-parameter sharding, rather than flattening parameters into a 1D tensor and then splitting. This brings several direct benefits:
- A clearer state dictionary, with explicit semantics for each layer’s sharding layout, making save/load and debugging easier;
- More natural composition with other dimensions such as tensor parallelism and expert parallelism, making it easier to build multi-dimensional parallelism grids;
- Finer sharding granularity, with more controllable memory peaks and communication scheduling.
How FSDP2 Works
The FSDP2 training loop is essentially “aggregate when needed, release when done”:
- Before computing a layer in the forward pass, all-gather temporarily reconstructs the full weights for that layer from the shards held across ranks;
- Once the layer finishes, the full parameters are released, keeping only the local shard;
- During backpropagation, all-gather runs again; after computation, reduce-scatter is applied to the gradients so each rank keeps only the gradient for its own shard;
- The optimizer updates each shard independently.
This mechanism keeps communication volume proportional to the parameter count and hides latency through overlap of communication and computation.
Illustrative code (pseudocode, shown only to illustrate the API shape):
from torch.distributed.fsdp import fully_shardfrom torch.distributed.device_mesh import init_device_mesh# Build the data-parallel device meshmesh = init_device_mesh("accel", (dp_world_size,), mesh_dim_names=("dp",))# Shard per layer: shard each decoder layer of the Transformer separatelyfor block in model.blocks:fully_shard(block, mesh=mesh)# Shard the root module as a wholefully_shard(model, mesh=mesh)optimizer = AdamW(model.parameters(), lr=1e-3, betas=(0.9, 0.95))
Three Key Stages of the Full Training Pipeline
1. Model loading and shard initialization
A trillion-parameter model cannot be loaded into memory all at once. In practice, parameter metadata (the shape/dtype in the state_dict) is parsed on the CPU or storage side, then materialized layer by layer as shards on the device mesh. Loading must ensure each rank materializes only its own shard, avoiding transient memory spikes that would exceed capacity limits.
2. Shard scheduling
Shard scheduling decides which parameter ranges each rank is responsible for and how the communication groups for all-gather/reduce-scatter are partitioned. A sound schedule aligns with the computation order—aggregate the layers about to be used and release them immediately afterward—so that communication overlaps as much as possible with computation, reducing idle device time.
3. Gradient synchronization and update
After backpropagation, reduce-scatter reduces gradients by shard, and each rank performs optimizer updates only on its local shard. This spreads the optimizer states (momentum, variance, and so on) evenly across all GPUs, avoiding the full optimizer overhead on a single card.
Special Considerations for Multimodal Models
Multimodal models typically contain a text encoder, a vision/image encoder, and cross-modal alignment modules (such as projection layers and connectors). Different modules vary greatly in parameter count, operator types, and compute characteristics:
- Vision encoders are mostly convolutional or ViT-based, with high activation memory usage;
- The text backbone is mostly a Transformer decoder and forms the bulk of the parameters;
- The parallelism strategy for cross-modal fusion layers must align with both sides.
For this reason, engineering practice often applies differentiated parallelism strategies to different submodules: shard the parameter-heavy text backbone thoroughly, supplement the activation-heavy vision branch with activation recomputation, and reserve reasonable communication groups in the device mesh to avoid any single dimension becoming an overall throughput bottleneck.
Software-Stack Adaptation for Domestic AI Accelerators
Migrating this training pipeline to domestic AI accelerators is fundamentally about completing compatibility and performance on a unified programming and operator software stack, not rewriting the training logic. The core work typically includes:
- Operator adaptation: Key Transformer operators (attention, LayerNorm/RMSNorm, matrix multiplication, reduction, and so on) need efficient implementations on the target hardware, covering precisions such as BF16/FP16; missing operators must be filled in through composition or custom kernels.
- Collective communication adaptation: Primitives such as all-gather, reduce-scatter, all-reduce, and broadcast must be implemented efficiently over the inter-device interconnect topology and support the communication-computation overlap that FSDP2 requires.
- Framework compatibility: Abstraction layers such as the distributed framework, DTensor, and device mesh must be correctly mapped to the target backend, ensuring consistent sharding layouts, random-number behavior, and mixed-precision behavior.
- Numerical consistency: In mixed-precision training, the numerical behavior of the forward/backward passes must stay close enough to the reference implementation to avoid divergence or slower convergence of the loss curve.
Key Engineering Optimizations
- Mixed precision: Weights participate in computation as BF16/FP16 while FP32 master weights and reduction accumulation are retained, balancing memory usage and training stability.
- Activation recomputation: Recomputing forward activations during backpropagation trades time for memory and is almost indispensable for trillion-parameter training.
- Gradient accumulation: Accumulating gradients over small micro-batches effectively enlarges the global batch size under limited memory and stabilizes the convergence curve.
- Multi-dimensional parallelism combinations: Combining FSDP (sharding along the data dimension) with tensor parallelism, pipeline parallelism, and sequence/context parallelism, tuned for different model scales and cluster topologies.
Best Practices and Summary
Training trillion-parameter multimodal models is a systems engineering effort: an FSDP2-centered sharding framework handles “splitting apart and gathering together,” mixed precision and activation recomputation handle “fitting it in,” multi-dimensional parallelism handles “running fast,” and operator and communication adaptation on domestic accelerators determine “running through and running stably.”
For developers, the recommended rollout order is:
- First validate FSDP2 training logic and the convergence curve on mature hardware;
- Then verify compatibility and performance of the domestic stack operator by operator and collective-communication primitive by primitive;
- Next tune the parallelism strategy and recomputation granularity for the model structure;
- Finally build complete logging, monitoring and alerting, and checkpoint-resume capabilities to support long-running training.
Whether it is the general AI compute and supporting capabilities offered by Baidu AI Cloud, or the domestic AI software stacks from various vendors, the core methodology of large-scale training is the same: shard the model, overlap the communication, and account for memory precisely—only then can training be completed stably and efficiently in the trillion-parameter era.
