Reland "[RPC] Use qualified name str directly in RPC torch script code path" (#35489)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/35489

Relanding https://github.com/pytorch/pytorch/pull/34733.

Fix is in https://github.com/pytorch/pytorch/pull/34988

Test Plan:
```
buck test mode/dev-nosan //caffe2/test/distributed/rpc:rpc_fork
```

```
buck test mode/dev-nosan //caffe2/test/distributed/rpc/jit:rpc_fork

buck build mode/dev-nosan //caffe2/test/distributed/rpc/jit:rpc_fork && \
buck-out/gen/caffe2/test/distributed/rpc/jit/rpc_fork\#binary.par \
-r test_return_local_script_class_rref_in_py_and_use_in_script

buck build mode/dev-nosan //caffe2/test/distributed/rpc/jit:rpc_fork && \
buck-out/gen/caffe2/test/distributed/rpc/jit/rpc_fork\#binary.par \
-r test_return_local_script_module_rref_in_py_and_use_in_script
```

Differential Revision: D20661748

fbshipit-source-id: d550daab8d689d0a9aa2450f3bdb7417ab79dae2
This commit is contained in:
Shihao Xu
2020-03-26 23:39:00 -07:00
committed by Facebook GitHub Bot
parent d2d40c45b6
commit ac639d927a
4 changed files with 12 additions and 24 deletions

View File

@ -23,7 +23,7 @@ namespace {
auto dur = std::chrono::duration_cast<std::chrono::microseconds>( \
std::chrono::high_resolution_clock::now() - startTime); \
RpcAgent::getCurrentRpcAgent()->addGilWaitTime(dur); \
}
} // NOLINT
// PythonTypeResolver that inherits from Script::Resolver to
// support resolving types together with ScriptTypeParser.
@ -65,7 +65,6 @@ PythonRpcHandler::PythonRpcHandler() {
pySerialize_ = getFunction(module, "serialize");
pyDeserialize_ = getFunction(module, "deserialize");
pyHandleException_ = getFunction(module, "_handle_exception");
pyGetQualifiedName_ = py::module::import("torch.jit").attr("_qualified_name");
jitCompilationUnit_ = torch::jit::get_python_cu();
typeParser_ = std::make_shared<jit::ScriptTypeParser>(
std::make_shared<PythonTypeResolver>());
@ -77,7 +76,6 @@ void PythonRpcHandler::cleanup() {
pySerialize_ = py::none();
pyDeserialize_ = py::none();
pyHandleException_ = py::none();
pyGetQualifiedName_ = py::none();
jitCompilationUnit_ = nullptr;
typeParser_ = nullptr;
}
@ -133,11 +131,6 @@ void PythonRpcHandler::handleExceptionGILHeld(const py::object& obj) {
pyHandleException_(obj);
}
c10::QualifiedName PythonRpcHandler::getQualifiedName(const py::object& obj) {
PROFILE_GIL_SCOPED_ACQUIRE;
return c10::QualifiedName(pyGetQualifiedName_(obj).cast<std::string>());
}
TypePtr PythonRpcHandler::parseTypeFromStr(const std::string& type_str) {
return typeParser_->parseType(type_str);
}