Trillion-Parameter LLM Training Adaptation Guide for Domestic AI Accelerators
Running trillion-parameter large models on domestic AI accelerators is not about copying training scripts, but about solving four constraints at once: memory, communication, scheduling, and stability. This guide explains why training adaptation grows more complex as model scale increases, breaks down the three core bottlenecks (the memory wall, the communication wall, and the scheduling and stability wall), and compares parallel strategies such as DDP, FSDP, tensor parallelism, pipeline parallelism, and expert parallelism. It then walks through a complete PyTorch-style FSDP adaptation pipeline covering model loading and sharding, mixed-precision forward/backward passes, gradient synchronization, and a troubleshooting checklist, followed by hardware-software co-optimization for operators, collective communication, and numerical stability, plus the engineering practices needed to keep long-running training jobs stable and reproducible.
Bottom line first: Training adaptation is systems engineering, not moving code
Running trillion-parameter models on domestic AI accelerators is not simply about copying your training scripts to a new platform. You have to solve four constraints simultaneously:
- Memory constraints: Parameters, gradients, optimizer states, and activations can exhaust a single device’s memory quickly.
- Communication constraints: In multi-device, multi-node settings, parameter gathering, gradient reduction, and activation exchange add significant overhead.
- Scheduling constraints: Large-scale training needs stable resource allocation, checkpoint/resume, fault isolation, and automatic recovery.
- Stability constraints: Training runs last a long time, and any single anomaly can affect final convergence and project timelines.
So the essence of training adaptation is: on domestic AI accelerators and their software stack, choose the right parallel strategy and wire up model loading, sharding, mixed precision, gradient synchronization, and monitoring with fault tolerance so that the model trains stably and efficiently over the long run. The rest of this guide covers five areas: bottlenecks, parallel strategies, the complete pipeline, hardware-software co-optimization, and engineering practices.
Why training adaptation gets more complex in the trillion-parameter era
As model scale grows from tens of billions to hundreds of billions and then trillions of parameters, three things change about the training task.
First, the model is no longer just “weights.” In mixed-precision training, for example, memory must also hold gradients, optimizer states, learning-rate-related state, and the activations needed for backpropagation. The larger the model, the heavier the training state.
Second, training no longer relies on a single device or single machine. Trillion-parameter models typically require multiple nodes and multiple devices working together, which makes distributed communication a core part of the training pipeline.
Third, training time grows substantially. Large-scale jobs often run for days or even weeks, so checkpoint/resume, checkpoint saving, fault recovery, and metric monitoring stop being optional and become baseline capabilities.
The goal of training adaptation, then, is not to make the code “start,” but to give the model the ability to run reproducibly, scale out, and run continuously on the target compute platform.
The three core bottlenecks of trillion-parameter training
1. The memory wall: a single device cannot hold the full state
When training a trillion-parameter model, a single accelerator often cannot fit the complete model state, because:
- The parameters themselves occupy memory;
- Gradients require additional space;
- Adam-family optimizers usually maintain momentum and variance;
- Backpropagation needs cached activations;
- Framework runtime, communication buffers, and temporary tensors also consume memory.
For this reason, you must use sharding strategies to distribute parameters, gradients, and optimizer states across multiple devices.
2. The communication wall: a hidden cost as parallel scale grows
As training scales from a single machine to a large cluster, devices need to exchange data frequently. Common communication patterns include:
- Parameter gathering;
- Gradient reduction;
- Sharded parameter synchronization;
- Activation and gradient communication in tensor parallelism;
- Stage-to-stage transfers in pipeline parallelism.
If communication cannot sufficiently overlap with computation, devices stall waiting, and compute utilization drops.
3. The scheduling and stability wall: the engineering challenge of long runs
Large-model training is not a short sprint but a long systems-engineering effort. Pay particular attention to:
- Whether checkpoints are saved regularly;
- Whether the job can recover quickly after a failure;
- Whether training metrics can be monitored in real time;
- Whether faulty nodes can be isolated;
- Whether data order, random seeds, and parallel configuration are reproducible.
These capabilities determine whether a training job can move from “it runs” to “it stays running.”
How to choose a parallel strategy: DDP, FSDP, tensor parallelism, pipeline parallelism, and expert parallelism
In large-scale training, a single parallel strategy is usually not enough and often needs to be combined.
| Parallel strategy | Memory effect | Communication characteristics | Typical use cases | Implementation complexity |
|---|---|---|---|---|
| Data Parallel (DDP) | Limited memory savings; each device keeps a full model replica | Noticeable gradient AllReduce communication | Small-to-medium models, quick validation | Low |
| Fully Sharded Data Parallel (FSDP) | High memory savings; parameters, gradients, and optimizer states can be sharded | Gather parameters in forward, reduce gradients in backward | Hundred-billion to trillion-parameter models | Medium |
| Tensor Parallel (TP) | Can split intra-layer matrix computation | Frequent communication, demanding on interconnect | Very large, very wide single layers | High |
| Pipeline Parallel (PP) | Splits by layer to reduce per-device load | Point-to-point communication between stages | Very deep models, cross-stage scheduling | High |
| Expert Parallel (EP) | Distributes computation across MoE experts | Routing and inter-expert communication | MoE sparse architectures | Medium-high |
The selection logic can be summarized as:
- If a single device cannot hold the full model: prefer FSDP.
- If a single layer still cannot fit after FSDP: introduce tensor parallelism.
- If the model has many layers and a single device cannot hold them all: introduce pipeline parallelism.
- If it is a MoE architecture: combine with expert parallelism.
- If communication becomes the bottleneck: check the network topology, communication library, and the degree of communication-computation overlap.
A common combination in practice is:
FSDP to control the baseline memory footprint + tensor parallelism to handle oversized single layers + pipeline parallelism to split depth + expert parallelism to optimize the MoE structure.
The complete adaptation pipeline on domestic compute
The following uses PyTorch-style FSDP as an example of a practical training adaptation pipeline. Note that different domestic accelerators may achieve similar capabilities through vendor adaptation layers, compatibility interfaces, or domestic training frameworks; device types, communication backends, and API names in the code need to be adjusted for your target platform.
1. Prerequisites
The example assumes the following:
- Python 3.9 or newer;
- PyTorch 2.x;
- Distributed training support;
- The target domestic accelerator’s driver, runtime, and software stack installed;
- The corresponding communication library and operator library installed;
- A training script that supports
torchrunor an equivalent launcher.
Launch example:
torchrun \--standalone \--nnodes=1 \--nproc_per_node=8 \train_fsdp.py \--config config.yaml
Key parameters usually include:
world_size: the total number of processes participating in training;local_rank: the current process’s device index within a single node;sharding_strategy: the sharding strategy, for exampleFULL_SHARD;mixed_precision: the mixed-precision configuration;micro_batch_size: per-device, per-step batch size;grad_accum_steps: the number of gradient accumulation steps;max_seq_len: the maximum sequence length;max_steps: the maximum number of training steps.
2. Model loading and sharding
For trillion-parameter models, pay special attention to sharding boundaries, tensor layouts, parameter names, and precision types when loading weights. Example:
import osimport torchfrom torch.distributed.fsdp import FullyShardedDataParallel as FSDPfrom torch.distributed.fsdp import ShardingStrategyfrom torch.distributed.fsdp import MixedPrecisionlocal_rank = int(os.environ.get("LOCAL_RANK", 0))device_type = os.environ.get("DEVICE_TYPE", "cuda")device = torch.device(f"{device_type}:{local_rank}")# Build the modelmodel = build_transformer(num_layers=args.num_layers,hidden_size=args.hidden_size,num_attention_heads=args.num_attention_heads,)# Load pretrained weights or an existing checkpointmodel = load_checkpoint(model, path=args.checkpoint_path)model = model.to(device)# Wrap the model with FSDP# Note: the FSDP here is a PyTorch-style interface; domestic platforms may use a compatible interface or adaptation layermodel = FSDP(model,sharding_strategy=ShardingStrategy.FULL_SHARD,mixed_precision=MixedPrecision(param_dtype=torch.bfloat16,reduce_dtype=torch.float32,buffer_dtype=torch.bfloat16,),device_id=local_rank,use_orig_params=True,)
The key point here: the wrapped model must be reassigned to the model used for training, not just to a local variable.
3. Forward, backward, and gradient update
Example training loop:
optimizer = torch.optim.AdamW(model.parameters(),lr=1e-4,weight_decay=0.01,)# When using BF16, loss scaling can usually be disabled# When using FP16, it is recommended to enable loss scalingscaler = torch.cuda.amp.GradScaler(enabled=args.use_fp16)amp_dtype = torch.float16 if args.use_fp16 else torch.bfloat16for step in range(args.max_steps):optimizer.zero_grad(set_to_none=True)for _ in range(args.grad_accum_steps):input_ids, labels = next(dataloader)with torch.autocast(device_type=device_type, dtype=amp_dtype):outputs = model(input_ids=input_ids,labels=labels,)loss = outputs.loss# With gradient accumulation, the loss needs to be scaledloss = loss / args.grad_accum_stepsif scaler.is_enabled():scaler.scale(loss).backward()else:loss.backward()if scaler.is_enabled():scaler.step(optimizer)scaler.update()else:optimizer.step()
Two points to note:
- BF16 vs. FP16: BF16 has a dynamic range closer to FP32 and usually does not need loss scaling; FP16 has a narrower dynamic range and may need loss scaling to avoid gradient underflow.
- Gradient accumulation and zeroing timing: gradients from multiple micro-batches must be accumulated, and the optimizer update runs once at the end.
optimizer.zero_grad()should complete before the parameter update to avoid leftover gradients from the previous round.
4. Common problems and troubleshooting checklist
Common issues during domestic-compute adaptation include:
| Symptom | Possible cause | Investigation and remediation |
|---|---|---|
| OOM (out of memory) | Batch too large, sequence too long, no sharding, too many activations | Reduce micro batch, increase gradient accumulation, enable activation recomputation, enable FSDP or add tensor parallelism |
| Dimension mismatch | Model config does not match the weights; inconsistent hidden size, layer count, or vocab size | Check the config, checkpoint keys, tensor shapes, and sharding scheme |
| Communication timeout | Network issues, communication library version mismatch, insufficient inter-node bandwidth | Check device status, communication library version, and node connectivity; adjust the communication timeout as needed |
| Loss spikes or NaN | Learning rate too high, improper mixed precision, bad data, no gradient clipping | Lower the learning rate, check data distribution, enable gradient clipping, verify the BF16/FP16 configuration |
| Low throughput | Communication not overlapping, insufficient operator performance, frequent synchronized scheduling | Analyze the compute-vs-communication time split, optimize the operator library, tune the parallel strategy and batch size |
| Training interrupted midway | Node failure, process crash, disk write failure | Save checkpoints, enable checkpoint/resume, check storage and logging systems |
Hardware-software co-optimization: adaptation focus for domestic AI accelerators and the software stack
Trillion-parameter model training is not purely a software problem, but a systems-engineering effort spanning hardware, drivers, operator libraries, communication libraries, and training frameworks. When adapting domestic AI accelerators for training, focus on the following areas.
1. Operator adaptation and performance optimization
Transformer models make heavy use of operators such as attention, matrix multiplication, LayerNorm/RMSNorm, Softmax, and activation functions. Domestic accelerators need to ensure:
- Operators produce correct results;
- Operator performance meets training throughput requirements;
- Common mixed precisions such as BF16 and FP16 are supported;
- Large tensors, variable-length sequences, and complex graph structures can be handled.
If some operators are missing or underperform, consider graph compilation, operator fusion, or framework-level substitution.
2. Communication libraries and topology optimization
Distributed training depends on collective communication. When adapting, focus on:
- Whether the communication library matches the target hardware;
- Whether it supports common primitives such as AllReduce, AllGather, and ReduceScatter;
- Whether it can overlap with computation;
- Whether it adapts to multi-node, multi-device topology;
- Whether it can handle large-scale parameter gathering and gradient reduction.
In large-scale training, communication optimization often affects overall throughput more than single-device operator optimization.
3. Mixed precision and numerical stability
BF16 and FP16 can improve throughput and reduce memory, but they also affect numerical stability. When adapting, you need to:
- Confirm the optimizer supports mixed precision;
- Confirm gradient reduction uses FP32;
- Evaluate loss scaling for FP16 training;
- Monitor changes in loss, gradient norm, and parameter norm;
- Save context at anomalous steps to make them reproducible.
4. Framework adaptation layers and ecosystem compatibility
Adaptation to domestic compute typically follows one of two paths:
- Adaptation layers for mainstream training frameworks: on mainstream frameworks like PyTorch, adapt through device backends, operator libraries, and communication backends provided by the vendor or community. The advantage is a mature ecosystem and lower migration cost.
- Domestic or deeply optimized training frameworks: deeply optimized for specific hardware, potentially offering advantages in operator fusion, graph compilation, and distributed scheduling, but with higher migration and learning costs.
When choosing, weigh model compatibility, team experience, performance goals, operational cost, and ecosystem support together.
Stability and engineering practices
For large-scale training, stability often matters more than one-off performance.
1. Periodic checkpoints
Save checkpoints at fixed step counts or fixed time intervals, including:
- Model parameters;
- Optimizer state;
- Learning-rate scheduler state;
- Data loader progress;
- Current training step;
- Random seeds and parallel configuration.
2. Checkpoint/resume
When restoring from the latest checkpoint, ensure:
- Parameter shards load correctly;
- Optimizer state is restored;
- Data order continues seamlessly;
- The parallel configuration matches the one used when saving;
- The learning-rate scheduler state continues to advance.
3. Fault tolerance and automatic restart
In a cluster environment, combine with a scheduling platform to implement:
- Node health checks;
- Faulty-node isolation;
- Automatic task restart;
- Centralized log collection;
- Alert notifications.
4. Full-pipeline monitoring
At a minimum, monitor these metrics:
- Per-step training time;
- Throughput;
- Memory usage;
- Communication time;
- CPU/GPU/NPU utilization;
- Loss curve;
- Gradient norm;
- Parameter norm;
- Checkpoint saving time.
5. Reproducibility and continuous tuning
To improve reproducibility, fix:
- Data order;
- Random seeds;
- Parallel configuration;
- Batch size;
- Precision scheme;
- Software stack versions.
At the same time, gradually tune the parallel strategy, batch size, gradient accumulation steps, and precision scheme through small-scale experiments, striking a balance among memory, speed, and stability.
Conclusion
Adapting trillion-parameter large-model training to domestic compute is fundamentally a systems-engineering effort under four constraints: memory, communication, scheduling, and stability. With a sharding strategy such as FSDP as the foundation, combined with tensor parallelism, pipeline parallelism, and expert parallelism, and supported by model loading, mixed precision, gradient synchronization, hardware-software co-optimization, and monitoring with fault tolerance, ultra-large-scale models can train stably.
For engineering teams, the value of training adaptation is not just making the model “run,” but making the training job reproducible, scalable, operable, and continuously iterable. As domestic-compute software stacks, parallel strategies, and engineering tools keep maturing, trillion-parameter model training will gradually move from complex problem-solving to standardized workflows, providing a solid foundation for an open and thriving large-model ecosystem.
