Trillion-Parameter LLM Training on Domestic AI Accelerators: An End-to-End Engineering Guide

    This article explains how to adapt trillion-parameter large language model training to domestic AI accelerators. It covers memory and communication constraints, DP/TP/PP/FSDP selection, FSDP implementation, checkpoint loading, shard scheduling, numerical consistency, observability, fault tolerance, and a practical troubleshooting checklist.

    1. How Do Domestic AI Accelerators Handle Trillion-Parameter Training?

    When model parameters scale from hundreds of billions to trillions, a single accelerator cannot simultaneously hold the full model replica, optimizer states, activations, and communication buffers. Training adaptation therefore becomes more than launching a script. It requires a complete, reproducible, and observable pipeline covering model loading, shard scheduling, compute-communication overlap, backward gradient synchronization, and checkpoint/resume.

    For domestic AI accelerators, adaptation challenges usually fall into three areas:

    1. Operator coverage, especially mixed precision, normalization, attention, loss functions, and distributed operators.
    2. Maturity of collective communication libraries, including support for large-scale stable communication via AllGather, ReduceScatter, AllReduce, Broadcast, and other primitives.
    3. Validated version combinations of training frameworks and hardware backends.

    To answer questions such as “How should domestic accelerators be adapted?”, “How should FSDP be selected?”, and “How should training divergence be diagnosed?”, a unified engineering judgment framework is needed.

    2. Memory Wall and Communication Wall: Estimate First, Then Choose

    1. How to Estimate the Memory Wall?

    Large model training memory is not limited to model parameters. For mixed-precision training with the Adam optimizer, common per-parameter overhead can be broken down as follows:

    • Weights: usually 2 bytes;
    • Gradients: usually 2 bytes;
    • Adam first moment: usually 4 bytes;
    • Adam second moment: usually 4 bytes;
    • FP32 master weights or compatible copy: usually 4 bytes.

    Under this common accounting, each parameter requires about 16 bytes. If the framework does not keep master weights separately, it may require about 12 bytes. In other words, model state overhead is typically 12 to 16 times the parameter count. Activations, temporary buffers, communication buffers, optimizer intermediate states, and log snapshots also require additional memory.

    For a 1-trillion-parameter model, the theoretical model-state overhead is about 12 to 16 TB. Even if sharded across 1,000 accelerators, each accelerator would still bear about 12 to 16 GB. Adding activations and communication buffers significantly increases OOM risk. In practice, estimate four categories separately: model state + activations + communication buffers + framework reservation, rather than looking only at parameter count.

    2. How to Measure the Communication Wall?

    In multi-accelerator training, communication overhead depends on interconnect bandwidth, parallel strategy, model structure, and compute-communication overlap. It should not be assumed that communication dominates step time; it should be measured. Common metrics include:

    • Step time;
    • Throughput metrics such as tokens/s or samples/s;
    • Communication time recorded in the profiler, such as AllGather, ReduceScatter, and AllReduce time;
    • Exposed communication time: communication not overlapped with computation;
    • Communication ratio: exposed communication time / step time.

    If the communication ratio remains high, check whether parallel partitioning is reasonable, shard granularity is too fine, communication buffers are sufficient, device interconnect topology matches the workload, and compute and communication are truly overlapped.

    3. How to Choose Among DP, TP, PP, and FSDP?

    Trillion-parameter training usually combines multiple parallelism strategies rather than relying on one. Common options are:

    Strategy Memory benefit Communication characteristics Typical use case Main limitation
    Data parallelism DP Almost no reduction in per-accelerator model memory Gradient AllReduce Model fits on a single accelerator and simple scaling is desired Does not solve the memory wall
    Tensor parallelism TP Reduces per-layer parameter and activation memory Frequent AllReduce; sensitive to bandwidth Multi-accelerator single-node setups with high-speed interconnects High communication overhead; sensitive to cross-node links
    Pipeline parallelism PP Reduces memory by partitioning layers P2P communication between adjacent stages Very deep models with many layers Pipeline bubbles
    Fully sharded data parallelism FSDP Shards parameters, gradients, and optimizer states AllGather + ReduceScatter Trillion-parameter, multi-accelerator data parallelism Depends on collective communication libraries and framework stability

    In practice, common combinations include TP + PP + FSDP or TP + PP + DP. Three principles are recommended:

    1. Keep TP within a single node’s high-speed interconnect domain where possible.
    2. Use PP to reduce pressure from layer count and combine it with micro-batches to reduce bubbles.
    3. Use FSDP to compress model state along the data-parallel dimension.

    If model structures vary significantly, such as multimodal models containing a vision encoder, a text backbone, and projection layers, different sharding granularity can be configured for different modules.

    4. How to Implement FSDP?

    FSDP, or fully sharded data parallelism, shards parameters, gradients, and optimizer states along the data-parallel dimension. Each device stores only its responsible shard. Parameters are temporarily gathered when computation is needed, non-local shards are released after computation, gradients are synchronized through ReduceScatter after the backward pass, and local optimizer states are updated.

    A typical execution flow is as follows:

    Stage Key action Memory change Communication action
    Before forward computation The current layer needs parameters Full parameters temporarily increase AllGather parameter shards
    During forward/backward computation Full parameters are used for computation Non-local shards are released after computation Computation can overlap with communication for the next layer
    After backward propagation Gradient reduction and redistribution Local gradient shards are retained ReduceScatter gradients
    Optimizer update Only local shard state is updated Optimizer state shards remain resident Usually no large communication

    The following code is illustrative. In actual use, confirm with the framework version whether the interface wraps the model in place or returns a new object. If a new object is returned, it must be remounted to the root model. Otherwise, the optimizer and training loop may still reference unsharded modules.

    1. # Prerequisites: PyTorch 2.x; the collective communication backend supports AllGather and ReduceScatter;
    2. # Domestic accelerators require matching driver, runtime, communication library, and training framework versions.
    3. # Note: fully_shard interfaces may differ across versions. The code below expresses the engineering structure only.
    4. from torch.distributed.fsdp import fully_shard, MixedPrecision, ShardingStrategy
    5. def build_fsdp_model(model, mesh, mp_policy):
    6. root = model
    7. for name, module in list(model.named_modules()):
    8. if not is_trainable_block(module):
    9. continue
    10. new_module = fully_shard(
    11. module,
    12. mesh=mesh, # Device mesh determines the sharding dimension
    13. mp_policy=mp_policy, # Mixed-precision policy
    14. sharding_strategy=ShardingStrategy.FULL_SHARD,
    15. )
    16. # If the interface returns a new wrapped object, remount it to the parent module;
    17. # if it wraps in place, replacement is unnecessary.
    18. if new_module is not None and new_module is not module:
    19. set_child_by_name(root, name, new_module)
    20. return root
    21. model = build_fsdp_model(model, mesh, mp_policy)
    22. optimizer = build_sharded_optimizer(model, lr=1e-5)
    23. for batch in dataloader:
    24. loss = model(batch).loss
    25. loss.backward() # Backward pass triggers ReduceScatter
    26. optimizer.step()
    27. optimizer.zero_grad()

    During engineering implementation, pay special attention to three points:

    1. FSDP wrapping order must match the model structure to avoid duplicate or missing wrapping.
    2. The optimizer must be constructed on sharded parameters.
    3. The mixed-precision policy must match operator support on domestic accelerators to avoid accuracy anomalies or performance regression.

    5. End-to-End Training Pipeline: Three Key Stages and an Acceptance Checklist

    1. Model Loading and Format Alignment

    Trillion-parameter model weight files are large. During loading, verify checkpoint format, weight layout, naming mappings, and precision types. Distributed loading should use memory mapping, parallel reads, and shard caching to avoid single-machine I/O becoming a startup bottleneck. After loading, full weights must be correctly partitioned across devices according to the current TP, PP, and FSDP partitioning scheme. Any mapping error may cause numerical errors or training divergence.

    2. Shard Scheduling and Memory Management

    Shard scheduling determines which parameters are assigned to which accelerator, when they are gathered, and when they are released. Validate the following:

    • Whether shard granularity is too coarse or too fine;
    • Whether AllGather can overlap with computation;
    • Whether ReduceScatter causes communication spikes during the backward phase;
    • Whether sufficient communication buffers are reserved;
    • Whether non-local parameter shards are released in time;
    • Whether OOM logs contain detailed memory allocation traces.

    3. Gradient Synchronization and Numerical Consistency

    FSDP performs gradient reduction and redistribution through ReduceScatter. During adaptation, it is not enough to verify only that training runs; numerical correctness must also be checked. It is recommended to run small-scale loss curve alignment experiments, comparing results from domestic accelerators with a reference implementation, and checking loss trends, gradient norms, and outputs of key layers.

    A domestic accelerator adaptation acceptance checklist should include at least the following:

    • Version matrix: driver, firmware, runtime, communication library, training framework, and model code;
    • Operator coverage: forward, backward, mixed precision, optimizer, loss function, and common normalization and attention operators;
    • Collective communication: AllGather, ReduceScatter, AllReduce, Broadcast, and Barrier;
    • Numerical consistency: loss curve alignment, gradient norms, and key-layer output comparison;
    • Throughput stability: whether tokens/s remains stable and whether there are long-term drops;
    • Memory stability: whether frequent OOM occurs and whether memory fragmentation exists;
    • Fault tolerance: checkpoint saving, checkpoint/resume, and failure recovery;
    • Logging capability: observability of communication, memory, throughput, loss, and device status.

    6. Engineering Implementation: Stability Matters More Than Single-Point Performance

    Trillion-parameter training often lasts for days or even weeks, so engineering safeguards are as important as parallel strategy. First, regularly save model states, optimizer states, data cursors, and random seeds so training can resume from the latest checkpoint after failures. In cloud environments, object storage can be used for checkpoints and datasets to balance capacity, throughput, and reliability.

    Second, training jobs can be orchestrated through a container platform to provide resource isolation, task queuing, and elastic scheduling. Third, establish an observability system to continuously collect tokens/s, step time, communication ratio, memory usage, loss changes, and device health status. Training logs can be aggregated through a log service, while monitoring and alerting can warn about sudden loss spikes, throughput drops, device failures, and communication timeouts.

    Finally, during new hardware adaptation, missing operators or underperforming operators are common. Solutions include completing operator implementations, optimizing memory layouts, and continuing tuning through operator fusion, communication compression, and compute-communication overlap.

    7. Common Fault Troubleshooting

    Symptom Common causes Diagnosis suggestions Remediation direction
    OOM Large activations, unreasonable sharding granularity, excessive buffers Check memory allocation logs and calculate proportions of parameters, activations, and communication buffers Reduce micro-batch size, adjust FSDP granularity, and release temporary variables
    Loss does not converge or diverges Weight mapping errors, precision anomalies, incorrect optimizer states Align small-sample loss curves, check gradient norms and key-layer outputs Fix loading mappings, switch mixed precision, and rebuild the optimizer
    Throughput drops sharply Lack of communication overlap, shards too fine, I/O bottleneck Analyze the profiler and check AllGather and ReduceScatter proportions Adjust parallel strategy, increase shard granularity, and optimize data reading
    Accelerator drops offline Hardware failure, driver anomaly, abnormal temperature or power Check device logs, monitoring alerts, and health checks Isolate faulty nodes, restart the job, and resume from checkpoint
    Communication timeout Topology mismatch, communication library version anomaly, network jitter between nodes Check communication library logs, node interconnect, and collective communication test results Adjust communication backend parameters, fix topology, and retry communication self-checks

    8. Conclusion: A Reusable Adaptation Methodology

    Training trillion-parameter models on domestic compute is not a single-point optimization but an engineering methodology combining software and hardware. The key path can be summarized in five steps:

    1. Understand constraints: identify bottlenecks using memory formulas and communication-ratio measurements;
    2. Select parallelism correctly: combine DP, TP, PP, and FSDP according to model structure and interconnect topology;
    3. Use sharding effectively: reduce model-state memory through FSDP and control communication overlap;
    4. Complete the pipeline: ensure loading, sharding, and synchronization are correct and numerically consistent;
    5. Provide engineering safeguards: use fault tolerance, observability, and cloud infrastructure to support long-running training.

    As domestic software and hardware ecosystems mature, the goal of training adaptation will shift from “whether it can run” to “whether it can run stably, efficiently, and reproducibly.” By mastering this methodology and using an acceptance checklist to drive engineering reviews, teams can more reliably address the challenges of trillion-parameter model training.