Getting Large Model Training Working on Domestic GPUs: A Practical Walkthrough
This article explains why closing the end-to-end training loop matters more than chasing peak compute when running large model training on domestic GPUs. It covers environment preparation, parallel strategy trade-offs between memory and communication, numerical stability under mixed precision, observability and fault localization, and a four-hundred-step acceptance checklist across two nodes with sixteen GPUs.
1. Why a Closed Loop Matters More Than Raw Speed
In large-scale pretraining engineering, a common mistake is to focus all attention on peak compute while ignoring whether the end-to-end loop is actually closed. A closed loop means the entire path — data loading, graph construction, parallel partitioning, backpropagation, gradient reduction, optimizer update, and checkpoint save and restore — runs reliably back and forth on the target hardware. Only when this path completes hundreds of iterations in a row with a smooth loss curve, no steady growth in memory usage, and no periodic collapse in throughput are you in a position to discuss performance tuning.
Take a run of four hundred iterations on two nodes with sixteen GPUs. The choice of this scale is itself an engineering decision: it is large enough to expose problems that only surface after multiple rounds of iteration, such as cross-node communication, memory fragmentation, and numerical overflow, yet small enough to produce a conclusion within a short time window. That makes it a suitable acceptance baseline for hardware and software adaptation.
2. Environment Preparation: Move Uncertainty Forward
The cost of debugging the loop is often determined at the environment stage. It helps to narrow down variables in the following order:
- Align driver, runtime, and communication library versions. The driver version, runtime version, and collective communication library version on both machines must be exactly identical. Any subtle difference can show up as an intermittent hang.
- Confirm the network topology. Establish the number of NICs, link bandwidth, and whether traffic crosses switch tiers, then choose the communication backend and timeout thresholds accordingly.
- Isolate dependencies. Use containers or a dedicated virtual environment to pin dependencies and avoid system-level package pollution.
- Run a single-node self-check. Get a small-scale task working on multiple GPUs within one machine first, then extend to multiple nodes, enlarging the fault domain layer by layer.
The startup logic below is illustrative and only expresses structure, not a specific API:
# Pseudocode: minimal skeleton of a training entry pointfor step in range(total_steps):batch = next(dataloader)with autocast(dtype="bfloat16"):loss = model(batch).lossloss.backward()optimizer.step()optimizer.zero_grad(set_to_none=True)if step % save_every == 0:save_checkpoint(step)if step % log_every == 0:log(step, loss, grad_norm, throughput)
3. Parallel Strategy: A Two-Dimensional Trade-off Between Memory and Communication
Single-node multi-GPU setups usually start with tensor parallelism to reduce per-layer memory pressure, scale throughput across nodes with data parallelism, and add pipeline parallelism to split layers when necessary. Three constraints govern how these combine:
- The degree of tensor parallelism is limited by the number of GPUs per node and the inter-GPU interconnect bandwidth. Over-partitioning introduces a large volume of small-message communication and costs more than it saves.
- The gradient reduction volume of data parallelism is proportional to the parameter count. When cross-node bandwidth is insufficient, consider gradient compression or bucket overlap first.
- Pipeline parallelism amplifies the bubble ratio, so the number of micro-batches must match the number of layers.
In practice, the safer approach is to confirm numerical correctness with a smaller parallel degree first, then raise the parallel degree step by step and watch for the inflection point in the throughput curve.
4. Numerical Stability: Using Mixed Precision Correctly
The risks of half-precision training concentrate in three places: gradient underflow, insufficient precision in optimizer states, and drift in normalization statistics. Common mitigations include maintaining single-precision master weights, setting a reasonable loss scaling strategy, and keeping higher precision for normalization layers and residual branches. In a short four-hundred-step validation run, record gradient norms and activation distributions as you go. If a norm jumps by an order of magnitude, localize the problem to the specific module immediately rather than rolling back the whole run.
5. Observability and Fault Localization
Long-loop debugging depends on data. Collect at least four categories of metrics: a breakdown of per-step time (compute, communication, data wait), peak memory and fragmentation rate, gradient norm, and throughput as a function of step count. When a hang occurs, check first whether collective communication is in a mismatched state. When throughput looks jagged, suspect contention for bandwidth between data loading and checkpoint writes. Write checkpoints asynchronously to object storage, and keep the most recent few so you can roll back quickly.
6. Acceptance Checklist
- Four hundred consecutive steps without interruption, with loss decreasing monotonically or staying flat;
- No continuous memory growth, and controllable variance in per-step time;
- Recovery from the latest checkpoint after an interruption, with loss continuing seamlessly;
- A complete metrics dashboard and reproducible experiment records.
Once this loop is closed, move on to hyperparameter search and performance tuning. The overall efficiency will be significantly better than tuning from the very start. The combination of general capabilities such as container platforms, object storage, and monitoring and alerting on Baidu AI Cloud can provide standardized infrastructure support for this kind of training validation.
