Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
63ab12c8
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看板
提交
63ab12c8
编写于
3月 12, 2018
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update test_optimizer
上级
4fdd114d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
63 addition
and
27 deletion
+63
-27
python/paddle/fluid/tests/unittests/test_optimizer.py
python/paddle/fluid/tests/unittests/test_optimizer.py
+63
-27
未找到文件。
python/paddle/fluid/tests/unittests/test_optimizer.py
浏览文件 @
63ab12c8
...
@@ -21,31 +21,43 @@ from paddle.fluid.backward import append_backward
...
@@ -21,31 +21,43 @@ from paddle.fluid.backward import append_backward
class
TestOptimizer
(
unittest
.
TestCase
):
class
TestOptimizer
(
unittest
.
TestCase
):
def
test_sgd_optimizer
(
self
):
def
test_sgd_optimizer
(
self
):
init_program
=
framework
.
Program
()
def
check_sgd_optimizer
(
optimizer_attr
):
program
=
framework
.
Program
()
init_program
=
framework
.
Program
()
block
=
program
.
global_block
()
program
=
framework
.
Program
()
mul_x
=
block
.
create_parameter
(
block
=
program
.
global_block
()
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
mul_x
=
block
.
create_parameter
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
shape
=
[
5
,
10
],
mul_out
=
block
.
create_var
(
lod_level
=
0
,
dtype
=
"float32"
,
shape
=
[
5
,
8
],
lod_level
=
0
,
name
=
"mul.out"
)
name
=
"mul.x"
,
mean_out
=
block
.
create_var
(
optimize_attr
=
optimizer_attr
)
dtype
=
"float32"
,
shape
=
[
1
],
lod_level
=
0
,
name
=
"mean.out"
)
mul_y
=
block
.
create_var
(
block
.
append_op
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
type
=
"mul"
,
mul_out
=
block
.
create_var
(
inputs
=
{
"X"
:
mul_x
,
dtype
=
"float32"
,
shape
=
[
5
,
8
],
lod_level
=
0
,
name
=
"mul.out"
)
"Y"
:
mul_y
},
mean_out
=
block
.
create_var
(
outputs
=
{
"Out"
:
mul_out
},
dtype
=
"float32"
,
shape
=
[
1
],
lod_level
=
0
,
name
=
"mean.out"
)
attrs
=
{
"x_num_col_dims"
:
1
})
block
.
append_op
(
block
.
append_op
(
type
=
"mul"
,
type
=
"mean"
,
inputs
=
{
"X"
:
mul_out
},
outputs
=
{
"Out"
:
mean_out
})
inputs
=
{
"X"
:
mul_x
,
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.01
)
"Y"
:
mul_y
},
opts
,
_
=
sgd_optimizer
.
minimize
(
mean_out
,
init_program
)
outputs
=
{
"Out"
:
mul_out
},
attrs
=
{
"x_num_col_dims"
:
1
})
block
.
append_op
(
type
=
"mean"
,
inputs
=
{
"X"
:
mul_out
},
outputs
=
{
"Out"
:
mean_out
})
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.01
)
opts
,
_
=
sgd_optimizer
.
minimize
(
mean_out
,
init_program
)
return
opts
opts
=
check_sgd_optimizer
({
'learning_rate'
:
1.1
})
self
.
assertEqual
(
len
(
opts
),
3
)
self
.
assertEqual
(
len
(
opts
),
3
)
self
.
assertEqual
([
op
.
type
for
op
in
opts
],
self
.
assertEqual
([
op
.
type
for
op
in
opts
],
[
"fill_constant"
,
"elementwise_mul"
,
"sgd"
])
[
"fill_constant"
,
"elementwise_mul"
,
"sgd"
])
opts
=
check_sgd_optimizer
({
'learning_rate'
:
1.0
})
self
.
assertEqual
(
len
(
opts
),
1
)
self
.
assertEqual
([
op
.
type
for
op
in
opts
],
[
"sgd"
])
class
TestMomentumOptimizer
(
unittest
.
TestCase
):
class
TestMomentumOptimizer
(
unittest
.
TestCase
):
class
MockMomentum
(
optimizer
.
MomentumOptimizer
):
class
MockMomentum
(
optimizer
.
MomentumOptimizer
):
...
@@ -60,7 +72,11 @@ class TestMomentumOptimizer(unittest.TestCase):
...
@@ -60,7 +72,11 @@ class TestMomentumOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
@@ -110,7 +126,11 @@ class TestMomentumOptimizer(unittest.TestCase):
...
@@ -110,7 +126,11 @@ class TestMomentumOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
@@ -169,7 +189,11 @@ class TestAdagradOptimizer(unittest.TestCase):
...
@@ -169,7 +189,11 @@ class TestAdagradOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
@@ -229,7 +253,11 @@ class TestAdamOptimizer(unittest.TestCase):
...
@@ -229,7 +253,11 @@ class TestAdamOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
@@ -292,7 +320,11 @@ class TestAdamaxOptimizer(unittest.TestCase):
...
@@ -292,7 +320,11 @@ class TestAdamaxOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
@@ -352,7 +384,11 @@ class TestDecayedAdagradOptimizer(unittest.TestCase):
...
@@ -352,7 +384,11 @@ class TestDecayedAdagradOptimizer(unittest.TestCase):
program
=
framework
.
Program
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
mul_x
=
block
.
create_parameter
(
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
)
dtype
=
"float32"
,
shape
=
[
5
,
10
],
lod_level
=
0
,
name
=
"mul.x"
,
optimize_attr
=
{
'learning_rate'
:
1.1
})
mul_y
=
block
.
create_var
(
mul_y
=
block
.
create_var
(
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
dtype
=
"float32"
,
shape
=
[
10
,
8
],
lod_level
=
0
,
name
=
"mul.y"
)
mul_out
=
block
.
create_var
(
mul_out
=
block
.
create_var
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录