Optimizing a Two-Node, 16-GPU LLM Training Pipeline: From Communication to Validation
As large language models grow, a single server often cannot hold the complete training state. A two-node, 16-GPU setup has therefore become a common starting point for many teams. Stable and efficient training at this scale depends on coordinating topology, communication, parallelism, memory usage, and fault tolerance. This article uses the optimization of a large language model on a two-node, 16-GPU cluster as an example, outlining what to check at each stage and which metrics can be used for validation. The parameter values mentioned are examples only; actual configurations should be verified against the specific hardware and software versions in use.
1. Verify the Hardware Topology First
Before starting training, determine how the GPUs inside each server are connected. Accelerators may be linked through NVLink, NVSwitch, PCIe switches, or other dedicated interconnects, and the bandwidth differences between these paths can be substantial.
NVLink usually provides much higher bandwidth than paths that traverse PCIe. This has a particularly significant impact on tensor parallelism, where communication is required at every layer. The following commands can help inspect the topology:
nvidia-smi topo -mlspcinumactl --hardware
nvidia-smi topo -m shows the connection relationships between GPUs, lspci displays the PCI device tree, and numactl --hardware shows the NUMA nodes and their associated memory.
When binding processes, place the GPUs belonging to the same tensor-parallel group on the same set of high-speed links. If the hardware allows it, keep them within the same NUMA node as well to reduce the overhead of cross-node memory access. NUMA placement is an optional optimization and depends on the actual hardware topology. Link quality and bandwidth should take priority.
2. Node-to-Node Networking: Distinguish RoCEv2 from InfiniBand
RDMA is commonly used for communication between two servers. RoCEv2 runs over Ethernet, while InfiniBand is a separate networking architecture. Their tuning methods are different and should not be mixed.
For RoCEv2, the switches should be configured with Priority Flow Control (PFC) and Explicit Congestion Notification (ECN). The goal is to build a lossless Ethernet network and reduce retransmissions caused by packet loss. Incorrect PFC settings can cause deadlocks or congestion spreading, so stress testing should be performed before production deployment. During testing, monitor the switch pause-frame counters. Also verify that the GID index used by the network adapter matches the switch deployment design.
For InfiniBand, follow the vendor’s deployment guidance and use its native congestion-control, service-level (SL), and QoS settings. InfiniBand should not be configured by directly applying PFC and ECN settings intended for Ethernet networks.
RPS and RFS are Linux kernel mechanisms for distributing TCP/IP receive traffic across queues. They only apply to traffic that passes through the kernel network stack. RDMA traffic bypasses that stack, so changing RPS or RFS will not improve RDMA bandwidth.
For RoCE and InfiniBand, more relevant items include the network adapter’s MTU, queue and interrupt affinity, and the performance tools provided by the vendor. For example, ib_write_bw can be used to measure point-to-point bandwidth. The measured result should be used as the basis for evaluation.
3. Parallelism Strategy: Combining ZeRO, TP, and DP
At the 16-GPU scale, a single parallelism strategy is often insufficient. The configuration used in this example combines ZeRO with tensor parallelism (TP) and data parallelism (DP).
Tensor parallelism splits an individual matrix multiplication across multiple GPUs. Because every forward and backward pass requires collective communication, TP has a high communication frequency and is best placed on fast intra-node links.
Data parallelism synchronizes gradients across multiple model replicas. Its communication frequency is lower, but each synchronization can involve a larger amount of data. In this example, data-parallel communication is performed across nodes.
ZeRO partitions parameters, gradients, and optimizer states across the GPUs in the data-parallel group, reducing the memory consumption of each GPU.
Terminology should be used precisely. “3D parallelism” generally refers to the combination of data parallelism, tensor parallelism, and pipeline parallelism (PP). Because this setup uses ZeRO, TP, and DP only, “hybrid parallelism” is the more accurate term.
If pipeline parallelism is introduced later, the team must additionally determine the number of layers assigned to each stage and the number of micro-batches, then revalidate the pipeline bubble ratio and overall throughput.
4. Memory Management: Activation Checkpointing and the Allocator
Large-model training can easily encounter out-of-memory (OOM) errors. ZeRO-3 reduces the memory used by parameters, gradients, and optimizer states, but activations can still consume a significant amount of GPU memory.
Activation checkpointing is a common solution. During the forward pass, only activations from selected layers are stored. The remaining activations are recomputed during the backward pass. This trades additional computation for lower memory usage. The overhead depends on the checkpointing granularity, so the impact on throughput should be measured on the actual model before deciding how broadly to apply it.
Memory fragmentation can also cause failures. PyTorch’s caching allocator retains previously allocated memory, and after a long-running process has performed many allocations, the total amount of free memory may be sufficient while no contiguous block is large enough for a new allocation.
Options such as expandable_segments in PYTORCH_CUDA_ALLOC_CONF may help improve allocation behavior. Their effectiveness should be evaluated with torch.cuda.memory_stats() or nvidia-smi.
When investigating an OOM error, use the following order:
- Confirm that activation checkpointing is actually enabled.
- Reduce the per-GPU batch size.
- Check whether the sequence length is higher than expected.
- Consider a more aggressive partitioning strategy.
5. Initialization and Fault Tolerance
Distributed training depends on a global process group. The initialization and fault-tolerance configuration should be validated as part of the training pipeline rather than treated as an afterthought.
