Getting Large Model Training Working on Domestic GPUs: A Practical Guide

    This article walks through a practical approach to validating an end-to-end large model pretraining pipeline on domestic GPU hardware, using a two-node, 16-GPU, 400-step run as a minimal verifiable loop. It covers environment and dependency alignment, parallel strategy trade-offs, data pipeline reproducibility, stability monitoring and fault localization, and a step-by-step performance tuning path once the pipeline is stable. The goal is to confirm that the software, communication, and storage stacks are aligned before pursuing throughput optimization.

    1. Background and Problem Definition

    In large model pretraining, “getting the pipeline working” and “getting good results” are two different levels of goals. The former focuses on whether the end-to-end flow is closed: whether data can be read correctly, whether the model can be partitioned correctly, whether gradients can be propagated back correctly, and whether parameter updates can be written to disk correctly. The latter involves convergence speed, accuracy alignment, and throughput optimization. When many teams switch hardware platforms, the first priority should be pipeline validation rather than chasing throughput metrics directly.

    A two-node, 16-GPU, 400-step run is essentially a “minimal verifiable loop.” The number of steps does not need to be large, but it should cover enough code paths: forward pass, backward pass, optimizer update, gradient clipping, mixed-precision scaling, and checkpoint saving and restoration. If these 400 steps complete stably and the loss curve decreases smoothly, it means the software stack, communication stack, and storage stack are aligned.

    2. Environment Preparation and Dependency Alignment

    The most common cause of pipeline failures is not the algorithm but mismatched dependency versions. A layered verification approach is recommended:

    • Driver and runtime: confirm that the accelerator card driver, runtime libraries, and communication libraries are within the same compatibility matrix;
    • Framework layer: the training framework version must match the operator library to avoid missing custom operators;
    • Communication layer: confirm that the cross-node communication backend is available and that NIC and switch configurations are consistent;
    • Storage layer: the dataset must be accessible to all nodes via the same path.

    An illustrative environment self-check script:

    1. import os, subprocess
    2. def check_env():
    3. print("world_size:", os.environ.get("WORLD_SIZE"))
    4. print("rank:", os.environ.get("RANK"))
    5. # Print runtime and communication library versions for archival comparison
    6. subprocess.run(["python", "-c",
    7. "import torch;print('framework',torch.__version__)"])

    Archive the self-check output as a baseline file, so that any subsequent anomaly can be diffed against the baseline for localization.

    3. Parallel Strategy Trade-offs

    A two-node, 16-GPU setup is a small-scale cluster where both memory and communication bandwidth are relatively tight, so the parallel strategy needs careful design:

    1. Prioritize data parallelism. Do tensor parallelism or pipeline parallelism partitioning within a single node first, then data parallelism across nodes, which can significantly reduce cross-node communication volume.
    2. Use gradient accumulation instead of large batches. Trade accumulation steps for an equivalent global batch size to avoid memory overflow.
    3. Enable activation recomputation as needed. Recomputation saves memory but increases computation by about 30%, so it should be enabled only after the pipeline is stable.
    4. Shard optimizer states. Sharding optimizer states across GPUs is the most direct way to relieve memory pressure.

    Configuration example:

    1. config = dict(
    2. tensor_parallel_size=2,
    3. pipeline_parallel_size=1,
    4. gradient_accumulation_steps=8,
    5. micro_batch_size=1,
    6. recompute_granularity="full",
    7. optimizer_state_shard=True,
    8. )

    4. Data Pipeline and Reproducibility

    On the data side, three things must be ensured: no duplicate shards, reproducible ordering, and controllable sample length distribution. In practice, it is recommended to fix the random seed for the data loader and record the shard mapping table. If streaming reads are used, confirm that the correct offset can be resumed after checkpoint restoration; otherwise, an illusion of “loss jump after resume” will appear.

    1. def build_loader(seed=1234, shards=16):
    2. # Fix the seed to ensure shards do not overlap across ranks
    3. return dict(seed=seed, num_shards=shards, shuffle=True)

    5. Stability, Monitoring, and Fault Localization

    Although 400 steps is short, it is enough to expose hidden problems. It is recommended to collect at least the following metrics: per-step loss, gradient norm, parameter update norm, peak memory per GPU, proportion of cross-node communication time, and per-step time. When anomalies occur, troubleshoot in the following order:

    • Loss is NaN: first check the mixed-precision scaling factor and gradient clipping threshold;
    • Throughput drops sharply: check for slow GPUs and compare the variance of per-step time across ranks;
    • Process hangs: mostly caused by unaligned collective communication; check whether any rank exited early;
    • Abnormal curve after recovery: verify that the data offset and optimizer state are fully loaded.

    Collecting logs and metrics into a unified logging service and monitoring/alerting system, combined with archiving checkpoints to object storage, can greatly reduce the cost of reproducing problems.

    6. Performance Tuning Path

    Only talk about optimization after the pipeline is stable. The recommended order is: first eliminate data loading bottlenecks (increase read concurrency and prefetch depth), then optimize communication (overlap computation and communication, adjust communication groups), and finally adjust operators and the recomputation ratio. Change only one variable per round, and use the average per-step time over a fixed step interval as the sole evaluation criterion to avoid being misled by occasional jitter.

    7. Conclusion

    Completing large-scale pretraining on domestic accelerator card platforms follows a methodology highly consistent with the general process: use a minimal verifiable loop to confirm the pipeline, use baseline archiving to support localization, and use single-variable tuning to approach the performance ceiling. The value of a two-node, 16-GPU, 400-step run lies not in scale but in compressing the risk points of the entire pipeline into a range that can be verified in hours, providing a reliable basis for subsequent scaling to more nodes. If elastic scaling is needed, container platforms and queued task scheduling can be used for resource orchestration, making the validation process itself reusable and automatable.