Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7fe5f9cc
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7fe5f9cc
编写于
11月 06, 2020
作者:
Z
Zhang Ting
提交者:
GitHub
11月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unittest random failure (#28363)
* fix random failure * use two input(x) * fix model
上级
fad4744a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
28 addition
and
28 deletion
+28
-28
python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py
...paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py
+28
-28
未找到文件。
python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py
浏览文件 @
7fe5f9cc
...
...
@@ -122,24 +122,23 @@ class TestFusedBnAddActAPI(unittest.TestCase):
param_attr
=
self
.
conv_param_attr1
,
bias_attr
=
False
,
data_format
=
'NHWC'
)
bn1
=
fluid
.
layers
.
batch_norm
(
input
=
conv1_1
,
param_attr
=
self
.
bn_param_attr1
,
bias_attr
=
self
.
bn_bias_attr1
,
act
=
None
,
data_layout
=
'NHWC'
)
conv1_2
=
fluid
.
layers
.
conv2d
(
input
=
x
,
filter_size
=
3
,
input
=
conv1_1
,
filter_size
=
1
,
num_filters
=
32
,
stride
=
1
,
padding
=
1
,
act
=
None
,
param_attr
=
self
.
conv_param_attr2
,
bias_attr
=
False
,
data_format
=
'NHWC'
)
bn1
=
fluid
.
layers
.
batch_norm
(
input
=
conv1_1
,
param_attr
=
self
.
bn_param_attr1
,
bias_attr
=
self
.
bn_bias_attr1
,
act
=
None
,
data_layout
=
'NHWC'
)
bn2
=
fluid
.
layers
.
batch_norm
(
input
=
conv1_
2
,
input
=
conv1_
1
,
param_attr
=
self
.
bn_param_attr2
,
bias_attr
=
self
.
bn_bias_attr2
,
act
=
None
,
...
...
@@ -157,7 +156,7 @@ class TestFusedBnAddActAPI(unittest.TestCase):
sgd
,
use_dynamic_loss_scaling
=
True
,
init_loss_scaling
=
128.0
)
sgd
.
minimize
(
loss
)
return
x
,
y
,
loss
return
loss
def
check
(
self
,
place
,
use_cuda
):
paddle
.
seed
(
1
)
...
...
@@ -168,24 +167,27 @@ class TestFusedBnAddActAPI(unittest.TestCase):
# build_fused_program: turn on fuse_bn_add_act_ops
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
x
,
y
,
loss
=
self
.
build_origin_program
(
main_program
,
startup_program
,
loss
=
self
.
build_origin_program
(
main_program
,
startup_program
,
use_cuda
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
x
,
y
],
place
=
place
)
build_strategy_fused
=
fluid
.
BuildStrategy
()
build_strategy_fused
.
fuse_bn_add_act_ops
=
True
binary_fused
=
fluid
.
CompiledProgram
(
main_program
).
with_data_parallel
(
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy_fused
)
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
train
(),
batch_size
=
batch_size
)
exe
=
fluid
.
Executor
(
place
)
loss_vals_fused
=
[]
x_data
=
[]
y_data
=
[]
scope
=
fluid
.
Scope
()
with
fluid
.
scope_guard
(
scope
):
exe
.
run
(
startup_program
)
for
_
in
range
(
iters
):
data
=
next
(
train_reader
())
x
=
np
.
random
.
random
((
batch_size
,
1
,
28
,
28
)).
astype
(
"float32"
)
y
=
np
.
random
.
random
((
batch_size
,
1
)).
astype
(
"int64"
)
x_data
.
append
(
x
)
y_data
.
append
(
y
)
loss_v
=
exe
.
run
(
binary_fused
,
feed
=
feeder
.
feed
(
data
),
feed
=
{
"x"
:
x
,
"y"
:
y
},
fetch_list
=
[
loss
])
loss_vals_fused
.
append
(
loss_v
[
0
][
0
])
...
...
@@ -193,17 +195,15 @@ class TestFusedBnAddActAPI(unittest.TestCase):
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
fuse_bn_add_act_ops
=
False
binary
=
fluid
.
CompiledProgram
(
main_program
).
with_data_parallel
(
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy
)
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
train
(),
batch_size
=
batch_size
)
loss_name
=
loss
.
name
,
build_strategy
=
build_strategy_fused
)
loss_vals
=
[]
scope
=
fluid
.
Scope
()
with
fluid
.
scope_guard
(
scope
):
exe
.
run
(
startup_program
)
for
_
in
range
(
iters
):
data
=
next
(
train_reader
())
for
i
in
range
(
iters
):
loss_v
=
exe
.
run
(
binary
,
feed
=
feeder
.
feed
(
data
),
feed
=
{
"x"
:
x_data
[
i
],
"y"
:
y_data
[
i
]},
fetch_list
=
[
loss
])
loss_vals
.
append
(
loss_v
[
0
][
0
])
...
...
@@ -222,16 +222,16 @@ class TestFusedBnAddActAPI(unittest.TestCase):
place
=
fluid
.
CUDAPlace
(
0
)
x
,
y
,
loss
=
self
.
build_fused_program
(
main_program
,
startup_program
,
use_cuda
=
True
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
x
,
y
],
place
=
place
)
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
train
(),
batch_size
=
16
)
exe
=
fluid
.
Executor
(
place
)
scope
=
fluid
.
Scope
()
with
fluid
.
scope_guard
(
scope
):
exe
.
run
(
startup_program
)
for
_
in
range
(
5
):
data
=
next
(
train_reader
())
x
=
np
.
random
.
random
((
4
,
1
,
28
,
28
)).
astype
(
"float32"
)
y
=
np
.
random
.
random
((
4
,
1
)).
astype
(
"int64"
)
loss_v
=
exe
.
run
(
main_program
,
feed
=
feeder
.
feed
(
data
),
feed
=
{
"x"
:
x
,
"y"
:
y
},
fetch_list
=
[
loss
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录