Adapting FSDP2 for 2.8T-Parameter MoE Training on Domestic Chinese GPUs: Practical Engineering Guide
Training a 2.8-trillion-parameter sparse MoE model requires sharding parameters, gradients, and optimizer states across many accelerators. This guide explains how FSDP2's fully_shard mechanism works, how it interacts with expert parallelism, and how to build reliable multimodal data pipelines, checkpointing, and fault-tolerance strategies for trillion-parameter-scale training on domestic Chinese GPU clusters.
Scope
This article is written for infrastructure and training engineers who need to train ultra-large sparse MoE models on clusters built from domestic Chinese GPUs. The methods described apply to trillion-parameter-scale models that use expert architectures. This article does not evaluate the training results of any specific model, nor does it compare performance across platforms. Publicly available materials do not disclose the throughput, per-step latency, cluster size, or total training duration of this adaptation effort, so the sections below focus only on methodology and engineering practices.
Why Sharding Is Mandatory
Take a 2.8-trillion-parameter model as an example. Storing the weights alone in bf16 requires roughly 5.6 TB of memory. Adding gradients and AdamW optimizer states multiplies the total footprint several times over. A single accelerator’s memory is far smaller than this figure, so parameters, gradients, and optimizer states must all be partitioned across many devices.
FSDP2 Sharding and Communication Mechanics
FSDP2 shards parameters at the module level via fully_shard. The core workflow is as follows:
- Forward pass: Before entering a layer, an all-gather collects the layer’s full parameters. After computation finishes, non-local shards are released to save memory.
- Backward pass: After each layer produces gradients, a reduce-scatter performs the reduction and distributes the results to each rank. Each rank retains only the gradient shard it owns.
- Optimizer update: Each rank updates only its own shard of parameters and optimizer states.
This means no device ever aggregates the full gradients. The main gradient-communication cost comes from reduce-scatter, while the main parameter-communication cost comes from the all-gathers in the forward and backward passes.
Sharding Strategy and MoE Expert Layers
By default, FSDP2 splits parameter tensors along dimension 0. Expert weights are typically stored in stacked form, with a shape like [num_experts, hidden_dim, intermediate_dim]. After sharding along dimension 0, different ranks hold the weights of different experts, which is easily mistaken for expert parallelism. The difference:
- FSDP sharding: Parameter storage is partitioned, but the layer’s parameters are still all-gathered during the forward pass, and computation happens locally.
- Expert parallelism (EP): Expert weights reside permanently on specific devices, and tokens are routed and sent via all-to-all to the devices hosting their assigned experts.
In practice, the two are usually combined. Non-expert parameters are sharded with FSDP2 within the data-parallel group, while expert parameters are partitioned across devices with EP. A two-dimensional device mesh is recommended so that the data-parallel and expert-parallel dimensions remain separate. In addition, imbalanced expert loads can leave some ranks waiting for long periods; this should be controlled with routing auxiliary losses or capacity factors.
Gradient Accumulation and Communication Overlap
With gradient accumulation, intermediate micro-batches do not need gradient reduction. You can call model.set_requires_gradient_sync(False) during intermediate steps and restore it to True before the final micro-batch.
Communication granularity is determined by how fully_shard groups modules. Grouping by layer is a common choice. Groups that are too small increase the number of communication operations; groups that are too large raise peak memory usage during each collective. Prefetching allows the next layer’s all-gather to overlap with the current layer’s computation.
For numerical precision, you can use MixedPrecisionPolicy to set parameters to bf16 and gradient reduction to fp32. Higher reduction precision improves numerics but also increases communication volume, so the trade-off depends on available bandwidth.
from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicymp = MixedPrecisionPolicy(param_dtype=torch.bfloat16, reduce_dtype=torch.float32)for layer in model.layers:fully_shard(layer, mesh=mesh, mp_policy=mp)fully_shard(model, mesh=mesh, mp_policy=mp)
Example launch command (single node, 8 GPUs):
torchrun --nproc_per_node=8 train.py
For multi-node runs, execute the command once per node, setting --node_rank according to the node index:
torchrun --nnodes=4 --node_rank=$NODE_RANK \--master_addr=$MASTER_ADDR --master_port=29500 \--nproc_per_node=8 train.py
Multimodal Data Pipeline
In multimodal training, the read speed and preprocessing cost of images, audio, and text differ significantly. If all stages run serially in the same process, the slowest stage drags down the entire training loop. The table below shows a reusable way to split the pipeline:
| Stage | Input | Common bottleneck | Queue setup | Failure handling |
|---|---|---|---|---|
| Reading | Sharded files or object storage data | I/O latency | Queue length matches the number of prefetched batches | Retry; skip and log after exceeding retry limit |
| Decoding | Image and audio binaries | CPU decode throughput | Number of decode processes matches GPUs per node | Isolate corrupted samples |
| Augmentation | Decoded tensors | CPU compute | Independent queue per stage | Count and drop abnormal samples |
| Batching | Sequences of varying lengths | Compute wasted on padding | Bucket by length | Truncate overlong samples and log the count |
| Host-to-device | Batches in host memory | Host-to-device copy bandwidth | Use pinned memory with double buffering | Resubmit the batch on copy failure |
Bounded queues prevent unbounded memory growth. Queues that are too small cause data starvation; queues that are too large consume excessive host memory. A practical approach is to estimate queue length from each stage’s per-batch latency first, then calibrate using actual GPU idle time during training.
Long-sequence training typically introduces sequence parallelism, which splits very long sequences across multiple devices. The sequence-parallel group and FSDP’s data-parallel group must be created separately; they cannot share the same communication group.
Checkpointing and Fault Tolerance
Ultra-large-scale training is measured in weeks, and interruptions are costly. A checkpoint must include:
- Sharded model weights
- Optimizer states
- RNG states
- The data loader’s read position
- Learning rate scheduler state
Use a distributed checkpointing interface (such as torch.distributed.checkpoint) to write shards in parallel, avoiding any single rank aggregating all parameters.
The following parameters are example configurations and should be adjusted based on actual per-step latency and node failure rates:
- Save frequency: every 500 steps.
- Retention policy: keep the 3 most recent full checkpoints, plus one long-term snapshot per week.
- Anomaly thresholds: stop training if the loss becomes NaN or exceeds several times its moving average. Trigger an alert when the gradient norm exceeds a multiple of its historical percentile. Thresholds should be calibrated in small-scale experiments rather than copied directly.
A rollback discards all training steps after the most recent valid checkpoint. The compute time lost is roughly “steps since the last checkpoint × per-step latency.” Before rolling back, verify checkpoint integrity and confirm the files load correctly.
Troubleshooting Checklist
| Symptom | Possible cause | Remedy |
|---|---|---|
| OOM during forward pass | Too many all-gathered parameters resident at once | Reduce prefetch depth, or enable reshard-after-forward |
| Collective communication timeout | A slow node, or rank mapping inconsistent with topology | Check inter-node bandwidth; verify rank-to-physical-device mapping |
| Loss suddenly becomes NaN | Learning rate too high, or low-precision overflow | Roll back to the previous checkpoint, lower the learning rate, check reduction precision |
| Loss jumps after resume | Data loader or RNG state not restored correctly | Check the checkpoint contents against the list and verify item by item |
| Some ranks waiting for long periods | Imbalanced expert load | Count tokens per expert; tune the routing auxiliary loss |
Performance Data and Evaluation Methodology
Data that has not yet been made public includes cluster size, per-step latency, throughput, MFU, total training duration, and the number of failure recoveries. Until these figures are published, this adaptation should not be interpreted as representing any particular performance tier.
Teams or developers who want to evaluate their own platforms can run controlled experiments on smaller models: use the same model architecture, the same data, and the same random seed; record throughput, memory usage, and loss curves separately; then compare convergence speed.
Risks and Alternatives
- Proprietary software stacks are usually bound to specific framework versions. Before upgrading the framework or drivers, run regression tests on a test cluster.
- If some operators are not yet covered, the framework may fall back to slower implementation paths, noticeably degrading training speed. Before going live, verify the execution path of each critical operator.
- If the target platform has incomplete FSDP2 support, FSDP1 or DeepSpeed ZeRO-3 can serve as alternatives. Before switching, verify that checkpoint formats are compatible.
- When the data-parallel scale is small, tensor parallelism can be considered as a starting point.
