Prevent RRef unpickle to block waiting for OwnerRRef creation (#36785)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36785
Currently, RRef unpickle (both Python and TorchScript) will block
until the OwnerRRef has been created by the original `rpc.remote`
call, if it is an OwnerRRef. This is not ideal as the correctness
would then depends on the number of threads configuration. This
commit changed that behavior. Both `rpc.remote` and the unpickle
can create OwnerRRefs. More specifically, whichever one arrives
first will create the OwnerRRef and the subsequent ones will
retrieve the same OwnerRRef, so that no one is blocking.
Test Plan: Imported from OSS
Differential Revision: D21083089
Pulled By: mrshenli
fbshipit-source-id: 34ef063d50549b01c968b47815c4fe9fac179d3d