From a540769b308aafa474289c2157e3d18e0a085220 Mon Sep 17 00:00:00 2001 From: Wilber Date: Mon, 25 Oct 2021 13:04:02 +0800 Subject: [PATCH] [cherry-pick] enable trt test check and fix trt ut error (#36549) (#36655) --- 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 + .../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 + 15 files changed, 87 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index bae0c89c0c..414beef69f 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -1155,6 +1155,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 == "roi_align") { 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 9dc89bb983..a87cab3430 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 1e6c94f145..33eb90b9f9 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 2d18738b61..60c203f4cb 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_flatten.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_flatten.py index 4b461c75f0..7b0089ab9a 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 9a3c9aff61..37d23cb18d 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 a109abdc29..0c7eae5f85 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 f9c3d09ef4..2f75e4e723 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 0224f20ec7..fb62be400a 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 4122e2623c..fbb78fceb3 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 cf7ab11c35..4355b83557 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 8a44617dc8..51bcee0803 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 264ba31ad2..c6a8147236 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 e162988bbb..5eb4e8505f 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 ad325bb0ab..31b4d027f1 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