Hi,
That’s so good.
However, I try to run your code with my PC. the output is
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-1-c234795e743f> in <module>
     37     world_size = 2
     38 
---> 39     mp.spawn(run_worker, args=(world_size, ), nprocs=world_size, join=True)

~/opt/anaconda3/lib/python3.7/site-packages/torch/multiprocessing/spawn.py in spawn(fn, args, nprocs, join, daemon, start_method)
    198                ' torch.multiprocessing.start_process(...)' % start_method)
    199         warnings.warn(msg)
--> 200     return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')

~/opt/anaconda3/lib/python3.7/site-packages/torch/multiprocessing/spawn.py in start_processes(fn, args, nprocs, join, daemon, start_method)
    156 
    157     # Loop on join until it returns True or raises an exception.
--> 158     while not context.join():
    159         pass
    160 

~/opt/anaconda3/lib/python3.7/site-packages/torch/multiprocessing/spawn.py in join(self, timeout)
    111                 raise Exception(
    112                     "process %d terminated with exit code %d" %
--> 113                     (error_index, exitcode)
    114                 )
    115 

Exception: process 1 terminated with exit code 1

I try with
"""RPC with Torch"""
"""run.py:"""
#!/usr/bin/env python
import os
import torch
import torch.distributed as dist
from torch.multiprocessing import Process
import torch.distributed.rpc as rpc
import numpy as np

def create_dict():
    return {1:'a', 2:'b', 3:'c'}


def intersect_dict(dict1, dict2_rref):
    ret = {}
    for key in dict2_rref.local_value():
        if key in dict1:
            ret[key] = dict1[key]
    return ret

def run(dst):
    dict1 = {1:'a', 3:'c', 4:'d'}
    dict2_rref = rpc.remote(dst, create_dict)
    intersect = rpc.rpc_sync(dst, intersect_dict, args=(dict1, dict2_rref))
    print(intersect)
        
def init_process(rank, size, fn, backend='gloo'):
    """ Initialize the distributed environment. """
    os.environ['MASTER_ADDR'] = '127.0.0.1'
    os.environ['MASTER_PORT'] = '29500'
    #dist.init_process_group(backend, rank=rank, world_size=size)
    #fn(rank, size)
    if rank == 1:
        rpc.init_rpc("worker0", rank=rank, world_size=world_size)
        fn("worker1")
    else:
        rpc.init_rpc("worker1", rank=rank, world_size=world_size)

    rpc.shutdown()

if __name__ == "__main__":
    size = 2
    processes = []
    for rank in range(size):
        p = Process(target=init_process, args=(rank, size, run))
        p.start()
        processes.append(p)

    for p in processes:
        p.join()

And it worked on my PC.
Could you please explain why mp.spawn error in this case?
thanks,