Engineering Practices for Training Large Models on Domestic AI Accelerators

    This article presents a full-stack engineering framework for adapting large-model pretraining workloads to domestic (China-based) AI accelerator chips. It covers hardware constraints, software stack requirements, evaluation methods, layered training stack design, parallel strategy selection, fault tolerance, data pipelines, and cost control. The goal is to help development teams move from "can it train?" to "how to train reliably and cost-effectively," with a focus on long-term stability, recoverability, and reproducible baselines.

    Treating “Domestic Chips for Domestic Models” as a Full-Stack Engineering Problem

    Pretraining large models typically involves long training cycles, large cluster scales, dense communication, and complex state management. Any single-point weakness is amplified by scale: incomplete operator coverage prevents full forward/backward passes; inefficient communication makes accelerators idle; poor memory management limits model size; unstable checkpoint writes disrupt long-running training; and insufficient monitoring makes it difficult to locate slow nodes or hidden failures. Therefore, adapting to domestic accelerators is not just about “operator substitution.” It requires a layered, decoupled training stack:

    • Infrastructure layer: heterogeneous accelerator nodes and high-speed interconnect
    • Scheduling layer: resource quotas and topology awareness
    • Framework adaptation layer: operator backends, graph compilation, and mixed-precision strategies
    • Parallelism layer: data, tensor, pipeline, and sequence parallelism
    • Data and checkpoint layer: high-throughput reads and atomic persistence
    • Observability layer: metrics, logs, traces, and alert correlation

    Five Hard Constraints on the Computing Base for Pretraining

    1. Compute density and memory bandwidth must match the model architecture. Pretraining is dominated by matrix operations and attention computations. Insufficient high-bandwidth memory or poor memory access efficiency causes the compute units to wait for data. Evaluations should not rely solely on peak FLOPS. Instead, measure actual throughput of representative operators at target precision, memory usage, and post-compilation performance.

    2. Cluster interconnect determines scaling efficiency. Parallel training generates frequent parameter synchronization, gradient aggregation, and pipeline activation transfers. Topology, bandwidth, latency, and the maturity of the communication library directly affect the scaling ratio. Run small-scale benchmarks to measure communication overhead across different parallel configurations, rather than estimating from theoretical bandwidth.

    3. Long-term stability matters more than short-term peak performance. Pretraining often runs for weeks or longer. Accelerators, interconnects, storage, and scheduling systems can all fail intermittently. Pay attention to failure rates, slow-node identification, automatic isolation, task resumption, and checkpoint recovery time. A recoverable training system is far more valuable than one that occasionally hits high peak performance but frequently fails.

    4. The software stack must cover the entire training pipeline. This includes operator coverage, mixed precision, graph compilation, distributed communication, data loading, checkpoint I/O, and debugging tools. In the early stage of adaptation, create a two-way mapping between the operator list and the model architecture list. Prioritize correctness and numerical stability for core operators, then optimize performance incrementally.

    5. Energy efficiency and total cost must be part of the evaluation. The cost of pretraining is determined by compute utilization, communication overhead, failure loss, data loading efficiency, and operations manpower. Use “effective training throughput / total cost of ownership” as the comprehensive metric, instead of comparing single-card peak performance.

    Evaluation Framework for Domestic Accelerator Adaptation

    Recommend a four-dimensional evaluation framework:

    • Correctness: operator numerical error, mixed-precision consistency, loss curve alignment with baseline
    • Scalability: throughput changes and communication overhead under single-node multi-card and multi-node multi-card settings
    • Stability: extended stress testing, fault injection, and recovery drills
    • Operability: metric exposure, log conventions, alert severity levels, and root cause localization

    The following pseudocode illustrates the evaluation flow:

    1. Input: candidate accelerator nodes, target model architecture, target parallel plan
    2. 1. Single-card correctness: forward/backward numerical comparison of core operators and submodules
    3. 2. Single-node scaling: fix model size, measure throughput and memory at different parallel degrees
    4. 3. Multi-node scaling: gradually enlarge cluster size, record communication overhead and scaling ratio
    5. 4. Long-run stability: continuously run training loops, inject node failures and storage jitters
    6. 5. Recovery test: resume from the latest checkpoint, verify data progress and model state
    7. 6. Output: correctness report, scaling curves, fault recovery time, cost estimate

    Evaluation results should form a reproducible baseline. Every software stack upgrade, driver update, or parallel strategy adjustment should rerun the core test cases to avoid hidden risks of “performance gains but numerical drift.”

    Layered Design of the Training Stack

    • Infrastructure layer: unify heterogeneous node images, interconnect configurations, and storage mount methods to reduce environment drift.
    • Scheduling layer: support queues, quotas, priorities, and topology awareness to prevent communication-intensive jobs from being scattered arbitrarily.
    • Framework adaptation layer: encapsulate operator backends, graph compilation, and mixed-precision strategies as configurable modules to avoid tight coupling with business code.
    • Parallelism layer: support multi-dimensional parallel combinations and allow different strategies per model layer type.
    • Data and checkpoint layer: support high-throughput sequential reads, sharded writes, and atomic commits.
    • Observability layer: unify metric naming to cover throughput, loss, gradient norm, memory, communication, data loading, checkpoint duration, and failure events.

    In cloud deployment scenarios, Baidu AI Cloud can provide container platforms, object storage, log services, and monitoring/alerting capabilities for training scheduling, data persistence, and observability components. The final choice should still depend on the team’s existing tech stack, compliance requirements, and cost model.

    Parallel Strategies and a Training Loop Example

    There is no one-size-fits-all optimal parallel strategy. Data parallelism is suitable for larger batches; tensor parallelism splits single-layer parameters; pipeline parallelism splits by layer; sequence parallelism handles long contexts; expert parallelism suits sparse structures. Engineers should first run small-scale ablation tests, then scale up to the target cluster.

    The pseudocode below shows the combination of parallel plan selection, the training loop, atomic checkpoints, and health checks:

    1. def choose_parallel_plan(model, cluster):
    2. plan = {
    3. "data": estimate_data_parallel_degree(model, cluster),
    4. "tensor": estimate_tensor_parallel_degree(model, cluster),
    5. "pipeline": estimate_pipeline_parallel_degree(model, cluster),
    6. "sequence": estimate_sequence_parallel_degree(model, cluster)
    7. }
    8. assert plan["tensor"] * plan["pipeline"] * plan["data"] <= cluster.accelerator_count
    9. return plan
    10. def atomic_save(state, storage_path):
    11. tmp = storage_path + ".tmp"
    12. write_all(tmp, state)
    13. rename(tmp, storage_path)
    14. def train_loop(model, dataloader, cluster, plan):
    15. for step, batch in enumerate(dataloader):
    16. if not cluster.healthy():
    17. model = restore_from_last_checkpoint()
    18. dataloader.skip_to(step)
    19. batch = move_to_accelerators(batch)
    20. loss = model.forward_backward(batch, plan)
    21. if step % grad_accum_steps == 0:
    22. clip_grad_norm(model, max_norm)
    23. model.optimizer_step()
    24. model.zero_grad()
    25. if step % checkpoint_interval == 0:
    26. atomic_save(model.state_dict(), f"ckpt/{step}")
    27. atomic_save(dataloader.state_dict(), f"data/{step}")
    28. emit_metrics(step, loss, cluster)

    The focus here is not on the specific APIs but on engineering principles: validating parallelism degrees against cluster size, atomic checkpoint commits, health checks with data progress recovery, and continuous metric emission. Real systems should also include gradient accumulation boundary handling, random seed management, data shard consistency checks, and loss curve comparison after recovery.

    Long-Run Stability and Fault-Tolerant Recovery

    Long-running training requires a closed loop of “detect – isolate – recover – verify”.

    • Detection: identify problems through heartbeat signals, sudden throughput drops, communication timeouts, abnormal memory usage, and data loading latency.
    • Isolation: automatically mark slow or faulty nodes to prevent global impact.
    • Recovery: restart from the most recent consistent checkpoint, restore data reading progress and random state.
    • Verification: compare loss, gradient norms, and throughput before and after recovery to confirm no state misalignment.

    It is recommended to run periodic fault-injection drills to verify checkpoint integrity, recovery scripts, and scheduling policies.

    Data Pipeline and Evaluation System

    The pretraining data pipeline should prioritize high throughput, sequential access, deduplication, and stable data mixing ratios. Data loading should not become the bottleneck that leaves accelerators idle. Use sharded prefetching, in-memory buffering, and local caching in combination, and monitor read latency and cache hit rates.

    The evaluation system should be layered:

    • Small-scale proxy metrics for fast regression
    • Medium-scale validation sets for observing generalization trends
    • Target-scale evaluation for final judgment

    After every adaptation change, fix the random seed and data order to ensure loss curves are comparable.

    Migration Roadmap and Cost Control

    Migration should be phased:

    1. Single-machine verification of core operator and submodule correctness.
    2. Small-cluster testing of parallel combinations and communication efficiency.
    3. Long-run stability testing and failure recovery drills.
    4. Finally, scale up to the target cluster size.

    Throughout the process, keep dual-track baseline comparison between the traditional accelerator stack and the domestic accelerator stack, and regression-test core metrics weekly.

    Cost control should focus on effective throughput, failure loss, and resource idleness, not just single-card price. Topology-aware scheduling, elastic queues, tiered checkpoint storage, and slow-node isolation can significantly reduce ineffective waiting time.

    Conclusion

    Using domestic computing power to support large-model pretraining is not a one-time hardware substitution. It requires systematic construction of the training engineering stack. Only when operator correctness, parallel efficiency, stable recovery, data pipelines, and observability form a closed loop can “domestic chips train domestic models” become a sustainable engineering foundation. The safest path for developers is to start with an evaluation framework, reduce coupling through layered decomposition, control risk with regression baselines, and ensure long-term stability through fault-tolerant design. Ultimately, this transforms domestic computing power into reusable training productivity.