From 29fe24ed6fb413ef751b5b63793276627b202bdb Mon Sep 17 00:00:00 2001 From: BHmingyang Date: Mon, 5 Aug 2024 13:24:58 +0800 Subject: [PATCH 1/2] Use stardand collections for type hints in some py files --- test/ir/inference/test_trt_convert_gather.py | 5 +++-- test/ir/inference/test_trt_convert_gelu.py | 8 +++++--- .../inference/test_trt_convert_grid_sampler.py | 5 +++-- test/ir/inference/test_trt_convert_group_norm.py | 8 +++++--- .../inference/test_trt_convert_hard_sigmoid.py | 5 +++-- test/ir/inference/test_trt_convert_hard_swish.py | 8 +++++--- .../inference/test_trt_convert_index_select.py | 5 +++-- .../inference/test_trt_convert_instance_norm.py | 10 ++++++---- test/ir/inference/test_trt_convert_inverse.py | 5 +++-- test/ir/inference/test_trt_convert_layer_norm.py | 16 +++++++++------- 10 files changed, 45 insertions(+), 30 deletions(-) diff --git a/test/ir/inference/test_trt_convert_gather.py b/test/ir/inference/test_trt_convert_gather.py index fbf5c818b01bb..52c9bf3c18527 100644 --- a/test/ir/inference/test_trt_convert_gather.py +++ b/test/ir/inference/test_trt_convert_gather.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 @@ -118,7 +119,7 @@ def generate_input3(axis): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): if len(self.shape) == 1: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_gelu.py b/test/ir/inference/test_trt_convert_gelu.py index aa64994ad4cf7..6536a33a6c8d4 100644 --- a/test/ir/inference/test_trt_convert_gelu.py +++ b/test/ir/inference/test_trt_convert_gelu.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_input1(dims, attrs: List[Dict[str, Any]]): + def generate_input1(dims, attrs: list[dict[str, Any]]): if dims == 0: return np.ones([]).astype(np.float32) elif dims == 1: @@ -70,7 +72,7 @@ def generate_input1(dims, attrs: List[Dict[str, Any]]): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): if self.dims == 0: self.dynamic_shape.min_input_shape = {"input_data": []} diff --git a/test/ir/inference/test_trt_convert_grid_sampler.py b/test/ir/inference/test_trt_convert_grid_sampler.py index 00a78c46e85c2..5b719f022554b 100644 --- a/test/ir/inference/test_trt_convert_grid_sampler.py +++ b/test/ir/inference/test_trt_convert_grid_sampler.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 @@ -94,7 +95,7 @@ def generate_input2(): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(): if self.dims == 4: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_group_norm.py b/test/ir/inference/test_trt_convert_group_norm.py index ea28c63945d34..8e76193d48286 100644 --- a/test/ir/inference/test_trt_convert_group_norm.py +++ b/test/ir/inference/test_trt_convert_group_norm.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 @@ -35,7 +37,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]], batch): + def generate_input(attrs: list[dict[str, Any]], batch): if attrs[0]['data_layout'] == 'NCHW': return np.random.random([batch, 32, 64, 64]).astype(np.float32) else: @@ -101,7 +103,7 @@ def generate_bias(): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = {"input_data": [1, 16, 16, 16]} self.dynamic_shape.max_input_shape = { diff --git a/test/ir/inference/test_trt_convert_hard_sigmoid.py b/test/ir/inference/test_trt_convert_hard_sigmoid.py index 69d7594fd4373..bcc8056af4860 100644 --- a/test/ir/inference/test_trt_convert_hard_sigmoid.py +++ b/test/ir/inference/test_trt_convert_hard_sigmoid.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 @@ -64,7 +65,7 @@ def generate_input(shape): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): if self.input_dim == 2: self.dynamic_shape.min_input_shape = {"input_data": [1, 8]} diff --git a/test/ir/inference/test_trt_convert_hard_swish.py b/test/ir/inference/test_trt_convert_hard_swish.py index 381712bb59636..43f382903275d 100644 --- a/test/ir/inference/test_trt_convert_hard_swish.py +++ b/test/ir/inference/test_trt_convert_hard_swish.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 @@ -37,7 +39,7 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: return True def sample_program_configs(self): - def generate_input1(attrs: List[Dict[str, Any]]): + def generate_input1(attrs: list[dict[str, Any]]): return np.ones([1, 3, 32, 32]).astype(np.float32) for threshold in [6.0]: @@ -76,7 +78,7 @@ def generate_input1(attrs: List[Dict[str, Any]]): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 16, 16]} self.dynamic_shape.max_input_shape = {"input_data": [2, 3, 32, 32]} diff --git a/test/ir/inference/test_trt_convert_index_select.py b/test/ir/inference/test_trt_convert_index_select.py index 7573414c34265..54a857d93bfda 100644 --- a/test/ir/inference/test_trt_convert_index_select.py +++ b/test/ir/inference/test_trt_convert_index_select.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 @@ -96,7 +97,7 @@ def generate_input3(axis): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): if len(self.shape) == 1: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_instance_norm.py b/test/ir/inference/test_trt_convert_instance_norm.py index 3200003821d36..fbcd8a7a7a36c 100644 --- a/test/ir/inference/test_trt_convert_instance_norm.py +++ b/test/ir/inference/test_trt_convert_instance_norm.py @@ -13,10 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import os 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 @@ -37,10 +39,10 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: return True def sample_program_configs(self): - def generate_input1(attrs: List[Dict[str, Any]], shape_input): + def generate_input1(attrs: list[dict[str, Any]], shape_input): return np.random.random(shape_input).astype(np.float32) - def generate_input2(attrs: List[Dict[str, Any]], shape_input): + def generate_input2(attrs: list[dict[str, Any]], shape_input): return np.random.random(shape_input[1]).astype(np.float32) for batch in [1, 2, 4]: @@ -103,7 +105,7 @@ def generate_input2(attrs: List[Dict[str, Any]], shape_input): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): if self.in_dim == 2: self.dynamic_shape.min_input_shape = {"input_data": [1, 4]} diff --git a/test/ir/inference/test_trt_convert_inverse.py b/test/ir/inference/test_trt_convert_inverse.py index 87adffe106d05..54fd7acc9a858 100644 --- a/test/ir/inference/test_trt_convert_inverse.py +++ b/test/ir/inference/test_trt_convert_inverse.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 @@ -58,7 +59,7 @@ def generate_input1(): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = { "input_data": [1, 1], diff --git a/test/ir/inference/test_trt_convert_layer_norm.py b/test/ir/inference/test_trt_convert_layer_norm.py index 63a7c9ac62793..a4a95003562c3 100644 --- a/test/ir/inference/test_trt_convert_layer_norm.py +++ b/test/ir/inference/test_trt_convert_layer_norm.py @@ -13,9 +13,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 @@ -42,10 +44,10 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: return True def sample_program_configs(self): - def generate_input1(attrs: List[Dict[str, Any]], shape_input): + def generate_input1(attrs: list[dict[str, Any]], shape_input): return np.random.random(shape_input).astype(np.float32) - def generate_input2(attrs: List[Dict[str, Any]], shape_input): + def generate_input2(attrs: list[dict[str, Any]], shape_input): begin = attrs[0]["begin_norm_axis"] sum = 1 for x in range(begin, len(shape_input)): @@ -99,7 +101,7 @@ def generate_input2(attrs: List[Dict[str, Any]], shape_input): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (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]} @@ -170,10 +172,10 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool: return True def sample_program_configs(self): - def generate_input1(attrs: List[Dict[str, Any]], shape_input): + def generate_input1(attrs: list[dict[str, Any]], shape_input): return np.ones(shape_input).astype(np.float32) - def generate_input2(attrs: List[Dict[str, Any]], shape_input): + def generate_input2(attrs: list[dict[str, Any]], shape_input): begin = attrs[0]["begin_norm_axis"] sum = 1 for x in range(begin, len(shape_input)): @@ -227,7 +229,7 @@ def generate_input2(attrs: List[Dict[str, Any]], shape_input): def sample_predictor_configs( self, program_config - ) -> (paddle_infer.Config, List[int], float): + ) -> (paddle_infer.Config, list[int], float): def generate_dynamic_shape(attrs): self.dynamic_shape.min_input_shape = {"input_data": [1, 64, 3, 3]} self.dynamic_shape.max_input_shape = {"input_data": [4, 64, 3, 9]} From 9e162ecac1d32201385e72164d7f30d591dc1d1a Mon Sep 17 00:00:00 2001 From: SigureMo Date: Fri, 9 Aug 2024 03:14:16 +0800 Subject: [PATCH 2/2] fix wrong annotations --- test/ir/inference/test_trt_convert_gather.py | 2 +- test/ir/inference/test_trt_convert_gelu.py | 2 +- test/ir/inference/test_trt_convert_grid_sampler.py | 2 +- test/ir/inference/test_trt_convert_group_norm.py | 2 +- test/ir/inference/test_trt_convert_hard_sigmoid.py | 2 +- test/ir/inference/test_trt_convert_hard_swish.py | 2 +- test/ir/inference/test_trt_convert_index_select.py | 2 +- test/ir/inference/test_trt_convert_instance_norm.py | 2 +- test/ir/inference/test_trt_convert_inverse.py | 2 +- test/ir/inference/test_trt_convert_layer_norm.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/ir/inference/test_trt_convert_gather.py b/test/ir/inference/test_trt_convert_gather.py index 24e77a1e4138f..d5c7cf136fde2 100644 --- a/test/ir/inference/test_trt_convert_gather.py +++ b/test/ir/inference/test_trt_convert_gather.py @@ -123,7 +123,7 @@ def generate_input3(axis): 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 len(self.shape) == 1: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_gelu.py b/test/ir/inference/test_trt_convert_gelu.py index 6536a33a6c8d4..babde6bf20810 100644 --- a/test/ir/inference/test_trt_convert_gelu.py +++ b/test/ir/inference/test_trt_convert_gelu.py @@ -72,7 +72,7 @@ def generate_input1(dims, 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): if self.dims == 0: self.dynamic_shape.min_input_shape = {"input_data": []} diff --git a/test/ir/inference/test_trt_convert_grid_sampler.py b/test/ir/inference/test_trt_convert_grid_sampler.py index 5b719f022554b..a3bcc8daa3ad0 100644 --- a/test/ir/inference/test_trt_convert_grid_sampler.py +++ b/test/ir/inference/test_trt_convert_grid_sampler.py @@ -95,7 +95,7 @@ def generate_input2(): 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 == 4: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_group_norm.py b/test/ir/inference/test_trt_convert_group_norm.py index 8e76193d48286..7d2d3cf3754af 100644 --- a/test/ir/inference/test_trt_convert_group_norm.py +++ b/test/ir/inference/test_trt_convert_group_norm.py @@ -103,7 +103,7 @@ def generate_bias(): 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, 16, 16, 16]} self.dynamic_shape.max_input_shape = { diff --git a/test/ir/inference/test_trt_convert_hard_sigmoid.py b/test/ir/inference/test_trt_convert_hard_sigmoid.py index bcc8056af4860..3d8f0ba3d3432 100644 --- a/test/ir/inference/test_trt_convert_hard_sigmoid.py +++ b/test/ir/inference/test_trt_convert_hard_sigmoid.py @@ -65,7 +65,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.input_dim == 2: self.dynamic_shape.min_input_shape = {"input_data": [1, 8]} diff --git a/test/ir/inference/test_trt_convert_hard_swish.py b/test/ir/inference/test_trt_convert_hard_swish.py index 43f382903275d..12d62d9597d8e 100644 --- a/test/ir/inference/test_trt_convert_hard_swish.py +++ b/test/ir/inference/test_trt_convert_hard_swish.py @@ -78,7 +78,7 @@ def generate_input1(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, 16, 16]} self.dynamic_shape.max_input_shape = {"input_data": [2, 3, 32, 32]} diff --git a/test/ir/inference/test_trt_convert_index_select.py b/test/ir/inference/test_trt_convert_index_select.py index abaafe9fe7461..afb61074c159d 100644 --- a/test/ir/inference/test_trt_convert_index_select.py +++ b/test/ir/inference/test_trt_convert_index_select.py @@ -99,7 +99,7 @@ def generate_input3(axis): 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 len(self.shape) == 1: self.dynamic_shape.min_input_shape = { diff --git a/test/ir/inference/test_trt_convert_instance_norm.py b/test/ir/inference/test_trt_convert_instance_norm.py index fbcd8a7a7a36c..755b3c4bff28c 100644 --- a/test/ir/inference/test_trt_convert_instance_norm.py +++ b/test/ir/inference/test_trt_convert_instance_norm.py @@ -105,7 +105,7 @@ def generate_input2(attrs: list[dict[str, Any]], shape_input): 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.in_dim == 2: self.dynamic_shape.min_input_shape = {"input_data": [1, 4]} diff --git a/test/ir/inference/test_trt_convert_inverse.py b/test/ir/inference/test_trt_convert_inverse.py index 54fd7acc9a858..656bb809b0285 100644 --- a/test/ir/inference/test_trt_convert_inverse.py +++ b/test/ir/inference/test_trt_convert_inverse.py @@ -59,7 +59,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(attrs): self.dynamic_shape.min_input_shape = { "input_data": [1, 1], diff --git a/test/ir/inference/test_trt_convert_layer_norm.py b/test/ir/inference/test_trt_convert_layer_norm.py index a4a95003562c3..e56378bc95b65 100644 --- a/test/ir/inference/test_trt_convert_layer_norm.py +++ b/test/ir/inference/test_trt_convert_layer_norm.py @@ -101,7 +101,7 @@ def generate_input2(attrs: list[dict[str, Any]], shape_input): 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]}