Only create OwnerRRefs when processing remote calls (#31163)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/31163
The purpose is to unblock integration with TorchScript. Currently,
an OwnerRRef will be created by either a remote call or a to_here
call, whichever arrives first. However, when making RRef an IValue,
we need to know the type of value held by the RRef, which is
retrived by checking the return type of the TorchScript function.
The TorchScript function is only avaible during the remote call
but not in the to_here() call. Hence, an OwnerRRef can only be
created when processing a remote call. This commit implements this
behavior by introducing a conditional variable for every OwnerRRef
in the RRefContext, and let the to_here() call and PyRRef::unpickle
block on the CV until the value is ready.
Test Plan: Imported from OSS
Differential Revision: D18949591
Pulled By: mrshenli
fbshipit-source-id: 17513c6f1fd766885ea8e1cd38f672a403fa4222