Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ac94b135
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看板
未验证
提交
ac94b135
编写于
6月 28, 2023
作者:
R
RedContritio
提交者:
GitHub
6月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate for static op reduce_prod (#54316)
上级
add77ccb
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
32 addition
and
147 deletion
+32
-147
paddle/fluid/operators/reduce_ops/reduce_prod_op.cc
paddle/fluid/operators/reduce_ops/reduce_prod_op.cc
+0
-90
paddle/fluid/operators/reduce_ops/reduce_prod_op.h
paddle/fluid/operators/reduce_ops/reduce_prod_op.h
+0
-41
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
+2
-3
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
+12
-0
paddle/phi/ops/compat/reduce_sig.cc
paddle/phi/ops/compat/reduce_sig.cc
+0
-11
未找到文件。
paddle/fluid/operators/reduce_ops/reduce_prod_op.cc
已删除
100644 → 0
浏览文件 @
add77ccb
// 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/operators/reduce_ops/reduce_prod_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/fluid/framework/infershape_utils.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
framework
{
class
OpDesc
;
}
// namespace framework
namespace
imperative
{
class
OpBase
;
}
// namespace imperative
}
// namespace paddle
namespace
paddle
{
namespace
operators
{
class
ReduceProdCompositeGradOpMaker
:
public
prim
::
CompositeGradOpMakerBase
{
public:
using
prim
::
CompositeGradOpMakerBase
::
CompositeGradOpMakerBase
;
void
Apply
()
override
{
// get inputs
paddle
::
Tensor
x
=
this
->
GetSingleForwardInput
(
"X"
);
paddle
::
Tensor
out
=
this
->
GetSingleForwardOutput
(
"Out"
);
paddle
::
Tensor
out_grad
=
this
->
GetSingleOutputGrad
(
"Out"
);
// get attr
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"
);
// get output
paddle
::
Tensor
x_grad_t
=
this
->
GetSingleInputGrad
(
"X"
);
// get output ptr
auto
x_grad
=
this
->
GetOutputPtr
(
&
x_grad_t
);
// get output orginal name
std
::
string
x_grad_name
=
this
->
GetOutputName
(
x_grad_t
);
VLOG
(
6
)
<<
"Runing prod_grad composite func"
;
// call composite backward func
prim
::
prod_grad
<
prim
::
DescTensor
>
(
x
,
out
,
out_grad
,
axis
,
keep_dim
,
reduce_all
,
x_grad
);
// recover output name
this
->
RecoverOutputName
(
x_grad_t
,
x_grad_name
);
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
class
ReduceProdOpMaker
:
public
ops
::
ReduceBaseOpMaker
{
protected:
virtual
std
::
string
GetName
()
const
{
return
"reduce_prod"
;
}
virtual
std
::
string
GetOpType
()
const
{
return
"Reduce reduce_prod"
;
}
};
DECLARE_INFER_SHAPE_FUNCTOR
(
reduce_prod
,
ReduceProdInferShapeFunctor
,
PD_INFER_META
(
phi
::
ReduceIntArrayAxisInferMetaBase
));
REGISTER_OPERATOR
(
reduce_prod
,
ops
::
ReduceBaseOp
,
ReduceProdOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
,
ops
::
ReduceProdCompositeGradOpMaker
,
ReduceProdInferShapeFunctor
);
REGISTER_OPERATOR
(
reduce_prod_grad
,
ops
::
ReduceGradOp
);
paddle/fluid/operators/reduce_ops/reduce_prod_op.h
已删除
100644 → 0
浏览文件 @
add77ccb
// 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
ProdGradFunctor
{
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
)
{
dx
->
device
(
place
)
=
dy
->
broadcast
(
dim
)
*
y
->
broadcast
(
dim
)
*
x
->
inverse
();
}
};
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/reduce_ops/unity_build_rule.cmake
浏览文件 @
ac94b135
...
...
@@ -4,9 +4,8 @@
# Generally, the combination rules in this file do not need to be modified.
# If there are some redefined error in compiling with the source file which
# in combination rule, you can remove the source file from the following rules.
register_unity_group
(
cc reduce_all_op.cc reduce_any_op.cc reduce_prod_op.cc
)
register_unity_group
(
cu reduce_all_op.cu reduce_any_op.cu reduce_prod_op.cu
reduce_prod_op.part.cu
)
register_unity_group
(
cc reduce_all_op.cc reduce_any_op.cc
)
register_unity_group
(
cu reduce_all_op.cu reduce_any_op.cu
)
# The following groups are to make better use of `/MP` which MSVC's parallel
# compilation instruction when compiling in Unity Build.
register_unity_group
(
cu frobenius_norm_op.cu
)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
ac94b135
...
...
@@ -2029,15 +2029,20 @@
backward
:
prod_grad (reduce_prod_grad)
inputs
:
x
:
X
attrs
:
{
dims
:
dim
,
keep_dim
:
keep_dim
}
outputs
:
out
:
Out
attrs
:
{
dims
:
dim
,
keep_dim
:
keep_dim
}
int_array
:
dims
:
data_type
:
int
support_tensor
:
true
extra
:
attrs
:
[
bool use_mkldnn = false
]
get_expected_kernel_type
:
prod
:
GetReduceExpectedKernelType
prod_grad
:
GetReduceGradExpectedKernelType
manual_signature
:
[
prod
]
-
op
:
put_along_axis
backward
:
put_along_axis_grad
...
...
paddle/phi/api/yaml/static_backward.yaml
浏览文件 @
ac94b135
...
...
@@ -222,6 +222,17 @@
func
:
pool3d_grad
param
:
[
x
,
out
,
out_grad
,
kernel_size
,
strides
,
paddings
,
ceil_mode
,
exclusive
,
data_format
,
pooling_type
,
global_pooling
,
adaptive
,
padding_algorithm
]
-
backward_op
:
prod_grad
forward
:
prod (Tensor x, IntArray dims={0}, bool keep_dim=false, bool reduce_all=false, int in_dtype=-1, DataType out_dtype=DataType::UNDEFINED) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, IntArray dims={0}, bool keep_dim=false, bool reduce_all=false)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
prod_grad
composite
:
prod_grad(x, out, out_grad, dims, keep_dim, 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
浏览文件 @
ac94b135
...
...
@@ -433,6 +433,18 @@
param
:
[
x
,
kernel_size
,
strides
,
paddings
,
ceil_mode
,
exclusive
,
data_format
,
pooling_type
,
global_pooling
,
adaptive
,
padding_algorithm
]
backward
:
pool3d_grad
-
op
:
prod
args
:
(Tensor x, IntArray dims={0}, bool keep_dim=false, bool reduce_all=false, int in_dtype=-1, DataType out_dtype=DataType::UNDEFINED)
output
:
Tensor(out)
infer_meta
:
func
:
ReduceIntArrayAxisInferMetaBase
param
:
[
x
,
dims
,
keep_dim
,
reduce_all
,
out_dtype
]
kernel
:
func
:
prod
param
:
[
x
,
dims
,
keep_dim
,
reduce_all
,
out_dtype
]
data_type
:
x
backward
:
prod_grad
-
op
:
randint
args
:
(int low, int high, IntArray shape = {}, DataType dtype = DataType::INT64, int seed = 0)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/reduce_sig.cc
浏览文件 @
ac94b135
...
...
@@ -167,14 +167,6 @@ KernelSignature ReduceMeanGradOpArgumentMapping(
{
"X@GRAD"
});
}
KernelSignature
ReduceProdGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
UNUSED
)
{
return
KernelSignature
(
"prod_grad"
,
{
"X"
,
"Out"
,
"Out@GRAD"
},
{
"dim"
,
"keep_dim"
,
"reduce_all"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
reduce_sum
,
sum
);
...
...
@@ -188,7 +180,6 @@ PD_REGISTER_BASE_KERNEL_NAME(reduce_all, all);
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_ARG_MAPPING_FN
(
reduce_sum
,
phi
::
ReduceSumOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_mean
,
phi
::
ReduceMeanOpArgumentMapping
);
...
...
@@ -202,5 +193,3 @@ PD_REGISTER_ARG_MAPPING_FN(reduce_any, phi::ReduceAnyOpArgumentMapping);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_mean_grad
,
phi
::
ReduceMeanGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
reduce_prod_grad
,
phi
::
ReduceProdGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录