Practical Guide to Training Large Models on Domestic GPUs: Validating the Full Pipeline

    This article explains why validating the end-to-end training pipeline matters more than chasing benchmark scores when training large models on domestic accelerators. It covers environment preparation with layered version locking, choosing data parallelism first and adding tensor or pipeline parallelism when memory is tight, memory and compute optimizations such as mixed precision, gradient accumulation, activation recomputation and optimizer state sharding, observability metrics and fault diagnosis for common failures, and a final checklist. The goal is a closed, reproducible pipeline that can serve as a baseline for scaling and long-running tests.

    1. Background: Why a Working Pipeline Matters More Than a High Score

    In large model engineering, training a model stably on domestic accelerators usually goes through three progressive stages: single-card forward and backward passes work, single-node multi-card precision is aligned, and multi-node multi-card runs continue for a long time without interruption. Many teams hit problems in the second stage, such as loss not decreasing, NaN gradients, or out-of-memory errors. In the third stage, distributed-specific failures add up: communication timeouts, hung processes, and corrupted checkpoints.

    That is why a validation like “two nodes and sixteen cards completing four hundred consecutive training steps” is not about model quality. It proves the entire pipeline is closed: data can be read, operators can compute, gradients can be synchronized, state can be written to disk, and failures can be recovered from. Once the pipeline is closed, tuning hyperparameters, scaling up, and swapping model architectures all become controllable engineering iterations.

    2. Environment Preparation: Reducing Uncertainty to the Minimum

    More than half of pipeline validation failures come from the environment layer. A “lock by layer” approach is recommended:

    1. Driver and runtime layer: fix the accelerator driver, runtime library, and communication library versions, and maintain a traceable version list to avoid version drift between nodes.
    2. Framework layer: distribute the same training framework image to both machines, and do not install different packages manually on a single node.
    3. Dependency layer: package custom operators and compiled artifacts together and ship them with the image, avoiding a situation where it runs on one machine but not the other.

    An illustrative version check script:

    1. # Illustrative only: check whether key components match across two nodes
    2. for host in node-a node-b; do
    3. echo "== $host =="
    4. ssh "$host" "cat /etc/accel/runtime.version; \
    5. python -c 'import torch;print(torch.__version__)'"
    6. done

    After the consistency check passes, run a minimal operator self-check: train a small two-layer network on a single card and confirm the forward pass, backward pass, and optimizer step all work and produce finite values.

    3. Parallelism Strategy: Data Parallelism First, Model Parallelism as Needed

    Two nodes with sixteen cards is a small-scale but already distributed scenario. The recommended strategy:

    • Prefer data parallelism: each card holds a full model replica, and gradients are all-reduced through collective communication. It is simple to implement and scales linearly, and it fits cases where the parameter count fits in a single card’s memory.
    • Introduce tensor parallelism or pipeline parallelism when memory is insufficient: split a single layer’s operators or split by layer across cards, at the cost of more frequent communication and higher implementation complexity.
    • For combined parallelism, keep the product of parallel degrees within the total number of cards, and keep communication domains within the high-speed intra-node interconnect as much as possible, leaving only data parallel traffic to cross nodes.

    A typical launch parameter skeleton (illustrative; exact names vary by framework):

    1. # Illustrative: 8 cards per node, 2 nodes in total
    2. config = dict(
    3. tensor_parallel_size=2, # intra-node split
    4. pipeline_parallel_size=1,
    5. data_parallel_size=8, # 2 nodes * 8 cards / (2*1)
    6. micro_batch_size=1,
    7. gradient_accumulation_steps=8,
    8. )

    The key point is to keep global_batch = micro_batch * grad_accum * dp_size at the value you expect; otherwise the learning rate and convergence behavior shift overall.

    4. Memory and Compute Optimization: Keeping Four Hundred Steps Stable

    Memory is the most common hard constraint in pipeline validation. Try the following in order of increasing cost:

    1. Mixed precision: use low precision for the forward pass, keep higher precision for the master copy of parameters and optimizer states, and use loss scaling to avoid gradient underflow.
    2. Gradient accumulation: trade time for memory by splitting a large batch into multiple micro batches.
    3. Activation recomputation: save only necessary activations and recompute them during the backward pass; memory drops significantly but computation increases by about thirty percent.
    4. Optimizer state sharding: shard optimizer states along the data parallel dimension so each card updates only the part it is responsible for.
    5. Communication and computation overlap: run gradient reduction in parallel with backward computation to reduce bubbles.
    1. # Illustrative: mixed precision + gradient accumulation
    2. scaler = GradScaler()
    3. for step, batch in enumerate(loader):
    4. with autocast():
    5. loss = model(batch).loss / accum_steps
    6. scaler.scale(loss).backward()
    7. if (step + 1) % accum_steps == 0:
    8. scaler.step(optimizer); scaler.update(); optimizer.zero_grad()

    5. Observability and Fault Diagnosis

    Four hundred consecutive steps must be observable. Collect at least four categories of metrics: throughput (time per step and sample throughput), memory (peak usage and fragmentation trend), communication (share of time spent in collective communication), and numerical health (loss and gradient norm).

    Common anomalies and the order to investigate them:

    • Loss is NaN: first check the learning rate and loss scaling, then check for abnormal samples in the data, and finally suspect operator precision issues.
    • Throughput drops sharply: check whether a card is throttling or overheating, and whether a slow node is dragging down the all-reduce.
    • Process hangs: usually caused by mismatched collective communication waits; confirm all ranks have the same step count and that conditional branches do not depend on data content.
    • Resume from checkpoint fails: confirm that optimizer state, learning rate scheduler, random number state, and data reading position are all saved completely.

    6. Checklist

    • Component versions match exactly across both nodes, and the minimal operator self-check passes;
    • The product of parallel degrees equals the total number of cards, and communication domains match the topology;
    • The global batch matches the learning rate, and gradient accumulation steps are correct;
    • Accuracy loss with mixed precision and recomputation enabled is within an acceptable range;
    • A checkpoint is written every few tens of steps, and a real recovery drill is performed once;
    • The monitoring dashboard covers all four metric categories, throughput, memory, communication, and numerical health, with alerts configured.

    Completing these steps, four hundred consecutive steps on two nodes and sixteen cards is only the starting point; the pipeline can now serve as a baseline for model architecture replacement, scaling, and long-stability testing. If elastic scheduling and resource isolation are needed, general cloud capabilities such as container platforms, object storage, and monitoring alerts can carry the deployment, and the general infrastructure categories offered by Baidu AI Cloud for this kind of training engineering scenario can also serve as one reference for the deployment model.