Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
c10da26c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c10da26c
编写于
10月 05, 2017
作者:
S
sidgoyal78
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify implementation
上级
d28b3094
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
28 addition
and
23 deletion
+28
-23
paddle/operators/momentum_op.cc
paddle/operators/momentum_op.cc
+20
-15
paddle/operators/momentum_op.h
paddle/operators/momentum_op.h
+6
-6
python/paddle/v2/framework/tests/test_momentum_op.py
python/paddle/v2/framework/tests/test_momentum_op.py
+2
-2
未找到文件。
paddle/operators/momentum_op.cc
浏览文件 @
c10da26c
...
@@ -57,25 +57,30 @@ class MomentumOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -57,25 +57,30 @@ class MomentumOpMaker : public framework::OpProtoAndCheckerMaker {
MomentumOpMaker
(
framework
::
OpProto
*
proto
,
MomentumOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Param"
,
"Input parameter"
);
AddInput
(
"Param"
,
AddInput
(
"Grad"
,
"Input gradient"
);
"(Tensor, default Tensor<float>) "
AddInput
(
"Velocity"
,
"Input velocity"
);
"Input parameter that has to be updated"
);
AddInput
(
"LearningRate"
,
"Input learning rate"
);
AddInput
(
"Grad"
,
"(Tensor, default Tensor<float>) "
AddOutput
(
"ParamOut"
,
"Output parameter"
);
"Input gradient of the parameter"
);
AddOutput
(
"VelocityOut"
,
"Output velocity"
);
AddInput
(
"Velocity"
,
"(Tensor, default Tensor<float>) "
AddAttr
<
float
>
(
"mu"
,
"Momentum coefficient"
);
"Input velocity (corresponding to the parameter) "
"that has to be updated"
);
AddInput
(
"LearningRate"
,
"(Tensor, default Tensor<float>) "
"Input learning rate"
);
AddOutput
(
"ParamOut"
,
"(Tensor) Output updated parameter"
);
AddOutput
(
"VelocityOut"
,
"(Tensor) Output updated velocity"
);
AddAttr
<
float
>
(
"mu"
,
"(float) Momentum coefficient"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Momentum Algorithm (momentum).
Momentum Algorithm (momentum).
velocity_out = mu * velocity - learning_rate * grad
velocity = mu * velocity + gradient
param_out = param + velocity_out
param = param - learning_rate * velocity
Ref: Sutskever, Ilya, et al. "On the importance of initialization
and momentum in deep learning." ICML 2013;
http://jmlr.org/proceedings/papers/v28/sutskever13.pdf
)DOC"
);
)DOC"
);
}
}
...
...
paddle/operators/momentum_op.h
浏览文件 @
c10da26c
...
@@ -36,16 +36,16 @@ class MomentumOpKernel : public framework::OpKernel<T> {
...
@@ -36,16 +36,16 @@ class MomentumOpKernel : public framework::OpKernel<T> {
float
mu
=
ctx
.
Attr
<
float
>
(
"mu"
);
float
mu
=
ctx
.
Attr
<
float
>
(
"mu"
);
auto
p
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Param"
));
auto
p
aram
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Param"
));
auto
g
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Grad"
));
auto
g
rad
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Grad"
));
auto
v
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Velocity"
));
auto
v
elocity
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Velocity"
));
float
l
r
=
ctx
.
Input
<
Tensor
>
(
"LearningRate"
)
->
data
<
float
>
()[
0
];
float
l
earning_rate
=
ctx
.
Input
<
Tensor
>
(
"LearningRate"
)
->
data
<
float
>
()[
0
];
auto
p_out
=
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
p_out
=
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
v_out
=
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
v_out
=
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
place
=
ctx
.
GetEigenDevice
<
Place
>
();
auto
place
=
ctx
.
GetEigenDevice
<
Place
>
();
v_out
.
device
(
place
)
=
mu
*
v
-
lr
*
g
;
v_out
.
device
(
place
)
=
velocity
*
mu
+
grad
;
p_out
.
device
(
place
)
=
p
+
v_out
;
p_out
.
device
(
place
)
=
p
aram
-
learning_rate
*
v_out
;
}
}
};
};
...
...
python/paddle/v2/framework/tests/test_momentum_op.py
浏览文件 @
c10da26c
...
@@ -22,8 +22,8 @@ class TestMomentumOp(OpTest):
...
@@ -22,8 +22,8 @@ class TestMomentumOp(OpTest):
self
.
attrs
=
{
'mu'
:
mu
}
self
.
attrs
=
{
'mu'
:
mu
}
velocity_out
=
mu
*
velocity
-
learning_rate
*
grad
velocity_out
=
mu
*
velocity
+
grad
param_out
=
param
+
velocity_out
param_out
=
param
-
learning_rate
*
velocity_out
self
.
outputs
=
{
'ParamOut'
:
param_out
,
'VelocityOut'
:
velocity_out
}
self
.
outputs
=
{
'ParamOut'
:
param_out
,
'VelocityOut'
:
velocity_out
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录