here is the ddp.py from master… other server has only difference it has master_ip address
import torch.distributed as dist
import torch.multiprocessing as mp
import os
import torch.nn as nn
import torch.optim as optim
from torch.nn.parallel import DistributedDataParallel as DDP


def cleanup():
	dist.destroy_process_group()

def example(rank, world_size):
	os.environ['MASTER_ADDR'] = 'localhost'
	os.environ['MASTER_PORT'] = '12355'

	# create default process group
	dist.init_process_group("gloo", rank=rank, world_size=world_size)
	# create local model
	model = nn.Linear(10, 10)
	# construct DDP model
	ddp_model = DDP(model)
	# define loss function and optimizer
	loss_fn = nn.MSELoss()
	optimizer = optim.SGD(ddp_model.parameters(), lr=0.001)

	# forward pass
	outputs = ddp_model(torch.randn(20, 10))
	labels = torch.randn(20, 10)
	# backward pass
	loss_fn(outputs, labels).backward()
	# update parameters
	optimizer.step()
	print(outputs)

	cleanup()



def main():
	world_size = 2
	mp.spawn(example,
		args=(world_size,),
		nprocs=world_size,
		join=True)

if __name__=="__main__":
	main()