Skip to content

Commit

Permalink
[Typing][PEP585 Upgrade][BUAA][216-225] Use standard collections for …
Browse files Browse the repository at this point in the history
…type hints for 10 uts in `test/ir/inference/` (#67024)
  • Loading branch information
MufanColin authored Aug 6, 2024
1 parent 297ec11 commit 943b3ce
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
5 changes: 4 additions & 1 deletion test/ir/inference/test_trt_convert_roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
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
from trt_layer_auto_scan_test import SkipReasons, TrtLayerAutoScanTest

import paddle.inference as paddle_infer

if TYPE_CHECKING:
from collections.abc import Generator


class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
Expand Down
8 changes: 5 additions & 3 deletions test/ir/inference/test_trt_convert_roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import random
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
Expand All @@ -36,7 +38,7 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = random.randint(1024, 1 << 30)

def generate_input1(attrs: List[Dict[str, Any]]):
def generate_input1(attrs: list[dict[str, Any]]):
return np.random.random([1, 56, 56, 192]).astype(np.float32)

for axis in [[1, 2]]:
Expand Down Expand Up @@ -73,7 +75,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, 56, 56, 192]
Expand Down
5 changes: 4 additions & 1 deletion test/ir/inference/test_trt_convert_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
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
from trt_layer_auto_scan_test import SkipReasons, TrtLayerAutoScanTest

import paddle.inference as paddle_infer

if TYPE_CHECKING:
from collections.abc import Generator


class TrtConvertScaleTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,7 +73,7 @@ def generate_input3():

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],
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_scatter_nd_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,7 +74,7 @@ def generate_input3():

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],
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +66,7 @@ def generate_input1(batch):

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 = {"input1": [1, 3, 24, 24]}
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_share_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +93,7 @@ def generate_input(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 = {"input_data": [1]}
Expand Down
8 changes: 5 additions & 3 deletions test/ir/inference/test_trt_convert_shuffle_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +30,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]], batch):
def generate_input1(attrs: list[dict[str, Any]], batch):
return np.ones([batch, 6, 24, 24]).astype(np.float32)

for batch in [1, 2, 4]:
Expand Down Expand Up @@ -58,7 +60,7 @@ def generate_input1(attrs: List[Dict[str, Any]], batch):

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 = {
"shuffle_channel_input": [1, 6, 24, 24]
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,7 +64,7 @@ def generate_input(batch):

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 == 4:
self.dynamic_shape.min_input_shape = {
Expand Down
8 changes: 5 additions & 3 deletions test/ir/inference/test_trt_convert_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +63,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.random.random([6, 6, 64, 64]).astype(np.float32)

for axes in [[0, 1], [1, 3], [2, 3]]:
Expand Down Expand Up @@ -106,7 +108,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, 32, 32]}
self.dynamic_shape.max_input_shape = {"input_data": [8, 8, 64, 64]}
Expand Down

0 comments on commit 943b3ce

Please sign in to comment.