Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a896d1ce
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看板
未验证
提交
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");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
...
@@ -12,82 +12,116 @@
...
@@ -12,82 +12,116 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
unittest
from
auto_scan_test
import
PassAutoScanTest
,
SkipReasons
from
program_config
import
TensorConfig
,
ProgramConfig
,
OpConfig
import
numpy
as
np
import
numpy
as
np
from
inference_pass_test
import
InferencePassTest
import
paddle.inference
as
paddle_infer
import
paddle.fluid
as
fluid
from
functools
import
partial
import
paddle.fluid.core
as
core
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
from
paddle.fluid.core
import
PassVersionChecker
import
unittest
import
hypothesis
class
RepeatedFcReluFusePass3Test
(
InferencePassTest
):
from
hypothesis
import
given
,
settings
,
seed
,
example
,
assume
def
setUp
(
self
):
import
hypothesis.strategies
as
st
fc_num
=
3
from
functools
import
reduce
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
"data"
,
shape
=
[
-
1
,
3
,
64
,
64
],
dtype
=
"float32"
)
class
TestRepeatedFcReluFusePass
(
PassAutoScanTest
):
param_attr
=
fluid
.
ParamAttr
(
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
initializer
=
fluid
.
initializer
.
Xavier
(
uniform
=
False
),
return
True
learning_rate
=
0.001
)
conv_out
=
fluid
.
layers
.
conv2d
(
def
sample_program_config
(
self
,
draw
):
input
=
data
,
x_col
=
draw
(
st
.
sampled_from
([
1
]))
num_filters
=
3
,
y_col
=
draw
(
st
.
sampled_from
([
1
]))
filter_size
=
3
,
axis
=
draw
(
st
.
sampled_from
([
-
1
,
1
]))
bias_attr
=
param_attr
,
batch_size
=
draw
(
st
.
integers
(
min_value
=
1
,
max_value
=
4
))
act
=
None
)
dim
=
draw
(
st
.
sampled_from
([
32
,
64
,
128
]))
fc_outs
=
[]
fc_outs
.
append
(
def
generate_input
():
fluid
.
layers
.
fc
(
input
=
[
conv_out
],
act
=
"relu"
,
size
=
1000
))
return
np
.
random
.
random
([
batch_size
,
dim
]).
astype
(
np
.
float32
)
for
i
in
range
(
1
,
fc_num
):
fc_outs
.
append
(
def
generate_weight
(
shape
):
fluid
.
layers
.
fc
(
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
input
=
[
fc_outs
[
i
-
1
]],
act
=
"relu"
,
size
=
1000
))
self
.
feeds
=
{
attrs
=
[{
"data"
:
np
.
random
.
random
([
1
,
3
,
64
,
64
]).
astype
(
"float32"
),
"x_col"
:
x_col
,
}
"y_col"
:
y_col
self
.
fetch_list
=
[
fc_outs
[
fc_num
-
1
]]
},
{
"axis"
:
axis
def
test_check_output
(
self
):
},
{
use_gpu
=
False
'batch_size'
:
batch_size
,
self
.
check_output_with_option
(
use_gpu
)
'dim'
:
dim
}]
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'repeated_fc_relu_fuse_pass'
))
mul_op1
=
OpConfig
(
type
=
"mul"
,
inputs
=
{
"X"
:
[
"input_data"
],
class
RepeatedFcReluFusePass9Test
(
InferencePassTest
):
"Y"
:
[
"mul1_weight"
]},
def
setUp
(
self
):
outputs
=
{
"Out"
:
[
"mul1_output"
]},
fc_num
=
9
attrs
=
{
"x_num_col_dims"
:
x_col
,
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
"y_num_col_dims"
:
y_col
})
data
=
fluid
.
data
(
name
=
"data"
,
shape
=
[
-
1
,
3
,
64
,
64
],
dtype
=
"float32"
)
elt_op1
=
OpConfig
(
param_attr
=
fluid
.
ParamAttr
(
type
=
"elementwise_add"
,
initializer
=
fluid
.
initializer
.
Xavier
(
uniform
=
False
),
inputs
=
{
"X"
:
[
"mul1_output"
],
learning_rate
=
0.001
)
"Y"
:
[
"elementwise1_weight"
]},
conv_out
=
fluid
.
layers
.
conv2d
(
outputs
=
{
"Out"
:
[
"elementwise1_output"
]},
input
=
data
,
attrs
=
{
"axis"
:
axis
})
num_filters
=
3
,
filter_size
=
3
,
relu_op1
=
OpConfig
(
bias_attr
=
param_attr
,
type
=
"relu"
,
act
=
None
)
inputs
=
{
"X"
:
[
"elementwise1_output"
]},
fc_outs
=
[]
outputs
=
{
"Out"
:
[
"relu1_output"
]},
fc_outs
.
append
(
attrs
=
{})
fluid
.
layers
.
fc
(
input
=
[
conv_out
],
act
=
"relu"
,
size
=
1000
))
for
i
in
range
(
1
,
fc_num
):
mul_op2
=
OpConfig
(
fc_outs
.
append
(
type
=
"mul"
,
fluid
.
layers
.
fc
(
inputs
=
{
"X"
:
[
"relu1_output"
],
input
=
[
fc_outs
[
i
-
1
]],
act
=
"relu"
,
size
=
1000
))
"Y"
:
[
"mul2_weight"
]},
self
.
feeds
=
{
outputs
=
{
"Out"
:
[
"mul2_output"
]},
"data"
:
np
.
random
.
random
([
1
,
3
,
64
,
64
]).
astype
(
"float32"
),
attrs
=
{
"x_num_col_dims"
:
x_col
,
}
"y_num_col_dims"
:
y_col
})
self
.
fetch_list
=
[
fc_outs
[
fc_num
-
1
]]
elt_op2
=
OpConfig
(
def
test_check_output
(
self
):
type
=
"elementwise_add"
,
use_gpu
=
False
inputs
=
{
"X"
:
[
"mul2_output"
],
self
.
check_output_with_option
(
use_gpu
)
"Y"
:
[
"elementwise2_weight"
]},
outputs
=
{
"Out"
:
[
"elementwise2_output"
]},
self
.
assertTrue
(
attrs
=
{
"axis"
:
axis
})
PassVersionChecker
.
IsCompatible
(
'repeated_fc_relu_fuse_pass'
))
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__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录