I want to execute a function at the worker side and return the results to the master. However, I find that the results is different when placing rpc_async at a different .py file

Method 1
master.py:

import os
import torch
import torch.distributed.rpc as rpc
from torch.distributed.rpc import RRef
from test import sub_fun

os.environ['MASTER_ADDR'] = '10.5.26.19'
os.environ['MASTER_PORT'] = '5677'

rpc.init_rpc("master", rank=0, world_size=2)
rref = torch.Tensor([0])
sub_fun(rref)
rpc.shutdown()

test.py

def f(rref):
   print("function is executed on master")

def sub_fun(rref):
   x = rpc.rpc_async("worker", f, args=(rref,))

worker.py:
import os
import torch
import torch.distributed.rpc as rpc
from torch.distributed.rpc import RRef

os.environ['MASTER_ADDR'] = '10.5.26.19'
os.environ['MASTER_PORT'] = '5677'

def f(rref):
    print("function is executed on worker")
rpc.init_rpc("worker", rank=1, world_size=2)
rpc.shutdown()

I found that the output is “function is executed on master” at the worker side.

Method 2
when I put the two functions: sub_fun and f in the master.py rather than the test.py, the result is “function is executed on worker”.
Why the two ways output the different results. and how can I get the result 2 with the method 1.
My torch version is ‘1.5.0+cu92’