Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a2d3c335
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看板
未验证
提交
a2d3c335
编写于
3月 28, 2023
作者:
张
张春乔
提交者:
GitHub
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate for cumprod (#52047)
* mv cumprod * add attrs * Update backward.yaml * Update backward.yaml
上级
6d0fa6f2
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
28 addition
and
139 deletion
+28
-139
paddle/fluid/operators/cumprod_op.cc
paddle/fluid/operators/cumprod_op.cc
+0
-94
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+10
-0
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+0
-10
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-9
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+9
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+9
-0
paddle/phi/ops/compat/cumprod_sig.cc
paddle/phi/ops/compat/cumprod_sig.cc
+0
-26
未找到文件。
paddle/fluid/operators/cumprod_op.cc
已删除
100644 → 0
浏览文件 @
6d0fa6f2
// Copyright (c) 2021 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/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
class
CumprodOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
};
class
CumprodOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor), The input tensor of cumprod op."
);
AddOutput
(
"Out"
,
"(Tensor), The output tensor of cumprod op."
);
AddAttr
<
int
>
(
"dim"
,
"(int), The dim along which the input tensors will be cumproded"
);
AddComment
(
R"DOC(Cumprod operator. Return the cumprod results of the input elements along the dim.
For example, if input X is a tensor with rank 1 and N elements, the output will also be a tensor
with rank 1 and N elements, and elements y[i] = x[0] * x[1] * x[2] *...* x[i] (0<=i<N))DOC"
);
}
};
template
<
typename
T
>
class
CumprodGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
grad_op
)
const
override
{
grad_op
->
SetType
(
"cumprod_grad"
);
grad_op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
grad_op
->
SetInput
(
"Out"
,
this
->
Output
(
"Out"
));
grad_op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
grad_op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
grad_op
->
SetAttrMap
(
this
->
Attrs
());
}
};
class
CumprodGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"CumprodGrad"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Out"
),
"Input"
,
"Out"
,
"CumprodGrad"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input"
,
"framework::GradVarName(
\"
Out
\"
)"
,
"CumprodGrad"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"Output"
,
"framework::GradVarName(
\"
X
\"
)"
,
"CumprodGrad"
);
ctx
->
ShareDim
(
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
));
ctx
->
ShareLoD
(
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
cumprod
,
CumprodInferShapeFunctor
,
PD_INFER_META
(
phi
::
UnchangedInferMetaCheckAxis
));
REGISTER_OPERATOR
(
cumprod
,
ops
::
CumprodOp
,
ops
::
CumprodOpMaker
,
ops
::
CumprodGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
CumprodGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
CumprodInferShapeFunctor
);
REGISTER_OPERATOR
(
cumprod_grad
,
ops
::
CumprodGradOp
);
paddle/phi/api/yaml/backward.yaml
浏览文件 @
a2d3c335
...
...
@@ -337,6 +337,16 @@
func
:
cross_grad
data_type
:
out_grad
-
backward_op
:
cumprod_grad
forward
:
cumprod (Tensor x, int dim) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, int dim)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
cumprod_grad
-
backward_op
:
det_grad
forward
:
det (Tensor x) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
a2d3c335
...
...
@@ -273,16 +273,6 @@
data_type
:
softmax
inplace
:
(softmax -> input_grad)
-
backward_op
:
cumprod_grad
forward
:
cumprod (Tensor x, int dim) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, int dim)
output
:
Tensor(x_grad)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
kernel
:
func
:
cumprod_grad
-
backward_op
:
cumsum_grad
forward
:
cumsum(Tensor x, Scalar axis, bool flatten, bool exclusive, bool reverse) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, Scalar axis, bool flatten, bool exclusive, bool reverse)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
a2d3c335
...
...
@@ -388,15 +388,6 @@
data_type
:
input
backward
:
cross_entropy_with_softmax_grad
-
op
:
cumprod
args
:
(Tensor x, int dim)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMetaCheckAxis
kernel
:
func
:
cumprod
backward
:
cumprod_grad
-
op
:
cumsum
args
:
(Tensor x, Scalar axis, bool flatten, bool exclusive, bool reverse)
output
:
Tensor(out)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
a2d3c335
...
...
@@ -398,6 +398,15 @@
outputs
:
out
:
Out
-
op
:
cumprod
backward
:
cumprod_grad
inputs
:
x
:
X
attrs
:
dim
:
dim
outputs
:
out
:
Out
-
op
:
cumsum
backward
:
cumsum_grad
inputs
:
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
a2d3c335
...
...
@@ -320,6 +320,15 @@
data_type
:
x
backward
:
cross_grad
-
op
:
cumprod
args
:
(Tensor x, int dim)
output
:
Tensor(out)
infer_meta
:
func
:
UnchangedInferMetaCheckAxis
kernel
:
func
:
cumprod
backward
:
cumprod_grad
-
op
:
det
args
:
(Tensor x)
output
:
Tensor
...
...
paddle/phi/ops/compat/cumprod_sig.cc
已删除
100644 → 0
浏览文件 @
6d0fa6f2
// Copyright (c) 2022 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/phi/core/compat/op_utils.h"
namespace
phi
{
KernelSignature
CumprodGradGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"cumprod_grad"
,
{
"X"
,
"Out"
,
"Out@GRAD"
},
{
"dim"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
cumprod_grad
,
phi
::
CumprodGradGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录