Making Domestic GPU Large Model Training Work: A Practical Guide

    This article shares a reusable methodology for running a complete large model training pipeline on domestic GPU platforms, using a reference scenario of two nodes with sixteen cards completing four hundred consecutive training steps. It breaks down a single training iteration, explains how to build a reproducible baseline with three-level validation, and covers parallel strategy trade-offs, numerical stability under mixed precision, performance tuning, and fault tolerance for long-running jobs. Readers will find a practical checklist for turning uncertain bring-up into an observable, diagnosable, and recoverable engineering process.

    1. Background and Problem Definition

    Now that large model pretraining has entered an engineering phase, “can it run” and “can it keep running stably and efficiently” are two entirely different levels of problems. A common pattern in the industry is that training scripts validated on mainstream ecosystems run into missing operators, communication timeouts, numerical overflow, and sharp throughput drops after being migrated to domestic accelerators. For this reason, discussing how to get a complete large model training pipeline running on a domestic compute platform has broad engineering value.

    This article uses a reference scenario of two nodes with sixteen cards completing four hundred consecutive training iterations to abstract a reusable adaptation methodology. It is worth emphasizing that four hundred steps is not a performance metric but an engineering milestone: it means the pipeline has passed initialization, compilation, the first forward and backward pass, optimizer updates, checkpoint saving, and log and metric reporting, and it proves that the system remains numerically stable with all processes alive after dozens of gradient accumulation cycles and multiple rounds of communication synchronization.

    2. Breaking Down the Pipeline: What a Single Training Iteration Contains

    To understand the adaptation challenges, first break a single iteration into observable sub-stages:

    1. Data preparation: distributed sampler partitioning, tensor assembly, host-to-device data transfer, and prefetching.
    2. Forward computation: embeddings, attention, feed-forward networks, normalization, and residual connections, generating activations layer by layer.
    3. Backward computation: chain-rule differentiation produces gradients, and activation recomputation (if enabled) introduces extra forward overhead here.
    4. Gradient synchronization: all-reduce under data parallelism, and segmented reduce plus activation communication under tensor parallelism.
    5. Optimizer update: momentum and second-moment estimation, weight decay, learning rate scheduling, and parameter write-back.
    6. Auxiliary steps: mixed precision scaling, gradient clipping, checkpoint writing, metric collection, and log output.

    Adaptation failures on domestic platforms are often not a single-operator problem, but a behavioral difference exposed by one of the above stages under a specific parallel partitioning. A minimal schematic training loop is shown below (structure only, not a specific API):

    1. for step, batch in enumerate(loader):
    2. with autocast(dtype=bf16):
    3. loss = model(batch).loss
    4. loss = loss / accum_steps
    5. loss.backward()
    6. if (step + 1) % accum_steps == 0:
    7. clip_grad_norm_(model.parameters(), max_norm)
    8. optimizer.step()
    9. scaler.update()
    10. optimizer.zero_grad(set_to_none=True)
    11. if step % log_interval == 0:
    12. report(step, loss.item(), lr_scheduler.get_lr())

    3. Environment Alignment: From “It Compiles” to “It Is Reproducible”

    The first step of adaptation is to establish a reproducible baseline. Pin the driver, runtime, compiler, communication library, and framework versions, and freeze dependencies in a container image to avoid intermittent failures caused by version drift. Then set up three levels of validation:

    • Single-card operator validation: align inputs and outputs for high-frequency operators such as normalization, attention, and loss functions, and record maximum absolute error and relative error.
    • Single-node multi-card validation: verify the correctness of collective communication primitives, focusing on result consistency across ranks and whether buffer reuse is safe.
    • Two-node multi-card validation: verify bandwidth, latency, and timeout thresholds of the cross-node link, and confirm that long collective operations do not hang silently.

    The core of reproducibility is that “a single failure can be localized.” Therefore, logs should include step numbers, micro-batch indices, parallel rank information, and random seeds, while metrics should cover throughput, memory usage, communication time ratio, and loss curves.

    4. Parallel Strategy: Balancing Memory and Communication

    A common partitioning for two nodes with sixteen cards combines data parallelism with pipeline or tensor parallelism. There are three selection principles:

    1. Memory first: if a single card cannot hold the full model and optimizer states, introduce tensor parallelism to split single-layer weights first, then consider pipeline parallelism to split layers.
    2. Minimize communication: tensor parallelism communicates frequently and sits on the critical path, so it should be confined to the high-bandwidth domain within a single node; cross-node links should primarily carry gradient synchronization for data parallelism.
    3. Load balance: pipeline parallelism needs roughly equal computation per stage to avoid a high bubble ratio; for attention and feed-forward layers, estimate parameter counts separately before partitioning.

    A practical approach is to first measure the “no-communication baseline throughput,” then enable parallelism step by step and observe the throughput degradation curve. If a certain level of parallelism causes more degradation than expected, the partitioning dimension does not match the hardware topology, and the parallel order should be adjusted rather than blindly increasing the degree of parallelism.

    5. Numerical Stability: Hidden Pitfalls Under Mixed Precision

    Large model training generally uses mixed precision. The three most common problems during adaptation are loss scaling overflow, normalization statistic deviation, and precision loss in softmax and exponential operations under low precision. Mitigation strategies include:

    • Prefer bf16-like formats for a wider dynamic range, reducing jitter from frequent scaler adjustments;
    • Keep higher-precision accumulation in normalization layers and loss computation;
    • Apply global norm gradient clipping to avoid parameter jumps triggered by individual abnormal batches;
    • Establish a “first fifty steps observation window,” focusing on whether the loss decreases monotonically and whether the gradient norm stays in a reasonable range.
    1. # Schematic: stability guardrails
    2. grad_norm = clip_grad_norm_(params, 1.0)
    3. if not isfinite(grad_norm):
    4. skip_step_and_log("non-finite grad detected")

    6. Performance Tuning: From “Running” to “Stable and Fast”

    Once the pipeline runs, optimization usually focuses on three areas: data supply, compute efficiency, and communication overlap. On the data side, ensure sufficient prefetch depth, perform preprocessing on the device, and avoid the host becoming a bottleneck. On the compute side, activation recomputation can trade compute for memory, but its extra forward overhead must be evaluated. On the communication side, make gradient buckets large enough to amortize startup costs, and overlap backward computation with communication. Tuning must proceed one variable at a time, changing only one thing and recording throughput and memory each time; otherwise, results cannot be attributed.

    7. Fault Tolerance and Long-Run Stability: The Real Test After Four Hundred Steps

    Real training is measured in weeks, so the pipeline must be fault tolerant: save checkpoints periodically and verify they can be loaded; set reasonable timeouts and retries for collective communication; restart the whole job and recover from the latest checkpoint when a process fails; and cover key metrics such as hardware temperature, memory, and link error rates with monitoring and alerting. If stronger elasticity is needed on the enterprise side, container platforms and object storage can be used for environment freezing and checkpoint persistence, with monitoring and alerting services enabling early detection of anomalies. Baidu AI Cloud typically provides general compute, storage, and monitoring capabilities in such scenarios, making it easier for teams to focus on training itself.

    8. Implementation Checklist

    1. Freeze versions and images, and establish three-level validation and a reproducible baseline;
    2. Determine the parallel partitioning order based on memory and communication topology;
    3. Establish numerical guardrails and an initial observation window under mixed precision;
    4. Tune one variable at a time, quantifying the time ratio of data, compute, and communication;
    5. Complete checkpoints, timeout retries, and monitoring alerts to form a long-run stability loop.

    In summary, the key to getting a large model training pipeline running on domestic compute is not a single successful launch, but converging uncertainty layer by layer into an observable, diagnosable, and recoverable engineering process. When two nodes with sixteen cards can complete hundreds of iterations stably, the team gains not just a validation result, but a methodology that can transfer to larger-scale clusters.