The foloowing multiGPU CUDA job is not working. It hangs: import os
import time
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.utils.data import DataLoader, DistributedSampler
from edges import *
from regressors import *
from training import *
from mlflow_utils import *
from torch.optim.lr_scheduler import CosineAnnealingWarmRestarts
from torch_geometric.data import Batch
if name == "main":
run_training()
Help me finding the problem
Assistant
I can see a critical issue in your distributed training code that's likely causing it to hang. The main problem is in your data loading and synchronization:
python
if rank == 0:
train_set, test_set = process_and_combine_cached_datasets(
configs, root="data", upcast=True, compressed=True
)
if multigpu:
if rank != 0:
train_set, test_set = process_and_combine_cached_datasets(
configs, root="data", upcast=True, compressed=True
)
# dist.barrier() # This barrier is commented out!
The commented-out dist.barrier() is almost certainly the issue. Without this barrier:
Each process loads the dataset independently
Some processes might finish loading data before others
The training loop can start with processes out of sync, leading to deadlocks
Fix recommendation: Uncomment the barrier to ensure all processes are synchronized after loading the datasets:
python
if multigpu:
if rank != 0:
train_set, test_set = process_and_combine_cached_datasets(
configs, root="data", upcast=True, compressed=True
)
dist.barrier() # Ensure all processes have loaded the data
Other potential issues to check:
Make sure proper initialization variables for the distributed process group are set elsewhere in your code (MASTER_ADDR, MASTER_PORT)
The batch size (1024) might be too large, causing OOM issues
Consider adding additional barriers at critical synchronization points
Would you like me to explain more about how distributed synchronization works in PyTorch?