Adapting Large Model Training for Domestic AI Accelerators: An Engineering Roadmap

    A practical engineering guide to adapting large model training—including MoE architectures—onto domestic AI accelerator chips. It covers memory estimation, operator verification, the three-layer software stack, parallelism strategy, memory optimization, layered stability testing, checkpoint-based fault recovery, and performance tuning practices.

    Adapting Large Model Training for Domestic AI Accelerators: An Engineering Roadmap

    1. Calculate Memory First, Then Talk About Parallelism

    Before starting any adaptation work, the team should estimate the total memory required for training. Taking mixed-precision training with the Adam optimizer as an example, each parameter consumes roughly 16 bytes: 2 bytes for BF16 weights, 2 bytes for BF16 gradients, and 12 bytes combined for the FP32 master weights, first-order momentum, and second-order momentum. A model with 1 trillion parameters requires about 16 TB of memory for the full training state.

    This number sets the lower bound on device count. Even with optimizer state sharding, the aggregate device memory must cover this scale, with headroom left for activations, communication buffers, and memory fragmentation. Therefore, whether a given number of cards can launch a training run should be judged first from the total parameter count.

    For MoE models, the total parameter count is far larger than the parameters actually activated per token. Memory should be estimated based on total parameters, while compute should be estimated based on activated parameters. These two must be calculated separately, otherwise resource needs will be over- or under-estimated.

    2. Operator Coverage and Numerical Alignment

    MoE architectures rely on operators such as expert routing, grouped matrix multiplication, and variable-length sequence attention. On a new platform, these operators may be missing entirely, or implemented but with low performance. The team needs to verify the forward and backward results of every operator against a reference implementation and compare the errors.

    The focus of numerical alignment is mixed precision. BF16 and FP32 may round differently on different chips, and accumulated error grows with training steps. A recommended approach is to first compare outputs and gradient norms on a single layer and a single step, then compare loss curves. Error thresholds should be defined before testing begins and written into the test scripts—they should not be adjusted after seeing the results.

    3. Software Stack and Migration Cost

    Most domestic compute platforms adopt a three-layer structure: a programming model compatibility layer, a deep learning framework adaptation layer, and a communication library. The compatibility layer allows existing kernel code to be ported at low cost. The framework adaptation layer connects to mainstream training frameworks via plugins or backend extensions, minimizing changes to training scripts. The communication library implements standard collective communication interfaces, abstracting away differences in the underlying interconnect hardware.

    This layering reduces the learning cost of migration. However, the team must still complete operator alignment, communication tuning, and stability validation—work that no compatibility layer can replace.

    4. Composing Parallelism Strategies and Their Constraints

    Common parallelism strategies include data parallelism (DP), tensor parallelism (TP), pipeline parallelism (PP), and expert parallelism (EP). When combining them, the following constraints must hold:

    • TP × PP × DP equals the total number of training devices;
    • The EP group size must divide the DP group size, since experts are sharded within the DP group;
    • global_batch_size equals micro_batch_size × DP × gradient accumulation steps.

    Below is an example configuration assuming 16 devices with 64 GB of memory each:

    1. parallel_config = {
    2. "tensor_parallel_size": 4, # intra-node tensor parallelism
    3. "pipeline_parallel_size": 2, # cross-node pipeline parallelism
    4. "data_parallel_size": 2, # 4 × 2 × 2 = 16
    5. "expert_parallel_size": 2, # must divide data_parallel_size
    6. "micro_batch_size": 1,
    7. "grad_accumulation_steps": 64, # global batch = 1 × 2 × 64 = 128
    8. "sequence_length": 4096,
    9. "precision": "bf16",
    10. "recompute": "selective", # recompute only memory-heavy layers
    11. }

    This configuration only works for models with a relatively small total parameter count. Sixteen 64 GB devices provide roughly 1 TB of memory in total, which cannot hold the training state of the 1-trillion-parameter model estimated in Section 1. The team should first estimate memory from model size, then choose the device count, and finally derive the parallelism configuration.

    5. Memory Optimization Techniques

    • Selective recomputation: recompute only layers with large activations and low recomputation cost. Recomputation adds compute time, so the trade-off between memory and throughput must be measured empirically.
    • Optimizer state sharding: shard the first- and second-order momentums across devices in the DP group to eliminate duplicate storage. Sharding increases communication volume during parameter aggregation.
    • Gradient accumulation: accumulate multiple micro-batches to reach the target global batch size. It saves memory but increases per-step latency and affects how the learning rate schedule is converted.

    6. Layered Stability Validation

    Validation should proceed in layers, moving to the next layer only after the previous one passes.

    1. Single-step correctness: at small scale, compare forward loss and gradient norms; errors must fall within predefined thresholds.
    2. Short-term convergence alignment: run tens to hundreds of steps and overlay the loss curve with the reference curve. If the trends match and the deviation does not diverge, operators, communication, and mixed precision are basically correct.
    3. Long-run stability: run continuously for tens of thousands of steps or longer, spanning complete data epochs, while watching for slow memory growth, collective communication timeouts or hangs, and sustained thermal or power throttling.

    It should be clear that a 400-step test only proves the system can train for a short period—it does not prove long-term stability. If each step takes 3 seconds, 400 steps take only about 20 minutes. Long-term stability conclusions must come from longer-running data.

    7. Fault Recovery Checklist

    Stability also depends on the checkpointing mechanism. The team should verify the following items one by one:

    • Save frequency: save at fixed time or step intervals, keeping save overhead within an acceptable proportion of training time;
    • Load validation: after recovery, compare the loss of the first step with the loss before the interruption; the two should match or differ only within numerical error;
    • Resume from interruption: simulate process failures and record the time from interruption to fully resumed training;
    • Data consistency: confirm that the data read position after recovery continues seamlessly from the interruption point, avoiding repeated or skipped samples.

    8. Notes on Performance Tuning

    Common optimization directions include overlapping communication with computation, operator fusion, MoE load balancing, and interleaved pipeline scheduling. Every optimization may change numerical behavior or peak memory usage, so each should be validated through the same process:

    • Record throughput, peak memory, and loss curves before and after the change;
    • Confirm that the loss curve matches the baseline;
    • Record the version of each change so it can be rolled back.

    Take communication-computation overlap as an example: it can hide part of the communication time, but it requires extra memory as buffers. If memory is already near the limit, overlap may instead cause out-of-memory failures.

    9. Conclusion

    The key to adapting large model training is to first compute resource requirements precisely, then design the parallelism plan, and finally prove the results are reliable through layered testing. The team should ensure that every number can be traced back to a calculation or a test record. For case data that has not been publicly verified, the team’s own test results should be treated as the authoritative source.