Practical Guide to Training Large Language Models on Domestic GPU Clusters

    This article walks through the engineering practice of validating a large language model training pipeline on a domestic accelerator platform, using two nodes with 16 cards in total for a 400-step smoke test. It covers layered environment preparation, how to choose and trade off parallelism strategies, numerical stability with mixed precision, communication optimization and throughput evaluation, and checkpointing with fault recovery. The goal is to show how to get a multi-node pipeline running correctly and resumably first, then tune performance in stages.

    1. Background and Problem Definition

    As model sizes keep growing, the training question has shifted from “can it run on a single card” to “can it finish reliably across multiple nodes and cards.” A complete training pipeline typically involves data loading, computation graph construction, mixed-precision computation, gradient synchronization, optimizer state updates, and checkpoint saving and restoration. A weak link in any of these stages can lower overall throughput or even interrupt training.

    A typical engineering case in the industry recently: on a domestic accelerator card platform, two nodes with 16 cards in total were used to run a 400-step training validation of a large-parameter language model. The 400 steps are not meant to reach final convergence; they verify the completeness and stability of the pipeline. This is a typical short smoke test. The value of such validation is that it exposes most engineering issues at a controllable time cost.

    It is worth stressing that getting the pipeline working is not the same as having optimal performance. Running through means correct functionality, normal communication, and numerical stability; performance tuning then pushes compute utilization further on that basis. The two should proceed in stages, and aggressive optimization should be avoided before the pipeline is stable.

    2. Layered Preparation of Hardware and Software Environment

    Environment issues in multi-node training often take more time than algorithm issues. It is recommended to prepare in three layers:

    1. Driver and runtime layer: unify accelerator card driver and runtime library versions, ensuring all nodes are exactly consistent. Version drift is one of the most hidden sources of failure in distributed training.
    2. Communication and topology layer: confirm inter-node high-speed interconnect bandwidth, NIC binding, and topology detection results, ensuring every card maps to the correct communication channel.
    3. Framework and dependency layer: pin the deep learning framework, compiler toolchain, and operator library versions, and deliver via containers to avoid “runs on a single machine, fails on multiple machines.”

    A sample environment check script can be written as follows, used to do a consistency check before officially starting:

    1. import os, subprocess, hashlib
    2. def node_fingerprint():
    3. # Collect driver, runtime, and framework versions to generate a fingerprint for cross-node comparison
    4. cmd = "cat /proc/driver/version 2>/dev/null; python -c 'import sys;print(sys.version)'"
    5. out = subprocess.check_output(cmd, shell=True).decode()
    6. return hashlib.md5(out.encode()).hexdigest()
    7. local = node_fingerprint()
    8. rank = int(os.environ.get("RANK", "0"))
    9. print(f"[rank {rank}] env fingerprint = {local}")

    The fingerprints output by each node must be identical; otherwise, the environment issue should be resolved before starting training.

    3. Choosing and Trading Off Parallelism Strategies

    Two nodes with 16 cards is a medium scale. Common parallelism combinations include data parallelism, tensor parallelism, pipeline parallelism, and their hybrid forms. Selection principles are as follows:

    • Prioritize data parallelism: simple to implement and good scalability, but memory usage grows linearly with model size, and gradient synchronization communication volume is large.
    • Tensor parallelism: splits single-layer matrix computation across cards, reducing per-card memory pressure, but is extremely sensitive to inter-card bandwidth and is usually limited within a single node.
    • Pipeline parallelism: splits by layers, reducing peak memory, but introduces pipeline bubbles and requires a reasonable number of micro-batches.
    • Memory optimization methods: activation recomputation, optimizer state sharding, mixed precision, and low-precision communication can significantly increase the trainable scale without adding hardware.

    A practical order of judgment is: first estimate the total memory demand of model weights, gradients, optimizer states, and activations, then decide the split dimensions; do not choose a parallelism method first and then work backward to the configuration.

    4. Numerical Stability and Mixed-Precision Essentials

    Mixed precision can significantly reduce memory and bandwidth pressure, but it is also a common source of numerical anomalies. Three points need engineering attention:

    1. Loss scaling: dynamically scale gradients to prevent gradient underflow in low precision.
    2. High precision for key quantities: normalization layer parameters, optimizer master weights, and loss accumulation usually retain higher precision.
    3. Overflow monitoring: track the gradient overflow ratio; if it stays persistently high, adjust the scaling strategy or fall back the precision of some operators.

    Pseudocode example:

    1. for step, batch in enumerate(loader):
    2. with autocast(dtype="bfloat16"):
    3. loss = model(batch).loss
    4. scaled = loss * scale
    5. scaled.backward()
    6. grad_norm = clip_and_unscale(grads, scale)
    7. if overflow(grad_norm):
    8. scale *= 0.9 # Lower the scaling factor and skip this step's update
    9. optimizer.zero_grad()
    10. continue
    11. optimizer.step()
    12. scale = min(scale * 1.05, MAX_SCALE)

    5. Communication Optimization and Throughput Evaluation

    The throughput ceiling of multi-node training is usually determined by communication. Actionable optimization directions include gradient bucketing with computation-communication overlap, hierarchical reduction to leverage intra-node high bandwidth, fixed communication buffers to avoid repeated allocation, and binding separate resources for communication streams. When evaluating, observe three metrics at the same time: per-step time, per-card compute utilization, and communication wait ratio. If the communication wait ratio stays above 30% for a long time, the optimization focus is on communication rather than operators.

    6. Stability, Checkpoints, and Fault Recovery

    Long-cycle training must assume hardware will fail. It is recommended to: asynchronously save checkpoints at fixed step intervals, saving optimizer states and random number states to ensure resumable training; set threshold alerts for key metrics and integrate logging services and monitoring alert capabilities; run training tasks on a container platform, combined with object storage for checkpoint archiving, to achieve automatic rescheduling and resume-from-checkpoint after node failures.

    7. Conclusion

    The core of getting the two-node, 16-card training pipeline working is to solidly implement five things in stages: environment consistency, parallel splitting, numerical stability, communication efficiency, and fault-tolerant recovery. Ensuring correct functionality and resumability first, then doing performance tuning, is the path with the highest return on investment. For enterprises that need elastic compute and a complete operations system, a training foundation can be built on general capabilities such as Baidu AI Cloud’s container platform, object storage, logging service, and monitoring alerts, focusing energy on the model and data themselves.