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

    This article walks through the engineering work required to get a full large model training loop running on domestic accelerator cards, using a two-node, sixteen-GPU, 400-step run as the acceptance baseline. It covers three-layer environment alignment across drivers, runtime, and operator libraries; how to choose and combine data, tensor, and pipeline parallelism; correct mixed-precision settings for numerical stability; data pipeline throughput; observability and checkpointing for fault tolerance; and a troubleshooting order for common failures such as hangs, NaN loss, out-of-memory errors, and throughput jitter.

    1. Why Getting the Training Loop Working Matters More Than Raw Speed

    Adapting large model training to domestic accelerator cards typically goes through three stages: first make single-GPU operators correct, then make single-node multi-GPU communication correct, and only then talk about multi-node scaling efficiency. Many teams get stuck at the second stage, and the cause is usually not a lack of compute but a semantic mismatch somewhere in the pipeline.

    “Getting the training loop working” means the entire closed loop — data loading, forward pass, backward pass, gradient synchronization, parameter update, and checkpoint save and restore — can run continuously, stably, and reproducibly for several hundred steps, with a loss curve that matches expectations. Only when the loop is closed does subsequent performance tuning become meaningful.

    Two nodes with sixteen GPUs and 400 steps is a representative validation scale: it is large enough to expose cross-node communication issues, memory fragmentation, and uneven data sharding, without consuming excessive resources. The key points are broken down below in engineering order.

    2. Environment Foundation: Aligning Drivers, Runtime, and Operator Libraries

    The difficulty of adapting to domestic compute concentrates on “three-layer alignment”: the driver layer, the runtime layer, and the operator library layer. In practice, it is advisable to fix one validated version combination and bake it into a container image to avoid environment drift across machines.

    • Drivers and firmware: unify versions, run a startup self-check, and confirm that the multi-GPU topology and interconnect bandwidth meet expectations.
    • Runtime and communication libraries: confirm that cross-node communication uses the high-speed network rather than falling back to the management interface. This is the first determining factor for multi-node scaling efficiency.
    • Operator libraries and framework adaptation layer: prioritize the officially maintained operator coverage list, and substitute missing operators with equivalent combinations rather than falling back directly to host-side computation.

    A minimal environment self-check script:

    1. import os, torch
    2. def env_check():
    3. assert torch.cuda.is_available(), "Accelerator cards are not visible"
    4. n = torch.cuda.device_count()
    5. print("Visible GPU count:", n, "Local rank:", os.environ.get("RANK"))
    6. # Run a small matrix multiplication on each GPU to confirm operators work
    7. for i in range(n):
    8. a = torch.randn(512, 512, device=f"cuda:{i}")
    9. b = torch.mm(a, a).sum().item()
    10. assert b == b, f"Unexpected result on GPU {i}"
    11. print("Environment self-check passed")

    3. Parallelism Strategy: Data Parallelism as the Base, Tensor and Pipeline Parallelism as Needed

    The most common combination on two nodes with sixteen GPUs is “data parallelism + tensor parallelism” or “data parallelism + pipeline parallelism.” The choice depends not on the GPU count but on model size and the remaining memory per GPU.

    • Data parallelism: each GPU holds a full model replica, and gradients are synchronized via all-reduce. It is simple to implement but puts the most pressure on memory and communication bandwidth, making it suitable for small and medium models.
    • Tensor parallelism: splits a single layer’s matrices across GPUs with frequent communication. It is strongly recommended to keep it within a single node to avoid amplifying cross-node traffic.
    • Pipeline parallelism: splits by layer with micro-batch scheduling, which can significantly reduce per-GPU memory but requires careful handling of bubbles and load balancing.
    • Memory optimization: activation recomputation, optimizer state sharding, and mixed precision are typically used in combination.

    An abstract representation of a parallel configuration:

    1. config = {
    2. "dp_size": 8, # Data parallel size
    3. "tp_size": 2, # Tensor parallel size; should not cross nodes
    4. "pp_size": 1, # Pipeline parallel size
    5. "micro_batch": 2,
    6. "grad_accum": 8, # Gradient accumulation to effectively enlarge the global batch
    7. "amp_dtype": "bfloat16",
    8. }
    9. assert config["dp_size"] * config["tp_size"] * config["pp_size"] == 16

    4. Numerical Stability: Using Mixed Precision Correctly

    Mixed precision is where problems most often appear when adapting to domestic cards. bfloat16 has a wide dynamic range and low precision loss, so it is usually the first choice. If float16 is used, loss scaling is required, and gradient underflow must be monitored.

    • Keep float32 accumulation for key operators such as normalization, loss computation, and optimizer updates.
    • Use dynamic loss scaling factors, with automatic fallback when overflow occurs repeatedly.
    • Print the gradient norm every few steps; abnormal growth often appears before the loss diverges.
    1. scaler = torch.cuda.amp.GradScaler(init_scale=2**16, growth_factor=2.0)
    2. for step, batch in enumerate(loader):
    3. with torch.cuda.amp.autocast(dtype=torch.bfloat16):
    4. loss = model(batch).loss
    5. scaler.scale(loss).backward()
    6. scaler.step(optimizer); scaler.update(); optimizer.zero_grad()

    5. Data Engineering: Throughput Sets the Ceiling

    Whether 400 steps complete smoothly often depends on a stable data supply. It is recommended to preprocess the dataset into a fixed-length shard format, store it on object storage or a local high-speed cache disk, and use multi-process prefetching on the training side with a fixed random seed for reproducibility. The number of shards should ideally be an integer multiple of the parallelism degree to avoid some GPUs idling and causing synchronization waits.

    6. Observability and Fault Tolerance: Turning 400 Steps into a Deliverable Result

    • Metrics to monitor: per-GPU memory usage, interconnect bandwidth utilization, per-step time, loss, and gradient norm.
    • Logging and alerting: connect to a general-purpose logging service and monitoring and alerting capabilities so that anomalies trigger automatic notifications.
    • Checkpoints: save at fixed step intervals, including the model, optimizer, learning rate schedule, and data cursor, to ensure consistent resumption from a checkpoint.
    • Reproducibility: record the image version, configuration hash, and random seed to form a traceable experiment record.

    7. Common Failures and Troubleshooting Order

    1. Hanging with no progress: first check whether cross-node communication has fallen back to a low-speed link.
    2. NaN loss: check mixed precision and the accumulation precision of key operators.
    3. Out of memory: first reduce the micro-batch, then enable activation recomputation, and finally adjust the parallel split.
    4. Throughput jitter: check whether data shards are balanced and whether there are enough prefetch threads.

    8. Conclusion

    Getting the large model training loop working on domestic compute is essentially a systems engineering exercise: environment alignment determines whether training can start, the parallelism strategy determines whether it can scale, numerical stability determines whether it can converge, and observability determines whether results can be delivered. Using two nodes with sixteen GPUs and 400 steps as the acceptance baseline, together with general-purpose foundational capabilities on Baidu AI Cloud such as container platforms, object storage, and monitoring and alerting, teams can turn a one-off validation into a reusable training pipeline and build a reliable foundation for larger-scale training later.