Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9a36fd4b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9a36fd4b
编写于
6月 15, 2023
作者:
C
Charles-hit
提交者:
GitHub
6月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support composite higher grad maker auto gen (#54666)
* support composite higher grad maker * fix composite maker higher order gen
上级
3a275162
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
20 deletion
+26
-20
paddle/fluid/operators/generator/templates/op.c.j2
paddle/fluid/operators/generator/templates/op.c.j2
+1
-1
paddle/fluid/operators/generator/templates/operator_utils.c.j2
...e/fluid/operators/generator/templates/operator_utils.c.j2
+25
-19
未找到文件。
paddle/fluid/operators/generator/templates/op.c.j2
浏览文件 @
9a36fd4b
...
@@ -44,7 +44,7 @@ using paddle::framework::GradVarName;
...
@@ -44,7 +44,7 @@ using paddle::framework::GradVarName;
{{backward_op_reused_maker(op, op_dict[op["forward"]["name"]], op["invoke"])}}
{{backward_op_reused_maker(op, op_dict[op["forward"]["name"]], op["invoke"])}}
{% endif %}
{% endif %}
{% if op is composite_op %}
{% if op is composite_op %}
{{composite_grad_op_maker(op_dict[op["name"]])}}
{{composite_grad_op_maker(op_dict[op["name"]]
, op_dict[op["forward"]["name"]]
)}}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
} // namespace operators
} // namespace operators
...
...
paddle/fluid/operators/generator/templates/operator_utils.c.j2
浏览文件 @
9a36fd4b
...
@@ -681,13 +681,15 @@ class {{name | to_pascal_case}}OpMaker : public framework::SingleGradOpMaker<T>
...
@@ -681,13 +681,15 @@ class {{name | to_pascal_case}}OpMaker : public framework::SingleGradOpMaker<T>
};
};
{% endmacro %}
{% endmacro %}
{% macro composite_grad_op_maker(backward_op) %}
{% macro composite_grad_op_maker(backward_op
, forward_op
) %}
{% set op_name = backward_op["op_name"] %}
{% set op_name = backward_op["op_name"] %}
{% set inputs = backward_op["inputs"] | to_variable_names("name")%}
{% set inputs = backward_op["inputs"] | to_variable_names("name")%}
{% set input_dict = backward_op["input_dict"] %}
{% set input_dict = backward_op["input_dict"] %}
{% set fluid_inputs = backward_op["inputs"] | to_variable_names("fluid_name")%}
{% set fluid_inputs = backward_op["inputs"] | to_variable_names("fluid_name")%}
{% set forward_fluid_inputs = backward_op["forward"]["inputs"] | to_variable_names("fluid_name")%}
{% set forward_fluid_inputs = backward_op["forward"]["inputs"] | to_variable_names("fluid_name")%}
{% set forward_fluid_outputs = backward_op["forward"]["outputs"] | to_variable_names("fluid_name")%}
{% set forward_fluid_outputs = backward_op["forward"]["outputs"] | to_variable_names("fluid_name")%}
{% set forward_fluid_orig_inputs = forward_op["inputs"] | map(attribute="fluid_name") | list %}
{% set forward_fluid_orig_outputs = forward_op["outputs"] | map(attribute="fluid_name") | list %}
{% set attrs = backward_op["attrs"] | to_variable_names("name") %}
{% set attrs = backward_op["attrs"] | to_variable_names("name") %}
{% set fluid_attrs = backward_op["attrs"] | to_variable_names("fluid_name") %}
{% set fluid_attrs = backward_op["attrs"] | to_variable_names("fluid_name") %}
{% set attr_dict = backward_op["attr_dict"] %}
{% set attr_dict = backward_op["attr_dict"] %}
...
@@ -700,12 +702,12 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
...
@@ -700,12 +702,12 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
using prim::CompositeGradOpMakerBase::CompositeGradOpMakerBase;
using prim::CompositeGradOpMakerBase::CompositeGradOpMakerBase;
void Apply() override {
void Apply() override {
//get inputs
//get inputs
{{construct_composite_input(inputs, fluid_inputs, forward_fluid_inputs, forward_fluid_outputs, input_dict)}}
{{construct_composite_input(inputs, fluid_inputs, forward_fluid_inputs, forward_fluid_outputs,
forward_fluid_orig_inputs, forward_fluid_orig_outputs,
input_dict)}}
{{construct_composite_tensor_attr(attrs, fluid_attrs, attr_dict, op_name)}}
{{construct_composite_tensor_attr(attrs, fluid_attrs, attr_dict, op_name)}}
//get attr
//get attr
{{construct_composite_attr(attrs, fluid_attrs, attr_dict)}}
{{construct_composite_attr(attrs, fluid_attrs, attr_dict)}}
//get output
//get output
{{construct_composite_output(outputs, fluid_outputs, output_dict)}}
{{construct_composite_output(outputs, fluid_outputs,
forward_fluid_inputs, forward_fluid_orig_inputs,
output_dict)}}
//get output ptr
//get output ptr
{{construct_composite_output_ptr(outputs, output_dict)}}
{{construct_composite_output_ptr(outputs, output_dict)}}
//get output orginal name
//get output orginal name
...
@@ -718,51 +720,54 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
...
@@ -718,51 +720,54 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
};
};
{%- endmacro %}
{%- endmacro %}
{% macro construct_composite_input(inputs, fluid_inputs, forward_fluid_inputs, forward_fluid_outputs, input_dict) %}
{% macro construct_composite_input(inputs, fluid_inputs, forward_fluid_inputs, forward_fluid_outputs,
forward_fluid_orig_inputs, forward_fluid_orig_outputs,
input_dict) %}
{% set inputs_length = inputs | length %}
{% set inputs_length = inputs | length %}
{% for i in range(inputs_length) %}
{% for i in range(inputs_length) %}
{% set input_typename = input_dict[inputs[i]]["typename"] %}
{% set input_typename = input_dict[inputs[i]]["typename"] %}
{% set input_optional_flag = input_dict[inputs[i]]["optional"] %}
{% set input_optional_flag = input_dict[inputs[i]]["optional"] %}
{% if fluid_inputs[i] in forward_fluid_inputs %}
{% if fluid_inputs[i] in forward_fluid_inputs %}
{% set name_in_forward_orig = forward_fluid_orig_inputs[forward_fluid_inputs.index(fluid_inputs[i])]%}
{% if input_typename == "Tensor" %}
{% if input_typename == "Tensor" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalSingleForwardInput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetOptionalSingleForwardInput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetSingleForwardInput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetSingleForwardInput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% endif %}
{% endif %}
{% elif input_typename == "Tensor[]" %}
{% elif input_typename == "Tensor[]" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalMultiForwardInput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetOptionalMultiForwardInput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetMultiForwardInput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetMultiForwardInput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% elif fluid_inputs[i] in forward_fluid_outputs %}
{% elif fluid_inputs[i] in forward_fluid_outputs %}
{% set name_in_forward_orig = forward_fluid_orig_outputs[forward_fluid_outputs.index(fluid_inputs[i])]%}
{% if input_typename == "Tensor" %}
{% if input_typename == "Tensor" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalSingleForwardOutput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetOptionalSingleForwardOutput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetSingleForwardOutput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetSingleForwardOutput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% endif %}
{% endif %}
{% elif input_typename == "Tensor[]" %}
{% elif input_typename == "Tensor[]" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalMultiForwardOutput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetOptionalMultiForwardOutput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetMultiForwardOutput(
"{{fluid_inputs[i]}}"
);
auto {{inputs[i]}} = this->GetMultiForwardOutput(
{{name_in_forward_orig | to_opmaker_name}}
);
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% elif fluid_inputs[i][:-5] in forward_fluid_outputs %}
{% elif fluid_inputs[i][:-5] in forward_fluid_outputs %}
{% set name_in_forward_orig = forward_fluid_orig_outputs[forward_fluid_outputs.index(fluid_inputs[i][:-5])]%}
{% if input_typename == "Tensor" %}
{% if input_typename == "Tensor" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalSingleOutputGrad(
"{{fluid_inputs[i][:-5]}}"
);
auto {{inputs[i]}} = this->GetOptionalSingleOutputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetSingleOutputGrad(
"{{fluid_inputs[i][:-5]}}"
);
auto {{inputs[i]}} = this->GetSingleOutputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{% endif %}
{% endif %}
{% elif input_typename == "Tensor[]" %}
{% elif input_typename == "Tensor[]" %}
{% if input_optional_flag == True %}
{% if input_optional_flag == True %}
auto {{inputs[i]}} = this->GetOptionalMultiOutputGrad(
"{{fluid_inputs[i][:-5]}}"
);
auto {{inputs[i]}} = this->GetOptionalMultiOutputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{% else %}
{% else %}
auto {{inputs[i]}} = this->GetMultiOutputGrad(
"{{fluid_inputs[i][:-5]}}"
);
auto {{inputs[i]}} = this->GetMultiOutputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
...
@@ -803,14 +808,15 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
...
@@ -803,14 +808,15 @@ class {{op_name | to_composite_grad_opmaker_name}} : public prim::CompositeGradO
{% endfor %}
{% endfor %}
{%- endmacro %}
{%- endmacro %}
{% macro construct_composite_output(outputs, fluid_outputs, output_dict) %}
{% macro construct_composite_output(outputs, fluid_outputs,
forward_fluid_inputs, forward_fluid_orig_inputs,
output_dict) %}
{% set outputs_length = outputs | length %}
{% set outputs_length = outputs | length %}
{% for i in range(outputs_length) %}
{% for i in range(outputs_length) %}
{% set name_in_forward_orig = forward_fluid_orig_inputs[forward_fluid_inputs.index(fluid_outputs[i][:-5])]%}
{% set output_typename = output_dict[outputs[i]]["typename"] %}
{% set output_typename = output_dict[outputs[i]]["typename"] %}
{% if output_typename == "Tensor" %}
{% if output_typename == "Tensor" %}
auto {{outputs[i] + "_t"}} = this->GetSingleInputGrad(
"{{fluid_outputs[i][:-5]}}"
);
auto {{outputs[i] + "_t"}} = this->GetSingleInputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{% elif output_typename == "Tensor[]" %}
{% elif output_typename == "Tensor[]" %}
auto {{outputs[i] + "_t"}} = this->GetMultiInputGrad(
"{{fluid_outputs[i][:-5]}}"
);
auto {{outputs[i] + "_t"}} = this->GetMultiInputGrad(
{{name_in_forward_orig | to_opmaker_name}}
);
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endmacro %}
{%- endmacro %}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录