Rename variables and add comments (#27286)

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

The name `runUDFFunction` stutters because the F in UDF also stands
for function. Renamed these variables to be identical to their Python
equivalents. Renamed those to share a prefix and drop `internal`,
because internal functions can use an underscore prefix.

Test Plan: Imported from OSS

Differential Revision: D17808208

Pulled By: pietern

fbshipit-source-id: 7619f07fc8215203dfb1da1eb281845edcd2bb99
This commit is contained in:
Pieter Noordhuis
2019-10-08 11:22:18 -07:00
committed by Facebook Github Bot
parent f597926fe0
commit 48a571b29c
3 changed files with 38 additions and 23 deletions

View File

@ -22,9 +22,9 @@ PythonRpcHandler::PythonRpcHandler() {
AutoGIL ag;
py::object module =
py::module::import("torch.distributed.internal_rpc_utils");
runUDFFunction_ = getFunction(module, "run_python_udf_internal");
loadResultFunction_ = getFunction(module, "load_python_udf_result_internal");
serializeFunction_ = getFunction(module, "serialize");
pyRunFunction_ = getFunction(module, "_run_function");
pyLoadReturnValue_ = getFunction(module, "_load_return_value");
pySerialize_ = getFunction(module, "serialize");
}
PythonRpcHandler& PythonRpcHandler::getInstance() {
@ -38,8 +38,7 @@ std::vector<char> PythonRpcHandler::generatePythonUDFResult(
std::vector<torch::Tensor>& responseTensorTable) {
AutoGIL ag;
auto pargs = py::bytes(pickledPayload.data(), pickledPayload.size());
py::tuple pres =
serializeFunction_(runUDFFunction_(pargs, requestTensorTable));
py::tuple pres = pySerialize_(pyRunFunction_(pargs, requestTensorTable));
const auto& presStr = pres[0].cast<std::string>();
responseTensorTable = pres[1].cast<std::vector<torch::Tensor>>();
std::vector<char> payload(presStr.begin(), presStr.end());
@ -51,26 +50,26 @@ py::object PythonRpcHandler::loadPythonUDFResult(
const std::vector<torch::Tensor>& tensorTable) {
AutoGIL ag;
auto pargs = py::bytes(pickledPayload.data(), pickledPayload.size());
return loadResultFunction_(pargs, tensorTable);
return pyLoadReturnValue_(pargs, tensorTable);
}
py::object PythonRpcHandler::runPythonUDF(
const SerializedPyObj& serializedObj) {
AutoGIL ag;
return runUDFFunction_(
return pyRunFunction_(
py::bytes(serializedObj.payload_), serializedObj.tensors_);
}
SerializedPyObj PythonRpcHandler::serialize(const py::object& obj) {
AutoGIL ag;
py::tuple t = serializeFunction_(obj);
py::tuple t = pySerialize_(obj);
return SerializedPyObj(
t[0].cast<std::string>(), t[1].cast<std::vector<torch::Tensor>>());
}
py::object PythonRpcHandler::deserialize(const SerializedPyObj& serializedObj) {
AutoGIL ag;
return loadResultFunction_(
return pyLoadReturnValue_(
py::bytes(serializedObj.payload_), serializedObj.tensors_);
}