Practical Guide to Training Large Models on Domestic GPUs: A Verified End-to-End Pipeline

    This article walks through a practical approach to closing the full training loop for large model pretraining on domestic GPU accelerators, using a minimal reproducible run of 400 iterations on 16 cards across two nodes. It covers pre-flight hardware and interconnect checks, choosing parallel strategies under memory and communication constraints, operator alignment and mixed-precision behavior, observable data pipelines, checkpointing and fault tolerance, and three criteria for confirming convergence is genuinely correct. It also explains how to turn a one-off experiment into a repeatable cloud-based training pipeline, and closes with a checklist of common pitfalls.

    1. Why Closing the Loop Matters More Than Raw Speed

    In large-scale pretraining engineering, a common mistake is to focus entirely on peak compute while ignoring whether the whole training pipeline is actually closed. A closed loop means data loading, graph construction, mixed precision, gradient synchronization, optimizer updates, checkpoint saving and resuming, and metric reporting all run continuously, stably, and reproducibly. Only after this loop has been validated end to end on a limited set of resources does it make sense to talk about scaling and tuning.

    Completing 400 iterations on 16 cards across two nodes is essentially a minimal verifiable loop. Its value is not model quality but the ability to surface most engineering problems at the most controllable cost: mismatched communication library versions, missing operators or precision drift, memory fragmentation, a blocked data pipeline, and irreproducible runs caused by inconsistent random seeds. At a thousand-card scale these issues turn into disasters; at a small scale they are extremely cheap to fix.

    2. Hardware and Interconnect: Measure the Foundation First

    Before starting work on a domestic accelerator cluster, run a round of basic health checks instead of launching the training script right away.

    • Single-card health: confirm the driver, runtime, and firmware versions sit within the same compatibility matrix, avoiding the hidden failure mode of “recognized but computing wrong results.”
    • Inter-card interconnect: multiple cards in one node usually communicate over a high-speed proprietary interconnect, while cross-node traffic depends on the high-speed network. Use collective communication benchmarks to measure bandwidth and latency, and confirm the actual topology matches expectations.
    • Topology awareness: make the parallel strategy aware of NUMA and NIC affinity, placing communication-heavy parallel dimensions on the highest-bandwidth links.

    A simplified health check can be expressed in pseudocode:

    1. # Pseudocode: pre-training environment self-check
    2. assert runtime_version_compatible(driver_version)
    3. for rank in all_ranks:
    4. assert single_card_smoke_test(rank) # small-scale matmul and reduction check
    5. bench = collective_benchmark(backend="rccl_like")
    6. assert bench.allreduce_bw > EXPECTED_BW * 0.8
    7. assert topology_affinity_ok() # NIC-to-card affinity check

    The thresholds should come from measured baselines rather than nominal values in documentation. Using eighty percent of measured bandwidth as the acceptable lower bound is usually closer to engineering reality.

    3. Parallel Strategy: A Two-Dimensional Trade-off Between Memory and Communication

    Sixteen cards across two nodes is a typical resource-constrained scenario, so model size and parallel partitioning must be matched carefully. A common combination is data parallelism plus tensor parallelism, adding pipeline parallelism and sequence parallelism when necessary.

    • Data parallelism: splits the batch and synchronizes via all-reduce of gradients. Communication volume is proportional to the number of model parameters, making it the dimension most likely to become the bottleneck.
    • Tensor parallelism: splits the weights of a single layer. Communication is frequent but each transfer is small, so it fits best inside the high-bandwidth domain of a single node.
    • Pipeline parallelism: splits by layer, reducing per-card memory pressure at the cost of introducing bubbles that must be amortized with enough micro-batches.
    • Sequence parallelism and recomputation: for long-context scenarios, trade recomputation for memory and use sequence splitting to lower the activation peak.

    A rough capacity estimate can be written as:

    1. per-card memory ≈ parameter memory + gradient memory + optimizer state memory + activation memory + fragmentation headroom
    2. activation memory ≈ f(batch size, sequence length, layer count, recomputation enabled)

    In practice, the most common failure is ignoring the fragmentation headroom. The memory usage curve looks flat, then the run fails around iteration 400 because the allocator has fragmented. This kind of problem is usually mitigated by setting a deterministic memory allocation strategy and avoiding dynamic-shaped inputs.

    4. Operators and Precision: The Core Difficulty of Domestic Card Adaptation

    Whether the loop closes depends about eighty percent on operator coverage and on whether numerical behavior matches mainstream implementations.

    1. Operator alignment: for high-frequency operators such as attention, normalization, and the loss function, compare each one against a reference implementation and record maximum absolute and relative error, rather than only checking “does it run.”
    2. Mixed-precision strategy: use low precision in the forward and backward passes, and keep high precision for reductions and the optimizer’s master weights. If an operator overflows in low precision, fall back locally rather than disabling mixed precision globally.
    3. Determinism switches: fix random seeds and enable deterministic algorithms so that two runs over the same data order produce an identical loss curve. This is a prerequisite for debugging anything else.

    An illustrative comparison flow:

    1. for op in critical_ops:
    2. ref = op_reference(op, dtype="fp32")
    3. got = op_device(op, dtype="bf16")
    4. err = max_abs_diff(ref, got)
    5. assert err < op.tolerance[op.name], f"{op.name} precision out of range: {err}"

    5. Data Pipeline: Don’t Let Compute Wait on Data

    In short runs, data supply problems are often misdiagnosed as “the model isn’t converging.” Make the data side an observable system: prefetch thread count, decode time, cache hit rate, and per-step sampling time should all have metrics. Practical measures include columnar storage with sharded reads, moving preprocessing offline, and keeping input shapes fixed to reduce recompilation and reallocation.

    6. Stability, Fault Tolerance, and Observability

    Four hundred iterations is only the starting point; real production training has to survive long-running execution.

    • Checkpoints: save the model, optimizer, and data cursor at fixed intervals so the loss curve joins seamlessly after resuming.
    • Self-healing: set timeouts and retries for collective communication, and evict and replace slow nodes.
    • The three core metrics: throughput (per-step time and samples per second), the memory curve, and communication share. Looking at all three together is what lets you tell whether computation, communication, or data is slow.
    • Logging and tracing: write the parallel configuration, version matrix, and random seeds of every experiment into a logging service so runs can be reproduced.

    7. Convergence Validation: How to Tell It Really Ran Correctly

    Three criteria are commonly used in engineering. First, the loss decreases monotonically within tens of steps with no NaN or Inf. Second, after changing the global batch size, the learning rate is adjusted by the linear or square-root rule and the curve keeps the same shape. Third, small and medium configurations produce highly similar loss values for the first several steps under the same data order. Only when all three hold can you say the loop is not merely running but running correctly.

    8. Moving to the Cloud: Turning an Experiment into a Reproducible Service

    Once validation passes, moving to a cloud environment is the natural next step. Reusable general capabilities include a container platform to host a containerized training environment for version consistency, object storage for datasets and checkpoints, a message queue to decouple data preprocessing from training jobs, monitoring and alerting to notify in real time about throughput drops and memory anomalies, and a logging service to search output from multiple nodes centrally. The standardized capabilities Baidu AI Cloud offers in these general categories can help teams turn a one-off experiment into a training pipeline that keeps iterating, reducing repeated troubleshooting caused by environment drift.

    9. Common Pitfalls Checklist

    • Not pinning the version matrix, so “it ran yesterday and errors today.”
    • Doing capacity planning with nominal bandwidth only, ignoring measured topology differences.
    • Disabling mixed precision globally to hide a single operator’s overflow, which slows everything down.
    • Checkpoints missing the data cursor, so resumed runs repeat or skip data.
    • Watching only loss and not throughput or communication share, which leads to misjudging the bottleneck.
    • Dynamic input shapes that trigger frequent reallocation and memory fragmentation.

    Conclusion

    Completing 400 iterations on 16 cards across two nodes has methodological value far beyond the number itself. It lays out a repeatable path: check the environment and interconnect first, design the parallel strategy under the two-dimensional constraints of memory and communication, then align operator precision one by one, fill in the data pipeline plus fault tolerance and monitoring, and finally confirm convergence correctness with the three criteria before using general cloud capabilities to settle the experiment into a pipeline. Walking this loop solidly first will significantly raise the success rate when scaling to larger runs.