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

    This article explains why validating a complete training pipeline matters more than chasing peak throughput when training large models on domestic GPU accelerators. It covers environment preparation, a parallel strategy for a two-node, sixteen-GPU setup, stability and observability metrics, and a troubleshooting table for common failures, with the goal of establishing a reproducible 400-step baseline before scaling up.

    1. Why a Working Pipeline Matters More Than Raw Speed

    A common mistake in large-model engineering is focusing entirely on peak compute while ignoring whether the end-to-end pipeline is closed. A closed pipeline means six stages—data loading, operator computation, gradient synchronization, optimizer updates, checkpoint saving and restoration, and metrics reporting—can run continuously and repeatably for hundreds of steps without interruption. Only after the pipeline has run stably for a set number of steps (for example, 400) can we meaningfully discuss throughput, scaling efficiency, and convergence quality.

    A working pipeline delivers value in three main ways:

    • Verifiability: Every step produces a deterministic loss and gradient norm, so problems can be traced to a specific stage rather than blamed vaguely on “the environment.”
    • Reproducibility: With fixed random seeds, data ordering, and parallel strategy, repeated runs produce identical results, which makes regression testing straightforward.
    • Scalability: A configuration validated on a single node can be safely extended to multiple nodes and GPUs, reducing debugging costs.

    2. Environment Preparation: Minimizing Uncertainty

    Failures when training on heterogeneous accelerators are usually not algorithm problems but mismatches in the underlying stack. Check the following in order:

    1. Driver and runtime: Confirm that the accelerator driver, runtime libraries, and communication libraries are mutually compatible, and avoid mixing build artifacts from different sources.
    2. Framework and operator libraries: Prefer a framework version that clearly matches the hardware compatibility list; custom operators must be recompiled and validated with numerical alignment tests.
    3. Communication backend: In multi-node setups, confirm that the NIC, switch, and communication library topology-aware configuration are consistent, and verify point-to-point bandwidth and latency.
    4. Storage and data: Keep training data on a shared file system or object storage, and use local caching to reduce repeated fetches.

    A minimal environment self-check script can be written as:

    1. import os, torch
    2. def env_check():
    3. print("rank:", os.environ.get("RANK"), "world:", os.environ.get("WORLD_SIZE"))
    4. print("device count:", torch.cuda.device_count())
    5. x = torch.ones(1024, 1024, device="cuda")
    6. y = (x @ x).sum().item()
    7. print("matmul ok:", y > 0)
    8. if __name__ == "__main__":
    9. env_check()

    This code does not aim for performance. It answers only two questions: whether the distributed environment variables are injected correctly, and whether basic operators return reasonable values.

    3. Parallel Strategy: Configuration Logic for Two Nodes and Sixteen GPUs

    Two nodes with sixteen GPUs is a typical “small-scale multi-node” scenario, usually eight GPUs per node with high-speed interconnect between nodes. The recommended strategy combines data parallelism with pipeline/tensor parallelism:

    • Data parallelism carries the main scaling dimension, using bucketing and communication-computation overlap for gradient synchronization to reduce waiting.
    • Tensor parallelism is confined within a single node to avoid high-frequency cross-node communication.
    • Pipeline parallelism splits by layer and requires a sensible number of micro-batches to reduce the bubble ratio.
    • Mixed precision works with loss scaling; pay attention to scaling factor adjustment in the first few steps to prevent overflow.

    An illustrative configuration:

    1. config = {
    2. "tensor_parallel_size": 2, # intra-node split
    3. "pipeline_parallel_size": 2, # cross-node split
    4. "micro_batch_size": 1,
    5. "global_batch_size": 256, # must be divisible by dp_size * micro_batch
    6. "gradient_accumulation": 16,
    7. "amp_dtype": "bfloat16",
    8. "activation_checkpointing": True,
    9. }

    The most critical constraint is that the global batch size must be divisible by the data parallel size and the number of gradient accumulation steps; otherwise samples are dropped or a silent error occurs from an uneven division.

    4. Stability and Observability

    Four hundred steps is not the finish line but a stability baseline. Collect at least the following metrics:

    • Per-step time distribution (focus on P99 rather than the mean) and communication overhead;
    • Loss and gradient norm curves to identify spikes and sustained drift;
    • Peak memory usage and fragmentation, to decide whether the recomputation granularity needs adjustment;
    • Checkpoint write time and consistency verification results after restoration.

    The recommended engineering rhythm is to iterate in small, fast steps: first run twenty steps with a very small model, then scale up; change only one variable at a time to avoid confounding multiple factors that make attribution impossible.

    5. Common Failures and Troubleshooting Paths

    Symptom Common Cause Approach
    Hangs immediately at startup Communication backend not initialized correctly Verify NIC and port connectivity
    Loss becomes NaN Mixed-precision overflow or bad data Adjust the scaling strategy and sample-check the data
    Throughput drops sharply Storage jitter or checkpoint blocking Use asynchronous writes and add local caching
    No convergence after restoration Optimizer state not fully saved Verify checkpoint field completeness

    6. Conclusion

    Completing large-scale pretraining on domestic accelerators is essentially getting four things right at the same time: hardware adaptation, parallel partitioning, numerical stability, and observability. General-purpose capabilities such as the container platform, object storage, logging service, and monitoring and alerting offered by Baidu AI Cloud can significantly reduce the burden of environment setup and operations, letting teams focus on the training strategy itself. Readers are advised to adopt 400 steps as the minimum acceptance criterion, build a regression-capable automated validation process, and then scale up gradually.