Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1e34f9e1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
1e34f9e1
编写于
6月 02, 2023
作者:
R
RedContritio
提交者:
GitHub
6月 02, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate for static op reduce_max (#54286)
上级
d015ecf5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
29 addition
and
83 deletion
+29
-83
paddle/fluid/operators/reduce_ops/reduce_max_op.cc
paddle/fluid/operators/reduce_ops/reduce_max_op.cc
+0
-70
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+7
-2
paddle/phi/api/yaml/static_backward.yaml
paddle/phi/api/yaml/static_backward.yaml
+11
-0
paddle/phi/api/yaml/static_ops.yaml
paddle/phi/api/yaml/static_ops.yaml
+11
-0
paddle/phi/ops/compat/reduce_sig.cc
paddle/phi/ops/compat/reduce_sig.cc
+0
-11
未找到文件。
paddle/fluid/operators/reduce_ops/reduce_max_op.cc
已删除
100644 → 0
浏览文件 @
d015ecf5
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/operators/reduce_ops/reduce_min_max_op.h"
#include "paddle/fluid/prim/api/composite_backward/composite_backward_api.h"
#include "paddle/fluid/prim/utils/static/composite_grad_desc_maker.h"
#include "paddle/fluid/prim/utils/static/desc_tensor.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"
namespace
ops
=
paddle
::
operators
;
class
ReduceMaxOpMaker
:
public
ops
::
ReduceBaseOpMaker
{
protected:
virtual
std
::
string
GetName
()
const
{
return
"reduce_max"
;
}
virtual
std
::
string
GetOpType
()
const
{
return
"Reduce reduce_max"
;
}
};
namespace
paddle
{
namespace
operators
{
class
ReduceMaxCompositeGradOpMaker
:
public
prim
::
CompositeGradOpMakerBase
{
public:
using
prim
::
CompositeGradOpMakerBase
::
CompositeGradOpMakerBase
;
void
Apply
()
override
{
paddle
::
Tensor
x
=
this
->
GetSingleForwardInput
(
"X"
);
paddle
::
Tensor
out
=
this
->
GetSingleForwardOutput
(
"Out"
);
paddle
::
Tensor
out_grad
=
this
->
GetSingleOutputGrad
(
"Out"
);
std
::
vector
<
int
>
axis
=
this
->
Attr
<
std
::
vector
<
int
>>
(
"dim"
);
bool
keep_dim
=
this
->
Attr
<
bool
>
(
"keep_dim"
);
bool
reduce_all
=
this
->
Attr
<
bool
>
(
"reduce_all"
);
paddle
::
Tensor
x_grad_t
=
this
->
GetSingleInputGrad
(
"X"
);
paddle
::
Tensor
*
x_grad
=
this
->
GetOutputPtr
(
&
x_grad_t
);
std
::
string
x_grad_name
=
this
->
GetOutputName
(
x_grad_t
);
VLOG
(
6
)
<<
"Runing max_grad composite func"
;
prim
::
max_grad
<
prim
::
DescTensor
>
(
x
,
out
,
out_grad
,
axis
,
keep_dim
,
reduce_all
,
x_grad
);
this
->
RecoverOutputName
(
x_grad_t
,
x_grad_name
);
}
};
}
// namespace operators
}
// namespace paddle
DECLARE_INFER_SHAPE_FUNCTOR
(
reduce_max
,
ReduceMaxInferShapeFunctor
,
PD_INFER_META
(
phi
::
ReduceIntArrayAxisInferMetaBase
));
REGISTER_OPERATOR
(
reduce_max
,
ops
::
ReduceBaseOp
,
ReduceMaxOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
,
ops
::
ReduceMaxCompositeGradOpMaker
,
ReduceMaxInferShapeFunctor
);
REGISTER_OPERATOR
(
reduce_max_grad
,
ops
::
ReduceGradOp
)
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
1e34f9e1
...
...
@@ -1560,11 +1560,16 @@
{
axis
:
dim
,
keepdim
:
keep_dim
}
outputs
:
out
:
Out
extra
:
attrs
:
[
bool use_mkldnn = false
]
int_array
:
axis
:
data_type
:
int
extra
:
attrs
:
[
bool use_mkldnn = false
]
support_tensor
:
true
get_expected_kernel_type
:
max
:
GetReduceExpectedKernelType
max_grad
:
GetReduceGradExpectedKernelType
manual_signature
:
[
max
]
-
op
:
max_pool2d_with_index
inputs
:
...
...
paddle/phi/api/yaml/static_backward.yaml
浏览文件 @
1e34f9e1
...
...
@@ -75,6 +75,17 @@
param
:
[
x
,
out_grad
]
inplace
:
(out_grad -> x_grad)
-
backward_op
:
max_grad
forward
:
max (Tensor x, IntArray axis={0}, bool keepdim=false, bool reduce_all=false, int in_dtype=-1, int out_dtype=-1) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, IntArray axis={}, bool keepdim=false, bool reduce_all=false)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
max_grad
composite
:
max_grad(x, out, out_grad, axis, keepdim, reduce_all, x_grad)
-
backward_op
:
relu6_grad
forward
:
relu6 (Tensor x, float threshold = 6.0f) -> Tensor(out)
args
:
(Tensor out, Tensor out_grad)
...
...
paddle/phi/api/yaml/static_ops.yaml
浏览文件 @
1e34f9e1
...
...
@@ -262,6 +262,17 @@
matrix_rank_tol {dense, dense -> dense}
data_type
:
x
-
op
:
max
args
:
(Tensor x, IntArray axis={0}, bool keepdim=false, bool reduce_all=false, int in_dtype=-1, int out_dtype=-1)
output
:
Tensor(out)
infer_meta
:
func
:
ReduceIntArrayAxisInferMetaBase
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
kernel
:
func
:
max_raw
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
backward
:
max_grad
-
op
:
not_equal
args
:
(Tensor x, Tensor y, int axis = -1, bool force_cpu=false)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/reduce_sig.cc
浏览文件 @
1e34f9e1
...
...
@@ -175,14 +175,6 @@ KernelSignature ReduceMeanGradOpArgumentMapping(
{
"X@GRAD"
});
}
KernelSignature
ReduceMaxGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"max_grad"
,
{
"X"
,
"Out"
,
"Out@GRAD"
},
{
"dim"
,
"keep_dim"
,
"reduce_all"
},
{
"X@GRAD"
});
}
KernelSignature
ReduceMinGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"min_grad"
,
...
...
@@ -214,7 +206,6 @@ PD_REGISTER_BASE_KERNEL_NAME(reduce_any, any);
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_sum_grad
,
sum_grad
);
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_mean_grad
,
mean_grad
);
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_prod_grad
,
prod_grad
);
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_max_grad
,
max_grad
);
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_min_grad
,
min_grad
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_sum
,
phi
::
ReduceSumOpArgumentMapping
);
...
...
@@ -233,7 +224,5 @@ PD_REGISTER_ARG_MAPPING_FN(reduce_mean_grad,
phi
::
ReduceMeanGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_prod_grad
,
phi
::
ReduceProdGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_max_grad
,
phi
::
ReduceMaxGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_min_grad
,
phi
::
ReduceMinGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录