Practical Guide to Training Large Models on Domestic GPUs: End-to-End Pipeline Setup

    This article explains how to establish a stable end-to-end training pipeline for large models on domestic GPU accelerators, using a two-node, sixteen-card setup as the reference environment. It covers hardware topology constraints, how to combine tensor, pipeline, data, sequence, and expert parallelism, techniques for overlapping communication with computation, mixed-precision stability mechanisms, data pipeline engineering for long-context training, fault tolerance and observability, and a staged migration path from single-card validation to full production training.

    1. Why a Working Pipeline Matters More Than Raw Speed

    When training large models on domestic accelerator hardware, the first hurdle is usually not peak compute but whether the entire pipeline can close the loop reliably. The pipeline spans data loading, tokenization and packing, forward computation, backpropagation, gradient reduction, optimizer updates, and checkpoint saving and restoration. If any stage is missing or behaves inconsistently, the symptoms are the same: loss fails to drop, steps hang, or numerical overflow appears.

    A recent industry milestone illustrates the point: a domestic accelerator platform completed a 400-step validation run of a long-context, large-parameter model training pipeline at a two-node, sixteen-card scale. The valuable signal here is not the number 400 itself, but that cross-node parallelism, mixed precision, and fault tolerance mechanisms worked together on non-mainstream hardware. For engineering teams, this shifts the migration question from “can it start” to “can it keep training.”

    2. Hardware and Topology: Constraints of a Two-Node, Sixteen-Card Setup

    A two-node, sixteen-card configuration typically means eight accelerators per node, with high-speed networking between nodes and a high-bandwidth bus inside each node. Understanding the topology is a prerequisite for tuning, because communication cost is tightly coupled to data placement.

    • Intra-node bandwidth far exceeds inter-node bandwidth, so tensor parallelism (splitting a single layer’s matrix multiplications) should stay within a node.
    • Gradient reduction for data parallelism (splitting the batch) crosses nodes and is the main source of network pressure.
    • Pipeline parallelism (splitting layers) turns cross-node communication into point-to-point transfers that are latency-sensitive.
    • Memory capacity determines whether optimizer states can stay resident, which directly affects the choice of parallelism dimensions.

    A common mistake is mapping parallelism dimensions onto devices arbitrarily, producing many small cross-node messages and very low bandwidth utilization. A sound order is: first keep the tensor parallel degree within the number of cards in a single node, then use pipeline parallelism to split layers across nodes, and finally fill the remaining cards with data parallelism.

    3. Trade-offs When Combining Parallelism Strategies

    Parallelism for large model training is fundamentally a balance among memory, communication, and computation.

    1. Data parallelism: simplest to implement, but optimizer states and gradients scale memory pressure linearly with card count, so sharded optimizer states are needed.
    2. Tensor parallelism: sharply reduces per-layer memory, but requires two collective communications per layer, the highest communication frequency of all.
    3. Pipeline parallelism: memory-friendly with low communication volume, but introduces pipeline bubbles that need enough micro-batches to amortize.
    4. Sequence parallelism: for long-context scenarios, splits the sequence dimension to relieve activation growth.
    5. Expert parallelism: used in sparse architectures, and requires handling routing imbalance and all-to-all communication.

    The pseudocode below is illustrative only; it expresses dimension relationships and does not target any specific framework API:

    1. # Parallel dimensions: the product must equal the total card count
    2. parallel = {
    3. "tensor": 4, # kept within a single node
    4. "pipeline": 2, # layers split across nodes
    5. "data": 2, # remaining cards for data parallelism
    6. }
    7. assert parallel["tensor"] * parallel["pipeline"] * parallel["data"] == 16
    8. # Micro-batch count must be large enough to amortize pipeline bubbles
    9. micro_batches = 8
    10. global_batch = micro * parallel["data"] * grad_accum_steps

    4. Overlapping Communication and Computation: Hiding the Wait

    In multi-node training, the performance bottleneck is usually communication. Practical optimizations include:

    • Bucket gradients and reduce them in order, splitting large transfers into smaller chunks that can overlap;
    • Trigger reduction layer by layer during backpropagation to overlap computation and communication;
    • Use unified memory or a memory pool to reduce jitter from repeated allocation and release;
    • Recompute activations to trade compute for memory, avoiding forced reductions in parallelism caused by insufficient memory;
    • Fix communication buffers to avoid latency spikes from per-step dynamic allocation.

    Recomputation is not a case of more is better. Excessive recomputation multiplies forward compute and lengthens per-step time. A practical approach is to measure available memory headroom first, then enable recomputation gradually while watching whether the per-step time curve keeps dropping.

    5. Numerical Stability: Using Mixed Precision Correctly

    Half-precision training significantly improves throughput, but it requires stability mechanisms; otherwise loss spikes can appear within 400 steps.

    • Keep master weights in single precision, and use half precision for forward and backward passes;
    • Use dynamic loss scaling that automatically backs off and adjusts the scale factor on overflow;
    • Keep normalization layers and summation reductions in single-precision accumulation to avoid accumulation error over long sequences;
    • Clamp the numerical range of exponential terms in attention computation first;
    • Apply gradient clipping by global norm to suppress the impact of abnormal batches.
    1. # Pseudocode: dynamic loss scaling with overflow backoff
    2. scaled_loss = loss * scale
    3. scaled_loss.backward()
    4. if has_overflow(grads):
    5. scale = scale * 0.5
    6. skip_step()
    7. else:
    8. optimizer.step()
    9. scale = min(scale * 1.1, max_scale)

    6. Data Engineering: Where Throughput Actually Starts

    Even the best compute is dragged down by insufficient data supply. Long-context training is especially sensitive to sample packing:

    • Use variable-length sample concatenation with position interval markers to avoid cross-sample attention contamination;
    • Decouple data sharding from parallelism dimensions so that samples are neither duplicated nor omitted under any parallel configuration;
    • Store pre-tokenized results in object storage, leaving the training side with sequential reads and lightweight decoding;
    • Record data versions and random seeds to keep experiments reproducible;
    • Set up multi-level prefetching for data reads to hide storage latency.

    7. Fault Tolerance and Observability: Continuing Past Step 400

    A short run is only the start; long training cycles depend on fault tolerance design:

    • Save checkpoints triggered by both fixed step counts and elapsed time, writing asynchronously to avoid blocking training;
    • A checkpoint must include the model, optimizer, random state, and data cursor, with none missing;
    • After a node failure, the scheduling layer relaunches and resumes from the latest checkpoint;
    • Collect per-step time, memory level, communication bandwidth, and loss curves through monitoring and alerting;
    • Centralize stack traces in a logging service to quickly determine whether the issue is data, communication, or an operator.

    For teams migrating training to domestic hardware, a staged approach is recommended:

    1. Validate operator correctness and numerical consistency on a small single-card setup;
    2. Validate tensor parallelism and memory sharding on a single node with multiple cards;
    3. Validate cross-node communication and pipeline scheduling at the two-node, sixteen-card scale;
    4. Extend to stability observation over dozens of steps or more, confirming no slow drift;
    5. Add full fault tolerance and monitoring before entering formal training.

    In cloud environments, a container platform can handle environment固化, object storage can hold datasets and checkpoints, and monitoring, alerting, and logging services provide observability, letting teams focus on the two areas that truly decide success: parallelism strategy and numerical stability. Baidu AI Cloud’s general compute and storage combination for this kind of training scenario can serve as an infrastructure-level reference option.