diff --git a/test/ir/inference/CMakeLists.txt b/test/ir/inference/CMakeLists.txt index f53ae5c29c4dbb..66f7b2e5d465a8 100755 --- a/test/ir/inference/CMakeLists.txt +++ b/test/ir/inference/CMakeLists.txt @@ -172,6 +172,11 @@ if(WITH_GPU AND TENSORRT_FOUND) set_tests_properties(test_trt_convert_unary PROPERTIES TIMEOUT 600) set_tests_properties(test_trt_convert_pool2d PROPERTIES TIMEOUT 600) set_tests_properties(test_trt_convert_slice PROPERTIES TIMEOUT 600) + set_tests_properties(test_trt_convert_scale PROPERTIES TIMEOUT 600) + set_tests_properties(test_trt_convert_elementwise PROPERTIES TIMEOUT 600) + set_tests_properties(test_trt_convert_reduce PROPERTIES TIMEOUT 600) + set_tests_properties(test_trt_convert_compare_and_logical PROPERTIES TIMEOUT + 600) if(NOT WIN32) diff --git a/test/ir/inference/test_trt_convert_argsort.py b/test/ir/inference/test_trt_convert_argsort.py index 2941d2071bc9e8..9ec7c834f84e5a 100755 --- a/test/ir/inference/test_trt_convert_argsort.py +++ b/test/ir/inference/test_trt_convert_argsort.py @@ -30,7 +30,7 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: def sample_program_configs(self): def generate_input1(): if self.dims == 4: - return np.random.random([1, 3, 3, 4000]).astype(np.float32) + return np.random.random([1, 3, 3, 3840]).astype(np.float32) elif self.dims == 3: return np.random.random([1, 3, 24]).astype(np.int32) elif self.dims == 2: @@ -69,50 +69,52 @@ def generate_input1(): ) yield program_config + def generate_dynamic_shape(self): + if self.dims == 4: + self.dynamic_shape.min_input_shape = { + "input_data": [1, 3, 3, 3840], + } + self.dynamic_shape.max_input_shape = { + "input_data": [9, 3, 3, 3840], + } + self.dynamic_shape.opt_input_shape = { + "input_data": [6, 3, 3, 3840], + } + elif self.dims == 3: + self.dynamic_shape.min_input_shape = { + "input_data": [1, 3, 24], + } + self.dynamic_shape.max_input_shape = { + "input_data": [9, 3, 24], + } + self.dynamic_shape.opt_input_shape = { + "input_data": [6, 3, 24], + } + elif self.dims == 2: + self.dynamic_shape.min_input_shape = { + "input_data": [1, 24], + } + self.dynamic_shape.max_input_shape = { + "input_data": [9, 24], + } + self.dynamic_shape.opt_input_shape = { + "input_data": [6, 24], + } + else: + self.dynamic_shape.min_input_shape = { + "input_data": [24], + } + self.dynamic_shape.max_input_shape = { + "input_data": [24], + } + self.dynamic_shape.opt_input_shape = { + "input_data": [24], + } + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - if self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 3, 3, 4000], - } - self.dynamic_shape.max_input_shape = { - "input_data": [9, 3, 3, 4000], - } - self.dynamic_shape.opt_input_shape = { - "input_data": [6, 3, 3, 4000], - } - elif self.dims == 3: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 3, 24], - } - self.dynamic_shape.max_input_shape = { - "input_data": [9, 3, 24], - } - self.dynamic_shape.opt_input_shape = { - "input_data": [6, 3, 24], - } - elif self.dims == 2: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 24], - } - self.dynamic_shape.max_input_shape = { - "input_data": [9, 24], - } - self.dynamic_shape.opt_input_shape = { - "input_data": [6, 24], - } - else: - self.dynamic_shape.min_input_shape = { - "input_data": [24], - } - self.dynamic_shape.max_input_shape = { - "input_data": [25], - } - self.dynamic_shape.opt_input_shape = { - "input_data": [24], - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -124,14 +126,14 @@ def clear_dynamic_shape(): ] self.trt_param.workspace_size = 1073741824 # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 yield self.create_inference_config(), (1, 3), 1e-5 self.trt_param.precision = paddle_infer.PrecisionType.Half yield self.create_inference_config(), (1, 3), 1e-3 def test(self): - self.run_test() + self.run_test(run_pir=True) if __name__ == "__main__": diff --git a/test/ir/inference/test_trt_convert_elementwise.py b/test/ir/inference/test_trt_convert_elementwise.py index f76589c796b0a5..e178b49b58d176 100644 --- a/test/ir/inference/test_trt_convert_elementwise.py +++ b/test/ir/inference/test_trt_convert_elementwise.py @@ -111,21 +111,17 @@ def generate_weight(op_type): yield program_config + def generate_dynamic_shape(self): + # The input.dims[1] must be equal to the weight's length. + if self.dims == 4: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4, 4]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [4, 32, 16, 32]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - # The input.dims[1] must be equal to the weight's length. - if self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 32, 4, 4] - } - self.dynamic_shape.max_input_shape = { - "input_data": [4, 32, 32, 32] - } - self.dynamic_shape.opt_input_shape = { - "input_data": [4, 32, 16, 32] - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -141,26 +137,25 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-3, 1e-3) @@ -170,10 +165,10 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) -# This is the special test case +# # This is the special test case class TrtConvertElementwiseTestOneInputSpecialCase1(TrtLayerAutoScanTest): def is_program_valid(self, program_config: ProgramConfig) -> bool: return True @@ -205,7 +200,7 @@ def generate_weight(op_type): else: return np.random.randn(1).astype(np.float32) - for shape in [[32]]: + for shape in [[4]]: for op_type in [ "elementwise_add", "elementwise_mul", @@ -254,13 +249,15 @@ def generate_weight(op_type): yield program_config + def generate_dynamic_shape(self): + self.dynamic_shape.min_input_shape = {"input_data": [1]} + self.dynamic_shape.max_input_shape = {"input_data": [8]} + self.dynamic_shape.opt_input_shape = {"input_data": [4]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=True ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - self.dynamic_shape.min_input_shape = {"input_data": [32]} - self.dynamic_shape.max_input_shape = {"input_data": [64]} - self.dynamic_shape.opt_input_shape = {"input_data": [32]} def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -278,26 +275,25 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-3, 1e-3) @@ -307,7 +303,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) class TrtConvertElementwiseTestOneInput(TrtLayerAutoScanTest): @@ -346,7 +342,7 @@ def generate_weight(op_type): [32], [batch, 32], [batch, 32, 32], - [batch, 32, 16, 32], + [batch, 32, 4, 32], ]: for op_type in [ "elementwise_add", @@ -401,33 +397,29 @@ def generate_weight(op_type): yield program_config + def generate_dynamic_shape(self): + # The input.dims[1] must be equal to the weight's length. + if self.dims == 1: + self.dynamic_shape.min_input_shape = {"input_data": [32]} + self.dynamic_shape.max_input_shape = {"input_data": [32]} + self.dynamic_shape.opt_input_shape = {"input_data": [32]} + elif self.dims == 2: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} + elif self.dims == 3: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32]} + elif self.dims == 4: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [4, 32, 16, 32]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - # The input.dims[1] must be equal to the weight's length. - if self.dims == 1: - self.dynamic_shape.min_input_shape = {"input_data": [4]} - self.dynamic_shape.max_input_shape = {"input_data": [32]} - self.dynamic_shape.opt_input_shape = {"input_data": [16]} - elif self.dims == 2: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} - elif self.dims == 3: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32]} - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 32, 4, 4] - } - self.dynamic_shape.max_input_shape = { - "input_data": [4, 32, 32, 32] - } - self.dynamic_shape.opt_input_shape = { - "input_data": [4, 32, 16, 32] - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -445,26 +437,25 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-3, 1e-3) @@ -474,7 +465,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) class TrtConvertElementwiseTestTwoInputWithoutBroadcast(TrtLayerAutoScanTest): @@ -546,62 +537,64 @@ def generate_input(shape, op_type): yield program_config + def generate_dynamic_shape(self): + if self.dims == 1: + self.dynamic_shape.min_input_shape = { + "input_data1": [1], + "input_data2": [1], + } + self.dynamic_shape.max_input_shape = { + "input_data1": [128], + "input_data2": [128], + } + self.dynamic_shape.opt_input_shape = { + "input_data1": [32], + "input_data2": [32], + } + elif self.dims == 2: + self.dynamic_shape.min_input_shape = { + "input_data1": [1, 4], + "input_data2": [1, 4], + } + self.dynamic_shape.max_input_shape = { + "input_data1": [128, 256], + "input_data2": [128, 256], + } + self.dynamic_shape.opt_input_shape = { + "input_data1": [32, 64], + "input_data2": [32, 64], + } + elif self.dims == 3: + self.dynamic_shape.min_input_shape = { + "input_data1": [1, 4, 4], + "input_data2": [1, 4, 4], + } + self.dynamic_shape.max_input_shape = { + "input_data1": [128, 128, 256], + "input_data2": [128, 128, 256], + } + self.dynamic_shape.opt_input_shape = { + "input_data1": [2, 32, 16], + "input_data2": [2, 32, 16], + } + elif self.dims == 4: + self.dynamic_shape.min_input_shape = { + "input_data1": [1, 4, 4, 4], + "input_data2": [1, 4, 4, 4], + } + self.dynamic_shape.max_input_shape = { + "input_data1": [8, 128, 64, 128], + "input_data2": [8, 128, 64, 128], + } + self.dynamic_shape.opt_input_shape = { + "input_data1": [2, 64, 32, 32], + "input_data2": [2, 64, 32, 32], + } + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - if self.dims == 1: - self.dynamic_shape.min_input_shape = { - "input_data1": [1], - "input_data2": [1], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128], - "input_data2": [128], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [32], - "input_data2": [32], - } - elif self.dims == 2: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4], - "input_data2": [1, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128, 256], - "input_data2": [128, 256], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [32, 64], - "input_data2": [32, 64], - } - elif self.dims == 3: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4, 4], - "input_data2": [1, 4, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128, 128, 256], - "input_data2": [128, 128, 256], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [2, 32, 16], - "input_data2": [2, 32, 16], - } - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4, 4, 4], - "input_data2": [1, 4, 4, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [8, 128, 64, 128], - "input_data2": [8, 128, 64, 128], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [2, 64, 32, 32], - "input_data2": [2, 64, 32, 32], - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -619,24 +612,23 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), (1, 3), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), (1, 3), (1e-3, 1e-3) def add_skip_trt_case(self): @@ -644,7 +636,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) class TrtConvertElementwiseTestTwoInputWithBroadcast(TrtLayerAutoScanTest): @@ -758,31 +750,33 @@ def generate_input(shape, op_type): yield program_config + def generate_dynamic_shape(self): + max_shape = [ + [128], + [128, 128], + [128, 128, 128], + [128, 128, 128, 128], + ] + min_shape = [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]] + opt_shape = [[32], [32, 32], [32, 32, 32], [32, 32, 32, 32]] + + self.dynamic_shape.min_input_shape = { + "input_data1": min_shape[len(self.shape1) - 1], + "input_data2": min_shape[len(self.shape2) - 1], + } + self.dynamic_shape.max_input_shape = { + "input_data1": max_shape[len(self.shape1) - 1], + "input_data2": max_shape[len(self.shape2) - 1], + } + self.dynamic_shape.opt_input_shape = { + "input_data1": opt_shape[len(self.shape1) - 1], + "input_data2": opt_shape[len(self.shape2) - 1], + } + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - max_shape = [ - [128], - [128, 128], - [128, 128, 128], - [128, 128, 128, 128], - ] - min_shape = [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]] - opt_shape = [[32], [32, 32], [32, 32, 32], [32, 32, 32, 32]] - - self.dynamic_shape.min_input_shape = { - "input_data1": min_shape[len(self.shape1) - 1], - "input_data2": min_shape[len(self.shape2) - 1], - } - self.dynamic_shape.max_input_shape = { - "input_data1": max_shape[len(self.shape1) - 1], - "input_data2": max_shape[len(self.shape2) - 1], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": opt_shape[len(self.shape1) - 1], - "input_data2": opt_shape[len(self.shape2) - 1], - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -795,21 +789,20 @@ def clear_dynamic_shape(): # for static_shape clear_dynamic_shape() - if self.shape1[0] == self.shape2[0]: - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), (1, 3), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), (1, 3), (1e-3, 1e-3) + if not run_pir: + if self.shape1[0] == self.shape2[0]: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), (1, 3), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), (1, 3), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), (1, 3), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), (1, 3), (1e-3, 1e-3) def add_skip_trt_case(self): @@ -817,7 +810,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) class TrtConvertElementwiseTestOneInputCornerCase(TrtLayerAutoScanTest): @@ -912,35 +905,31 @@ def generate_weight(op_type): yield program_config + def generate_dynamic_shape(self): + # The input.dims[1] must be equal to the weight's length. + if self.dims == 1: + self.dynamic_shape.min_input_shape = {"input_data": [32]} + self.dynamic_shape.max_input_shape = {"input_data": [32]} + self.dynamic_shape.opt_input_shape = {"input_data": [32]} + elif self.dims == 2: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} + elif self.dims == 3: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32]} + elif self.dims == 4: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4, 32]} + self.dynamic_shape.max_input_shape = { + "input_data": [4, 32, 128, 32] + } + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32, 32]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - # The input.dims[1] must be equal to the weight's length. - if self.dims == 1: - self.dynamic_shape.min_input_shape = {"input_data": [4]} - self.dynamic_shape.max_input_shape = {"input_data": [64]} - self.dynamic_shape.opt_input_shape = {"input_data": [32]} - elif self.dims == 2: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} - elif self.dims == 3: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4]} - self.dynamic_shape.max_input_shape = { - "input_data": [4, 32, 256] - } - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 16]} - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 32, 4, 4] - } - self.dynamic_shape.max_input_shape = { - "input_data": [4, 32, 128, 256] - } - self.dynamic_shape.opt_input_shape = { - "input_data": [2, 32, 32, 16] - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -953,20 +942,19 @@ def clear_dynamic_shape(): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), (0, 3), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), (0, 3), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), (0, 3), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), (0, 3), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), (1, 2), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), (1, 2), (1e-3, 1e-3) def add_skip_trt_case(self): @@ -974,165 +962,166 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() - - -class TrtConvertElementwiseTestTwoInputSkipCase(TrtLayerAutoScanTest): - def is_program_valid(self, program_config: ProgramConfig) -> bool: - # if program_config.ops[0].type in "round": - return True - - def sample_program_configs(self): - def generate_input(shape, op_type): - if op_type == "elementwise_pow": - return np.random.randint( - low=1, high=10000, size=shape, dtype=np.int32 - ) - # Paddle mul support bool and TensorRT not - if op_type == "elementwise_mul": - return np.random.random(shape).astype(np.bool_) - - for shape in [[4], [4, 32], [2, 32, 16], [1, 8, 16, 32]]: - for op_type in [ - "elementwise_pow", - "elementwise_mul", - ]: - for axis in [0, -1]: - self.dims = len(shape) - dics = [{"axis": axis}] - ops_config = [ - { - "op_type": op_type, - "op_inputs": { - "X": ["input_data1"], - "Y": ["input_data2"], - }, - "op_outputs": {"Out": ["output_data"]}, - "op_attrs": dics[0], - "outputs_dtype": { - "output_data": ( - np.int32 - if op_type == "elementwise_pow" - else np.bool_ - ) - }, - } - ] - ops = self.generate_op_config(ops_config) - - program_config = ProgramConfig( - ops=ops, - weights={}, - inputs={ - "input_data1": TensorConfig( - data_gen=partial(generate_input, shape, op_type) - ), - "input_data2": TensorConfig( - data_gen=partial(generate_input, shape, op_type) - ), - }, - outputs=["output_data"], - ) - - yield program_config - - def sample_predictor_configs( - self, program_config - ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - if self.dims == 1: - self.dynamic_shape.min_input_shape = { - "input_data1": [1], - "input_data2": [1], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128], - "input_data2": [128], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [32], - "input_data2": [32], - } - elif self.dims == 2: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4], - "input_data2": [1, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128, 256], - "input_data2": [128, 256], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [32, 64], - "input_data2": [32, 64], - } - elif self.dims == 3: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4, 4], - "input_data2": [1, 4, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [128, 128, 256], - "input_data2": [128, 128, 256], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [2, 32, 16], - "input_data2": [2, 32, 16], - } - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data1": [1, 4, 4, 4], - "input_data2": [1, 4, 4, 4], - } - self.dynamic_shape.max_input_shape = { - "input_data1": [8, 128, 64, 128], - "input_data2": [8, 128, 64, 128], - } - self.dynamic_shape.opt_input_shape = { - "input_data1": [2, 64, 32, 32], - "input_data2": [2, 64, 32, 32], - } - - def clear_dynamic_shape(): - self.dynamic_shape.max_input_shape = {} - self.dynamic_shape.min_input_shape = {} - self.dynamic_shape.opt_input_shape = {} - - def generate_trt_nodes_num(attrs, dynamic_shape): - return 0, 4 - - attrs = [ - program_config.ops[i].attrs for i in range(len(program_config.ops)) - ] - - # for static_shape - clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) - - # for dynamic_shape - generate_dynamic_shape(attrs) - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), (0, 4), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), (0, 4), (1e-3, 1e-3) - - def add_skip_trt_case(self): - pass - - def test(self): - self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) + + +# class TrtConvertElementwiseTestTwoInputSkipCase(TrtLayerAutoScanTest): +# def is_program_valid(self, program_config: ProgramConfig) -> bool: +# # if program_config.ops[0].type in "round": +# return True + +# def sample_program_configs(self): +# def generate_input(shape, op_type): +# if op_type == "elementwise_pow": +# return np.random.randint( +# low=1, high=10000, size=shape, dtype=np.int32 +# ) +# # Paddle mul support bool and TensorRT not +# if op_type == "elementwise_mul": +# return np.random.random(shape).astype(np.bool_) + +# for shape in [[4], [4, 32], [2, 32, 16], [1, 8, 16, 32]]: +# for op_type in [ +# "elementwise_pow", +# "elementwise_mul", +# ]: +# for axis in [0, -1]: +# self.dims = len(shape) +# dics = [{"axis": axis}] +# ops_config = [ +# { +# "op_type": op_type, +# "op_inputs": { +# "X": ["input_data1"], +# "Y": ["input_data2"], +# }, +# "op_outputs": {"Out": ["output_data"]}, +# "op_attrs": dics[0], +# "outputs_dtype": { +# "output_data": ( +# np.int32 +# if op_type == "elementwise_pow" +# else np.bool_ +# ) +# }, +# } +# ] +# ops = self.generate_op_config(ops_config) + +# program_config = ProgramConfig( +# ops=ops, +# weights={}, +# inputs={ +# "input_data1": TensorConfig( +# data_gen=partial(generate_input, shape, op_type) +# ), +# "input_data2": TensorConfig( +# data_gen=partial(generate_input, shape, op_type) +# ), +# }, +# outputs=["output_data"], +# ) + +# yield program_config + +# def generate_dynamic_shape(self): +# if self.dims == 1: +# self.dynamic_shape.min_input_shape = { +# "input_data1": [1], +# "input_data2": [1], +# } +# self.dynamic_shape.max_input_shape = { +# "input_data1": [128], +# "input_data2": [128], +# } +# self.dynamic_shape.opt_input_shape = { +# "input_data1": [32], +# "input_data2": [32], +# } +# elif self.dims == 2: +# self.dynamic_shape.min_input_shape = { +# "input_data1": [1, 4], +# "input_data2": [1, 4], +# } +# self.dynamic_shape.max_input_shape = { +# "input_data1": [128, 256], +# "input_data2": [128, 256], +# } +# self.dynamic_shape.opt_input_shape = { +# "input_data1": [32, 64], +# "input_data2": [32, 64], +# } +# elif self.dims == 3: +# self.dynamic_shape.min_input_shape = { +# "input_data1": [1, 4, 4], +# "input_data2": [1, 4, 4], +# } +# self.dynamic_shape.max_input_shape = { +# "input_data1": [128, 128, 256], +# "input_data2": [128, 128, 256], +# } +# self.dynamic_shape.opt_input_shape = { +# "input_data1": [2, 32, 16], +# "input_data2": [2, 32, 16], +# } +# elif self.dims == 4: +# self.dynamic_shape.min_input_shape = { +# "input_data1": [1, 4, 4, 4], +# "input_data2": [1, 4, 4, 4], +# } +# self.dynamic_shape.max_input_shape = { +# "input_data1": [8, 128, 64, 128], +# "input_data2": [8, 128, 64, 128], +# } +# self.dynamic_shape.opt_input_shape = { +# "input_data1": [2, 64, 32, 32], +# "input_data2": [2, 64, 32, 32], +# } +# return self.dynamic_shape + +# def sample_predictor_configs( +# self, program_config, run_pir=False +# ) -> tuple[paddle_infer.Config, list[int], float]: + +# def clear_dynamic_shape(): +# self.dynamic_shape.max_input_shape = {} +# self.dynamic_shape.min_input_shape = {} +# self.dynamic_shape.opt_input_shape = {} + +# def generate_trt_nodes_num(attrs, dynamic_shape): +# return 0, 4 + +# attrs = [ +# program_config.ops[i].attrs for i in range(len(program_config.ops)) +# ] + +# # for static_shape +# clear_dynamic_shape() +# if not run_pir: +# self.trt_param.precision = paddle_infer.PrecisionType.Float32 +# program_config.set_input_type(np.float32) +# yield self.create_inference_config(), generate_trt_nodes_num( +# attrs, False +# ), (1e-5, 1e-5) +# self.trt_param.precision = paddle_infer.PrecisionType.Half +# program_config.set_input_type(np.float16) +# yield self.create_inference_config(), generate_trt_nodes_num( +# attrs, False +# ), (1e-3, 1e-3) + +# # for dynamic_shape +# self.generate_dynamic_shape() +# self.trt_param.precision = paddle_infer.PrecisionType.Float32 +# yield self.create_inference_config(), (0, 4), (1e-5, 1e-5) +# self.trt_param.precision = paddle_infer.PrecisionType.Half +# yield self.create_inference_config(), (0, 4), (1e-3, 1e-3) + +# def add_skip_trt_case(self): +# pass + +# def test(self): +# self.add_skip_trt_case() +# self.run_test(run_pir=True) class TrtConvertPowOp(TrtLayerAutoScanTest): @@ -1148,7 +1137,7 @@ def generate_input(shape): for batch in [1, 4]: for shape in [ [], - [32], + [4], [batch, 32], [batch, 32, 32], [batch, 32, 16, 32], @@ -1182,36 +1171,32 @@ def generate_input(shape): yield program_config + def generate_dynamic_shape(self): + if self.dims == 0: + self.dynamic_shape.min_input_shape = {"input_data": []} + self.dynamic_shape.max_input_shape = {"input_data": []} + self.dynamic_shape.opt_input_shape = {"input_data": []} + elif self.dims == 1: + self.dynamic_shape.min_input_shape = {"input_data": [1]} + self.dynamic_shape.max_input_shape = {"input_data": [8]} + self.dynamic_shape.opt_input_shape = {"input_data": [4]} + elif self.dims == 2: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} + elif self.dims == 3: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32]} + elif self.dims == 4: + self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4, 4]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32, 32]} + self.dynamic_shape.opt_input_shape = {"input_data": [4, 32, 16, 32]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - if self.dims == 0: - self.dynamic_shape.min_input_shape = {"input_data": []} - self.dynamic_shape.max_input_shape = {"input_data": []} - self.dynamic_shape.opt_input_shape = {"input_data": []} - elif self.dims == 1: - self.dynamic_shape.min_input_shape = {"input_data": [4]} - self.dynamic_shape.max_input_shape = {"input_data": [32]} - self.dynamic_shape.opt_input_shape = {"input_data": [16]} - elif self.dims == 2: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32]} - elif self.dims == 3: - self.dynamic_shape.min_input_shape = {"input_data": [1, 32, 4]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 32, 32]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 32, 32]} - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 32, 4, 4] - } - self.dynamic_shape.max_input_shape = { - "input_data": [4, 32, 32, 32] - } - self.dynamic_shape.opt_input_shape = { - "input_data": [4, 32, 16, 32] - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -1229,26 +1214,25 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-3, 1e-3) @@ -1258,7 +1242,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) class TrtConvertElementwise0D(TrtLayerAutoScanTest): @@ -1347,37 +1331,33 @@ def generate_input(dims, op_type): yield program_config + def generate_dynamic_shape(self): + # The input.dims[1] must be equal to the weight's length. + if self.dims == 0: + self.dynamic_shape.min_input_shape = {"input_data": []} + self.dynamic_shape.max_input_shape = {"input_data": []} + self.dynamic_shape.opt_input_shape = {"input_data": []} + if self.dims == 1: + self.dynamic_shape.min_input_shape = {"input_data": [1]} + self.dynamic_shape.max_input_shape = {"input_data": [8]} + self.dynamic_shape.opt_input_shape = {"input_data": [8]} + elif self.dims == 2: + self.dynamic_shape.min_input_shape = {"input_data": [1, 8]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 8]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 8]} + elif self.dims == 3: + self.dynamic_shape.min_input_shape = {"input_data": [1, 1, 4]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 16, 16]} + self.dynamic_shape.opt_input_shape = {"input_data": [2, 8, 8]} + elif self.dims == 4: + self.dynamic_shape.min_input_shape = {"input_data": [1, 8, 8, 8]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 8, 8, 8]} + self.dynamic_shape.opt_input_shape = {"input_data": [4, 8, 8, 8]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - # The input.dims[1] must be equal to the weight's length. - if self.dims == 0: - self.dynamic_shape.min_input_shape = {"input_data": []} - self.dynamic_shape.max_input_shape = {"input_data": []} - self.dynamic_shape.opt_input_shape = {"input_data": []} - if self.dims == 1: - self.dynamic_shape.min_input_shape = {"input_data": [1]} - self.dynamic_shape.max_input_shape = {"input_data": [16]} - self.dynamic_shape.opt_input_shape = {"input_data": [8]} - elif self.dims == 2: - self.dynamic_shape.min_input_shape = {"input_data": [1, 8]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 8]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 8]} - elif self.dims == 3: - self.dynamic_shape.min_input_shape = {"input_data": [1, 1, 4]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 16, 16]} - self.dynamic_shape.opt_input_shape = {"input_data": [2, 8, 8]} - elif self.dims == 4: - self.dynamic_shape.min_input_shape = { - "input_data": [1, 8, 8, 8] - } - self.dynamic_shape.max_input_shape = { - "input_data": [4, 8, 8, 8] - } - self.dynamic_shape.opt_input_shape = { - "input_data": [4, 8, 8, 8] - } def clear_dynamic_shape(): self.dynamic_shape.max_input_shape = {} @@ -1395,32 +1375,31 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-5, 1e-5) self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) yield self.create_inference_config(), generate_trt_nodes_num( attrs, True ), (1e-3, 1e-3) def test(self): - self.run_test() + self.run_test(run_pir=True) if __name__ == "__main__": diff --git a/test/ir/inference/test_trt_convert_reduce.py b/test/ir/inference/test_trt_convert_reduce.py index 69f0dfbb4b9bd6..e283bf7f3ded95 100644 --- a/test/ir/inference/test_trt_convert_reduce.py +++ b/test/ir/inference/test_trt_convert_reduce.py @@ -73,7 +73,7 @@ def generate_input1(dtype, attrs: list[dict[str, Any]]): [3, 4, 5], ]: for reduce_all in [True, False]: - for out_dtype in [-1, 0, 2, 5, 3, 6]: + for out_dtype in [-1, 0, 2, 5, 3]: if out_dtype != 0: reduce_type_list = [ "reduce_max", @@ -134,13 +134,15 @@ def generate_input1(dtype, attrs: list[dict[str, Any]]): yield program_config + def generate_dynamic_shape(self): + self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]} + self.dynamic_shape.max_input_shape = {"input_data": [4, 3, 64, 64]} + self.dynamic_shape.opt_input_shape = {"input_data": [1, 3, 64, 64]} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> tuple[paddle_infer.Config, list[int], float]: - def generate_dynamic_shape(attrs): - self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]} - self.dynamic_shape.max_input_shape = {"input_data": [4, 3, 64, 64]} - self.dynamic_shape.opt_input_shape = {"input_data": [1, 3, 64, 64]} def clear_dynamic_shape(): self.dynamic_shape.min_input_shape = {} @@ -165,19 +167,20 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-5, 1e-5) - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-5, 1e-5) + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( @@ -194,7 +197,7 @@ def add_skip_trt_case(self): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) if __name__ == "__main__": diff --git a/test/ir/inference/test_trt_convert_scale.py b/test/ir/inference/test_trt_convert_scale.py index 22bf8cb851af74..1dbeee7a2b4788 100644 --- a/test/ir/inference/test_trt_convert_scale.py +++ b/test/ir/inference/test_trt_convert_scale.py @@ -132,38 +132,34 @@ def generate_weight1(attrs: list[dict[str, Any]], is_int): yield program_config + def generate_dynamic_shape(self): + if self.dims == 4: + self.dynamic_shape.min_input_shape = {"scale_input": [1, 3, 24, 24]} + self.dynamic_shape.max_input_shape = {"scale_input": [4, 3, 24, 24]} + self.dynamic_shape.opt_input_shape = {"scale_input": [1, 3, 24, 24]} + elif self.dims == 3: + self.dynamic_shape.min_input_shape = {"scale_input": [1, 3, 24]} + self.dynamic_shape.max_input_shape = {"scale_input": [4, 3, 24]} + self.dynamic_shape.opt_input_shape = {"scale_input": [1, 3, 24]} + elif self.dims == 2: + self.dynamic_shape.min_input_shape = {"scale_input": [1, 24]} + self.dynamic_shape.max_input_shape = {"scale_input": [9, 48]} + self.dynamic_shape.opt_input_shape = {"scale_input": [1, 24]} + elif self.dims == 1: + self.dynamic_shape.min_input_shape = {"scale_input": [24]} + self.dynamic_shape.max_input_shape = {"scale_input": [24]} + self.dynamic_shape.opt_input_shape = {"scale_input": [24]} + elif self.dims == 0: + self.dynamic_shape.min_input_shape = {"scale_input": []} + self.dynamic_shape.max_input_shape = {"scale_input": []} + self.dynamic_shape.opt_input_shape = {"scale_input": []} + return self.dynamic_shape + def sample_predictor_configs( - self, program_config + self, program_config, run_pir=False ) -> Generator[ Any, Any, tuple[paddle_infer.Config, list[int], float] | None ]: - def generate_dynamic_shape(attrs): - if self.dims == 4: - self.dynamic_shape.min_input_shape = { - "scale_input": [1, 3, 24, 24] - } - self.dynamic_shape.max_input_shape = { - "scale_input": [4, 3, 24, 24] - } - self.dynamic_shape.opt_input_shape = { - "scale_input": [1, 3, 24, 24] - } - elif self.dims == 3: - self.dynamic_shape.min_input_shape = {"scale_input": [1, 3, 24]} - self.dynamic_shape.max_input_shape = {"scale_input": [4, 3, 24]} - self.dynamic_shape.opt_input_shape = {"scale_input": [1, 3, 24]} - elif self.dims == 2: - self.dynamic_shape.min_input_shape = {"scale_input": [1, 24]} - self.dynamic_shape.max_input_shape = {"scale_input": [9, 48]} - self.dynamic_shape.opt_input_shape = {"scale_input": [1, 24]} - elif self.dims == 1: - self.dynamic_shape.min_input_shape = {"scale_input": [24]} - self.dynamic_shape.max_input_shape = {"scale_input": [48]} - self.dynamic_shape.opt_input_shape = {"scale_input": [24]} - elif self.dims == 0: - self.dynamic_shape.min_input_shape = {"scale_input": []} - self.dynamic_shape.max_input_shape = {"scale_input": []} - self.dynamic_shape.opt_input_shape = {"scale_input": []} def clear_dynamic_shape(): self.dynamic_shape.min_input_shape = {} @@ -181,19 +177,20 @@ def generate_trt_nodes_num(attrs, dynamic_shape): # for static_shape clear_dynamic_shape() - self.trt_param.precision = paddle_infer.PrecisionType.Float32 - program_config.set_input_type(np.float32) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), 1e-5 - self.trt_param.precision = paddle_infer.PrecisionType.Half - program_config.set_input_type(np.float16) - yield self.create_inference_config(), generate_trt_nodes_num( - attrs, False - ), (1e-3, 1e-3) + if not run_pir: + self.trt_param.precision = paddle_infer.PrecisionType.Float32 + program_config.set_input_type(np.float32) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), 1e-5 + self.trt_param.precision = paddle_infer.PrecisionType.Half + program_config.set_input_type(np.float16) + yield self.create_inference_config(), generate_trt_nodes_num( + attrs, False + ), (1e-3, 1e-3) # for dynamic_shape - generate_dynamic_shape(attrs) + self.generate_dynamic_shape() self.trt_param.precision = paddle_infer.PrecisionType.Float32 program_config.set_input_type(np.float32) yield self.create_inference_config(), generate_trt_nodes_num( @@ -230,7 +227,7 @@ def teller2(program_config, predictor_config): def test(self): self.add_skip_trt_case() - self.run_test() + self.run_test(run_pir=True) if __name__ == "__main__": diff --git a/test/tensorrt/test_converter_manipulation.py b/test/tensorrt/test_converter_manipulation.py index 410e446f50cb6d..687a1bd7b4df08 100644 --- a/test/tensorrt/test_converter_manipulation.py +++ b/test/tensorrt/test_converter_manipulation.py @@ -385,6 +385,26 @@ def test_trt_result(self): self.check_trt_result() +class TestSplitWithNumSectionAndAxis2TRTPattern(TensorRTBaseTest): + def setUp(self): + self.python_api = paddle.split + self.api_args = { + "x": np.random.randn(3, 9, 5).astype("float32"), + "num_or_sections": [2, 3], + "axis": 2, + } + self.program_config = {"feed_list": ["x"]} + self.min_shape = {"x": [1, 9, 5]} + self.opt_shape = {"x": [2, 9, 5]} + self.max_shape = {"x": [3, 9, 5]} + + def test_trt_result_fp16(self): + self.check_trt_result(precision_mode="fp16") + + def test_trt_result_fp32(self): + self.check_trt_result() + + def split_api(input, num_or_sections, dim): return _C_ops.split(input, num_or_sections, dim) @@ -423,6 +443,26 @@ def test_trt_result(self): self.check_trt_result() +class TestSplitDynamicSectionAndAxis2TRTPattern(TensorRTBaseTest): + def setUp(self): + self.python_api = split_api + self.api_args = { + "x": np.random.randn(3, 9, 5).astype("float32"), + "num_or_sections": np.array([2, 3]).astype("int64"), + "axis": np.array([2]).astype("int64"), + } + self.program_config = {"feed_list": ["x", "num_or_sections", "axis"]} + self.min_shape = {"x": [1, 9, 5]} + self.opt_shape = {"x": [2, 9, 5]} + self.max_shape = {"x": [3, 9, 5]} + + def test_trt_result_fp16(self): + self.check_trt_result(precision_mode="fp16") + + def test_trt_result_fp32(self): + self.check_trt_result() + + class TestStackTRTPattern(TensorRTBaseTest): def setUp(self): self.python_api = paddle.stack