Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
891cf433
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看板
未验证
提交
891cf433
编写于
4月 10, 2023
作者:
W
Wang Xin
提交者:
GitHub
4月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for logcumsumexp op (#52682)
上级
aa35331f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
26 addition
and
136 deletion
+26
-136
paddle/fluid/operators/cum_op.cc
paddle/fluid/operators/cum_op.cc
+0
-78
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
+7
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+9
-0
paddle/phi/ops/compat/logcumsumexp_sig.cc
paddle/phi/ops/compat/logcumsumexp_sig.cc
+0
-39
未找到文件。
paddle/fluid/operators/cum_op.cc
浏览文件 @
891cf433
...
...
@@ -123,74 +123,6 @@ class CumsumCompositeGradOpMaker : public prim::CompositeGradOpMakerBase {
this
->
RecoverOutputName
(
dx
,
dx_name
);
}
};
class
LogcumsumexpOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"Input of logcumsumexp operator"
);
AddOutput
(
"Out"
,
"Output of logcumsumexp operator"
);
AddAttr
<
int
>
(
"axis"
,
"The dimension to accumulate along. -1 means the last "
"dimension [default -1]."
)
.
SetDefault
(
-
1
);
AddAttr
<
bool
>
(
"flatten"
,
"Whether to compute the logcumsumexp over the flattened array. "
"[default false]."
)
.
SetDefault
(
false
);
AddAttr
<
bool
>
(
"exclusive"
,
"Whether to perform exclusive logcumsumexp. [default false]."
)
.
SetDefault
(
false
);
AddAttr
<
bool
>
(
"reverse"
,
"If true, the logcumsumexp is performed in the reversed direction. "
"[default false]."
)
.
SetDefault
(
false
);
AddComment
(
R"DOC(
Returns the logarithm of the cumulative summation of the exponentiation of elements of input along the given axis.
By default, the first element of the result is the same of the first element of
the input. If exclusive is true, the first element of the result is the lowest finite value of the dtype of output tensor.
)DOC"
);
}
};
class
LogcumsumexpGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"logcumsumexp"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Out"
),
"Input"
,
"Out"
,
"logcumsumexp"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input"
,
"Out@GRAD"
,
"logcumsumexp"
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
};
template
<
typename
T
>
class
LogcumsumexpGradMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
void
Apply
(
GradOpPtr
<
T
>
grad_op
)
const
override
{
grad_op
->
SetType
(
"logcumsumexp_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
->
SetAttr
(
"axis"
,
PADDLE_GET_CONST
(
int
,
this
->
GetAttr
(
"axis"
)));
grad_op
->
SetAttr
(
"flatten"
,
PADDLE_GET_CONST
(
bool
,
this
->
GetAttr
(
"flatten"
)));
grad_op
->
SetAttr
(
"exclusive"
,
PADDLE_GET_CONST
(
bool
,
this
->
GetAttr
(
"exclusive"
)));
grad_op
->
SetAttr
(
"reverse"
,
PADDLE_GET_CONST
(
bool
,
this
->
GetAttr
(
"reverse"
)));
}
};
}
// namespace operators
}
// namespace paddle
...
...
@@ -200,9 +132,6 @@ DECLARE_INFER_SHAPE_FUNCTOR(cumsum,
CumsumInferShapeFunctor
,
PD_INFER_META
(
phi
::
CumScalarAxisInferMeta
));
DECLARE_INFER_SHAPE_FUNCTOR
(
logcumsumexp
,
LogcumsumexpInferShapeFunctor
,
PD_INFER_META
(
phi
::
CumInferMeta
));
REGISTER_OPERATOR
(
cumsum
,
ops
::
CumOp
,
ops
::
CumsumOpMaker
,
...
...
@@ -210,13 +139,6 @@ REGISTER_OPERATOR(cumsum,
ops
::
CumsumGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
CumsumGradMaker
<
paddle
::
imperative
::
OpBase
>
,
CumsumInferShapeFunctor
);
REGISTER_OPERATOR
(
logcumsumexp
,
ops
::
CumOp
,
ops
::
LogcumsumexpOpMaker
,
ops
::
LogcumsumexpGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
LogcumsumexpGradMaker
<
paddle
::
imperative
::
OpBase
>
,
LogcumsumexpInferShapeFunctor
);
REGISTER_OPERATOR
(
logcumsumexp_grad
,
ops
::
LogcumsumexpGradOp
);
REGISTER_OPERATOR
(
cumsum_grad
,
ops
::
CumGradOp
);
REGISTER_OP_VERSION
(
cumsum
).
AddCheckpoint
(
...
...
paddle/phi/api/yaml/backward.yaml
浏览文件 @
891cf433
...
...
@@ -966,6 +966,16 @@
func
:
log_softmax_grad
data_type
:
out_grad
-
backward_op
:
logcumsumexp_grad
forward
:
logcumsumexp(Tensor x, int axis=-1, bool flatten=false, bool exclusive=false, bool reverse=false) -> Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
args
:
(Tensor x, Tensor out, Tensor out_grad, int axis, bool flatten, bool exclusive, bool reverse)
output
:
Tensor(x_grad)
kernel
:
func
:
logcumsumexp_grad
-
backward_op
:
logit_grad
forward
:
logit (Tensor x, float eps = 1e-6f) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, float eps)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
891cf433
...
...
@@ -556,16 +556,6 @@
no_need_buffer
:
bias
optional
:
scale, bias
-
backward_op
:
logcumsumexp_grad
forward
:
logcumsumexp(Tensor x, int axis, bool flatten, bool exclusive, bool reverse) -> Tensor(out)
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
x
]
args
:
(Tensor x, Tensor out, Tensor out_grad, int axis, bool flatten, bool exclusive, bool reverse)
output
:
Tensor(x_grad)
kernel
:
func
:
logcumsumexp_grad
-
backward_op
:
logsumexp_grad
forward
:
logsumexp(Tensor x, int64_t[] axis, bool keepdim, bool reduce_all) -> Tensor(out)
args
:
(Tensor x, Tensor out, Tensor out_grad, int64_t[] axis, bool keepdim, bool reduce_all)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
891cf433
...
...
@@ -800,15 +800,6 @@
data_type
:
dtype
backend
:
place
-
op
:
logcumsumexp
args
:
(Tensor x, int axis, bool flatten, bool exclusive, bool reverse)
output
:
Tensor(out)
infer_meta
:
func
:
CumInferMeta
kernel
:
func
:
logcumsumexp
backward
:
logcumsumexp_grad
-
op
:
logspace
args
:
(Tensor start, Tensor stop, Tensor num, Tensor base, DataType dtype, Place place={})
output
:
Tensor(out)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
891cf433
...
...
@@ -1247,6 +1247,13 @@
extra
:
attrs
:
[
bool use_mkldnn = false
]
-
op
:
logcumsumexp
backward
:
logcumsumexp_grad
inputs
:
x
:
X
outputs
:
out
:
Out
-
op
:
logical_and
inputs
:
{
x
:
X
,
y
:
Y
}
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
891cf433
...
...
@@ -1003,6 +1003,15 @@
data_type
:
x
backward
:
log_softmax_grad
-
op
:
logcumsumexp
args
:
(Tensor x, int axis=-1, bool flatten=false, bool exclusive=false, bool reverse=false)
output
:
Tensor(out)
infer_meta
:
func
:
CumInferMeta
kernel
:
func
:
logcumsumexp
backward
:
logcumsumexp_grad
-
op
:
logical_and
args
:
(Tensor x, Tensor y)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/logcumsumexp_sig.cc
已删除
100644 → 0
浏览文件 @
aa35331f
// 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
LogcumsumexpOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"logcumsumexp"
,
{
"X"
},
{
"axis"
,
"flatten"
,
"exclusive"
,
"reverse"
},
{
"Out"
});
}
KernelSignature
LogcumsumexpGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"logcumsumexp_grad"
,
{
"X"
,
"Out"
,
"Out@GRAD"
},
{
"axis"
,
"flatten"
,
"exclusive"
,
"reverse"
},
{
"X@GRAD"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
logcumsumexp
,
phi
::
LogcumsumexpOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
logcumsumexp_grad
,
phi
::
LogcumsumexpGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录