End-to-End Guide to Two-Node, 16-Card Large Model Training on Domestic AI Accelerators
This article describes how to validate large model training across two nodes with 16 AI accelerator cards in total. It covers network and hardware planning, environment consistency checks, multi-node launch configuration, required changes to training scripts, and checkpoint design for saving and resuming training.
1. Why Validate Multi-Node Training
Training that runs on a single machine with multiple accelerator cards only shows that the model code, operators, and communication between cards work within that machine. Moving to multiple machines exposes three additional types of problems: network bandwidth and latency between nodes, whether the software environment matches across nodes, and whether job launch and process orchestration are configured correctly.
Two nodes with 16 accelerator cards is a suitable intermediate scale. If each node has 8 cards, two nodes are enough to exercise cross-node communication, and they make it practical to troubleshoot one node at a time. For this reason, this scale is often used as the starting point for validating a training pipeline.
This validation has three goals:
- Working links: all processes finish initialization, and collective communication works correctly.
- Stable training: training runs continuously to the planned number of steps, with a reasonable loss curve and no numerical anomalies.
- Recoverable process: checkpoints can be saved and loaded, and training can resume from the point of interruption.
Completing 400 steps is a validation milestone. It shows that the communication links run stably under the current configuration and data subset. It does not mean the model has converged, and it does not support conclusions about final model quality.
2. Hardware and Network Planning
Planning should settle the following points:
- Nodes and cards: 2 nodes with 8 cards each, for 16 compute devices in total.
- Inter-node network: Prefer a high-bandwidth, low-latency internal network. If only standard Ethernet is available, gradient synchronization across nodes can become a bottleneck. In that case, adjust the communication frequency or the parallelism strategy.
- Storage: Place datasets and checkpoints on shared storage that both nodes can access. Without shared storage, each node must keep a copy of the data at the same path, with identical contents.
- Clock synchronization: The system clocks of both machines must be aligned. Otherwise, log timelines are hard to compare, and timeout judgments become inaccurate.
Before the formal launch, complete three tests. First, confirm that the nodes can ping each other and that the ports used for training are reachable between them. Second, measure the send and receive bandwidth between nodes, and record throughput and latency at different message sizes as a baseline for later troubleshooting. Third, confirm on each node that the number of accelerator cards, memory capacity, and health status match the plan.
3. Keeping the Environment Consistent
The most common failures in multi-node training come from inconsistent environments across machines. The driver version, runtime version, deep learning framework version, and Python dependency versions must all match. The common practices are:
- Deploy all nodes from the same environment specification file or the same container image.
- Run an environment check script before each launch to print version information and compare it with a baseline.
- Pin dependency versions and random seeds to make results reproducible and problems easier to locate.
The following is an example environment check script. Replace the package names and version numbers with the ones you actually use:
import sysimport platformimport importlib# Baseline versions are recorded after the first successful validation. Placeholders are shown here for illustration only.BASELINE = {"<deep-learning-framework-package>": "<baseline-version>","<communication-dependency-package>": "<baseline-version>",}def check_env():print("python:", sys.version.split()[0], platform.machine())for pkg, expected in BASELINE.items():try:mod = importlib.import_module(pkg)actual = getattr(mod, "__version__", "unknown")except ImportError:actual = "not installed"status = "OK" if actual == expected else "MISMATCH"print(f"{pkg}: {actual} (baseline {expected}) {status}")if __name__ == "__main__":check_env()
The value of this script is that it turns the question “Do the two machines match?” into an automatic result. If any item shows MISMATCH, pause the launch and align the environments first.
4. Multi-Node Launch and Communication Configuration
The core of multi-node training is making sure every process knows its global rank, the total number of processes, and the address and port of the master node. A common approach is to pass this information through environment variables.
The following shows example configurations for two nodes. Apart from NODE_RANK, all other settings must be identical on both nodes:
# Master node (NODE_RANK=0)export MASTER_ADDR=192.168.1.10 # Internal IP of the master node, must be reachable from both nodesexport MASTER_PORT=29500 # Fixed port, open it in the firewall in advanceexport NNODES=2export NODE_RANK=0export NPROC_PER_NODE=8# Launch command: <training launch command> --config train.yaml# Worker node (NODE_RANK=1)export MASTER_ADDR=192.168.1.10export MASTER_PORT=29500export NNODES=2export NODE_RANK=1export NPROC_PER_NODE=8# Same launch command as above
Pay attention to the following points during configuration:
- MASTER_ADDR must be the internal address of the master node. Do not use localhost, or the worker node cannot find the master node.
- Each node’s NODE_RANK must be unique. If two nodes share the same number, initialization can hang.
- Start both nodes within the timeout window, one after the other. If the master node waits too long for the worker node to join, it can also trigger a timeout.
Inside each process, the global rank must be calculated from the environment variables. The following function shows the logic:
import osdef get_topology():nnodes = int(os.environ["NNODES"])node_rank = int(os.environ["NODE_RANK"])nproc = int(os.environ["NPROC_PER_NODE"])local_rank = int(os.environ.get("LOCAL_RANK", "0"))world_size = nnodes * nprocglobal_rank = node_rank * nproc + local_rankreturn global_rank, local_rank, world_sizerank, local_rank, world_size = get_topology()print(f"global_rank={rank}, local_rank={local_rank}, world_size={world_size}")
For example, the third card on node 1 has the global rank 1 × 8 + 3 = 11. After obtaining its rank, each process must bind to its assigned accelerator card and then call the distributed initialization function with world_size and rank. After successful initialization, every process should print a ready message that includes its own rank. This is the first signal that the communication links are working.
5. Key Changes to the Training Script
When moving a single-machine script to multiple machines, you usually need to change the following areas:
1. Data sharding
Each process must read a non-overlapping portion of the data. The sampler should split the data by global rank. Otherwise, the same samples are computed more than once, and the loss curve becomes distorted.
2. Batch size calculation
After moving to multiple machines, the global batch size depends on several factors:
def compute_global_batch(per_device_batch, grad_accum, world_size):return per_device_batch * grad_accum * world_sizeprint(compute_global_batch(per_device_batch=2, grad_accum=4, world_size=16)) # Output: 128
When the global batch size changes, the learning rate usually needs to be re-evaluated. Record the basis for any adjustment in the experiment log so that runs can be compared later.
3. Write permissions for logs and checkpoints
Only the process with global rank 0 should write logs and save checkpoints. If multiple processes write to the same file at once, the content can be corrupted or overwritten. Metrics from other processes should be aggregated to rank 0 through collective communication before being output.
4. Loss aggregation
The loss computed by each process differs. The loss shown in the logs should be the average across all processes, not the value from a single process. Otherwise, the curve fluctuates with the process number and becomes hard to interpret.
6. Data and Checkpoint Design
Long training runs depend on a reliable checkpoint mechanism. A complete checkpoint should contain the following:
- Model parameters and optimizer state
- The current state of the learning rate scheduler
- The current training step
- The state of the random number generator
- The position of the data sampler
If any of these items is missing, the resumed training may diverge from the original training trajectory. For example, if only the model parameters are saved and the optimizer state is not restored, the loss often jumps noticeably during the first few dozen steps after resuming.
The recommended saving strategy is as follows: save at a fixed interval of steps, keep only the most recent few versions to control storage usage. Checkpoints should be written to a temporary file first, and then renamed to the final file name after the write completes.
