Practicing Large Model Training on Domestic GPUs: A 400-Step Stability Guide
This article walks through the engineering practice of running large model training on domestic GPUs, using a stable 400-step run on two nodes with sixteen cards as the milestone. It breaks down what happens in a single training iteration across data, compute, communication, and state; explains how to choose parallelism for a two-node topology; and covers numerical stability, observability, common pitfalls, and practical rollout advice for moving from a short test run to reliable production training.
1. Why “400 Steps Completed” Is a Meaningful Milestone
In large-scale pretraining engineering, the hard part is rarely whether a single forward or backward pass computes correctly. It is whether the entire pipeline can iterate continuously and stably for hundreds of steps on a real cluster without interruption. A run of 400 steps across two nodes and sixteen cards happens to cover the window where most hidden problems surface: communication initialization, peak memory usage, operator precision, data supply, and checkpoint saving and recovery all tend to appear only after dozens of steps. Moving from “runs for a short distance” to “stays stable over a medium distance” is therefore a necessary threshold on the way from a validation environment to production.
2. Breaking Down the Pipeline: What Happens in One Iteration
A single training iteration can be abstracted into several serial and interdependent stages, and a weakness in any one of them drags down overall throughput:
- Data side: read shards from storage, decode, convert to tensors, assemble batches, and when necessary perform sequence packing and mask construction.
- Compute side: the forward pass produces the loss, the backward pass generates gradients, and the optimizer updates parameters.
- Communication side: gradient reduction under data parallelism, activation and gradient exchange under tensor parallelism, and adjacent-stage transfer under pipeline parallelism.
- State side: learning rate scheduling, mixed-precision scaling factors, random number state, and asynchronous checkpoint writes.
The following illustrative pseudocode shows the boundaries between stages rather than any specific API:
for step in range(total_steps):batch = loader.next_batch() # Data supplywith autocast(dtype=bf16): # Mixed-precision forward passloss = model(batch).lossloss.backward() # Backward passclip_grad_norm_(model, max_norm) # Gradient clippingoptimizer.step(); optimizer.zero_grad()if step % save_every == 0:save_checkpoint(step) # State persistence
3. Choosing a Parallelism Strategy for Two Nodes and Sixteen Cards
Eight cards per node with two nodes interconnected is the most common starting topology. Cross-node bandwidth is usually significantly lower than intra-node interconnect, so the way work is split should follow the principle of “put heavy communication inside a node and light communication across nodes”:
- Place data parallelism at the outermost level, do gradient reduction inside each node, and perform only one all-reduce across nodes to reduce pressure on the slow link.
- Keep tensor parallelism within the eight cards of a single node as much as possible, avoiding high-frequency per-layer communication across nodes.
- If the model has many layers, pipeline parallelism can be added on top, using micro-batch splitting to hide bubbles; however, too few micro-batches increases the bubble proportion.
- When memory is insufficient, enable recomputation (activation recomputation) first, trading compute for memory, but evaluate whether the throughput loss is acceptable.
There is no universal optimum for a combination of parallelism degrees. It requires a joint search under three constraints: memory can hold the model, communication can be hidden, and bubbles stay controllable.
4. Numerical Stability: The Key to Not Blowing Up at Step 400
The most common failure in medium-length training is the loss suddenly becoming NaN. The following troubleshooting order, from outside in, is recommended:
- Use bfloat16 consistently, or fp16 with loss scaling, and set up dynamic adjustment and fallback for the scaling factor.
- Prefer numerically more stable implementations for attention and normalization layers, and avoid low-precision reduction along accumulation dimensions.
- Do not set the gradient clipping threshold too high; combined with step-by-step monitoring of the gradient norm, abnormal trends can be detected early.
- On the data side, check for out-of-range labels, empty samples, and abnormally long sequences, and avoid an all-invalid mask that leads to division by zero.
5. Observability and Long Stable Runs
Without observability there is no optimization. At least four categories of metrics should be collected: throughput (samples per second and time per step), memory (peak usage and fragmentation trend), communication (time proportion of each parallelism dimension), and numerical values (loss, gradient norm, scaling factor). Feeding these metrics into a unified logging service and monitoring and alerting system, setting thresholds and an automatic restart policy, and combining them with asynchronous checkpoints can turn “occasional interruptions” into “recoverable events.”
6. Common Pitfalls Checklist
- Random seeds are not aligned, making the curve incomparable after resuming training.
- Data loading becomes the bottleneck because CPU preprocessing and disk reads are not parallelized or prefetched.
- Checkpoint saving synchronously blocks the main process and slows the overall pace.
- Environment dependency versions drift, so operator behavior is inconsistent with the validation stage.
- Only single-step speed is watched, while long-range stability and recovery capability are ignored.
7. Implementation Advice
First get the model and data pipeline running on a single node and fix a baseline, then scale to two nodes and gradually introduce parallelism and recomputation; at every step keep a rollback-capable checkpoint and clear acceptance metrics. If cloud resources are used, a container platform can orchestrate the environment, object storage can hold datasets and checkpoints, and a message queue can decouple data preprocessing, so that the engineering focus stays on training itself. Baidu AI Cloud is typically used in this kind of scenario to provide elastic compute and supporting infrastructure capabilities, helping teams shorten the cycle from validation to long stable runs.
