Actually, my code is like this(I would like to use distributed training on one machine with 4 gpus):
import torch
import torch.nn as nn
import torch.nn.functional as F
import time


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3,
            64,
            kernel_size = 3,
            stride = 2,
            padding = 1,)
        self.conv2 = nn.Conv2d(64,
            256,
            kernel_size = 3,
            stride = 2,
            padding = 1,)
        self.conv3 = nn.Conv2d(256,
            512,
            kernel_size = 3,
            stride = 2,
            padding = 1,)
        self.linear = nn.Linear(512, 10)

    def forward(self, x):
        x = self.conv1(x)
        x = self.conv2(x)
        x = self.conv3(x)
        x = F.avg_pool2d(x, x.size()[2:]).view(-1, 512)
        x = self.linear(x)
        return x

def train():
    torch.distributed.init_process_group(
                backend='nccl',
                init_method='tcp://127.0.0.1:33445',
                rank=0,
                world_size=2
                )
    net = Net()
    net.train()
    net.cuda()
    net = nn.parallel.DistributedDataParallel(net)

    optim = torch.optim.SGD(
            net.parameters(),
            lr = 1e-3,
            momentum = 0.9,
            weight_decay = 5e-4)
    criteria = nn.CrossEntroyLoss()

    for i in range(100):
        img = torch.randn(4, 3, 224, 224).cuda()
        lb = torch.randint(0, 10, [4,]).cuda()
        optim.zero_grad()
        out = net(img)
        loss = criteria(img, lb)
        loss.backward()
        optim.step()
        print(lb.size())


if __name__ == "__main__":
    train()

If I use torch.distributed.init_process_group(backend='nccl', init_method='env://'), I come into the above errors. If I use torch.distributed.init_process_group(backend='nccl', init_method='tcp://127.0.0.1:22334', world_size=2, rank=0) as in the code I patched above, the program will get stuck somewhere, and even the gpus are not started. What is the trouble with my code please?