Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typing][PEP585 Upgrade][BUAA][151-160] Use standard collections for type hints for 10 uts in test/ir/inference/ #67015

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_bitwise_or.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 @@ -70,7 +71,7 @@ def generate_input(batch):

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 == 4:
self.dynamic_shape.min_input_shape = {
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_bmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# 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 List

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand Down Expand Up @@ -66,7 +67,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):
self.dynamic_shape.min_input_shape = {
"input1_data": [10, 350, 75],
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_cast.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 @@ -103,7 +104,7 @@ def generate_input(type):

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": []}
Expand Down
10 changes: 6 additions & 4 deletions test/ir/inference/test_trt_convert_clip.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(dims, batch, dtype, attrs: List[Dict[str, Any]]):
def generate_input1(dims, batch, dtype, attrs: list[dict[str, Any]]):
if dims == 0:
return np.ones([]).astype(dtype)
elif dims == 1:
Expand All @@ -40,10 +42,10 @@ def generate_input1(dims, batch, dtype, attrs: List[Dict[str, Any]]):
else:
return np.ones([batch, 3, 32, 32]).astype(dtype)

def generate_weight1(attrs: List[Dict[str, Any]]):
def generate_weight1(attrs: list[dict[str, Any]]):
return np.array([np.random.uniform(1, 10)]).astype("float32")

def generate_weight2(attrs: List[Dict[str, Any]]):
def generate_weight2(attrs: list[dict[str, Any]]):
return np.array([np.random.uniform(10, 20)]).astype("float32")

for dims in [0, 1, 2, 3, 4]:
Expand Down
13 changes: 7 additions & 6 deletions test/ir/inference/test_trt_convert_compare_and_logical.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 @@ -91,7 +92,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.dims == 2:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -237,7 +238,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.dims == 2:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -398,7 +399,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.dims == 2:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -561,7 +562,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.dims == 2:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -726,7 +727,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.dims == 2:
shape_data = [2, 16]
Expand Down
14 changes: 8 additions & 6 deletions test/ir/inference/test_trt_convert_concat.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 @@ -39,7 +41,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):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
Expand All @@ -49,7 +51,7 @@ def generate_input1(attrs: List[Dict[str, Any]], batch):
elif self.dims == 1:
return np.ones([24]).astype(np.float32)

def generate_input2(attrs: List[Dict[str, Any]], batch):
def generate_input2(attrs: list[dict[str, Any]], batch):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
Expand All @@ -59,7 +61,7 @@ def generate_input2(attrs: List[Dict[str, Any]], batch):
elif self.dims == 1:
return np.ones([24]).astype(np.float32)

def generate_input3(attrs: List[Dict[str, Any]], batch):
def generate_input3(attrs: list[dict[str, Any]], batch):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
Expand All @@ -69,7 +71,7 @@ def generate_input3(attrs: List[Dict[str, Any]], batch):
elif self.dims == 1:
return np.ones([24]).astype(np.float32)

def generate_weight1(attrs: List[Dict[str, Any]]):
def generate_weight1(attrs: list[dict[str, Any]]):
return np.zeros([1]).astype(np.int32)

for dims in [2, 3, 4]:
Expand Down Expand Up @@ -155,7 +157,7 @@ def generate_weight1(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.num_input == 0:
if self.dims == 4:
Expand Down
16 changes: 9 additions & 7 deletions test/ir/inference/test_trt_convert_conv2d.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 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
Expand Down Expand Up @@ -50,15 +52,15 @@ 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]]):
return (
np.ones([batch, attrs[0]['groups'] * 3, 64, 64]).astype(
np.float32
)
/ 4
)

def generate_weight1(attrs: List[Dict[str, Any]]):
def generate_weight1(attrs: list[dict[str, Any]]):
return np.random.random([9, 3, 3, 3]).astype(np.float32) - 0.5

batch_options = [1, 2]
Expand Down Expand Up @@ -139,7 +141,7 @@ def generate_weight1(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):
input_groups = attrs[0]['groups'] * 3
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -233,13 +235,13 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(attrs: List[Dict[str, Any]]):
def generate_input1(attrs: list[dict[str, Any]]):
return (
np.random.random(attrs[0]['input_shape']).astype(np.float32)
- 0.5
)

def generate_data(attrs: List[Dict[str, Any]]):
def generate_data(attrs: list[dict[str, Any]]):
return (
np.random.random(attrs[0]['weight_shape']).astype(np.float32)
- 0.5
Expand Down Expand Up @@ -330,7 +332,7 @@ def generate_data(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 clear_dynamic_shape():
self.dynamic_shape.min_input_shape = {}
self.dynamic_shape.max_input_shape = {}
Expand Down
16 changes: 9 additions & 7 deletions test/ir/inference/test_trt_convert_conv2d_transpose.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 @@ -52,10 +54,10 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(batch, num_channels, attrs: List[Dict[str, Any]]):
def generate_input1(batch, num_channels, attrs: list[dict[str, Any]]):
return np.ones([batch, num_channels, 64, 64]).astype(np.float32)

def generate_weight1(num_channels, attrs: List[Dict[str, Any]]):
def generate_weight1(num_channels, attrs: list[dict[str, Any]]):
if attrs[0]['groups'] == 1:
return np.random.random(
[num_channels, num_channels, 3, 3]
Expand Down Expand Up @@ -136,7 +138,7 @@ def generate_weight1(num_channels, 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.num_channels == 2:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -254,12 +256,12 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(batch, num_channels, attrs: List[Dict[str, Any]]):
def generate_input1(batch, num_channels, attrs: list[dict[str, Any]]):
return (
np.ones([batch, num_channels, 20, 30]).astype(np.float32) / 100
)

def generate_weight1(num_channels, attrs: List[Dict[str, Any]]):
def generate_weight1(num_channels, attrs: list[dict[str, Any]]):
return (
np.random.random([num_channels, 64, 3, 3]).astype(np.float32)
/ 100
Expand Down Expand Up @@ -314,7 +316,7 @@ def generate_weight1(num_channels, 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, 128, 20, 30],
Expand Down
10 changes: 6 additions & 4 deletions test/ir/inference/test_trt_convert_conv3d_transpose.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 @@ -34,10 +36,10 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(batch, num_channels, attrs: List[Dict[str, Any]]):
def generate_input1(batch, num_channels, attrs: list[dict[str, Any]]):
return np.ones([batch, num_channels, 4, 20, 30]).astype(np.float32)

def generate_weight1(num_channels, attrs: List[Dict[str, Any]]):
def generate_weight1(num_channels, attrs: list[dict[str, Any]]):
return np.random.random([num_channels, 64, 3, 3, 3]).astype(
np.float32
)
Expand Down Expand Up @@ -91,7 +93,7 @@ def generate_weight1(num_channels, 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, 128, 4, 20, 30],
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_cross_multihead_matmul.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 @@ -242,7 +243,7 @@ def generate_weight2():

def sample_predictor_configs(
self, program_config
) -> (paddle_infer.Config, List[int], float):
) -> (paddle_infer.Config, list[int], float):
def generate_dynamic_shape(attrs):
# The last dim of input1 and input2 should be static.
self.dynamic_shape.min_input_shape = {
Expand Down