A Practical Guide to Training Trillion-Parameter Large Models

    This article explains how to adapt trillion-parameter large language models for training on heterogeneous compute platforms. It covers why these models are hard to run, including memory, communication, operator, and numerical stability bottlenecks, and then walks through a staged approach: choosing parallelism dimensions, sharding strategy, model loading, forward and backward orchestration, gradient reduction, and optimizer state management. It also outlines a three-layer method for adapting the software stack, a step-by-step validation order, a tuning checklist, and resource organization suggestions for cloud deployment.

    1. Background: Why Trillion-Parameter Models Are Hard to Run

    A recent flagship large language model with roughly 2.8 trillion total parameters was open-sourced, with both weights and inference code released. Models of this kind typically use a sparse expert structure, which decouples total parameter count from the number of parameters actually activated per token: total parameters determine memory and storage pressure, while activated parameters determine the compute required for a single forward pass. For training, the real difficulty is not that matrix multiplication is too slow. It is how to split a set of weights far larger than the memory of a single accelerator across hundreds or thousands of accelerators, and keep data flowing through the forward pass, backward pass, and optimizer update without structural bottlenecks.

    Adapting this kind of model for training on domestic heterogeneous compute platforms usually means clearing four hurdles:

    • The memory wall: parameters, gradients, optimizer states, and activations add up, so the actual per-device footprint under mixed precision is far larger than the parameter count alone.
    • The communication wall: sharded parameters must be repeatedly gathered and released between layers, and communication volume grows nonlinearly with cluster size.
    • Operator gaps: new attention variants, sparse routing, and normalization implementations often lack highly optimized native operators.
    • Numerical and stability issues: low-precision accumulation, uneven routing load, and gradient clipping are all significantly amplified at extreme scale.

    2. Overall Adaptation Approach: Decide Parallelism First, Then the Data Path

    The more reliable engineering order is “shard first, connect second, tune last,” rather than chasing peak throughput from the start.

    1. Choosing sharding dimensions. A common industry combination is a mix of data parallelism, tensor parallelism, pipeline parallelism, and expert parallelism. For sparse models, expert parallelism is almost mandatory, because it places different experts on different devices and avoids storing all expert weights on every device.
    2. Choosing a sharding strategy. Full sharding schemes centered on parameter sharding (often referred to as FSDP-style schemes in the industry) are more flexible for multimodal and variable-length input scenarios. They do not require tensor split shapes to be fixed in advance, which makes them friendlier to models whose structure iterates frequently.
    3. Criteria for a working data path. Whether adaptation is complete is not judged by single-step speed but by whether three things close the loop: whether the model can be fully loaded and correctly sharded; whether the backward pass can stably produce gradients and complete cross-device reduction; and whether optimizer states can be updated correctly and remain consistent after saving and restoring.

    3. Key Implementation: Four Stages of the Native Sharded Training Path

    3.1 Model Loading and Shard Mapping

    The core of the loading stage is decoupling the “logical model definition” from the “physical device placement.” The recommended approach is to first build the computation graph on a single device using metadata, then register each layer’s parameters as shard units according to the chosen strategy, and finally load weights in a streaming fashion to avoid reading all tensors into memory at once.

    1. # Example: shard wrapping and streaming load (pseudocode, structure only)
    2. for layer in model.layers:
    3. shard_unit = shard(layer, dim=0, device_mesh=mesh) # register shard
    4. load_weights_into(shard_unit, path=ckpt, stream=True) # stream weights
    5. optimizer = build_optimizer(model, mode="sharded") # shard optimizer states too

    The key point is that shard units that are too fine-grained create a large number of small-message communications, while units that are too coarse cause load imbalance. In practice, a common starting granularity is “one Transformer block” or “one expert group.”

    3.2 Forward and Backward Execution Orchestration

    Sharded parameters must be temporarily gathered into full tensors before the forward pass and released immediately after use. This “gather-compute-release” rhythm determines peak memory. Computation and communication can be overlapped so that gathering the next layer runs in parallel with computing the current layer. For activations, selective recomputation can balance memory against compute.

    3.3 Gradient Synchronization and Reduction

    After the backward pass, each device holds only sharded gradients, which need to be reduced along the sharding dimension. In engineering terms, reduction should be bucketed to control single-message size and reduce launch overhead, and reduction should be overlapped with backward computation to hide communication latency. Reduction precision should match accumulation precision; lowering precision to save bandwidth can cause divergence later.

    3.4 Optimizer Update and State Management

    Optimizer states (first- and second-order moments) are usually sharded like the parameters, and updates happen locally without extra communication. Checkpoints should be written out per shard, and on restore they should be remapped according to the current parallel topology, so training can resume even if the device count changes.

    4. A General Method for Adapting the Heterogeneous Software Stack

    When a model needs to move to a non-mainstream hardware ecosystem, it helps to proceed in three layers: operators, framework, and precision.

    • Operator layer: first build an operator coverage list and flag three kinds of problems: missing operators, operators that miss performance targets, and numerical inconsistencies. For missing operators, prefer equivalent compositions first, then gradually replace them with high-performance native implementations.
    • Framework layer: confirm that distributed primitives (collective communication, shard management, pipeline scheduling) have semantics consistent with mainstream implementations, especially whether communication supports asynchrony and overlap.
    • Precision layer: compare the outputs of the reference implementation and the ported implementation layer by layer, and only discuss performance after localizing differences to specific operators.

    A reusable troubleshooting order is: single-device forward alignment → single-device backward alignment → two-device gradient consistency → multi-device throughput and convergence alignment. Do not move to the next step until the current one passes, otherwise problems get amplified by scale and become hard to localize.

    5. Performance and Stability Tuning Checklist

    • Communication: bucket size, communication backend choice, topology-aware process group partitioning.
    • Memory: recomputation ratio, gather granularity, cache pool limits.
    • Computation: operator fusion, fused normalization and activation implementations, batching strategy for variable-length inputs.
    • Stability: gradient clipping thresholds, auxiliary loss for routing load balancing, automatic rollback on loss spikes.
    • Observability: bring throughput, peak memory, communication wait ratio, and per-step time into unified monitoring and alerting, and retain baselines through general capabilities such as logging and monitoring/alerting for regression comparison.

    6. Resource Organization Suggestions for Cloud Deployment

    If you use heterogeneous compute in the cloud, you can orchestrate training tasks on a container platform, store checkpoints and datasets in object storage, use a message queue to decouple data preprocessing from the main training flow, and track task health with general monitoring and alerting capabilities. In these scenarios, Baidu AI Cloud typically provides general-purpose capabilities such as containerized scheduling, object storage, logging, and monitoring; refer to the official product documentation for specific specifications. This article does not cover any undisclosed parameters.

    7. Conclusion

    Adapting trillion-parameter models for training is essentially a serious alignment between the freedom of model structure and the constraints of hardware execution. As long as shard granularity, communication orchestration, and numerical consistency are handled solidly, and the layer-by-layer alignment validation method is followed, heterogeneous compute can carry the full training pipeline of a flagship model.