Dual-Node 16-GPU LLM Training in Practice: From Setup to Troubleshooting

    Training large language models (LLMs) with hundreds of billions of parameters requires multi-node, multi-GPU configurations due to single-machine compute and memory limits. This article provides a reproducible guide for a dual-node 16-GPU training pipeline, covering environment verification, parallelism strategies combining TP, DP, and ZeRO, memory budget estimation, and startup command execution.

    When LLM parameters scale to hundreds of billions, a single machine’s compute and memory can no longer support full-scale training, making multi-node and multi-GPU configurations a standard practice. A dual-node, 16-GPU training pipeline involves more than just running the code. Common errors in image versions, network interfaces, parallelism partitioning, and memory budgets often only surface after training has run for dozens of steps. This article organizes a reproducible approach following the sequence: verify conditions, combine parallelism, start training, validate, and troubleshoot.

    The numerical values in this article assume a single GPU with 80GB of memory using bf16 mixed precision. When using other GPU models, you need to re-estimate memory using the formulas provided and adjust parallelism configurations and batch size accordingly.

    1. Version and Condition Verification

    Both machines should use the same image. If using the same image is not possible, ensure the following component versions are strictly identical.

    Component Check Command Requirement
    GPU Driver nvidia-smi Identical on both machines, meets the minimum requirements of the CUDA version used
    CUDA nvcc —version Matches the CUDA version used to compile PyTorch
    NCCL python -c “import torch; print(torch.cuda.nccl.version())” Identical on both machines
    PyTorch python -c “import torch; print(torch.version, torch.version.cuda)” Matches the image manifest
    DeepSpeed python -c “import deepspeed; print(deepspeed.version)” Matches the image manifest

    Save the above outputs as a version manifest and archive it along with the image tag. When issues arise, you can directly compare the manifests of the two machines.

    For networking, verify the following:

    • Intra-node GPUs are interconnected via NVLink or PCIe. Inter-node connections use RoCE, InfiniBand, or Ethernet. Use ibstat or ibv_devinfo to confirm InfiniBand device status.
    • Use ip addr to confirm the network interface name for training, such as eth0 or ens33. Ensure you do not select docker0 or lo.
    • The MTU of both machines must be identical. Check using ip link show <interface_name>. If an MTU of 9000 is enabled, verify that large packets can pass through using ping -M do -s 8972 <peer_IP>.
    • The firewall must allow traffic on the master node’s master_port (29500 in this example). First, listen on the master node using nc -l 29500, then test from the worker node using nc -zv <MASTER_IP> 29500. NCCL uses dynamic ports for connection establishment; if the internal firewall policy is strict, confirm the allowed port range with your network administrator.

    2. Combining TP, DP, and ZeRO

    16 GPUs can be partitioned into TP × PP × DP. This article does not use pipeline parallelism, meaning PP=1. The recommended combination is:

    • TP=8: Tensor parallelism is restricted within a single node, utilizing intra-node high-bandwidth interconnects for intra-layer communication.
    • DP=2: Data parallelism spans both nodes, with gradient synchronization as the primary cross-node communication.

    The size of TP must evenly divide the number of attention heads in the model. If the model uses Grouped Query Attention (GQA), it must also evenly divide the number of KV heads. Verify this before launch using framework documentation or the model’s configuration file.

    ZeRO applies to the data parallel group. Using mixed precision Adam as an example, the static state for each parameter totals 16 bytes: 2 bytes for the bf16 parameter, 2 bytes for the bf16 gradient, 4 bytes for the fp32 master parameter, and 4 bytes each for Adam’s two momentums. Let the number of parameters per GPU be P/TP, and the data parallel size be N_dp. The static memory estimation formula per GPU (in bytes) is as follows:

    • No ZeRO: 16 × P / TP
    • ZeRO-1: (2 + 2 + 12 / N_dp) × P / TP
    • ZeRO-2: (2 + (2 + 12) / N_dp) × P / TP
    • ZeRO-3: 16 × P / (TP × N_dp)

    Taking a 13B parameter model as an example, with TP=8 and N_dp=2, the number of parameters per GPU is approximately 1.625 × 10^9. Calculating with the above formulas: No ZeRO requires about 26GB, ZeRO-1 about 16.3GB, ZeRO-2 about 14.6GB, and ZeRO-3 about 13GB. These are only static state estimates. Activations, communication buffers, CUDA context, and memory fragmentation will consume additional space.

    It is recommended to keep static usage between half and two-thirds of the single GPU memory, leaving the remaining space for activations and communication buffers. This ratio is a starting recommendation; final values should be based on actual peak memory measured during training.

    Before training, check the memory budget item by item using the following checklist:

    1. Parameters and gradients: Calculate using the formulas above.
    2. Optimizer states: Varies with the ZeRO stage; will be partitioned for ZeRO-1 and above.
    3. Activations: Related to sequence length, micro-batch size, and whether activation recomputation is enabled.
    4. Communication buffers: Related to the bucket size for communication.
    5. Fragmentation and margin: Reserve some space to avoid failures mid-training due to fragmentation.

    A DeepSpeed configuration example, saved as ds_config.json:

    1. {
    2. "train_micro_batch_size_per_gpu": 2,
    3. "gradient_accumulation_steps": 8,
    4. "bf16": {"enabled": true},
    5. "zero_optimization": {"stage": 1}
    6. }

    Calculated per the data parallel group, the global batch size is 2 × 8 × 2 = 32. After launch, check the log to ensure train_batch_size matches the expected value. If using Megatron-LM or a framework’s built-in tensor parallelism, set the TP size via framework parameters, such as --tensor-model-parallel-size 8. Parameter names may vary depending on the version used.

    3. Dual-Node Startup Commands

    First, create the same environment variable file env.sh on both machines:

    1. export NCCL_SOCKET_IFNAME=<interface_name>
    2. export GLOO_SOCKET_IFNAME=<interface_name>
    3. export NCCL_IB_HCA=<HCA_name, verified using ibstat>
    4. export NCCL_DEBUG=INFO
    5. export MASTER_ADDR=<master_node_internal_IP>
    6. export MASTER_PORT=29500

    Enable NCCL_DEBUG=INFO for the initial validation; it can be changed to WARN once stable. If the machines do not have InfiniBand, do not set NCCL_IB_HCA. Only during troubleshooting can you temporarily set NCCL_IB_DISABLE=1 to force socket usage, but this is slower and should not be used for formal training configurations.

    Both machines must execute the startup command, with the only difference being the node_rank.

    Master node (node_rank=0):

    1. source env.sh
    2. torchrun --nnodes=2 --node_rank=0 --nproc_per_node=8 \
    3. --master_addr=$MASTER_ADDR --master_port=$MASTER_PORT \
    4. train.py --