SIGBUS error with DistributedDataParallel (NCCL)

Hi, I’m trying to run a code to test DistributedDataParallel with nccl backend, but I’m receiving a SIGBUS error, if I change to DataParallel it works. Trying to run o 4 V100 GPUs.

Running with NCCL_DEBUG, TORCH_CPP_LOG_LEVEL, and TORCH_DISTRIBUTED_DEBUG, I got Something like this:

NCCL INFO Failed to open[.1]
 [2] NCCL INFO NET/Socket : Using [0]eth0:<0>
 [2] NCCL INFO Using network Socket
 [1] NCCL INFO Setting affinity for GPU 1 to fff000
 [2] NCCL INFO Setting affinity for GPU 2 to 0fff
 [0] NCCL INFO Setting affinity for GPU 0 to fff000
 [3] NCCL INFO Setting affinity for GPU 3 to 0fff
 [0] NCCL INFO Channel 00/02 :    0   1   2   3
 [0] NCCL INFO Channel 01/02 :    0   1   2   3
 [0] NCCL INFO Trees [0] 1/-1/-1->0->-1 [1] 1/-1/-1->0->-1
 [0] NCCL INFO Channel 00 : 0[100000] -> 1[200000] via SHM/direct/direct
 [0] NCCL INFO Channel 01 : 0[100000] -> 1[200000] via SHM/direct/direct
 [2] NCCL INFO Trees [0] 3/-1/-1->2->1 [1] 3/-1/-1->2->1
 [1] NCCL INFO Trees [0] 2/-1/-1->1->0 [1] 2/-1/-1->1->0
 [3] NCCL INFO Trees [0] -1/-1/-1->3->2 [1] -1/-1/-1->3->2
"python3.9/site-packages/torch/multiprocessing/", line 140, in join
    raise ProcessExitedException(
torch.multiprocessing.spawn.ProcessExitedException: process 3 terminated with signal SIGBUS

Do you have a code example so that we can repro?

Thank you for responding. Sure, I’ll provide the entire script since it’s small. Additionally, when I switch the backend to “gloo,” it works. I’m currently running it in JupyterLab with Azure. Perhaps there’s an issue with the instance.

import torch
import torch.nn.functional as F
from import Dataset, DataLoader
from datautils import MyTrainDataset

import torch.multiprocessing as mp
from import DistributedSampler
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.distributed import init_process_group, destroy_process_group
import os

def ddp_setup(rank, world_size):
        rank: Unique identifier of each process
        world_size: Total number of processes
    os.environ["MASTER_ADDR"] = "localhost"
    os.environ["MASTER_PORT"] = "12355"
    init_process_group(backend="nccl", rank=rank, world_size=world_size)

class Trainer:
    def __init__(
        model: torch.nn.Module,
        train_data: DataLoader,
        optimizer: torch.optim.Optimizer,
        gpu_id: int,
        save_every: int,
    ) -> None:
        self.gpu_id = gpu_id
        self.model =
        self.train_data = train_data
        self.optimizer = optimizer
        self.save_every = save_every
        self.model = DDP(model, device_ids=[gpu_id])

    def _run_batch(self, source, targets):
        output = self.model(source)
        loss = F.cross_entropy(output, targets)

    def _run_epoch(self, epoch):
        b_sz = len(next(iter(self.train_data))[0])
        print(f"[GPU{self.gpu_id}] Epoch {epoch} | Batchsize: {b_sz} | Steps: {len(self.train_data)}")
        for source, targets in self.train_data:
            source =
            targets =
            self._run_batch(source, targets)

    def _save_checkpoint(self, epoch):
        ckp = self.model.module.state_dict()
        PATH = "", PATH)
        print(f"Epoch {epoch} | Training checkpoint saved at {PATH}")

    def train(self, max_epochs: int):
        for epoch in range(max_epochs):
            if self.gpu_id == 0 and epoch % self.save_every == 0:

def load_train_objs():
    train_set = MyTrainDataset(2048)  # load your dataset
    model = torch.nn.Linear(20, 1)  # load your model
    optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)
    return train_set, model, optimizer

def prepare_dataloader(dataset: Dataset, batch_size: int):
    return DataLoader(

def main(rank: int, world_size: int, save_every: int, total_epochs: int, batch_size: int):
    ddp_setup(rank, world_size)
    dataset, model, optimizer = load_train_objs()
    train_data = prepare_dataloader(dataset, batch_size)
    trainer = Trainer(model, train_data, optimizer, rank, save_every)

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description='simple distributed training job')
    parser.add_argument('total_epochs', type=int, help='Total epochs to train the model')
    parser.add_argument('save_every', type=int, help='How often to save a snapshot')
    parser.add_argument('--batch_size', default=32, type=int, help='Input batch size on each device (default: 32)')
    args = parser.parse_args()
    world_size = torch.cuda.device_count()
    mp.spawn(main, args=(world_size, args.save_every, args.total_epochs, args.batch_size), nprocs=world_size)
import torch
from import Dataset

class MyTrainDataset(Dataset):
    def __init__(self, size):
        self.size = size = [(torch.rand(20), torch.rand(1)) for _ in range(size)]

    def __len__(self):
        return self.size
    def __getitem__(self, index):

Hi,Did you solve this problem?I hit the same question when i try to run training in Kubernetes.Also when use gloo and it works

I also was trying to run on Kubernetes, and it’s related with the shared memory of the container.