Adapting Trillion-Parameter MoE Models for Training: Key Steps and Practical Guidelines
This guide covers the main considerations for training trillion-parameter Mixture-of-Experts (MoE) models on general-purpose compute clusters after their weights are released. It covers parallelism strategy, memory budgeting, communication scheduling, and training stability, with examples of FSDP2 combined with expert parallelism, distributed checkpoint loading, and gradient synchronization for experts that receive no tokens.
Introduction: Training Adaptation Is the Real Challenge After Open-Sourcing the Weights
After a trillion-parameter Mixture-of-Experts (MoE) model is open-sourced, obtaining the weights is only the first step. Whether the model can train stably and efficiently on a general-purpose compute cluster depends on four areas: parallelism strategy, communication scheduling, memory budget, and fault recovery. This article organizes the key adaptation points around these four areas.
The numbers in this article are example configurations or empirical starting points. They do not represent measured results from any specific cluster. Actual values should be calibrated against baseline data from your own cluster.
The following sections address three common questions in turn: how to choose a parallelism strategy for trillion-parameter MoE models, how to optimize memory, and how to keep training stable.
1. Understanding the Model Architecture First
Before designing a training plan, identify the constraints that the model architecture imposes.
Parameter scale and activation scale are separate. The total parameter count of an MoE model is large, but each token passes through only a few experts. As a result, memory pressure comes mainly from parameters, gradients, and optimizer states rather than from activations. This differs from the bottleneck in dense models, so the memory budget should start from the parameter side.
Take mixed-precision training as an example. Each parameter typically takes about 16 bytes: 2 bytes for the BF16 parameter, 2 bytes for the BF16 gradient, and 4 bytes each for the FP32 master weight, the first Adam moment, and the second Adam moment. For a model with 1 trillion parameters, the full state is about 16 TB. If the state is sharded across 512 accelerators, each accelerator holds about 32 GB on average, leaving the remaining memory for activations and communication buffers. This is a rough estimate. The actual value depends on the sharding method and expert layout.
Routing introduces irregular communication. Which experts a token is routed to depends on the input content. As a result, the volume of All-to-All communication changes at every step. Cluster interconnect bandwidth and topology awareness directly affect training speed.
Multimodal inputs lengthen the data pipeline. Preprocessing time for text and vision inputs can vary widely. Data preprocessing, feature alignment, and sequence packing should run in separate processes from model computation. Prefetch queues can absorb fluctuations in preprocessing time.
2. Parallelism Strategy: Combining FSDP2 and Expert Parallelism
For trillion-parameter models, data parallelism alone cannot handle the load. This article uses native FSDP2 as the sharding framework for non-expert parameters and adds expert parallelism (EP) on top of it.
Versions and environment. PyTorch 2.6 and later provide the official fully_shard interface. Record the framework version, NCCL version, and driver version in training logs. This makes runs easier to reproduce and problems easier to troubleshoot.
Main improvements in FSDP2. First, sharding units are finer-grained. Parameters, gradients, and optimizer states are organized into smaller shard blocks. Combined with asynchronous all-gather and reduce-scatter, this reduces communication bubbles. Second, memory semantics are clearer. The timing of sharding and gathering is explicit, so peak memory can be estimated in advance, which supports quantitative budgeting. Third, FSDP2 suits pipelined data feeding. Computation time differs across modalities, and FSDP2’s scheduling makes it easier to coordinate with the data pipeline.
How expert parallelism is combined. Expert parameters are split across EP groups, while non-expert parameters are sharded with FSDP. Expert replicas are sharded once more along the data-parallel dimension. The two approaches compose orthogonally, forming a hybrid “EP × DP × TP” topology.
Take 512 accelerators with 8 accelerators per node as an example. A configuration of EP=8, DP=64, TP=1 gives 8 × 64 × 1 = 512. The EP group sits within a node, so All-to-All traffic stays on the high-bandwidth intra-node interconnect. Cross-node traffic carries only the parameter and gradient synchronization along the DP dimension. If TP is introduced, evaluate the all-reduce overhead of each layer separately.
Overlapping communication with computation. Through prefetch settings, the all-gather of the next layer’s parameters runs in parallel with the forward computation of the current layer. The same approach applies to the backward pass: the reduce-scatter of gradients overlaps with the backward computation of the previous layer. To check whether the overlap works, look at the profile and confirm that communication kernels fall into the idle gaps between computation kernels.
Boundary conditions. When a model has few layers and each layer is small, communication time is hard to hide behind computation, so FSDP2 delivers limited gains. When cross-node EP bandwidth is insufficient, All-to-All becomes a bottleneck. In that case, reduce the EP group size or adjust the expert placement. After introducing TP, each layer adds an extra all-reduce. Use profiling to confirm that the gain outweighs the added cost.
3. Building the Training Pipeline: Loading, Scheduling, and Gradient Synchronization
A deliverable training pipeline consists of three closed loops: loading, scheduling, and synchronization.
3.1 Distributed Checkpoint Loading
Checkpoints for trillion-parameter models are typically several terabytes, so serial reading is not practical. Use a distributed checkpoint format, such as the DCP format of torch.distributed.checkpoint or sharded Safetensors with an index file. Each parallel group reads only the shards it needs, and checkpoints can be re-sharded across different parallel configurations.
Below is a skeleton of the loading process. Refer to the documentation for your version for the exact interfaces.
from torch.distributed.checkpoint.state_dict import get_state_dict, set_state_dictimport torch.distributed.checkpoint as dcp# First retrieve the state dict under the current sharding layout as the load targetmodel_sd, optim_sd = get_state_dict(model, optimizer)state = {"model": model_sd, "optim": optim_sd}# All ranks make this call the same way, each reading its local shardsdcp.load(state, checkpoint_id=ckpt_dir)set_state_dict(model, optimizer,model_state_dict=state["model"],optim_state_dict=state["optim"])
Use a consistent definition for loading time. Measure from process start to the first training step. Record cold starts and warm starts separately, and average three runs for each. File system caching significantly affects warm-start results, so warm-start and cold-start data should not be compared directly.
3.2 Shard Scheduling
In each training step, the parameter all-gather before the forward pass must overlap with computation. The gradient reduce-scatter during backpropagation should also enter the communication queue as early as possible. The core principle is that communication should not wait on computation unnecessarily, and computation should not wait on communication unnecessarily. In practice, orchestrate communication and computation at the CUDA stream level (or the equivalent streams on other devices). Place them on different streams, and use event synchronization to enforce dependencies.
3.3 Gradient Synchronization and Empty Expert Buckets
In MoE training, some experts may receive no tokens in a given step, so they produce no gradients. The most likely problem in this case is deadlock.
Collective operations require every rank in the group to make the same number of calls in the same order. If one rank skips an all-reduce because it has no local gradients, the other ranks wait indefinitely. Therefore, never decide whether to make a collective call based on local, per-rank conditions.
The correct approach has two steps. First, all ranks in the group count the tokens each expert processes in this step. One all-reduce then produces a globally consistent active mask. Second, all ranks iterate over the expert buckets in the same fixed order by expert ID. Active experts are reduced normally, and experts with a global token count of zero are skipped. Because the mask is globally consistent, every rank makes the same skip decision, so no misalignment occurs.
```python
Step 1: Obtain global token counts across the group to build a consistent active mask
token_counts = local_token_counts_per_expert.clone()
dist.all_reduce(token_counts, group=ep_dp_group)
active_mask = token_counts > 0
Step 2: All ranks iterate over expert buckets in the same order
for expert_id in range(num_experts):
if not active_mask[expert_id]:
continue # Skipped consistently across the group, so no misalignment
buf
