Bringing Up Large-Scale LLM Training on Domestic GPUs: A Practical Guide

    This article walks through a practical end-to-end setup for pretraining a large language model on domestic accelerator hardware, using a small two-node, 16-card cluster that completed 400 training iterations of a very large sparse-parameter model. It breaks the training pipeline into six layers, explains how to choose parallelism (tensor, data, pipeline, sequence, and expert) under tight memory and bandwidth limits, and covers memory budgeting, numerical stability, fault tolerance, monitoring, and cost control. Readers will find reusable methodology, sample configuration and training-loop code, and a checklist of common pitfalls for validating and scaling a training pipeline.

    1. Background and Problem Definition

    Running the pretraining pipeline of a large language model on domestic accelerator hardware has moved past the “can it run at all” stage into the “run stably, run fast, run cheaply” stage. A recent representative case ran 400 training iterations of a very large sparse-parameter model end to end on a small cluster of 16 accelerators across two nodes, validating the full path from data loading and computation graph construction to parallel partitioning and optimizer updates.

    The value of such a validation is not the number of steps completed, but the real engineering problems it surfaces. A small multi-node setup iterates quickly and costs little; its drawback is that network bandwidth, memory capacity, and per-card compute all sit close to a critical threshold, so any misconfiguration is amplified quickly. The rest of this article breaks the process down into a reusable methodology.

    2. Six Key Stages of the Training Pipeline

    A complete training pipeline can be abstracted into six layers. A gap in any one of them leads to either “starts but does not run through” or “runs through but does not converge.”

    1. Hardware and driver layer: accelerator drivers, communication libraries, and compiler versions must form a matched, closed set. Version mismatch is the most common cause of startup failure.
    2. Data layer: tokenization, sample packing, sequence concatenation, data sharding, and prefetching.
    3. Model layer: attention implementation, positional encoding, sparse expert routing, and load balancing.
    4. Parallelism layer: combinations of data, tensor, pipeline, sequence, and expert parallelism.
    5. Numerical layer: mixed precision, loss scaling, gradient clipping, and numerical stability handling.
    6. Operations layer: logging, metrics, checkpoint resume, and fault self-healing.

    3. Parallelism Strategy: Partitioning Across Two Nodes and 16 Cards

    With few devices, the choice of parallelism strategy is more sensitive than in a large cluster. A common robust starting point is four-way tensor parallelism inside each node to reduce per-layer activation and weight memory, and two-way data parallelism across the two nodes to enlarge the global batch. If the model is deep and memory is tight, add pipeline parallelism and set the number of micro-batches to two or three times the number of pipeline stages to shrink the bubble.

    Illustrative configuration (pseudocode, expressing partitioning relationships only):

    1. # Parallel dimensions: intra-node tensor parallel 4, inter-node data parallel 2
    2. parallel = dict(tp=4, dp=2, pp=1, sp=1, ep=1)
    3. global_batch = micro_batch * grad_accum * parallel["dp"]
    4. assert global_batch % (parallel["tp"] * parallel["dp"]) == 0

    Note that communication volume changes sharply with the parallelism dimensions: tensor parallelism demands high intra-node interconnect bandwidth, while pipeline parallelism is friendlier to inter-node links. In a two-node setup, place the high-communication-density partitioning inside the node first.

    4. Memory and Numerical Stability

    Estimate the memory budget from five items: weights + gradients + optimizer states + activations + temporary buffers. Mixed-precision training typically keeps single-precision master weights and optimizer momentum, while activations trade compute for memory through recomputation. A practical approach is to enable activation recomputation first to get a run through, then disable it layer by layer to find the balance point between throughput and memory.

    For numerical stability, use a smaller learning rate and a longer warmup early in training, together with gradient clipping to suppress abnormal updates. For sparse expert structures, also monitor routing entropy and expert load distribution to avoid a few overloaded experts leaving the rest of the compute idle.

    1. for step, batch in enumerate(loader):
    2. with autocast(dtype="bfloat16"):
    3. loss = model(batch).loss / grad_accum
    4. loss.backward()
    5. if (step + 1) % grad_accum == 0:
    6. clip_grad_norm_(model.parameters(), max_norm=1.0)
    7. optimizer.step(); optimizer.zero_grad(set_to_none=True)
    8. if step % 50 == 0:
    9. log(step, loss=loss.item() * grad_accum, lr=scheduler.get_lr())

    5. Fault Tolerance, Monitoring, and Cost Accounting

    Four hundred steps is only a short validation. Long-running training must solve three things: first, periodically save sharded checkpoints so that any single-card failure can recover from the most recent checkpoint; second, collect throughput, peak memory, communication wait, and loss curves into a unified logging and alerting system to form a comparable baseline; third, factor resource cost into the evaluation. Requesting compute on demand through an elastic container platform, storing datasets and checkpoints in object storage, and decoupling data preprocessing with a message queue can significantly reduce idle waste.

    In related practice at Baidu AI Cloud, these capabilities are typically assembled from general-purpose cloud product categories: a container platform hosts distributed training jobs, object storage holds checkpoints, and logging plus monitoring and alerting provide observability, so that pipeline validation can focus on the algorithm and parallelism strategy itself.

    6. Common Pitfalls Checklist

    • Version closure not locked, causing a mismatch between the communication library and the driver;
    • Global batch not divisible by the parallelism degree, or an incorrect gradient accumulation count;
    • Checkpoints not saved in sharded form, so recovery fails as soon as the topology changes;
    • Insufficient data prefetching, leaving GPUs idle while waiting on I/O;
    • Watching only the loss and not the gradient norm, which hides abnormal updates.

    7. Conclusion

    Completing several hundred training steps on a two-node, 16-card setup is essentially a pipeline health check on a “minimum viable cluster.” Make the four things solid — parallel partitioning, memory budgeting, numerical stability, and fault-tolerant monitoring — and, with the observability and storage capabilities available on general-purpose cloud, you can reproduce the pipeline stably at low cost and gradually scale it up.