Adapting Trillion-Parameter Models for Training: Three Key Stages in Practice
This article walks through the training adaptation of an open-source model with about 2.8 trillion parameters. It breaks the full path into hardware, software stack, framework, and model layers, then covers model loading in detail. The article explains how to estimate memory needs for weights and optimizer states, how to load sharded weights efficiently, how to verify file integrity, and how to structure the loading code.
1. Background and Scope
Recently, the industry open-sourced a flagship model with roughly 2.8 trillion parameters. As model size grows from hundreds of billions to trillions of parameters, adding compute alone is no longer enough. Training frameworks, communication libraries, operator adaptation, and memory management must be designed together.
For AI computing platforms developed in China, whether such models can be trained stably is a direct measure of ecosystem maturity. This article uses one typical training adaptation as a reference and walks through the full path across four layers: hardware, software stack, framework, and model. The parameter counts and memory figures come from the original background material. This article makes no additional claims about the specific training details of that model.
2. Four Layers of Training Adaptation
Adaptation problems can be split by layer. Each layer has different key metrics, common bottlenecks, and troubleshooting entry points.
| Layer | Key Metrics | Common Bottlenecks | Troubleshooting Entry Points |
|---|---|---|---|
| Hardware | BF16/FP8 peak compute, memory capacity and bandwidth, inter-card interconnect bandwidth | Insufficient per-card memory; low interconnect bandwidth reduces scaling efficiency | Single-card compute benchmarks; intra-node and inter-node bandwidth tests |
| Software stack | Operator coverage, communication library versions, driver and runtime compatibility | Missing operators fall back to slow paths; library and driver versions do not match | Operator inventory comparison; version compatibility matrix |
| Framework | Sharding strategy, memory watermark, communication count and latency | Shards that are too fine cause excessive communication; shards that are too coarse push peak memory over the limit | Framework performance profiling tools; communication latency statistics |
| Model | Layer count, expert count, vision encoder structure, multimodal input shapes | Mismatched shapes between vision and text branches cause synchronization waits | Shape checks for single-layer forward and backward passes |
The framework layer splits model parameters across cards and decides the scheduling order of communication and computation. The software stack layer makes sure the framework’s distributed strategy runs correctly on the underlying hardware. Special model structures, such as multimodal branches and mixture-of-experts (MoE) layers, affect the sharding rules at the framework layer.
3. Core Stage 1: Model Loading
3.1 Estimating Memory Requirements
At BF16 precision, the global weights of a model with 2.8 trillion parameters require about:
2.8×10¹² parameters × 2 bytes ≈ 5.6 TB
This is the total weight size across all cards, not the memory used by a single card. The memory each card actually needs depends on the number of shards.
Training also requires optimizer states. With a common mixed-precision scheme, each parameter needs about 16 bytes: 2 bytes for the BF16 weight, 2 bytes for the BF16 gradient, 4 bytes for the FP32 master weight, and 4 bytes each for the first and second Adam moments. The global training state is therefore about:
2.8×10¹² × 16 bytes ≈ 44.8 TB
This figure excludes activations and communication buffers. If 1,024 cards use full sharding, each card holds about 44 GB (decimal) of training state. An actual configuration should recalculate this based on the memory capacity of the hardware in use.
3.2 Loading Methods
The loading stage relies on three key practices.
Lazy construction: Build the model structure on the meta device first. The meta device records only tensor shapes and data types and allocates no real memory. After sharding, allocate only the portion each card is responsible for. This avoids the memory peak caused by fully instantiating the model first.
Indexed reading: The header of a safetensors file records the name, shape, data type, and byte offset of each tensor. The loader can read only the byte range assigned to its process instead of the entire file. This significantly reduces I/O pressure.
Integrity verification: Each shard file should come with a hash manifest. After loading, compare the locally computed hashes with the manifest. Full verification consumes considerable I/O and CPU. A practical approach is to verify file-level hashes first, then spot-check key tensors.
3.3 Structural Example Code
The code below shows how loading and sharding can be organized. It is a structural example. Names such as LargeModel, load_sharded_weights, BACKEND, and DEVICE must be replaced with the actual implementation. Communication backend names and device types for platforms developed in China should follow the relevant vendor’s PyTorch adaptation documentation.
import torchimport torch.distributed as distfrom torch.distributed.device_mesh import init_device_meshfrom torch.distributed.fsdp import fully_shard, MixedPrecisionPolicydist.init_process_group(backend=BACKEND)world_size = dist.get_world_size()mesh = init_device_mesh(DEVICE, (world_size,))mp_policy = MixedPrecisionPolicy(param_dtype=torch.bfloat16, # Parameter precision for forward and backward computationreduce_dtype=torch.float32, # Gradient reduction uses FP32 to reduce accumulation error)with torch.device("meta"): # Build the structure only; do not
