Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
db77937e
P
Paddle
项目概览
机器未来
/
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看板
提交
db77937e
编写于
10月 05, 2017
作者:
S
sidgoyal78
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix learning_rate usage for momentum
上级
c10da26c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
15 deletion
+17
-15
paddle/operators/momentum_op.h
paddle/operators/momentum_op.h
+17
-15
未找到文件。
paddle/operators/momentum_op.h
浏览文件 @
db77937e
...
...
@@ -19,33 +19,35 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenVector
=
framework
::
EigenVector
<
T
,
MajorType
,
IndexType
>
;
template
<
typename
Place
,
typename
T
>
class
MomentumOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
param_out
=
ctx
.
Output
<
Tensor
>
(
"ParamOut"
);
auto
velocity_out
=
ctx
.
Output
<
Tensor
>
(
"VelocityOut"
);
auto
param_out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"ParamOut"
);
auto
velocity_out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"VelocityOut"
);
auto
param
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Param"
);
auto
velocity
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Velocity"
);
auto
grad
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Grad"
);
auto
learning_rate
=
ctx
.
Input
<
framework
::
Tensor
>
(
"LearningRate"
);
param_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
velocity_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
float
mu
=
ctx
.
Attr
<
float
>
(
"mu"
);
auto
param
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Param"
));
auto
grad
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Grad"
));
auto
velocity
=
EigenVector
<
T
>::
Flatten
(
*
ctx
.
Input
<
Tensor
>
(
"Velocity"
));
float
learning_rate
=
ctx
.
Input
<
Tensor
>
(
"LearningRate"
)
->
data
<
float
>
()[
0
];
auto
p_out
=
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
v_out
=
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
p_out
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
param_out
);
auto
v_out
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
velocity_out
);
auto
p
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
param
);
auto
v
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
velocity
);
auto
g
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
grad
);
auto
lr
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
learning_rate
);
auto
place
=
ctx
.
GetEigenDevice
<
Place
>
();
v_out
.
device
(
place
)
=
velocity
*
mu
+
grad
;
p_out
.
device
(
place
)
=
param
-
learning_rate
*
v_out
;
Eigen
::
DSizes
<
int
,
1
>
grad_dsize
(
grad
->
numel
());
v_out
.
device
(
place
)
=
v
*
mu
+
g
;
p_out
.
device
(
place
)
=
p
-
lr
.
broadcast
(
grad_dsize
)
*
v_out
;
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录