Engineering Path for Adapting Alternative Compute Platforms to Train Trillion-Parameter Open-Source Models
This article explores the engineering path for adapting alternative compute platforms to train trillion-parameter open-source models. It details how to estimate static memory and communication volumes, explains the principles and configuration boundaries of FSDP2, and outlines a three-step training pipeline covering model loading, sharding scheduling, and gradient synchronization. The content provides technical insights into distributed parallelism, memory management, and communication efficiency for ultra-large-scale model training.
1. Background and Terminology
Recently, the industry has seen open-source flagship large models with parameter scales reaching 2.8 trillion. The boundaries of model capabilities have been pushed higher again, which also imposes new requirements on training and inference infrastructure. Any compute platform intending to host the training of such models must solve engineering problems such as distributed parallelism, memory management, and communication efficiency.
Several hardware vendors are advancing the adaptation of their hardware to mainstream open-source models. The type of case discussed in this article involves completing ultra-large-scale model training adaptation using integrated training and inference accelerator cards based on alternative GPU architectures. “Integrated training and inference” here means that the same accelerator card supports both training and inference tasks simultaneously.
To avoid conceptual confusion, this article uniformly uses the following terminology:
- Alternative Compute Platform: A computing system composed of self-developed chips, drivers, communication libraries, and software stacks distinct from the mainstream CUDA ecosystem.
- Heterogeneous Compute Platform: A platform composed of multiple compute units, with programming interfaces and ecosystems different from the mainstream CUDA architecture.
- Adaptation: Enabling the operator calls, communication primitives, and scheduling logic of upper-layer training frameworks to run correctly on the target hardware.
It should be noted that the adaptation cases in the source material for this article do not provide specific names, model names, hardware models, or verification metrics. Therefore, the following discussion treats it as a directional case study rather than a verified conclusion. Readers should refer to officially released materials if they wish to cite specific numbers.
2. Calculate Memory and Communication First
The first problem in trillion-parameter training is estimating memory and communication volume. The estimation results determine how many cards are needed and which parallelism strategy to adopt.
2.1 Static Memory Estimation
Static memory refers to the memory occupied by model weights, gradients, and optimizer states. The calculation formula is as follows:
Static Memory ≈ Parameter Count × Bytes per Parameter
Taking the common BF16 mixed-precision training with the Adam optimizer as an example, the byte distribution per parameter is as follows:
| Item | Bytes per Parameter |
|---|---|
| Weights (BF16) | 2 |
| Gradients (BF16) | 2 |
| Optimizer states (FP32 master weights, 1st-order momentum, 2nd-order momentum, 4 bytes each) | 12 |
| Total | 16 |
For a 2.8 trillion parameter model calculation:
- Weights only: 2.8×10^12 × 2 bytes ≈ 5.6 TB
- Total static: 2.8×10^12 × 16 bytes ≈ 44.8 TB
If calculated based on 64 GB of memory per card, it takes about 700 cards just to accommodate the static states. If the per-card memory is 96 GB, it requires about 467 cards. Neither of these figures accounts for activation values, communication buffers, and fragmentation; the actual number of cards will be higher.
The activation memory footprint depends on batch size, sequence length, and recomputation strategy, requiring separate measurement.
2.2 Communication Volume Estimation
The communication volume of sharded training can also be estimated. Taking FSDP’s full sharding mode as an example, each training step typically includes three types of data flows: forward parameter gathering, backward parameter gathering, and gradient reduce-scatter. During each full gather, the data volume received by a single card is approximately the model weight byte count multiplied by (N−1)/N, where N is the number of sharded cards. When N is large, this value approaches 5.6 TB.
If estimated based on an effective bandwidth of 50 GB/s per card, a single full gather would take about 112 seconds. This result is based on an ideal bandwidth assumption; actual latency depends on topology, congestion, and message size. However, it is sufficient to illustrate one fact: ultra-large models cannot rely solely on full sharding. They must be combined with intra-node tensor parallelism, mixed sharding, or pipeline parallelism to reduce cross-node communication volume.
3. Principles and Configuration Boundaries of FSDP2
3.1 From DDP to FSDP2
Traditional Data Parallelism (DDP) requires each card to hold a complete model replica, synchronizing gradients through AllReduce at each training step. It requires the entire model to fit on a single card, making it incapable of handling trillion-parameter scales.
FSDP (Fully Sharded Data Parallel) shards parameters, gradients, and optimizer states across cards. When computing a specific layer, cards temporarily gather the parameters of that layer via AllGather. After computation, non-local shards are immediately released. This process is repeated during backpropagation, and gradients are scattered to the corresponding cards via ReduceScatter.
The main changes in FSDP2 compared to the first-generation FSDP are as follows:
- Adopts a per-parameter sharding representation based on DTensor, reducing memory fragmentation and state management complexity caused by flattened parameters in the first generation;
- Supports setting different sharding granularities per module, such as calling the sharding interface independently for each Transformer block;
- Offers more flexible combinations of mixed-precision strategies and activation recomputation, making it easier to balance memory and computation.
The interface names and modules change across PyTorch versions. Newer versions are typically called via torch.distributed.fsdp.fully_shard, while earlier experimental interfaces are located under torch.distributed._composable. Please refer to the official documentation of the version you are using.
3.2 Comparison of Three Parallelism Methods
| Dimension | DDP | FSDP (1st Gen) | FSDP2 |
|---|---|---|---|
| Per-card memory | Full model replica, highest | Sharded, significantly reduced | Sharded, can be refined per module |
| Communication pattern | AllReduce per step | AllGather & ReduceScatter | Same as FSDP, adjustable per module |
| Applicable scale | Models that fit on a single card | Medium to large models | Ultra-large scale, requires hierarchical configuration |
| Configuration complexity | Low | Medium, relies on wrapping strategies | Medium, requires designing sharding granularity |
3.3 Configuration Items to Clarify
In ultra-large-scale training, FSDP2 is usually not used alone but combined with other parallelism methods. Common combinations include:
- Data parallel dimension: Handled by FSDP2 for parameter sharding, scaling across nodes;
- Intra-node tensor parallelism: Utilizes high-speed intra-node interconnects to split matrix operations in attention and feed-forward layers;
- Pipeline parallelism: Splits layers across nodes to further reduce memory pressure per segment.
Before training, the following configurations must be clarified:
- Device mesh: Define which cards belong to data parallelism, tensor parallelism, and pipeline parallelism. Communication groups must align with the physical topology.
- Sharding granularity: Typically sharded per Transformer block to avoid memory peaks from overly coarse granularity or excessive communication frequency from overly fine granularity.
- Mixed precision strategy: A common practice is to compute parameters in BF16 and perform reductions in FP32 to balance speed and numerical stability.
- Resharding strategy: Whether to release parameters immediately after the forward pass. Releasing saves memory but increases the number of gathers during the backward phase.
- Activation recomputation: Enable recomputation for specific layers, trading computation for memory.
3.4 Applicability Boundaries
FSDP2 is not superior to other solutions in all scenarios. The following situations require careful evaluation:
- When the model scale is not large and the number of cards is small, DDP or first-generation FSDP configurations are simpler, and the performance gap is not obvious;
- When cross-node bandwidth is insufficient, the communication overhead of full sharding will exceed computation time, requiring a switch to mixed sharding;
- If custom operators do not support DTensor semantics, additional adaptation is required; otherwise, errors will occur during the sharding phase.
4. Three-Step Execution Flow of the Training Pipeline
The complete training pipeline includes three stages: model loading, sharding scheduling, and gradient synchronization. Each stage has verifiable deliverables.
4.1 Model Loading
The weight file of a trillion-parameter model usually reaches the TB level and cannot be fully read into memory by a single process. The recommended workflow is as follows:
- Build the model skeleton on a meta device. This step only records tensor shapes and does not allocate actual memory.
- Apply the sharding strategy to the skeleton to complete the parameter sharding declaration.
- Use the Distributed Checkpoint interface so that each process only reads the shard it is responsible for.
- Verification after loading: The parameter shape of each process is consistent with the sharding plan, and the global parameter count matches the original model.
Checklist:
- Whether the number of shards in the checkpoint matches the current parallelism; if not, a resharding conversion must be performed first;
- Whether the read volume of each process is close to the theoretical value to avoid out-of-memory errors caused by a single process reading too much;
- Whether random seeds are set correctly according to processes and shards to ensure reproducibility.
4.2 Sharding Scheduling
Different modules have different computational characteristics, so their sharding methods should also differ. The table below provides a common starting plan, which needs to be adjusted according to the model structure and hardware topology.
| Module | Recommended Sharding Method | Checkpoint |
|---|---|---|
| Embedding Layer | Vocabulary dimension sharding, or overall sharding via FSDP | Whether the vocabulary size is divisible by the parallelism degree |
| Attention Layer | Head dimension for tensor parallelism, parameters sharded via FSDP | Whether the number of heads is divisible by the tensor parallelism degree |
| Feed-forward Layer | Intermediate dimension for tensor parallelism, parameters sharded via FSDP | Whether the matrix shapes are aligned after intermediate dimension splitting |
| Vision Encoder | As an independent sharding unit | Whether image tensor shapes match language model inputs |
Multimodal scenarios require additional handling. The tensor shapes and data pipelines of the vision encoder and the main language model backbone are often different. If both share the same sharding configuration, shape mismatches or idle communication can easily occur. It is recommended to group the vision encoder separately and set up explicit outputs between the two.
