未验证 提交 87054fe3 编写于 作者: H HongyuJia 提交者: GitHub

[Fix Bug] Fix random fail of CustomOp due to python lock (#54772)

上级 46c57674
...@@ -521,11 +521,8 @@ static PyObject* eager_api_run_custom_op(PyObject* self, ...@@ -521,11 +521,8 @@ static PyObject* eager_api_run_custom_op(PyObject* self,
std::string op_type = CastPyArg2AttrString(PyTuple_GET_ITEM(args, 0), 0); std::string op_type = CastPyArg2AttrString(PyTuple_GET_ITEM(args, 0), 0);
VLOG(7) << "Get things from python for Custom Op: " << op_type; VLOG(7) << "Get things from python for Custom Op: " << op_type;
paddle::CustomOpKernelContext ctx; paddle::CustomOpKernelContext ctx;
{
eager_gil_scoped_release guard;
auto meta_info_map = egr::Controller::Instance().GetOpMetaInfoMap(); auto meta_info_map = egr::Controller::Instance().GetOpMetaInfoMap();
PADDLE_ENFORCE_NE( PADDLE_ENFORCE_NE(meta_info_map.find(op_type),
meta_info_map.find(op_type),
meta_info_map.end(), meta_info_map.end(),
paddle::platform::errors::NotFound( paddle::platform::errors::NotFound(
"Can't find %s in Eager OpMetaInfoMap which should be " "Can't find %s in Eager OpMetaInfoMap which should be "
...@@ -536,8 +533,7 @@ static PyObject* eager_api_run_custom_op(PyObject* self, ...@@ -536,8 +533,7 @@ static PyObject* eager_api_run_custom_op(PyObject* self,
const auto& inputs = paddle::OpMetaInfoHelper::GetInputs(vec_map[0]); const auto& inputs = paddle::OpMetaInfoHelper::GetInputs(vec_map[0]);
const auto& attrs = paddle::OpMetaInfoHelper::GetAttrs(vec_map[0]); const auto& attrs = paddle::OpMetaInfoHelper::GetAttrs(vec_map[0]);
const auto& outputs = paddle::OpMetaInfoHelper::GetOutputs(vec_map[0]); const auto& outputs = paddle::OpMetaInfoHelper::GetOutputs(vec_map[0]);
const auto& inplace_map = const auto& inplace_map = paddle::OpMetaInfoHelper::GetInplaceMap(vec_map[0]);
paddle::OpMetaInfoHelper::GetInplaceMap(vec_map[0]);
for (size_t i = 0; i < inputs.size(); ++i) { for (size_t i = 0; i < inputs.size(); ++i) {
const auto& input = inputs.at(i); const auto& input = inputs.at(i);
// Parse op_type first, so that use i + 1 // Parse op_type first, so that use i + 1
...@@ -570,8 +566,7 @@ static PyObject* eager_api_run_custom_op(PyObject* self, ...@@ -570,8 +566,7 @@ static PyObject* eager_api_run_custom_op(PyObject* self,
std::vector<std::string> attr_name_and_type = paddle::ParseAttrStr(attr); std::vector<std::string> attr_name_and_type = paddle::ParseAttrStr(attr);
auto attr_type_str = attr_name_and_type[1]; auto attr_type_str = attr_name_and_type[1];
VLOG(7) << "Custom operator add attrs " << attr_name_and_type[0] VLOG(7) << "Custom operator add attrs " << attr_name_and_type[0]
<< " to CustomOpKernelContext. Attribute type = " << " to CustomOpKernelContext. Attribute type = " << attr_type_str;
<< attr_type_str;
PyObject* obj = PyTuple_GET_ITEM(args, attr_start_idx + i); PyObject* obj = PyTuple_GET_ITEM(args, attr_start_idx + i);
if (attr_type_str == "bool") { if (attr_type_str == "bool") {
ctx.EmplaceBackAttr(CastPyArg2AttrBoolean(obj, attr_start_idx + i)); ctx.EmplaceBackAttr(CastPyArg2AttrBoolean(obj, attr_start_idx + i));
...@@ -602,6 +597,8 @@ static PyObject* eager_api_run_custom_op(PyObject* self, ...@@ -602,6 +597,8 @@ static PyObject* eager_api_run_custom_op(PyObject* self,
attr_type_str)); attr_type_str));
} }
} }
{
eager_gil_scoped_release guard;
ctx.ConstructInplaceIndex(inputs, outputs, inplace_map); ctx.ConstructInplaceIndex(inputs, outputs, inplace_map);
const auto& inplace_reverse_idx_map = ctx.GetInplaceReverseIndexMap(); const auto& inplace_reverse_idx_map = ctx.GetInplaceReverseIndexMap();
for (size_t out_idx = 0; out_idx < outputs.size(); ++out_idx) { for (size_t out_idx = 0; out_idx < outputs.size(); ++out_idx) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册