From 23d253e1bee1995fd067aa55fb1377d81c160ab0 Mon Sep 17 00:00:00 2001 From: Zhen Wang Date: Mon, 1 Jun 2020 10:34:21 +0800 Subject: [PATCH] Fix out of range error for outs map. test=develop (#24774) --- paddle/fluid/pybind/op_function_generator.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/pybind/op_function_generator.cc b/paddle/fluid/pybind/op_function_generator.cc index a9075a333a0..e1a525f4641 100644 --- a/paddle/fluid/pybind/op_function_generator.cc +++ b/paddle/fluid/pybind/op_function_generator.cc @@ -75,7 +75,7 @@ std::map> op_passing_outs_map = { {"fill_constant", {"Out"}}, {"matmul", {"Out"}}, {"fake_quantize_dequantize_moving_average_abs_max", - {"OutScale", "OutAccum", "OutState"}}, + {"Out", "OutScale", "OutAccum", "OutState"}}, }; // clang-format off @@ -98,16 +98,12 @@ const char* INPUT_INITIALIZER_TEMPLATE_WITH_NULL_LIST = R"( } )"; -const char* OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL = R"( - if (%s != nullptr) { - outs["%s"] = {%s}; - } +const char* OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL = R"( + outs["%s"] = {%s}; )"; -const char* OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL_LIST = R"( - if (%s.size() != 0) { - outs["%s"] = %s; - } +const char* OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL_LIST = R"( + outs["%s"] = %s; )"; // if inputs is list, no need {} const char* ARG_OUT_NUM = R"(%sNum)"; @@ -246,8 +242,8 @@ GenerateOpFunctions(const std::string& module_name) { const auto out_template = output.duplicable() ? OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL_LIST : OUTPUT_INITIALIZER_TEMPLATE_WITH_NULL; - outs_initializer_with_null += paddle::string::Sprintf( - out_template, out_name, out_name, out_name); + outs_initializer_with_null += + paddle::string::Sprintf(out_template, out_name, out_name); } else { const auto out_template = output.duplicable() ? INPUT_LIST_INITIALIZER_TEMPLATE -- GitLab