Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a896d1ce
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
a896d1ce
编写于
12月 21, 2021
作者:
B
baoachun
提交者:
GitHub
12月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update repeated_fc_relu_fuse_pass ut (#37845)
* update repeated_fc_relu_fuse_pass ut * update ut
上级
f74ebd8a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
110 addition
and
76 deletion
+110
-76
python/paddle/fluid/tests/unittests/ir/inference/test_repeated_fc_relu_fuse_pass.py
...unittests/ir/inference/test_repeated_fc_relu_fuse_pass.py
+110
-76
未找到文件。
python/paddle/fluid/tests/unittests/ir/inference/test_repeated_fc_relu_fuse_pass.py
浏览文件 @
a896d1ce
# Copyright (c) 202
0
PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 202
1
PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
...
...
@@ -12,82 +12,116 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
from
auto_scan_test
import
PassAutoScanTest
,
SkipReasons
from
program_config
import
TensorConfig
,
ProgramConfig
,
OpConfig
import
numpy
as
np
from
inference_pass_test
import
InferencePassTest
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.core
import
PassVersionChecker
class
RepeatedFcReluFusePass3Test
(
InferencePassTest
):
def
setUp
(
self
):
fc_num
=
3
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
"data"
,
shape
=
[
-
1
,
3
,
64
,
64
],
dtype
=
"float32"
)
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Xavier
(
uniform
=
False
),
learning_rate
=
0.001
)
conv_out
=
fluid
.
layers
.
conv2d
(
input
=
data
,
num_filters
=
3
,
filter_size
=
3
,
bias_attr
=
param_attr
,
act
=
None
)
fc_outs
=
[]
fc_outs
.
append
(
fluid
.
layers
.
fc
(
input
=
[
conv_out
],
act
=
"relu"
,
size
=
1000
))
for
i
in
range
(
1
,
fc_num
):
fc_outs
.
append
(
fluid
.
layers
.
fc
(
input
=
[
fc_outs
[
i
-
1
]],
act
=
"relu"
,
size
=
1000
))
self
.
feeds
=
{
"data"
:
np
.
random
.
random
([
1
,
3
,
64
,
64
]).
astype
(
"float32"
),
}
self
.
fetch_list
=
[
fc_outs
[
fc_num
-
1
]]
def
test_check_output
(
self
):
use_gpu
=
False
self
.
check_output_with_option
(
use_gpu
)
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'repeated_fc_relu_fuse_pass'
))
class
RepeatedFcReluFusePass9Test
(
InferencePassTest
):
def
setUp
(
self
):
fc_num
=
9
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
"data"
,
shape
=
[
-
1
,
3
,
64
,
64
],
dtype
=
"float32"
)
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Xavier
(
uniform
=
False
),
learning_rate
=
0.001
)
conv_out
=
fluid
.
layers
.
conv2d
(
input
=
data
,
num_filters
=
3
,
filter_size
=
3
,
bias_attr
=
param_attr
,
act
=
None
)
fc_outs
=
[]
fc_outs
.
append
(
fluid
.
layers
.
fc
(
input
=
[
conv_out
],
act
=
"relu"
,
size
=
1000
))
for
i
in
range
(
1
,
fc_num
):
fc_outs
.
append
(
fluid
.
layers
.
fc
(
input
=
[
fc_outs
[
i
-
1
]],
act
=
"relu"
,
size
=
1000
))
self
.
feeds
=
{
"data"
:
np
.
random
.
random
([
1
,
3
,
64
,
64
]).
astype
(
"float32"
),
}
self
.
fetch_list
=
[
fc_outs
[
fc_num
-
1
]]
def
test_check_output
(
self
):
use_gpu
=
False
self
.
check_output_with_option
(
use_gpu
)
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'repeated_fc_relu_fuse_pass'
))
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
import
unittest
import
hypothesis
from
hypothesis
import
given
,
settings
,
seed
,
example
,
assume
import
hypothesis.strategies
as
st
from
functools
import
reduce
class
TestRepeatedFcReluFusePass
(
PassAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
def
sample_program_config
(
self
,
draw
):
x_col
=
draw
(
st
.
sampled_from
([
1
]))
y_col
=
draw
(
st
.
sampled_from
([
1
]))
axis
=
draw
(
st
.
sampled_from
([
-
1
,
1
]))
batch_size
=
draw
(
st
.
integers
(
min_value
=
1
,
max_value
=
4
))
dim
=
draw
(
st
.
sampled_from
([
32
,
64
,
128
]))
def
generate_input
():
return
np
.
random
.
random
([
batch_size
,
dim
]).
astype
(
np
.
float32
)
def
generate_weight
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
attrs
=
[{
"x_col"
:
x_col
,
"y_col"
:
y_col
},
{
"axis"
:
axis
},
{
'batch_size'
:
batch_size
,
'dim'
:
dim
}]
mul_op1
=
OpConfig
(
type
=
"mul"
,
inputs
=
{
"X"
:
[
"input_data"
],
"Y"
:
[
"mul1_weight"
]},
outputs
=
{
"Out"
:
[
"mul1_output"
]},
attrs
=
{
"x_num_col_dims"
:
x_col
,
"y_num_col_dims"
:
y_col
})
elt_op1
=
OpConfig
(
type
=
"elementwise_add"
,
inputs
=
{
"X"
:
[
"mul1_output"
],
"Y"
:
[
"elementwise1_weight"
]},
outputs
=
{
"Out"
:
[
"elementwise1_output"
]},
attrs
=
{
"axis"
:
axis
})
relu_op1
=
OpConfig
(
type
=
"relu"
,
inputs
=
{
"X"
:
[
"elementwise1_output"
]},
outputs
=
{
"Out"
:
[
"relu1_output"
]},
attrs
=
{})
mul_op2
=
OpConfig
(
type
=
"mul"
,
inputs
=
{
"X"
:
[
"relu1_output"
],
"Y"
:
[
"mul2_weight"
]},
outputs
=
{
"Out"
:
[
"mul2_output"
]},
attrs
=
{
"x_num_col_dims"
:
x_col
,
"y_num_col_dims"
:
y_col
})
elt_op2
=
OpConfig
(
type
=
"elementwise_add"
,
inputs
=
{
"X"
:
[
"mul2_output"
],
"Y"
:
[
"elementwise2_weight"
]},
outputs
=
{
"Out"
:
[
"elementwise2_output"
]},
attrs
=
{
"axis"
:
axis
})
relu_op2
=
OpConfig
(
type
=
"relu"
,
inputs
=
{
"X"
:
[
"elementwise2_output"
]},
outputs
=
{
"Out"
:
[
"relu2_output"
]},
attrs
=
{})
model_net
=
[
mul_op1
,
elt_op1
,
relu_op1
,
mul_op2
,
elt_op2
,
relu_op2
]
program_config
=
ProgramConfig
(
ops
=
model_net
,
weights
=
{
"mul1_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
dim
,
32
])),
"mul2_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
32
,
128
])),
"elementwise1_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
32
])),
"elementwise2_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
128
]))
},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
)),
},
outputs
=
[
"relu2_output"
])
return
program_config
def
sample_predictor_configs
(
self
,
program_config
):
config
=
self
.
create_inference_config
()
yield
config
,
[
"fusion_repeated_fc_relu"
],
(
1e-5
,
1e-5
)
def
test
(
self
):
self
.
run_and_statis
(
passes
=
[
"repeated_fc_relu_fuse_pass"
])
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录