From 06bd348d3c62874511f6f36af760063b50e054ca Mon Sep 17 00:00:00 2001 From: Wilber Date: Wed, 20 Oct 2021 11:26:10 +0800 Subject: [PATCH] update for trt convert ut. (#36549) --- paddle/fluid/inference/tensorrt/op_teller.cc | 8 +++ .../inference/test_trt_convert_activation.py | 1 + .../test_trt_convert_affine_channel.py | 1 + .../inference/test_trt_convert_elementwise.py | 1 + .../test_trt_convert_emb_eltwise_layernorm.py | 1 + .../ir/inference/test_trt_convert_flatten.py | 65 +++++++++++++++---- .../ir/inference/test_trt_convert_gather.py | 1 + .../inference/test_trt_convert_gather_nd.py | 1 + .../ir/inference/test_trt_convert_gelu.py | 1 + .../inference/test_trt_convert_group_norm.py | 1 + .../ir/inference/test_trt_convert_prelu.py | 14 ++++ .../ir/inference/test_trt_convert_reshape.py | 1 + .../ir/inference/test_trt_convert_scale.py | 1 + .../test_trt_convert_shuffle_channel.py | 1 + .../ir/inference/test_trt_convert_swish.py | 1 + .../inference/test_trt_convert_transpose.py | 1 + 16 files changed, 88 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index e7318d07611..0d0a656c5b6 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -1104,6 +1104,14 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8, return false; } } + +#if IS_TRT_VERSION_LT(7000) + if (!with_dynamic_shape) { + // TODO(inference): fix trt6 static plugin error. + VLOG(3) << "prelu static plugin in trt6 has bug."; + return false; + } +#endif } if (op_type == "mish") { diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py index 9dc89bb9836..a87cab3430c 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py @@ -14,6 +14,7 @@ from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons from program_config import TensorConfig, ProgramConfig +import unittest import numpy as np import paddle.inference as paddle_infer from functools import partial diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_affine_channel.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_affine_channel.py index 1e6c94f1454..33eb90b9f91 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_affine_channel.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_affine_channel.py @@ -14,6 +14,7 @@ from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons from program_config import TensorConfig, ProgramConfig +import unittest import numpy as np import paddle.inference as paddle_infer from functools import partial diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py index c8cba0f3723..992e0353837 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py @@ -14,6 +14,7 @@ from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons from program_config import TensorConfig, ProgramConfig +import unittest import numpy as np import paddle.inference as paddle_infer from functools import partial diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_emb_eltwise_layernorm.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_emb_eltwise_layernorm.py index d7b0bcd9080..356a2c942df 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_emb_eltwise_layernorm.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_emb_eltwise_layernorm.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertEmbEltwiseLayernormTest1(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_flatten.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_flatten.py index 4b461c75f0b..7b0089ab9ab 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_flatten.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_flatten.py @@ -14,6 +14,7 @@ from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons from program_config import TensorConfig, ProgramConfig +import unittest import numpy as np import paddle.inference as paddle_infer from functools import partial @@ -73,10 +74,20 @@ class TrtConvertFlattenTest_dim_2(TrtLayerAutoScanTest): self.dynamic_shape.opt_input_shape = {} def generate_trt_nodes_num(attrs, dynamic_shape): - if attrs[0]['axis'] == 1: - return 1, 2 + ver = paddle_infer.get_trt_compile_version() + if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130: + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 else: - return 0, 3 + if dynamic_shape: + return 0, 3 + + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 attrs = [ program_config.ops[i].attrs @@ -157,10 +168,20 @@ class TrtConvertFlattenTest_dim_3(TrtLayerAutoScanTest): self.dynamic_shape.opt_input_shape = {} def generate_trt_nodes_num(attrs, dynamic_shape): - if attrs[0]['axis'] == 1: - return 1, 2 + ver = paddle_infer.get_trt_compile_version() + if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130: + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 else: - return 0, 3 + if dynamic_shape: + return 0, 3 + + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 attrs = [ program_config.ops[i].attrs @@ -241,10 +262,20 @@ class TrtConvertFlattenTest_dim_4(TrtLayerAutoScanTest): self.dynamic_shape.opt_input_shape = {} def generate_trt_nodes_num(attrs, dynamic_shape): - if attrs[0]['axis'] == 1: - return 1, 2 + ver = paddle_infer.get_trt_compile_version() + if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130: + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 else: - return 0, 3 + if dynamic_shape: + return 0, 3 + + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 attrs = [ program_config.ops[i].attrs @@ -325,10 +356,20 @@ class TrtConvertFlattenTest_dim_5(TrtLayerAutoScanTest): self.dynamic_shape.opt_input_shape = {} def generate_trt_nodes_num(attrs, dynamic_shape): - if attrs[0]['axis'] == 1: - return 1, 2 + ver = paddle_infer.get_trt_compile_version() + if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130: + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 else: - return 0, 3 + if dynamic_shape: + return 0, 3 + + if attrs[0]['axis'] == 1: + return 1, 2 + else: + return 0, 3 attrs = [ program_config.ops[i].attrs diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather.py index 9a3c9aff61b..37d23cb18d8 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather.py @@ -19,6 +19,7 @@ import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set import logging +import unittest class TrtConvertGatherTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather_nd.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather_nd.py index a109abdc298..0c7eae5f85f 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather_nd.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gather_nd.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertGatherNdTest_dim_4_1(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gelu.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gelu.py index f9c3d09ef44..2f75e4e723e 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gelu.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_gelu.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertGeluTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py index b6b5aa9dbfe..203e86c4b25 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertGroupNormTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_prelu.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_prelu.py index 4122e2623cb..fbb78fceb3e 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_prelu.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_prelu.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertPreluTest(TrtLayerAutoScanTest): @@ -186,6 +187,19 @@ class TrtConvertPreluTest(TrtLayerAutoScanTest): "Need to repair the case: the output of GPU and tensorrt has diff when the input dimension is 2 in static shape mode." ) + ver = paddle_infer.get_trt_compile_version() + if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000: + + def teller(program_config, predictor_config): + if not predictor_config.tensorrt_dynamic_shape_enabled(): + return True + return False + + self.add_skip_case( + teller, SkipReasons.TRT_NOT_IMPLEMENTED, + "Need to repair the case: the output of GPU and tensorrt has diff in trt6, the prelu static plugin has bug." + ) + def test(self): self.add_skip_trt_case() self.run_test() diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py index cf7ab11c35d..4355b83557f 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertReshapeTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scale.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scale.py index 8a44617dc8d..51bcee08037 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scale.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scale.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertScaleTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py index 264ba31ad27..c6a81472360 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_swish.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_swish.py index e162988bbb1..5eb4e8505ff 100755 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_swish.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_swish.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertSwishTest(TrtLayerAutoScanTest): diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_transpose.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_transpose.py index ad325bb0ab3..31b4d027f17 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_transpose.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_transpose.py @@ -18,6 +18,7 @@ import numpy as np import paddle.inference as paddle_infer from functools import partial from typing import Optional, List, Callable, Dict, Any, Set +import unittest class TrtConvertTransposeTest(TrtLayerAutoScanTest): -- GitLab