Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
29f64c8c
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看板
未验证
提交
29f64c8c
编写于
12月 10, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
12月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine some grad op makers, test=develop (#21629)
上级
e2d849b9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
76 addition
and
30 deletion
+76
-30
paddle/fluid/op_use_default_grad_op_maker.spec
paddle/fluid/op_use_default_grad_op_maker.spec
+0
-4
paddle/fluid/operators/lstm_unit_op.cc
paddle/fluid/operators/lstm_unit_op.cc
+25
-4
paddle/fluid/operators/lstm_unit_op.cu
paddle/fluid/operators/lstm_unit_op.cu
+5
-7
paddle/fluid/operators/lstm_unit_op.h
paddle/fluid/operators/lstm_unit_op.h
+0
-3
paddle/fluid/operators/pool_with_index_op.cc
paddle/fluid/operators/pool_with_index_op.cc
+27
-10
paddle/fluid/operators/tensor_array_to_tensor_op.cc
paddle/fluid/operators/tensor_array_to_tensor_op.cc
+19
-2
未找到文件。
paddle/fluid/op_use_default_grad_op_maker.spec
浏览文件 @
29f64c8c
cos_sim
fsp
gru
lstm_unit
match_matrix_tensor
max_pool2d_with_index
max_pool3d_with_index
maxout
pool2d
pool3d
...
...
@@ -15,6 +12,5 @@ reshape
rnn_memory_helper
sequence_softmax
spp
tensor_array_to_tensor
transpose
unsqueeze
paddle/fluid/operators/lstm_unit_op.cc
浏览文件 @
29f64c8c
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/lstm_unit_op.h"
#include <memory>
namespace
paddle
{
namespace
operators
{
...
...
@@ -94,14 +95,34 @@ class LstmUnitGradOp : public framework::OperatorWithKernel {
}
};
template
<
typename
T
>
class
LstmUnitGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
std
::
unique_ptr
<
T
>
Apply
()
const
override
{
std
::
unique_ptr
<
T
>
op
(
new
T
());
op
->
SetType
(
"lstm_unit_grad"
);
op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
op
->
SetInput
(
"C_prev"
,
this
->
Input
(
"C_prev"
));
op
->
SetInput
(
"C"
,
this
->
Output
(
"C"
));
op
->
SetInput
(
framework
::
GradVarName
(
"H"
),
this
->
OutputGrad
(
"H"
));
op
->
SetInput
(
framework
::
GradVarName
(
"C"
),
this
->
OutputGrad
(
"C"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"C_prev"
),
this
->
InputGrad
(
"C_prev"
));
op
->
SetAttrMap
(
this
->
Attrs
());
return
op
;
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
lstm_unit
,
ops
::
LstmUnitOp
,
ops
::
LstmUnitOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
);
REGISTER_OPERATOR
(
lstm_unit
,
ops
::
LstmUnitOp
,
ops
::
LstmUnitOpMaker
,
ops
::
LstmUnitGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
LstmUnitGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
lstm_unit_grad
,
ops
::
LstmUnitGradOp
);
REGISTER_OP_CPU_KERNEL
(
lstm_unit
,
ops
::
LstmUnitKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
...
...
paddle/fluid/operators/lstm_unit_op.cu
浏览文件 @
29f64c8c
...
...
@@ -62,9 +62,9 @@ __global__ void LSTMUnitKernel(const int nthreads, const int dim,
template
<
typename
T
>
__global__
void
LSTMUnitGradientKernel
(
const
int
nthreads
,
const
int
dim
,
const
T
*
C_prev
,
const
T
*
X
,
const
T
*
C
,
const
T
*
H
,
const
T
*
C
_diff
,
const
T
*
H_diff
,
T
*
C_prev
_diff
,
T
*
X_diff
,
const
T
forget_bias
)
{
const
T
*
C_diff
,
const
T
*
H
_diff
,
T
*
C_prev_diff
,
T
*
X
_diff
,
const
T
forget_bias
)
{
CUDA_1D_KERNEL_LOOP
(
index
,
nthreads
)
{
const
int
n
=
index
/
dim
;
const
int
d
=
index
%
dim
;
...
...
@@ -146,7 +146,6 @@ class LstmUnitGradOpCUDAKernel : public framework::OpKernel<T> {
auto
*
X
=
x_tensor
->
data
<
T
>
();
auto
*
C_prev
=
c_prev_tensor
->
data
<
T
>
();
auto
*
C
=
c_tensor
->
data
<
T
>
();
auto
*
H
=
h_tensor
->
data
<
T
>
();
auto
*
H_diff
=
hdiff_tensor
->
data
<
T
>
();
auto
*
C_diff
=
cdiff_tensor
->
data
<
T
>
();
...
...
@@ -163,9 +162,8 @@ class LstmUnitGradOpCUDAKernel : public framework::OpKernel<T> {
int
n
=
N
*
D
;
int
grid
=
(
n
+
block
-
1
)
/
block
;
LSTMUnitGradientKernel
<
T
><<<
grid
,
block
>>>
(
n
,
D
,
C_prev
,
X
,
C
,
H
,
C_diff
,
H_diff
,
C_prev_diff
,
X_diff
,
forget_bias
);
LSTMUnitGradientKernel
<
T
><<<
grid
,
block
>>>
(
n
,
D
,
C_prev
,
X
,
C
,
C_diff
,
H_diff
,
C_prev_diff
,
X_diff
,
forget_bias
);
}
};
...
...
paddle/fluid/operators/lstm_unit_op.h
浏览文件 @
29f64c8c
...
...
@@ -88,7 +88,6 @@ class LstmUnitGradKernel : public framework::OpKernel<T> {
auto
x_tensor
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
c_prev_tensor
=
ctx
.
Input
<
Tensor
>
(
"C_prev"
);
auto
c_tensor
=
ctx
.
Input
<
Tensor
>
(
"C"
);
auto
h_tensor
=
ctx
.
Input
<
Tensor
>
(
"H"
);
auto
hdiff_tensor
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"H"
));
auto
cdiff_tensor
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"C"
));
...
...
@@ -100,7 +99,6 @@ class LstmUnitGradKernel : public framework::OpKernel<T> {
auto
*
X
=
x_tensor
->
data
<
T
>
();
auto
*
C_prev
=
c_prev_tensor
->
data
<
T
>
();
auto
*
C
=
c_tensor
->
data
<
T
>
();
auto
*
H
=
h_tensor
->
data
<
T
>
();
auto
*
H_diff
=
hdiff_tensor
->
data
<
T
>
();
auto
*
C_diff
=
cdiff_tensor
->
data
<
T
>
();
...
...
@@ -138,7 +136,6 @@ class LstmUnitGradKernel : public framework::OpKernel<T> {
C_prev
+=
D
;
X
+=
4
*
D
;
C
+=
D
;
H
+=
D
;
C_diff
+=
D
;
H_diff
+=
D
;
X_diff
+=
4
*
D
;
...
...
paddle/fluid/operators/pool_with_index_op.cc
浏览文件 @
29f64c8c
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/pool_with_index_op.h"
#include <memory>
namespace
paddle
{
namespace
operators
{
...
...
@@ -283,16 +284,33 @@ Example:
}
};
template
<
typename
T
>
class
MaxPoolWithIndexGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
std
::
unique_ptr
<
T
>
Apply
()
const
override
{
std
::
unique_ptr
<
T
>
op
(
new
T
());
op
->
SetType
(
this
->
ForwardOpType
()
+
"_grad"
);
op
->
SetAttrMap
(
this
->
Attrs
());
op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
op
->
SetInput
(
"Mask"
,
this
->
Output
(
"Mask"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
return
op
;
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
max_pool2d_with_index
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool2dWithIndexOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
);
REGISTER_OPERATOR
(
max_pool2d_with_index
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool2dWithIndexOpMaker
,
ops
::
MaxPoolWithIndexGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
MaxPoolWithIndexGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
max_pool2d_with_index_grad
,
ops
::
MaxPoolWithIndexOpGrad
);
REGISTER_OP_CPU_KERNEL
(
...
...
@@ -307,11 +325,10 @@ REGISTER_OP_CPU_KERNEL(
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
,
int
>
);
REGISTER_OPERATOR
(
max_pool3d_with_index
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool3dWithIndexOpMaker
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
true
>
);
REGISTER_OPERATOR
(
max_pool3d_with_index
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool3dWithIndexOpMaker
,
ops
::
MaxPoolWithIndexGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
MaxPoolWithIndexGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
max_pool3d_with_index_grad
,
ops
::
MaxPoolWithIndexOpGrad
);
REGISTER_OP_CPU_KERNEL
(
...
...
paddle/fluid/operators/tensor_array_to_tensor_op.cc
浏览文件 @
29f64c8c
...
...
@@ -273,6 +273,23 @@ class LoDTensorArray2TensorGradOp : public framework::OperatorBase {
}
};
template
<
typename
T
>
class
TensorArrayToTensorGradOpMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
protected:
std
::
unique_ptr
<
T
>
Apply
()
const
override
{
std
::
unique_ptr
<
T
>
op
(
new
T
());
op
->
SetType
(
"tensor_array_to_tensor_grad"
);
op
->
SetAttrMap
(
this
->
Attrs
());
op
->
SetInput
(
"X"
,
this
->
Input
(
"X"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
return
op
;
}
};
}
// namespace operators
}
// namespace paddle
USE_OP
(
concat
);
...
...
@@ -281,8 +298,8 @@ namespace ops = paddle::operators;
REGISTER_OPERATOR
(
tensor_array_to_tensor
,
ops
::
LoDTensorArray2TensorOp
,
ops
::
LoDTensorArray2TensorOpMaker
,
ops
::
LoDTensorArray2TensorOpInferShape
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
framework
::
OpDesc
,
true
>
,
paddle
::
framework
::
DefaultGradOpMaker
<
paddle
::
imperative
::
OpBase
,
tru
e
>
);
ops
::
TensorArrayToTensorGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
TensorArrayToTensorGradOpMaker
<
paddle
::
imperative
::
OpBas
e
>
);
REGISTER_OPERATOR
(
tensor_array_to_tensor_grad
,
ops
::
LoDTensorArray2TensorGradOp
,
ops
::
LoDTensorArray2TensorGradInferShape
,
ops
::
LoDTensorArray2TensorGradInferVarType
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录