diff --git a/paddle/phi/api/yaml/generator/templates/operator_utils.c.j2 b/paddle/phi/api/yaml/generator/templates/operator_utils.c.j2 index 0e684664c4884677b54352bd8b0a5644445f2683..3910da99d8ae3109b1b4fb5a29afde66c5078bf7 100644 --- a/paddle/phi/api/yaml/generator/templates/operator_utils.c.j2 +++ b/paddle/phi/api/yaml/generator/templates/operator_utils.c.j2 @@ -333,6 +333,7 @@ class {{name | to_pascal_case}}OpMaker : public framework::SingleGradOpMaker forward_output_orig_names)}}); {% endfor %} + grad_op->SetAttrMap(this->Attrs()); {% for attr in api["attrs"] %} {% set attr_name = attr["name"] %} {% if attr_name in forward_attr_names %} @@ -342,7 +343,6 @@ class {{name | to_pascal_case}}OpMaker : public framework::SingleGradOpMaker {% elif attr["typename"] == "Scalar" %} grad_op->SetInput("{{attr_name | to_pascal_case}}Tensor", this->Input("{{attr_name | to_pascal_case}}Tensor")); {% endif %} - grad_op->SetAttr("{{attr_name}}", this->GetAttr("{{forward_attr_orig_names[forward_attr_names.index(attr_name)]}}")); {% else %}{# maybe something wrong: backward op has more attrs than the forward one#} grad_op->AddAttr<{{attr["typename"] | to_op_attr_type}}>({{attr_name}}, "({{attr["typename"] | to_op_attr_type}}), exceptional attr {{attr_name}}"); grad_op->SetAttr("{{attr_name}}", {{process_default_value(attr)}});