Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0a17e98e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
0a17e98e
编写于
5月 23, 2023
作者:
L
Leo Chen
提交者:
GitHub
5月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use tempfile to save model in InferencePassTest (#54038)
上级
6133ca4e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
57 addition
and
35 deletion
+57
-35
test/ir/inference/inference_pass_test.py
test/ir/inference/inference_pass_test.py
+6
-1
test/ir/inference/test_trt_activation_pass.py
test/ir/inference/test_trt_activation_pass.py
+3
-2
test/ir/inference/test_trt_elementwise_op.py
test/ir/inference/test_trt_elementwise_op.py
+3
-2
test/ir/inference/test_trt_instance_norm_op.py
test/ir/inference/test_trt_instance_norm_op.py
+3
-2
test/ir/inference/test_trt_pool3d_op.py
test/ir/inference/test_trt_pool3d_op.py
+9
-6
test/ir/inference/test_trt_pool_op.py
test/ir/inference/test_trt_pool_op.py
+3
-2
test/ir/inference/test_trt_skip_layernorm_fuse_pass.py
test/ir/inference/test_trt_skip_layernorm_fuse_pass.py
+12
-8
test/ir/inference/test_trt_subgraph_pass.py
test/ir/inference/test_trt_subgraph_pass.py
+18
-12
未找到文件。
test/ir/inference/inference_pass_test.py
浏览文件 @
0a17e98e
...
@@ -12,7 +12,9 @@
...
@@ -12,7 +12,9 @@
# 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
os
import
random
import
random
import
tempfile
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
...
@@ -41,7 +43,10 @@ class InferencePassTest(unittest.TestCase):
...
@@ -41,7 +43,10 @@ class InferencePassTest(unittest.TestCase):
self
.
dynamic_shape_params
=
None
self
.
dynamic_shape_params
=
None
self
.
enable_lite
=
False
self
.
enable_lite
=
False
self
.
lite_parameters
=
None
self
.
lite_parameters
=
None
self
.
path
=
"./inference_pass/"
+
self
.
__class__
.
__name__
+
"/"
self
.
temp_dir
=
tempfile
.
TemporaryDirectory
()
self
.
path
=
os
.
path
.
join
(
self
.
temp_dir
.
name
,
'inference_pass'
,
self
.
__class__
.
__name__
)
np
.
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
random
.
seed
(
1
)
random
.
seed
(
1
)
...
...
test/ir/inference/test_trt_activation_pass.py
浏览文件 @
0a17e98e
...
@@ -53,8 +53,9 @@ class TensorRTSubgraphPassActivationTest(InferencePassTest):
...
@@ -53,8 +53,9 @@ class TensorRTSubgraphPassActivationTest(InferencePassTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
(
if
(
self
.
trt_parameters
.
precision
self
.
trt_parameters
.
precision
==
AnalysisConfig
.
Precision
.
Float32
==
AnalysisConfig
.
Precision
.
Float32
...
...
test/ir/inference/test_trt_elementwise_op.py
浏览文件 @
0a17e98e
...
@@ -53,8 +53,9 @@ class TensorRTSubgraphPassElementwiseBroadcastTest(InferencePassTest):
...
@@ -53,8 +53,9 @@ class TensorRTSubgraphPassElementwiseBroadcastTest(InferencePassTest):
return
paddle
.
tensor
.
math
.
add
(
x
=
data1
,
y
=
data2
)
return
paddle
.
tensor
.
math
.
add
(
x
=
data1
,
y
=
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
...
...
test/ir/inference/test_trt_instance_norm_op.py
浏览文件 @
0a17e98e
...
@@ -55,8 +55,9 @@ class TRTInstanceNormTest(InferencePassTest):
...
@@ -55,8 +55,9 @@ class TRTInstanceNormTest(InferencePassTest):
self
.
fetch_list
=
[
out
]
self
.
fetch_list
=
[
out
]
def
check_output
(
self
,
remove_cache
=
False
):
def
check_output
(
self
,
remove_cache
=
False
):
if
remove_cache
and
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
remove_cache
and
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
atol
=
1e-5
atol
=
1e-5
...
...
test/ir/inference/test_trt_pool3d_op.py
浏览文件 @
0a17e98e
...
@@ -84,8 +84,9 @@ class TensorRTPool3dTest(InferencePassTest):
...
@@ -84,8 +84,9 @@ class TensorRTPool3dTest(InferencePassTest):
self
.
fetch_list
=
[
pool_out
]
self
.
fetch_list
=
[
pool_out
]
def
check_output
(
self
):
def
check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
if
self
.
precision
==
AnalysisConfig
.
Precision
.
Float32
:
if
self
.
precision
==
AnalysisConfig
.
Precision
.
Float32
:
...
@@ -200,8 +201,9 @@ class TensorRTAdaptiveAvgPool3DTest(InferencePassTest):
...
@@ -200,8 +201,9 @@ class TensorRTAdaptiveAvgPool3DTest(InferencePassTest):
self
.
fetch_list
=
[
pool_out
]
self
.
fetch_list
=
[
pool_out
]
def
check_output
(
self
):
def
check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
...
@@ -300,8 +302,9 @@ class TensorRTAdaptiveMaxPool3DTest(InferencePassTest):
...
@@ -300,8 +302,9 @@ class TensorRTAdaptiveMaxPool3DTest(InferencePassTest):
self
.
fetch_list
=
[
pool_out
]
self
.
fetch_list
=
[
pool_out
]
def
check_output
(
self
):
def
check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
...
...
test/ir/inference/test_trt_pool_op.py
浏览文件 @
0a17e98e
...
@@ -86,8 +86,9 @@ class TensorRTPoolTest(InferencePassTest):
...
@@ -86,8 +86,9 @@ class TensorRTPoolTest(InferencePassTest):
self
.
fetch_list
=
[
out
]
self
.
fetch_list
=
[
out
]
def
check_output
(
self
):
def
check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
if
self
.
precision
==
AnalysisConfig
.
Precision
.
Float32
:
if
self
.
precision
==
AnalysisConfig
.
Precision
.
Float32
:
...
...
test/ir/inference/test_trt_skip_layernorm_fuse_pass.py
浏览文件 @
0a17e98e
...
@@ -60,8 +60,9 @@ class SkipLayernormFusePassTest0(InferencePassTest):
...
@@ -60,8 +60,9 @@ class SkipLayernormFusePassTest0(InferencePassTest):
return
paddle
.
add
(
data1
,
data2
)
return
paddle
.
add
(
data1
,
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.00001
)
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.00001
)
...
@@ -107,8 +108,9 @@ class SkipLayernormFusePassTest1(InferencePassTest):
...
@@ -107,8 +108,9 @@ class SkipLayernormFusePassTest1(InferencePassTest):
return
paddle
.
add
(
data1
,
data2
)
return
paddle
.
add
(
data1
,
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.00001
)
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.00001
)
...
@@ -154,8 +156,9 @@ class SkipLayernormFusePassTest2(InferencePassTest):
...
@@ -154,8 +156,9 @@ class SkipLayernormFusePassTest2(InferencePassTest):
return
paddle
.
add
(
data1
,
data2
)
return
paddle
.
add
(
data1
,
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.1
,
rtol
=
0.00001
)
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.1
,
rtol
=
0.00001
)
...
@@ -201,8 +204,9 @@ class SkipLayernormFusePassTest3(InferencePassTest):
...
@@ -201,8 +204,9 @@ class SkipLayernormFusePassTest3(InferencePassTest):
return
paddle
.
add
(
data1
,
data2
)
return
paddle
.
add
(
data1
,
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.1
,
rtol
=
0.00001
)
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.1
,
rtol
=
0.00001
)
...
...
test/ir/inference/test_trt_subgraph_pass.py
浏览文件 @
0a17e98e
...
@@ -128,8 +128,9 @@ class TensorRTSubgraphPassSplitSerializeTest(InferencePassTest):
...
@@ -128,8 +128,9 @@ class TensorRTSubgraphPassSplitSerializeTest(InferencePassTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
paddle
.
is_compiled_with_cuda
():
if
paddle
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
self
.
assertTrue
(
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
)
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
)
...
@@ -164,8 +165,9 @@ class TensorRTSubgraphPassDynamicSplitFp16SerializeTest(InferencePassTest):
...
@@ -164,8 +165,9 @@ class TensorRTSubgraphPassDynamicSplitFp16SerializeTest(InferencePassTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
paddle
.
is_compiled_with_cuda
():
if
paddle
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
self
.
check_output_with_option
(
use_gpu
,
1e-3
)
self
.
check_output_with_option
(
use_gpu
,
1e-3
)
self
.
assertTrue
(
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
)
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
)
...
@@ -313,8 +315,9 @@ class TensorRTSubgraphPassLayerNormDynamicTest(InferencePassTest):
...
@@ -313,8 +315,9 @@ class TensorRTSubgraphPassLayerNormDynamicTest(InferencePassTest):
self
.
serialize
=
True
self
.
serialize
=
True
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
paddle
.
is_compiled_with_cuda
():
if
paddle
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
...
@@ -332,8 +335,9 @@ class TensorRTSubgraphPassLayerNormDynamicFP16Test(
...
@@ -332,8 +335,9 @@ class TensorRTSubgraphPassLayerNormDynamicFP16Test(
self
.
serialize
=
True
self
.
serialize
=
True
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
paddle
.
is_compiled_with_cuda
():
if
paddle
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.01
)
self
.
check_output_with_option
(
use_gpu
,
atol
=
0.01
,
rtol
=
0.01
)
...
@@ -406,8 +410,9 @@ class TensorRTSubgraphPassElementwiseSerializeTest(
...
@@ -406,8 +410,9 @@ class TensorRTSubgraphPassElementwiseSerializeTest(
)
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
super
().
test_check_output
()
super
().
test_check_output
()
...
@@ -444,8 +449,9 @@ class TensorRTSubgraphPassElementwiseBroadcastDynamicTest(InferencePassTest):
...
@@ -444,8 +449,9 @@ class TensorRTSubgraphPassElementwiseBroadcastDynamicTest(InferencePassTest):
return
paddle
.
add
(
x
=
data1
,
y
=
data2
)
return
paddle
.
add
(
x
=
data1
,
y
=
data2
)
def
test_check_output
(
self
):
def
test_check_output
(
self
):
if
os
.
path
.
exists
(
self
.
path
+
"_opt_cache"
):
opt_path
=
os
.
path
.
join
(
self
.
path
,
'_opt_cache'
)
shutil
.
rmtree
(
self
.
path
+
"_opt_cache"
)
if
os
.
path
.
exists
(
opt_path
):
shutil
.
rmtree
(
opt_path
)
if
paddle
.
is_compiled_with_cuda
():
if
paddle
.
is_compiled_with_cuda
():
use_gpu
=
True
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
)
self
.
check_output_with_option
(
use_gpu
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录