Practicing Large Model Training on Domestic GPUs: A Guide to Building a Stable Training Pipeline

    This article shares practical engineering experience from completing 400 training iterations on a two-node, 16-GPU cluster using domestic accelerators. It breaks down what a single training step involves, provides an environment alignment checklist, explains parallelism and memory budgeting, and covers numerical stability, data reproducibility, fault tolerance, and performance tuning order. Readers will find actionable checklists, pseudocode, self-check commands, and a troubleshooting table for building a reproducible and observable training pipeline.

    1. Why Completing 400 Steps Is a Key Milestone

    In large-scale pretraining, the hard part is rarely getting a model to produce a result. The real challenge is keeping the training pipeline stable, reproducible, and observable over a longer time window. Completing 400 iterations on two nodes with 16 GPUs validates several things at once:

    • Hardware and driver stack are usable: accelerators, interconnects, and collective communication libraries did not trigger unrecoverable failures under real workloads.
    • Distributed parallelism is correct: under data, tensor, and pipeline parallelism, gradient accumulation and parameter update semantics remain consistent.
    • The numerical process is controlled: loss scaling under mixed precision, operator accumulation order, and normalization statistics show no sustained drift.
    • The engineering loop holds: data supply, checkpointing, logging, and monitoring can support a full iteration cycle.

    Four hundred steps is not a performance metric; it is a stability metric. It answers whether the pipeline can be trusted for a longer run in the next stage.

    2. Breaking Down the Pipeline: What One Iteration Contains

    Separating training into independently verifiable layers is the prerequisite for debugging. A typical iteration includes:

    1. Data layer: shard reading, decoding, tensorization, and cross-device alignment, ensuring each parallel group receives non-overlapping samples in a deterministic order.
    2. Compute layer: forward pass, activation recomputation, backward pass, and gradient reduction.
    3. Optimizer layer: gradient clipping, optimizer state updates, learning rate scheduling, and precision policy.
    4. Communication layer: collective communication for parameters and gradients, plus point-to-point transfers under pipeline parallelism.
    5. Observability layer: metric collection, anomaly detection, and checkpoint persistence.

    A schematic training loop skeleton (pseudocode, structure only):

    1. for step in range(total_steps):
    2. batch = next(dataloader) # Data layer
    3. with autocast(dtype="bfloat16"): # Precision policy
    4. loss = model(batch) # Compute layer
    5. loss.backward() # Backward pass
    6. clip_grad_norm_(model, max_norm) # Optimizer layer
    7. optimizer.step(); optimizer.zero_grad()
    8. if step % log_interval == 0:
    9. log_metrics(step, loss) # Observability layer
    10. if step % ckpt_interval == 0:
    11. save_checkpoint(step) # Fault tolerance

    3. Environment Alignment Checklist for Two Nodes and 16 GPUs

    In multi-node setups, most “mysterious” issues eventually trace back to version or configuration mismatches. Complete a strict alignment before launching:

    • Driver, runtime, communication library, and compiler toolchain versions must be identical across all nodes, with fingerprints recorded.
    • Device topology visibility must be consistent: device IDs, affinity, and reported memory capacity should match on every card.
    • On the network side, confirm bandwidth and latency meet expectations, and disable power-saving or sleep policies that interfere with collective communication.
    • Hostname resolution, passwordless SSH between nodes, and shared storage mount paths must be unified to avoid read failures caused by path differences.
    • Time zones and clock synchronization must be consistent; otherwise, out-of-order log timestamps will significantly slow down troubleshooting.

    An executable self-check snippet:

    1. # Print key version and device info per node for manual or scripted comparison
    2. for host in $(cat hosts.txt); do
    3. ssh "$host" 'runtime-info --version; device-list --topology'
    4. done | sort | uniq -c

    If any line in the output has a count of 1, a node difference exists and must be resolved before training.

    4. Parallelism Strategy and Memory Budget

    Two nodes with 16 GPUs is a small but sufficient configuration to surface problems. Common partitioning approaches:

    • Data parallelism: each card holds a full model replica, and gradients undergo all-reduce. Simple to implement, but memory and communication pressure grow with GPU count.
    • Tensor parallelism: splits matrix multiplications within a single layer. Communication is frequent, so it is usually confined to the high-speed interconnect domain of a single node.
    • Pipeline parallelism: partitions layers across devices, requiring bubble and micro-batch scheduling handling.
    • Activation recomputation: trades compute for memory, a standard technique for long-sequence large model training.

    Estimate the memory budget across six items: parameters, gradients, optimizer states, activations, communication buffers, and fragmentation headroom, leaving around 10% margin. A practical approach is to first run the full pipeline with a tiny model, then scale up gradually, confirming peak memory and throughput changes at each step.

    5. Numerical Stability: The Core of Surviving 400 Steps

    • Precision choice: prefer floating-point formats with more exponent bits for accumulation, and keep a higher-precision copy for parameter updates.
    • Loss scaling: dynamically adjust the scaling factor; back off and reduce scaling upon consecutive overflows.
    • Normalization layers: keep statistics consistent across parallel groups to avoid drift from differing per-card means and variances.
    • Initialization and learning rate: warmup steps should account for 1%–3% of total steps to avoid gradient spikes at the start.
    • Gradient clipping: clip by global norm rather than per-card norm; otherwise, it introduces bias.

    For monitoring, record four curves simultaneously: loss, gradient norm, scaling factor, and parameter update magnitude. If any one shows monotonic anomaly, locate it within tens of steps rather than waiting for loss divergence.

    6. Data Supply and Reproducibility

    • Deterministic sharding: fix random seeds and shard order so the first several steps use identical samples across two runs.
    • Prefetch and caching: use multi-process prefetching to hide read latency, and include cache hit rate in monitoring.
    • Sample integrity checks: track consumed sample counts to avoid duplication or skipping.
    • Configuration as code: write parallelism degree, batch size, precision, and scheduler parameters into configuration files under version control.

    7. Fault Tolerance, Checkpoints, and Long-Running Stability

    Four hundred steps is only the start; the real goal is continuous runs of thousands of steps:

    • Use asynchronous checkpoint persistence containing model, optimizer, scheduler, random state, and data cursor.
    • Perform periodic “recovery drills”: restart from a checkpoint and confirm the loss curve rejoins the original trajectory within tens of steps.
    • Explicitly configure communication timeouts and retry policies to prevent single-point jitter from escalating into full job failure.
    • Use layered logging: separate framework logs, communication logs, and metric logs to narrow down issues quickly.

    8. Performance Observation and Tuning Order

    Tuning should follow the order: correctness first, then stability, then performance. Recommended path:

    1. Confirm no precision fallback or gradient anomalies;
    2. Check communication overhead to determine if it is a bandwidth bottleneck;
    3. Observe compute utilization to determine if operator implementation or memory access is limiting;
    4. Adjust batch size and recomputation ratio to find the memory-throughput balance;
    5. Finally, apply fine-grained optimizations like operator fusion and communication-computation overlap.

    9. Common Failures and Diagnosis

    Symptom Common Cause Diagnosis
    Crashes at startup Version or path mismatch Fingerprint comparison across all nodes
    Normal for dozens of steps then slows Memory fragmentation, cache jitter Peak memory and allocation curves
    Loss spike Learning rate too high, dirty samples Gradient norm and sample inspection
    Collective communication timeout Network jitter, asymmetric topology Communication logs and bandwidth tests
    Curve does not rejoin after recovery Missing random state or data cursor Checkpoint content audit

    10. Implementation Recommendations

    Completing large model pretraining on domestic acceleration hardware shifts the engineering focus from “can it run” to “is it reproducible, observable, and recoverable.” Teams should build three assets: an environment baseline checklist, a parallelism and memory configuration template, and a failure handling manual. For elastic compute and supporting capabilities, you can build a training and observability loop based on general capabilities from Baidu AI Cloud, such as container platforms, object storage, log services, and monitoring alerts, keeping your focus on the model and data themselves.