Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e119177a
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看板
提交
e119177a
编写于
10月 04, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use unique_ptr
上级
14a59d2e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
72 addition
and
68 deletion
+72
-68
paddle/framework/backward.cc
paddle/framework/backward.cc
+5
-3
paddle/framework/backward_test.cc
paddle/framework/backward_test.cc
+9
-11
paddle/operators/mean_op.cc
paddle/operators/mean_op.cc
+7
-7
paddle/operators/minus_op.cc
paddle/operators/minus_op.cc
+14
-11
paddle/operators/pad_op.cc
paddle/operators/pad_op.cc
+10
-10
paddle/operators/scale_op.cc
paddle/operators/scale_op.cc
+7
-7
paddle/operators/softmax_with_cross_entropy_op.cc
paddle/operators/softmax_with_cross_entropy_op.cc
+11
-11
paddle/operators/sum_op.cc
paddle/operators/sum_op.cc
+9
-8
未找到文件。
paddle/framework/backward.cc
浏览文件 @
e119177a
...
...
@@ -36,9 +36,11 @@ static inline std::unique_ptr<OperatorBase> CreateGradOp(
auto
grad_descs
=
info
.
grad_op_maker_
(
op_desc
);
std
::
vector
<
std
::
unique_ptr
<
OperatorBase
>>
grad_ops
;
grad_ops
.
reserve
(
grad_descs
.
size
());
std
::
transform
(
grad_descs
.
begin
(),
grad_descs
.
end
(),
std
::
back_inserter
(
grad_ops
),
[](
OpDescBind
&
grad_desc
)
{
return
OpRegistry
::
CreateOp
(
&
grad_desc
);
});
std
::
transform
(
grad_descs
.
begin
(),
grad_descs
.
end
(),
std
::
back_inserter
(
grad_ops
),
[](
const
std
::
unique_ptr
<
OpDescBind
>&
grad_desc
)
{
return
OpRegistry
::
CreateOp
(
grad_desc
.
get
());
});
PADDLE_ENFORCE_GT
(
grad_ops
.
size
(),
0
);
if
(
grad_ops
.
size
()
==
1
)
{
return
std
::
move
(
grad_ops
[
0
]);
...
...
paddle/framework/backward_test.cc
浏览文件 @
e119177a
...
...
@@ -39,13 +39,13 @@ class RowWiseAddGradMaker : public SingleGradOpDescMaker {
using
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
OpDescBind
Apply
()
const
override
{
OpDescBind
grad_op
;
grad_op
.
SetInput
(
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
grad_op
.
SetOutput
(
GradVarName
(
"X"
),
InputGrad
(
"X"
));
grad_op
.
SetOutput
(
GradVarName
(
"b"
),
InputGrad
(
"b"
));
grad_op
.
SetType
(
"rowwise_add_grad"
);
return
grad_op
;
std
::
unique_ptr
<
OpDescBind
>
Apply
()
const
override
{
auto
grad_op
=
new
OpDescBind
()
;
grad_op
->
SetInput
(
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
grad_op
->
SetOutput
(
GradVarName
(
"X"
),
InputGrad
(
"X"
));
grad_op
->
SetOutput
(
GradVarName
(
"b"
),
InputGrad
(
"b"
));
grad_op
->
SetType
(
"rowwise_add_grad"
);
return
std
::
unique_ptr
<
OpDescBind
>
(
grad_op
)
;
}
};
...
...
@@ -147,10 +147,8 @@ class SumOpMaker : public framework::OpProtoAndCheckerMaker {
public:
SumOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"the input tensors of sum operator."
)
.
AsDuplicable
()
.
NotInGradient
();
AddOutput
(
"Out"
,
"the output tensor of sum operator."
).
NotInGradient
();
AddInput
(
"X"
,
"the input tensors of sum operator."
).
AsDuplicable
();
AddOutput
(
"Out"
,
"the output tensor of sum operator."
);
AddComment
(
""
);
}
};
...
...
paddle/operators/mean_op.cc
浏览文件 @
e119177a
...
...
@@ -57,13 +57,13 @@ class MeanGradMaker : public framework::SingleGradOpDescMaker {
using
framework
::
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
framework
::
OpDescBind
Apply
()
const
override
{
framework
::
OpDescBind
grad_op
;
grad_op
.
SetType
(
"mean_grad"
);
grad_op
.
SetInput
(
"X"
,
Input
(
"X"
));
grad_op
.
SetInput
(
framework
::
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
grad_op
.
SetOutput
(
framework
::
GradVarName
(
"X"
),
InputGrad
(
"X"
));
return
grad_op
;
std
::
unique_ptr
<
framework
::
OpDescBind
>
Apply
()
const
override
{
auto
*
grad_op
=
new
framework
::
OpDescBind
()
;
grad_op
->
SetType
(
"mean_grad"
);
grad_op
->
SetInput
(
"X"
,
Input
(
"X"
));
grad_op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
grad_op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
InputGrad
(
"X"
));
return
std
::
unique_ptr
<
framework
::
OpDescBind
>
(
grad_op
)
;
}
};
...
...
paddle/operators/minus_op.cc
浏览文件 @
e119177a
...
...
@@ -69,19 +69,22 @@ class MinusGradMaker : public framework::GradOpDescMakerBase {
public:
using
framework
::
GradOpDescMakerBase
::
GradOpDescMakerBase
;
std
::
vector
<
framework
::
OpDescBind
>
operator
()()
const
override
{
std
::
vector
<
framework
::
OpDescBind
>
ops
;
std
::
vector
<
std
::
unique_ptr
<
framework
::
OpDescBind
>>
operator
()()
const
override
{
std
::
vector
<
std
::
unique_ptr
<
framework
::
OpDescBind
>>
ops
;
ops
.
resize
(
2
);
ops
[
0
].
SetType
(
"scale"
);
ops
[
0
].
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
ops
[
0
].
SetOutput
(
"Out"
,
InputGrad
(
"X"
));
ops
[
0
].
SetAttr
(
"scale"
,
1.0
f
);
ops
[
1
].
SetType
(
"scale"
);
ops
[
1
].
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
ops
[
1
].
SetOutput
(
"Out"
,
InputGrad
(
"Y"
));
ops
[
1
].
SetAttr
(
"scale"
,
-
1.0
f
);
ops
[
0
].
reset
(
new
framework
::
OpDescBind
());
ops
[
0
]
->
SetType
(
"scale"
);
ops
[
0
]
->
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
ops
[
0
]
->
SetOutput
(
"Out"
,
InputGrad
(
"X"
));
ops
[
0
]
->
SetAttr
(
"scale"
,
1.0
f
);
ops
[
1
].
reset
(
new
framework
::
OpDescBind
());
ops
[
1
]
->
SetType
(
"scale"
);
ops
[
1
]
->
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
ops
[
1
]
->
SetOutput
(
"Out"
,
InputGrad
(
"Y"
));
ops
[
1
]
->
SetAttr
(
"scale"
,
-
1.0
f
);
return
ops
;
}
};
...
...
paddle/operators/pad_op.cc
浏览文件 @
e119177a
...
...
@@ -111,18 +111,18 @@ class PadOpGrad : public framework::OperatorWithKernel {
};
class
PadOpGradMaker
:
public
framework
::
SingleGradOpDescMaker
{
protected:
framework
::
OpDescBind
Apply
()
const
override
{
framework
::
OpDescBind
bind
;
bind
.
SetInput
(
"X"
,
Input
(
"X"
));
bind
.
SetInput
(
framework
::
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
bind
.
SetOutput
(
framework
::
GradVarName
(
"X"
),
InputGrad
(
"X"
));
bind
.
SetAttrMap
(
Attrs
());
return
bind
;
}
public:
using
framework
::
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
std
::
unique_ptr
<
framework
::
OpDescBind
>
Apply
()
const
override
{
auto
*
bind
=
new
framework
::
OpDescBind
();
bind
->
SetInput
(
"X"
,
Input
(
"X"
));
bind
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
OutputGrad
(
"Out"
));
bind
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
InputGrad
(
"X"
));
bind
->
SetAttrMap
(
Attrs
());
return
std
::
unique_ptr
<
framework
::
OpDescBind
>
(
bind
);
}
};
}
// namespace operators
...
...
paddle/operators/scale_op.cc
浏览文件 @
e119177a
...
...
@@ -57,13 +57,13 @@ class ScaleGradMaker : public framework::SingleGradOpDescMaker {
using
framework
::
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
framework
::
OpDescBind
Apply
()
const
override
{
framework
::
OpDescBind
grad_op
;
grad_op
.
SetType
(
"scale"
);
grad_op
.
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
grad_op
.
SetOutput
(
"Out"
,
InputGrad
(
"X"
));
grad_op
.
SetAttr
(
"scale"
,
GetAttr
(
"scale"
));
return
grad_op
;
std
::
unique_ptr
<
framework
::
OpDescBind
>
Apply
()
const
override
{
auto
*
grad_op
=
new
framework
::
OpDescBind
()
;
grad_op
->
SetType
(
"scale"
);
grad_op
->
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
grad_op
->
SetOutput
(
"Out"
,
InputGrad
(
"X"
));
grad_op
->
SetAttr
(
"scale"
,
GetAttr
(
"scale"
));
return
std
::
unique_ptr
<
framework
::
OpDescBind
>
(
grad_op
)
;
}
};
...
...
paddle/operators/softmax_with_cross_entropy_op.cc
浏览文件 @
e119177a
...
...
@@ -167,17 +167,17 @@ class SoftmaxGradMaker : public framework::SingleGradOpDescMaker {
using
framework
::
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
framework
::
OpDescBind
Apply
()
const
override
{
framework
::
OpDescBind
grad_op
;
grad_op
.
SetType
(
"softmax_with_cross_entropy_grad"
);
grad_op
.
SetInput
(
"Label"
,
Input
(
"Label"
));
grad_op
.
SetInput
(
"Softmax"
,
Output
(
"Softmax"
));
grad_op
.
SetInput
(
"Loss"
,
Output
(
"Loss"
));
grad_op
.
SetInput
(
framework
::
GradVarName
(
"Softmax"
),
OutputGrad
(
"Softmax"
));
grad_op
.
SetInput
(
framework
::
GradVarName
(
"Loss"
),
OutputGrad
(
"Loss"
));
grad_op
.
SetOutput
(
framework
::
GradVarName
(
"Logits"
),
InputGrad
(
"Logits"
));
grad_op
.
SetAttrMap
(
Attrs
());
return
grad_op
;
std
::
unique_ptr
<
framework
::
OpDescBind
>
Apply
()
const
override
{
auto
*
grad_op
=
new
framework
::
OpDescBind
()
;
grad_op
->
SetType
(
"softmax_with_cross_entropy_grad"
);
grad_op
->
SetInput
(
"Label"
,
Input
(
"Label"
));
grad_op
->
SetInput
(
"Softmax"
,
Output
(
"Softmax"
));
grad_op
->
SetInput
(
"Loss"
,
Output
(
"Loss"
));
grad_op
->
SetInput
(
framework
::
GradVarName
(
"Softmax"
),
OutputGrad
(
"Softmax"
));
grad_op
->
SetInput
(
framework
::
GradVarName
(
"Loss"
),
OutputGrad
(
"Loss"
));
grad_op
->
SetOutput
(
framework
::
GradVarName
(
"Logits"
),
InputGrad
(
"Logits"
));
grad_op
->
SetAttrMap
(
Attrs
());
return
std
::
unique_ptr
<
framework
::
OpDescBind
>
(
grad_op
)
;
}
};
...
...
paddle/operators/sum_op.cc
浏览文件 @
e119177a
...
...
@@ -60,19 +60,20 @@ class SumGradMaker : public framework::GradOpDescMakerBase {
public:
using
framework
::
GradOpDescMakerBase
::
GradOpDescMakerBase
;
std
::
vector
<
framework
::
OpDescBind
>
operator
()()
const
override
{
std
::
vector
<
std
::
unique_ptr
<
framework
::
OpDescBind
>>
operator
()()
const
override
{
auto
x_grads
=
InputGrad
(
"X"
);
std
::
vector
<
framework
::
OpDescBind
>
grad_ops
;
std
::
vector
<
std
::
unique_ptr
<
framework
::
OpDescBind
>
>
grad_ops
;
grad_ops
.
reserve
(
x_grads
.
size
());
auto
og
=
OutputGrad
(
"Out"
);
std
::
transform
(
x_grads
.
begin
(),
x_grads
.
end
(),
std
::
back_inserter
(
grad_ops
),
[
&
og
](
const
std
::
string
&
x_grad
)
{
framework
::
OpDescBind
grad_op
;
grad_op
.
SetType
(
"scale"
);
grad_op
.
SetInput
(
"X"
,
og
);
grad_op
.
SetOutput
(
"Out"
,
{
x_grad
});
grad_op
.
SetAttr
(
"scale"
,
1.0
f
);
return
grad_op
;
auto
*
grad_op
=
new
framework
::
OpDescBind
()
;
grad_op
->
SetType
(
"scale"
);
grad_op
->
SetInput
(
"X"
,
og
);
grad_op
->
SetOutput
(
"Out"
,
{
x_grad
});
grad_op
->
SetAttr
(
"scale"
,
1.0
f
);
return
std
::
unique_ptr
<
framework
::
OpDescBind
>
(
grad_op
)
;
});
return
grad_ops
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录