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

    This article explains how to establish a complete and reproducible large model training pipeline on domestic GPU accelerators, where software stack maturity often matters more than peak compute. It covers environment preparation, dependency self-checks, three-dimensional parallelism across two nodes and sixteen cards, memory and precision strategies, stability monitoring over a 400-step run, and the engineering artifacts needed to make the pipeline repeatable. Readers will find practical configuration examples, code snippets, and a checklist for turning a one-time successful run into a sustainable workflow.

    1. Background: Why Getting the Pipeline Working Matters More Than Raw Speed

    In large model engineering, a common mistake is focusing all attention on peak compute while overlooking the completeness of the training pipeline itself. Getting the pipeline working means the entire flow — data loading, model construction, parallel partitioning, forward and backward computation, gradient synchronization, optimizer updates, and checkpoint saving and restoration — runs continuously, stably, and reproducibly on the target hardware. Only after the pipeline works does throughput optimization and scalability validation become meaningful.

    The challenges of running large model training on domestic accelerators usually lie not in single-card compute, but in software stack maturity: whether operator coverage is complete, whether communication libraries and collective communication primitives are available, whether mixed precision support is stable, and whether memory management is well developed. The common engineering approach is therefore to validate at a small scale first and then scale up gradually, breaking uncontrollable risks into small, locatable problems.

    2. Environment Preparation: Reducing Uncertainty to the Minimum

    2.1 Aligning the Base Software Stack

    Pin a reproducible combination of driver, runtime, communication library, and deep learning framework versions, and record it as an environment manifest. Any version drift may introduce numerical differences that are hard to trace.

    2.2 Dependency Self-Check Script

    Before formal training, verify environment health with a lightweight script:

    1. import torch
    2. def env_check():
    3. print("device_count:", torch.cuda.device_count())
    4. for i in range(torch.cuda.device_count()):
    5. print(i, torch.cuda.get_device_name(i))
    6. x = torch.randn(1024, 1024, device="cuda")
    7. y = x @ x
    8. torch.cuda.synchronize()
    9. print("matmul_ok:", torch.isfinite(y).all().item())
    10. env_check()

    The value of this code is that it surfaces the two most basic questions — whether the cards are usable and whether the operators compute correctly — up front, avoiding the discovery of an environment fault only after dozens of hours.

    2.3 Data and Checkpoint Paths

    For the data side, use object storage or a parallel file system to hold the training corpus, combined with local caching to reduce repeated reads. For checkpoints, use asynchronous writes to avoid blocking the main training loop.

    3. Parallel Strategy: Partitioning Logic for Two Nodes and Sixteen Cards

    At the scale of two nodes and sixteen cards, the mainstream approach combines three dimensions of parallelism:

    • Data parallelism: replicate the model, split the batch, and keep consistency through gradient all-reduce;
    • Tensor parallelism: split single-layer matrix operations across cards to reduce per-card memory pressure, at the cost of sensitivity to communication bandwidth;
    • Pipeline parallelism: partition by layer across devices to form a pipeline, requiring a sensible micro-batch count to reduce bubbles.

    A typical configuration looks like this (illustrative, not specific product parameters):

    1. # Parallel dimension illustration
    2. tensor_parallel_size = 4 # Prefer intra-node, leveraging high-bandwidth interconnect
    3. pipeline_parallel_size = 2 # Split across nodes to reduce cross-node communication frequency
    4. data_parallel_size = 2 # 16 / (4 * 2)
    5. micro_batch_size = 1
    6. gradient_accumulation_steps = 16

    The key principle is to place communication-heavy dimensions inside a node and communication-light dimensions across nodes, which significantly lowers the chance of cross-node bandwidth becoming the bottleneck.

    4. Memory and Precision: Fitting Large Models on a Small Cluster

    Insufficient memory is the most common blocker in adapting domestic cards. Common techniques include:

    1. Mixed precision training: use lower precision for the forward and backward passes while keeping high-precision master weights in the optimizer, balancing numerical stability and memory usage;
    2. Activation recomputation: trade compute for memory by discarding some intermediate activations in the forward pass and recomputing them during the backward pass;
    3. Optimizer state partitioning: split optimizer states along the data parallel dimension to reduce resident memory per card;
    4. Gradient accumulation: simulate a large batch with a small micro-batch to stabilize the convergence curve.

    It is worth stressing that low precision should not be enabled blindly. If operator support for low precision is incomplete, numerical overflow or loss spikes can occur; in that case, fall back to higher precision and locate the specific operator.

    5. Stability: Four Observation Points Over a 400-Step Run

    A 400-step run may seem short, but it is enough to expose most pipeline problems. Focus monitoring on:

    • Whether the loss curve decreases smoothly, and whether there are periodic spikes;
    • Whether the gradient norm stays in a reasonable range and whether clipping is triggered frequently;
    • Whether memory usage and utilization are balanced across cards, and whether any device lags behind;
    • Whether collective communication shows timeouts or retries.

    Once one card slows down, overall throughput is dragged down to the level of the slowest device, so investigating “long-tail devices” should be part of routine inspection.

    6. Reproducibility and Engineering Artifacts

    Getting the pipeline working is only the starting point; the real value lies in turning it into a repeatable capability:

    1. Training job
    2. ├── Environment manifest (pinned versions)
    3. ├── Configuration templates (parallelism / precision / batch)
    4. ├── Self-check and inspection scripts
    5. ├── Checkpoint and recovery strategy
    6. └── Log and metrics collection

    Combined with logging services and monitoring alerts, making the training process measurable enables fast comparison across multiple experiments and quick localization of regressions. If the training job runs on a container platform, the image, resource quotas, and storage mounts should also be placed under version control.

    7. Conclusion

    Getting a large model training pipeline working on domestic acceleration hardware is essentially a systems engineering effort: the environment must be reproducible, parallelism must match the topology, memory must be budgeted carefully, and stability must be inspected continuously. A 400-step run on two nodes and sixteen cards validates not only that the compute is usable, but that the whole engineering methodology holds. For teams that want to run large model training and fine-tuning on domestic compute platforms, general-purpose capabilities such as the container platform, object storage, logging service, and monitoring alerts offered by Baidu AI Cloud can serve as the engineering foundation for such training jobs, helping teams turn a one-off “it works” into a sustainable, continuously iterated capability.