Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
397758fb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
397758fb
编写于
6月 07, 2023
作者:
R
RedContritio
提交者:
GitHub
6月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate for static op reduce_min (#54315)
上级
bfbc2263
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
117 deletion
+40
-117
paddle/fluid/operators/reduce_ops/reduce_min_max_op.h
paddle/fluid/operators/reduce_ops/reduce_min_max_op.h
+0
-59
paddle/fluid/operators/reduce_ops/reduce_min_op.cc
paddle/fluid/operators/reduce_ops/reduce_min_op.cc
+0
-40
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
+0
-2
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+19
-5
paddle/phi/api/yaml/static_backward.yaml
paddle/phi/api/yaml/static_backward.yaml
+10
-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_min_max_op.h
已删除
100644 → 0
浏览文件 @
bfbc2263
// 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.
#pragma once
#include "paddle/fluid/operators/reduce_ops/reduce_op.h"
namespace
paddle
{
namespace
operators
{
struct
MaxFunctor
{
template
<
typename
DeviceContext
,
typename
X
,
typename
Y
,
typename
Dim
>
void
operator
()(
const
DeviceContext
&
place
,
X
*
x
,
Y
*
y
,
const
Dim
&
dim
)
{
y
->
device
(
place
)
=
x
->
maximum
(
dim
);
}
};
struct
MinFunctor
{
template
<
typename
DeviceContext
,
typename
X
,
typename
Y
,
typename
Dim
>
void
operator
()(
const
DeviceContext
&
place
,
X
*
x
,
Y
*
y
,
const
Dim
&
dim
)
{
y
->
device
(
place
)
=
x
->
minimum
(
dim
);
}
};
struct
MaxOrMinGradFunctor
{
template
<
typename
DeviceContext
,
typename
X
,
typename
Y
,
typename
DX
,
typename
DY
,
typename
Dim
>
void
operator
()(
const
DeviceContext
&
place
,
X
*
x
,
Y
*
y
,
DX
*
dx
,
DY
*
dy
,
const
Dim
&
dim
,
int
size
)
{
auto
equals
=
(
*
x
)
==
y
->
broadcast
(
dim
);
auto
ones
=
dx
->
constant
(
1
);
auto
zeros
=
dx
->
constant
(
0
);
// If there are multiple minimum or maximum elements, the subgradient of
// each is the set [0, 1], and we pass gradient to all of them here.
dx
->
device
(
place
)
=
dy
->
broadcast
(
dim
)
*
equals
.
select
(
ones
,
zeros
);
}
};
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/reduce_ops/reduce_min_op.cc
已删除
100644 → 0
浏览文件 @
bfbc2263
// 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/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"
namespace
ops
=
paddle
::
operators
;
class
ReduceMinOpMaker
:
public
ops
::
ReduceBaseOpMaker
{
protected:
virtual
std
::
string
GetName
()
const
{
return
"reduce_min"
;
}
virtual
std
::
string
GetOpType
()
const
{
return
"Reduce reduce_min"
;
}
};
DECLARE_INFER_SHAPE_FUNCTOR
(
reduce_min
,
ReduceMinInferShapeFunctor
,
PD_INFER_META
(
phi
::
ReduceIntArrayAxisInferMetaBase
));
REGISTER_OPERATOR
(
reduce_min
,
ops
::
ReduceBaseOp
,
ReduceMinOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
,
ReduceMinInferShapeFunctor
);
REGISTER_OPERATOR
(
reduce_min_grad
,
ops
::
ReduceGradOp
)
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
浏览文件 @
397758fb
...
...
@@ -11,5 +11,3 @@ register_unity_group(cu reduce_all_op.cu reduce_any_op.cu reduce_prod_op.cu
# compilation instruction when compiling in Unity Build.
register_unity_group
(
cu frobenius_norm_op.cu
)
register_unity_group
(
cu logsumexp_op.cu
)
register_unity_group
(
cu reduce_max_op.cu
)
register_unity_group
(
cu reduce_min_op.cu
)
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
397758fb
...
...
@@ -1692,6 +1692,25 @@
out
:
Out
drop_empty_grad
:
[
inputs_grad
]
-
op
:
min (reduce_min)
backward
:
min_grad (reduce_min_grad)
inputs
:
x
:
X
outputs
:
out
:
Out
attrs
:
{
axis
:
dim
,
keepdim
:
keep_dim
}
extra
:
attrs
:
[
bool use_mkldnn = false
]
int_array
:
axis
:
data_type
:
int
support_tensor
:
true
get_expected_kernel_type
:
min
:
GetReduceExpectedKernelType
min_grad
:
GetReduceGradExpectedKernelType
manual_signature
:
[
min
]
-
op
:
minimum (elementwise_min)
backward
:
minimum_grad (elementwise_min_grad)
extra
:
...
...
@@ -2008,11 +2027,6 @@
extra
:
attrs
:
[
bool use_mkldnn = false
,
bool use_cudnn = false
]
-
op
:
reduce_min
backward
:
reduce_min_grad
extra
:
attrs
:
[
bool use_mkldnn = false
]
-
op
:
relu
backward
:
relu_grad, relu_double_grad (relu_grad_grad)
inputs
:
...
...
paddle/phi/api/yaml/static_backward.yaml
浏览文件 @
397758fb
...
...
@@ -123,6 +123,16 @@
func
:
max_grad
composite
:
max_grad(x, out, out_grad, axis, keepdim, reduce_all, x_grad)
-
backward_op
:
min_grad
forward
:
min (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
:
min_grad
-
backward_op
:
pool2d_double_grad
forward
:
pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x)
args
:
(Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm)
...
...
paddle/phi/api/yaml/static_ops.yaml
浏览文件 @
397758fb
...
...
@@ -309,6 +309,17 @@
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
backward
:
max_grad
-
op
:
min
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
:
min_raw
param
:
[
x
,
axis
,
keepdim
,
reduce_all
]
backward
:
min_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
浏览文件 @
397758fb
...
...
@@ -167,14 +167,6 @@ KernelSignature ReduceMeanGradOpArgumentMapping(
{
"X@GRAD"
});
}
KernelSignature
ReduceMinGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"min_grad"
,
{
"X"
,
"Out"
,
"Out@GRAD"
},
{
"dim"
,
"keep_dim"
,
"reduce_all"
},
{
"X@GRAD"
});
}
KernelSignature
ReduceProdGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"prod_grad"
,
...
...
@@ -197,7 +189,6 @@ PD_REGISTER_BASE_KERNEL_NAME(reduce_any, any);
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_min_grad
,
min_grad
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_sum
,
phi
::
ReduceSumOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_mean
,
phi
::
ReduceMeanOpArgumentMapping
);
...
...
@@ -213,5 +204,3 @@ 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_min_grad
,
phi
::
ReduceMinGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录