diff --git a/test/ir/inference/test_trt_convert_cumsum.py b/test/ir/inference/test_trt_convert_cumsum.py index 8f58f6b2ada60..d821d80e08e52 100644 --- a/test/ir/inference/test_trt_convert_cumsum.py +++ b/test/ir/inference/test_trt_convert_cumsum.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -109,7 +110,7 @@ def generate_input1(): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(): if self.dims == 0: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_deformable_conv.py b/test/ir/inference/test_trt_convert_deformable_conv.py index 5437682124bce..85eea45d28e9e 100644 --- a/test/ir/inference/test_trt_convert_deformable_conv.py +++ b/test/ir/inference/test_trt_convert_deformable_conv.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import Any, Dict, List +from typing import Any import numpy as np from program_config import ProgramConfig, TensorConfig @@ -41,9 +43,9 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: def sample_program_configs(self): def compute_output_size( - input_size: List[int], - kernel_sizes: List[int], - attrs: List[Dict[str, Any]], + input_size: list[int], + kernel_sizes: list[int], + attrs: list[dict[str, Any]], ): strides = attrs[0]['strides'] paddings = attrs[0]['paddings'] @@ -58,17 +60,17 @@ def compute_output_size( def generate_input1( batch: int, - input_size: List[int], - kernel_sizes: List[int], - attrs: List[Dict[str, Any]], + input_size: list[int], + kernel_sizes: list[int], + attrs: list[dict[str, Any]], ): return np.random.random([batch, 3] + input_size).astype(np.float32) def generate_offset1( batch: int, - input_size: List[int], - kernel_sizes: List[int], - attrs: List[Dict[str, Any]], + input_size: list[int], + kernel_sizes: list[int], + attrs: list[dict[str, Any]], ): output_size = compute_output_size(input_size, kernel_sizes, attrs) return np.random.random( @@ -77,9 +79,9 @@ def generate_offset1( def generate_mask1( batch: int, - input_size: List[int], - kernel_sizes: List[int], - attrs: List[Dict[str, Any]], + input_size: list[int], + kernel_sizes: list[int], + attrs: list[dict[str, Any]], ): output_size = compute_output_size(input_size, kernel_sizes, attrs) return np.random.random( @@ -88,9 +90,9 @@ def generate_mask1( def generate_filter1( batch: int, - input_size: List[int], - kernel_sizes: List[int], - attrs: List[Dict[str, Any]], + input_size: list[int], + kernel_sizes: list[int], + attrs: list[dict[str, Any]], ): filter = np.random.random([6, 3] + kernel_sizes) filter[0][0][0][0] = 8.8978638e-08 @@ -184,7 +186,7 @@ def generate_filter1( def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = { "input_data": [1, 3, 32, 32], diff --git a/test/ir/inference/test_trt_convert_depthwise_conv2d.py b/test/ir/inference/test_trt_convert_depthwise_conv2d.py index 5fd25562f33a9..752376bc29a8b 100644 --- a/test/ir/inference/test_trt_convert_depthwise_conv2d.py +++ b/test/ir/inference/test_trt_convert_depthwise_conv2d.py @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import itertools import unittest from functools import partial -from typing import Any, Dict, List +from typing import Any import numpy as np from program_config import ProgramConfig, TensorConfig @@ -43,11 +45,11 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: def sample_program_configs(self): self.trt_param.workspace_size = 1073741824 - def generate_input1(batch, attrs: List[Dict[str, Any]]): + def generate_input1(batch, attrs: list[dict[str, Any]]): groups = attrs[0]['groups'] return np.ones([batch, groups, 64, 64]).astype(np.float32) - def generate_weight1(attrs: List[Dict[str, Any]]): + def generate_weight1(attrs: list[dict[str, Any]]): return np.random.random([24, 1, 3, 3]).astype(np.float32) batch_options = [1] @@ -120,7 +122,7 @@ def generate_weight1(attrs: List[Dict[str, Any]]): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): groups = attrs[0]['groups'] self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py b/test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py index 4a0b0faf4df65..562cabd815870 100644 --- a/test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py +++ b/test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py @@ -17,7 +17,7 @@ import unittest from functools import partial from itertools import product -from typing import Any, Generator +from typing import TYPE_CHECKING, Any import numpy as np from program_config import ProgramConfig, TensorConfig @@ -25,6 +25,9 @@ import paddle.inference as paddle_infer +if TYPE_CHECKING: + from collections.abc import Generator + class TrtConvertDepthwiseConv2dTransposeTest(TrtLayerAutoScanTest): def is_program_valid(self, program_config: ProgramConfig) -> bool: diff --git a/test/ir/inference/test_trt_convert_dropout.py b/test/ir/inference/test_trt_convert_dropout.py index 99d5fb7d4b9b0..69c4274a72957 100644 --- a/test/ir/inference/test_trt_convert_dropout.py +++ b/test/ir/inference/test_trt_convert_dropout.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import Any, Dict, List +from typing import Any import numpy as np from program_config import ProgramConfig, TensorConfig @@ -28,7 +30,7 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: return True def sample_program_configs(self): - def generate_input(attrs: List[Dict[str, Any]]): + def generate_input(attrs: list[dict[str, Any]]): return np.ones([1, 3, 64, 64]).astype(np.float32) for dropout_implementation in [ @@ -76,7 +78,7 @@ def generate_input(attrs: List[Dict[str, Any]]): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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]} diff --git a/test/ir/inference/test_trt_convert_einsum.py b/test/ir/inference/test_trt_convert_einsum.py index 69e15856b45fa..38d1750f101c8 100644 --- a/test/ir/inference/test_trt_convert_einsum.py +++ b/test/ir/inference/test_trt_convert_einsum.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -91,7 +92,7 @@ def generate_equation1(dims): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): if self.dims == 1: self.dynamic_shape.min_input_shape = { @@ -251,7 +252,7 @@ def generate_equation_matrix_vector(dims, vec_shape): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): if self.dims == 1: self.dynamic_shape.min_input_shape = { @@ -383,7 +384,7 @@ def generate_input_matrix(input_shape): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): min_xshape = self.x_shape[:] max_xshape = self.x_shape[:] diff --git a/test/ir/inference/test_trt_convert_elementwise.py b/test/ir/inference/test_trt_convert_elementwise.py index b5ca0d05d47c8..9f77f924156b7 100644 --- a/test/ir/inference/test_trt_convert_elementwise.py +++ b/test/ir/inference/test_trt_convert_elementwise.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -110,7 +111,7 @@ def generate_weight(op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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: @@ -251,7 +252,7 @@ def generate_weight(op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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]} @@ -396,7 +397,7 @@ def generate_weight(op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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: @@ -539,7 +540,7 @@ def generate_input(shape, op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): if self.dims == 1: self.dynamic_shape.min_input_shape = { @@ -749,7 +750,7 @@ def generate_input(shape, op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): max_shape = [ [128], @@ -901,7 +902,7 @@ def generate_weight(op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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: @@ -1023,7 +1024,7 @@ def generate_input(shape, op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): if self.dims == 1: self.dynamic_shape.min_input_shape = { @@ -1169,7 +1170,7 @@ def generate_input(shape): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): if self.dims == 0: self.dynamic_shape.min_input_shape = {"input_data": []} @@ -1332,7 +1333,7 @@ def generate_input(dims, op_type): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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: diff --git a/test/ir/inference/test_trt_convert_elementwiseadd_transpose.py b/test/ir/inference/test_trt_convert_elementwiseadd_transpose.py index 012aaa00241b4..9fd9f17a0f029 100644 --- a/test/ir/inference/test_trt_convert_elementwiseadd_transpose.py +++ b/test/ir/inference/test_trt_convert_elementwiseadd_transpose.py @@ -11,9 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -130,7 +132,7 @@ def ele2_input_datagen(dics): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs, inputs): channel = inputs['ele_input_1'].shape[2] diff --git a/test/ir/inference/test_trt_convert_emb_eltwise_layernorm.py b/test/ir/inference/test_trt_convert_emb_eltwise_layernorm.py index 5e619a1f5b8fb..a350095386c7d 100644 --- a/test/ir/inference/test_trt_convert_emb_eltwise_layernorm.py +++ b/test/ir/inference/test_trt_convert_emb_eltwise_layernorm.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -263,7 +264,7 @@ def generate_weight4(size2): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> tuple[paddle_infer.Config, list[int], float]: def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = { "input_data1": [1, 4, 1], diff --git a/test/ir/inference/test_trt_convert_equal.py b/test/ir/inference/test_trt_convert_equal.py index 72e8a1574e72e..ce02c00afaa15 100644 --- a/test/ir/inference/test_trt_convert_equal.py +++ b/test/ir/inference/test_trt_convert_equal.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import unittest from functools import partial -from typing import List import numpy as np from program_config import ProgramConfig, TensorConfig @@ -82,7 +83,7 @@ def generate_input(shape): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> 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: