From 6580522769f35487dfedf817188605c69f2939e3 Mon Sep 17 00:00:00 2001 From: Zhanlue Yang Date: Tue, 8 Feb 2022 10:17:23 +0800 Subject: [PATCH] Fixed automatic codegen issues with grad attr_map (#39358) --- paddle/fluid/eager/auto_code_generator/eager_generator.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/eager/auto_code_generator/eager_generator.cc b/paddle/fluid/eager/auto_code_generator/eager_generator.cc index edfe1b832b..4f404bbf8e 100644 --- a/paddle/fluid/eager/auto_code_generator/eager_generator.cc +++ b/paddle/fluid/eager/auto_code_generator/eager_generator.cc @@ -64,6 +64,11 @@ static bool IgnoreGradAttribute(const std::string& op_type, } } + // Only allow SumOp + if (op_type != "sum") { + return true; + } + return false; } @@ -1693,7 +1698,7 @@ static std::string GenerateSingleOpBase( VLOG(6) << "Generated Outs Map"; // [Generation] Get Attrs Map - const char* ATTRS_TEMPLATE = " auto %s = this->attr_map_;\n"; + const char* ATTRS_TEMPLATE = " auto& %s = this->attr_map_;\n"; std::string grad_attrs_str = paddle::string::Sprintf(ATTRS_TEMPLATE, attrs_name); for (const auto& iter : grad_attrs) { -- GitLab