Prompt
How do I set up GPU cloud instances for distributed training across multiple nodes?
Latest observation
Setting up GPU cloud instances for distributed training across multiple nodes usually involves five parts:
- Provisioning the instances
- Networking them together
- Installing the same software stack on each node
- Configuring distributed training
- Launching and validating the job
Here’s a practical walkthrough.
1) Choose the right cloud setup
Pick a cloud provider and instance type that supports:
- GPUs: NVIDIA A100, H100, L4, V100, etc.
- Fast interconnects: ideally low-latency networking between nodes
- Enough CPU/RAM/storage to feed the GPUs
- Matching node specs across all workers
Common options:
- AWS: p4d/p5, g5
- GCP: A2, A3
- Azure: ND-series
- Runpod / Lambda / Paperspace / CoreWeave for managed GPU options
For multi-node training, a single placement group / cluster / proximity placement is important if the provider supports it.
2) Create a networked cluster
Best practices
- Put all nodes in the same VPC / subnet / region / availability zone
- Use private IPs for node-to-node communication
- Open only the needed ports:
- SSH:
22 - PyTorch DDP / NCCL ports: often
29500or your chosen master port - Any scheduler ports if using Ray, Slurm, etc.
- SSH:
- Enable security group rules allowing traffic between the nodes
- If possible, use high-speed networking (EFA on AWS, RDMA/IB where available)
Typical roles
- Master node: coordinates the job
- Worker nodes: run training processes
For many setups, one node acts as rank 0, and all others connect to it.
3) Install the same software stack on every node
Make sure every node has:
- Same OS version
- Same NVIDIA driver version
- Same CUDA/cuDNN version
- Same Python version
- Same ML framework version (PyTorch / TensorFlow / JAX)
- Same package dependencies
Example installation checklist
- NVIDIA driver
- CUDA toolkit (if needed by your framework install)
- Docker or Conda/venv
- PyTorch with CUDA support
- NCCL
- Your training codebase
Verify GPU access
Run on each node:
nvidia-smi
If using PyTorch:
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
4) Use a distributed training framework
For multi-node GPU training, common choices are:
- PyTorch Distributed Data Parallel (DDP) — most common
- torchrun — launcher for PyTorch distributed
- Horovod
- DeepSpeed
- Megatron-LM
- Ray Train
- TensorFlow MultiWorkerMirroredStrategy
If you’re using PyTorch, the standard approach is DDP + torchrun.
5) Configure distributed environment variables
You need these concepts:
- world size = total number of processes across all nodes
- rank = unique ID of each process
- local rank = GPU index on the current node
- master address/port = node 0’s address and a port used for rendezvous
Example for 2 nodes, 8 GPUs each
world_size = 16- Node 0 rank = 0
- Node 1 rank = 1
- Each node runs 8 processes, one per GPU
6) Launch with PyTorch torchrun
On node 0
export MASTER_ADDR=<node0-private-ip>
export MASTER_PORT=29500
export NNODES=2
export NODE_RANK=0
export NPROC_PER_NODE=8
torchrun \
--nnodes=$NNODES \
--node_rank=$NODE_RANK \
--nproc_per_node=$NPROC_PER_NODE \
--master_addr=$MASTER_ADDR \
--master_port=$MASTER_PORT \
train.py
On node 1
export MASTER_ADDR=<node0-private-ip>
export MASTER_PORT=29500
export NNODES=2
export NODE_RANK=1
export NPROC_PER_NODE=8
torchrun \
--nnodes=$NNODES \
--node_rank=$NODE_RANK \
--nproc_per_node=$NPROC_PER_NODE \
--master_addr=$MASTER_ADDR \
--master_port=$MASTER_PORT \
train.py
Inside train.py, initialize distributed training with PyTorch DDP:
import os
import torch
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
dist.init_process_group(backend="nccl")
local_rank = int(os.environ["LOCAL_RANK"])
torch.cuda.set_device(local_rank)
model = MyModel().cuda()
model = DDP(model, device_ids=[local_rank])
And use a DistributedSampler for your dataset:
from torch.utils.data.distributed import DistributedSampler
sampler = DistributedSampler(dataset)
loader = DataLoader(dataset, sampler=sampler, batch_size=...)
7) Make sure data is accessible
Options:
- Copy data to each node’s local SSD
- Use shared network storage (NFS, EFS, Filestore, etc.)
- Stream from object storage (S3/GCS/Azure Blob) with caching
For best performance:
- Put training data on local NVMe if possible
- Avoid slow shared storage if your data loader becomes the bottleneck
8) Test connectivity before training
From worker node, verify you can reach the master:
ping <master-private-ip>
nc -zv <master-private-ip> 29500
If NCCL fails, you may need to:
- Set
NCCL_DEBUG=INFO - Ensure the right network interface is used:
or the provider’s private interface nameexport NCCL_SOCKET_IFNAME=eth0 - Disable problematic interfaces if needed:
export NCCL_IB_DISABLE=1
9) Debug common issues
Common problems
- Mismatch in PyTorch/CUDA versions
- Port blocked by firewall/security group
- Wrong master IP
- Incorrect rank assignment
- Dataset not sharded correctly
- NCCL hangs due to networking issues
- Different GPU counts across nodes
Useful debug env vars
export NCCL_DEBUG=INFO
export TORCH_DISTRIBUTED_DEBUG=DETAIL
10) Consider managed orchestration tools
If you don’t want to manually manage multiple nodes, use:
- Kubernetes + Kubeflow
- Ray
- Slurm
- AWS SageMaker distributed training
- Azure ML
- Vertex AI
- Lightning Fabric / PyTorch Lightning strategy plugins
These can simplify:
- node startup
- fault tolerance
- job scheduling
- autoscaling
Minimal recommended setup
If you want the simplest reliable path:
- Use 2+ identical GPU instances
- Put them in the same VPC/subnet
- Use PyTorch DDP
- Launch with
torchrun - Store data on local NVMe or fast shared storage
- Verify NCCL networking and security group rules
Example high-level workflow
- Launch 2 GPU VMs in same region/VPC
- SSH into both
- Install identical drivers + PyTorch stack
- Copy your training code to both
- Expose port
29500between nodes - Start node 0 with rank 0
- Start node 1 with rank 1
- Confirm training logs show all ranks joining
- Monitor GPU utilization with
nvidia-smi
If you want, I can also give you:
- a provider-specific setup (AWS/GCP/Azure),
- a Docker-based distributed training setup, or
- a full PyTorch DDP example script with launch commands.