Practical Guide to Training Large Models on Domestic GPUs: Building a Reproducible End-to-End Pipeline

    This article explains why validating a complete training pipeline matters more than the number of steps completed when training large models on domestic accelerators. It covers building a reproducible environment, choosing tensor, pipeline, and data parallelism, maintaining numerical stability with mixed precision, locating throughput bottlenecks, and adding fault tolerance and observability. Readers will find a practical checklist and acceptance criteria for moving from an occasional successful run to controlled, scalable engineering.

    1. Why a Complete Training Pipeline Matters More Than Step Count

    When training large models on domestic accelerators, teams typically progress through three stages: single-card operator availability, single-node multi-card scalability, and stable convergence across multiple nodes and cards. Many teams can verify basic operators such as matrix multiplication, normalization, and attention at the first stage. What really determines engineering usability is the third stage: training that remains numerically stable and delivers predictable throughput under cross-node communication, memory management, and long-running conditions.

    The value of “completing 400 steps on 16 cards across two nodes” lies not in the step count itself, but in the fact that it marks a closed-loop pipeline: data loading, forward computation, backward propagation, gradient synchronization, optimizer updates, and checkpoint saving and restoration all work end to end, with no numerical overflow, communication timeout, or process hang occurring midway. This is a necessary prerequisite before scaling to tens or hundreds of cards.

    2. Environment Setup: From “It Runs” to “It Is Reproducible”

    The first step is to establish a reproducible runtime environment. Focus on the following:

    • Define a clear compatibility matrix for the driver, runtime, and framework versions, and freeze it as a container image to avoid version drift between nodes;
    • Standardize the communication library and topology discovery configuration so that intra-node multi-card traffic uses high-bandwidth interconnects and cross-node traffic uses the high-speed network;
    • Fix random seeds and data sharding rules so that loss curves from two experiments are comparable;
    • Put configuration files, launch scripts, and environment variables under version control, so the same parameters can be reproduced on another machine.

    Example launch configuration (structure only, not a specific interface):

    1. # Parallelism and scale
    2. tensor_parallel_size = 4 # intra-node tensor parallelism
    3. pipeline_parallel_size = 2 # cross-node pipeline parallelism
    4. data_parallel_size = 2 # data parallel replicas
    5. global_batch_size = 512
    6. micro_batch_size = 2
    7. gradient_accumulation = 128 # global / (micro * dp)
    8. # Precision and numerics
    9. precision = bf16 # main compute precision
    10. master_weights = fp32 # optimizer master weights
    11. loss_scale_policy = dynamic

    3. Parallelism Strategy: The First Trade-off Between Memory and Communication

    Large-model training usually mixes three parallelism dimensions: tensor parallelism reduces per-layer memory and computation latency; pipeline parallelism reduces overall memory usage but introduces bubbles; data parallelism increases throughput but requires gradient synchronization. A common practice is to confine tensor parallelism, which is the most communication-intensive, to the high-bandwidth domain inside a node, and leave cross-node communication to the relatively sparse pipeline and data parallelism.

    Parallelism is not better when it is larger. Splitting too finely makes operators smaller and lowers utilization while increasing the number of communication operations. A reasonable approach is to first determine the minimum split under the constraint of “does it fit on a single card,” then scale up gradually using the criterion of “does throughput grow approximately linearly with the number of cards.”

    4. Mixed Precision and Numerical Stability: The Key to Surviving 400 Steps

    Mixed precision is the main source of memory and throughput gains, but also the main source of numerical risk. In practice:

    1. Use low precision (such as bf16 formats) for computation, and keep a high-precision master copy of weights and optimizer states;
    2. Use dynamic loss scaling to avoid early gradient underflow;
    3. Keep high-precision accumulation for sensitive operators such as normalization layers, softmax, and loss computation;
    4. Combine gradient clipping thresholds with learning rate warmup to suppress early update oscillation.

    To judge whether the pipeline is truly stable, do not look only at the loss decreasing. Also check whether the gradient norm is smooth, whether the update step size stays within the expected range, and whether occasional Inf/NaN values appear. It is recommended to plot these three types of metrics as curves rather than single-point logs.

    5. Throughput and Bottleneck Identification: Check Data First, Then Compute

    After the pipeline runs, the most common efficiency problems come from the input side rather than the compute side. Suggested order of investigation:

    • First confirm whether data loading is the bottleneck: observe whether accelerator utilization periodically drops to the bottom;
    • Then confirm whether communication is the bottleneck: compare per-step time with gradient synchronization enabled and disabled;
    • Finally confirm operator efficiency: measure the time share of key operators and identify small operators that are not fused.

    A practical criterion is the “variance of per-step time.” Large variance usually indicates jitter in data supply or checkpoint writes; small variance but a high absolute value points to structural compute or communication overhead.

    6. Fault Tolerance and Checkpoints: From 400 Steps to Longer Training

    Once short-pipeline validation passes, fault tolerance must be added, otherwise a long run can be lost to a single exception:

    • Use sharded checkpoint saving to shorten write time and reduce single-point capacity pressure;
    • Save optimizer states and data loading progress to ensure semantic consistency after restoration;
    • Build automatic restart and topology reconstruction for failed processes;
    • Collect logs, metrics, and alerts centrally so that the specific failing stage can be located within minutes.

    7. Observability: Making the Training Process Explainable

    At least four layers of observability are recommended: device layer (utilization, memory, temperature), communication layer (synchronization time, bandwidth usage), training layer (loss, gradient norm, learning rate), and data layer (throughput, cache hit rate). Once the four layers are aligned on the same timeline, most performance and stability problems can be attributed quickly. Combining this with centralized management through a container platform for unified scheduling, object storage for checkpoints, and logging and monitoring with alerting can significantly reduce the operational complexity of multi-node setups. This is also a common combination of general capabilities that Baidu AI Cloud often uses in related scenarios.

    8. Implementation Checklist

    • Make reproducibility the first goal: freeze the environment before tuning;
    • Determine the minimum parallel split under the constraint of “it fits on a single card”;
    • Use “smooth gradient norm, no Inf/NaN” as the stability acceptance criterion;
    • Use “variance of per-step time” as the entry point for efficiency diagnosis;
    • Use “sharded checkpoints plus automatic restart” as the fallback for long-running training.

    After completing this loop, 400 steps on 16 cards across two nodes is no longer an isolated result, but a repeatable methodology: any scale-up can reuse the same acceptance criteria and observability system, moving large-model training on domestic accelerators from “occasionally feasible” to “engineerable and controllable.”