Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
706d2c08
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看板
未验证
提交
706d2c08
编写于
12月 28, 2021
作者:
B
baoachun
提交者:
GitHub
12月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update seq_concat_fc_fuse_pass ut (#38538)
上级
0c7153a4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
121 addition
and
13 deletion
+121
-13
python/paddle/fluid/tests/unittests/ir/inference/test_seq_concat_fc_fuse_pass.py
...ts/unittests/ir/inference/test_seq_concat_fc_fuse_pass.py
+121
-13
未找到文件。
python/paddle/fluid/tests/unittests/ir/inference/test_seq_concat_fc_fuse_pass.py
浏览文件 @
706d2c08
# 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,21 +12,129 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
unittest
from
auto_scan_test
import
PassAutoScanTest
,
IgnoreReasons
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
AnalysisConfig
from
paddle.fluid.core
import
PassVersionChecker
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
TestSeqConcatFcFusePass
(
PassAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
def
sample_program_config
(
self
,
draw
):
ref_level
=
draw
(
st
.
sampled_from
([
0
]))
axis1
=
draw
(
st
.
sampled_from
([
1
]))
x_col
=
draw
(
st
.
sampled_from
([
1
]))
y_col
=
draw
(
st
.
sampled_from
([
1
]))
axis2
=
draw
(
st
.
sampled_from
([
1
]))
use_cudnn
=
False
use_mkldnn
=
False
act_type
=
draw
(
st
.
sampled_from
([
"tanh"
,
"sigmoid"
,
"relu"
]))
batch_size
=
draw
(
st
.
integers
(
min_value
=
1
,
max_value
=
1
))
dim
=
draw
(
st
.
integers
(
min_value
=
1
,
max_value
=
1000
))
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
sequence_expand_op1
=
OpConfig
(
type
=
"sequence_expand"
,
inputs
=
{
"X"
:
[
"input_data1"
],
"Y"
:
[
"input_data2"
]},
outputs
=
{
"Out"
:
[
"seq_exp1_out"
]},
attrs
=
{
"ref_level"
:
ref_level
})
sequence_expand_op2
=
OpConfig
(
type
=
"sequence_expand"
,
inputs
=
{
"X"
:
[
"input_data1"
],
"Y"
:
[
"input_data3"
]},
outputs
=
{
"Out"
:
[
"seq_exp2_out"
]},
attrs
=
{
"ref_level"
:
ref_level
})
concat_op
=
OpConfig
(
type
=
"concat"
,
inputs
=
{
"X"
:
[
"input_data1"
,
"seq_exp1_out"
,
"seq_exp2_out"
]},
outputs
=
{
"Out"
:
[
"concat_output"
]},
attrs
=
{
'axis'
:
axis1
})
mul_op
=
OpConfig
(
type
=
"mul"
,
inputs
=
{
"X"
:
[
"concat_output"
],
"Y"
:
[
"mul_weight"
]},
outputs
=
{
"Out"
:
[
"mul_out"
]},
attrs
=
{
"x_num_col_dims"
:
x_col
,
"y_num_col_dims"
:
y_col
})
elt_op
=
OpConfig
(
type
=
"elementwise_add"
,
inputs
=
{
"X"
:
[
"mul_out"
],
"Y"
:
[
"elt_weight"
]},
outputs
=
{
"Out"
:
[
"elt_out"
]},
attrs
=
{
"axis"
:
axis2
})
act_op
=
OpConfig
(
type
=
act_type
,
inputs
=
{
"X"
:
[
"elt_out"
]},
outputs
=
{
"Out"
:
[
"act_out"
]},
attrs
=
{
"use_cudnn"
:
use_cudnn
,
"use_mkldnn"
:
use_mkldnn
})
model_net
=
[
sequence_expand_op1
,
sequence_expand_op2
,
concat_op
,
mul_op
,
elt_op
,
act_op
]
program_config
=
ProgramConfig
(
ops
=
model_net
,
weights
=
{
"mul_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
384
,
dim
])),
"elt_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
,
[
dim
]))
},
inputs
=
{
"input_data1"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
[
batch_size
,
128
]),
lod
=
[[
0
,
1
]]),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
[
batch_size
,
128
]),
lod
=
[[
0
,
1
]]),
"input_data3"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
[
batch_size
,
128
]),
lod
=
[[
0
,
1
]])
},
outputs
=
[
"act_out"
])
return
program_config
def
sample_predictor_configs
(
self
,
program_config
):
config
=
self
.
create_inference_config
()
yield
config
,
[
"fusion_seqexpand_concat_fc"
],
(
1e-5
,
1e-5
)
def
add_ignore_pass_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
if
program_config
.
ops
[
-
1
].
type
==
"relu"
:
return
True
return
False
self
.
add_ignore_check_case
(
teller1
,
IgnoreReasons
.
PASS_ACCURACY_ERROR
,
"The pass output has diff in a specific case. We need to fix it as soon as possible."
)
class
SeqConcatFCFusePassTest
(
InferencePassTest
):
def
test_compatible
(
self
):
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'seq_concat_fc_fuse_pass'
))
def
test
(
self
):
self
.
run_and_statis
(
quant
=
False
,
passes
=
[
"seq_concat_fc_fuse_pass"
])
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录