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][171-180] Use standard collections for type hints for 10 uts in test/ir/inference/ #67017

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions test/ir/inference/test_trt_convert_expand_as_v2.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 @@ -36,7 +38,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]]):
if self.dims == 4:
self.input_shape = [1, 8, 1, 32]
return np.random.random([1, 8, 1, 32]).astype(np.float32)
Expand Down Expand Up @@ -92,7 +94,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):
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -180,7 +182,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]]):
if self.dims == 1:
self.input_shape = [1]
return np.random.random([1]).astype(np.float32)
Expand Down Expand Up @@ -230,7 +232,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():
if self.dims == 1:
self.dynamic_shape.min_input_shape = {"expand_v2_input": [1]}
Expand Down
22 changes: 12 additions & 10 deletions test/ir/inference/test_trt_convert_expand_v2.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 @@ -36,7 +38,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]]):
if self.dims == 4:
self.input_shape = [1, 1, 4, 6]
return np.random.random([1, 1, 4, 6]).astype(np.float32)
Expand All @@ -50,13 +52,13 @@ def generate_input1(attrs: List[Dict[str, Any]]):
self.input_shape = [48]
return np.random.random([48]).astype(np.float32)

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

def generate_shapeT1_data(attrs: List[Dict[str, Any]]):
def generate_shapeT1_data(attrs: list[dict[str, Any]]):
return np.array([2]).astype(np.int32)

def generate_shapeT2_data(attrs: List[Dict[str, Any]]):
def generate_shapeT2_data(attrs: list[dict[str, Any]]):
return np.array([24]).astype(np.int32)

for dims in [4, 3, 2, 1]:
Expand Down Expand Up @@ -93,7 +95,7 @@ def generate_shapeT2_data(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 == 4:
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -186,7 +188,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]]):
if self.dims == 1:
self.input_shape = [1]
return np.random.random([1]).astype(np.float32)
Expand Down Expand Up @@ -236,7 +238,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():
if self.dims == 1:
self.dynamic_shape.min_input_shape = {"expand_v2_input": [1]}
Expand Down Expand Up @@ -275,7 +277,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]]):
if self.dims == 4:
self.input_shape = [1, 1, 4, 6]
return np.random.random([1, 1, 4, 6]).astype(np.float32)
Expand Down Expand Up @@ -366,7 +368,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():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
Expand Down
14 changes: 8 additions & 6 deletions test/ir/inference/test_trt_convert_fill_any_like.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 @@ -32,7 +34,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]]):
if self.dims == 4:
self.input_shape = [1, 1, 4, 6]
if self.dtype == 0:
Expand Down Expand Up @@ -61,13 +63,13 @@ def generate_input1(attrs: List[Dict[str, Any]]):
self.input_shape = [48]
return np.random.random([48]).astype(np.int32)

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

def generate_shapeT1_data(attrs: List[Dict[str, Any]]):
def generate_shapeT1_data(attrs: list[dict[str, Any]]):
return np.array([2]).astype(np.int32)

def generate_shapeT2_data(attrs: List[Dict[str, Any]]):
def generate_shapeT2_data(attrs: list[dict[str, Any]]):
return np.array([24]).astype(np.int32)

for dims in [1, 2, 3, 4]:
Expand Down Expand Up @@ -107,7 +109,7 @@ def generate_shapeT2_data(attrs: List[Dict[str, Any]]):

def sample_predictor_configs(
self, program_config
) -> (paddle_infer.Config, List[int], int):
) -> tuple[paddle_infer.Config, list[int], int]:
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_fill_constant.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 @@ -153,7 +154,7 @@ def generate_input_data():

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.mode == "ValueTensor":
self.input_shape = [1, 1]
Expand Down
7 changes: 4 additions & 3 deletions test/ir/inference/test_trt_convert_flash_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 @@ -246,7 +247,7 @@ def generate_weight1():

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 last dim of input1 and input2 should be static.
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -545,7 +546,7 @@ def generate_weight1():

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, 4096, 320],
Expand Down
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 @@ -80,7 +81,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 == 0:
self.dynamic_shape.min_input_shape = {"input_data": []}
Expand Down
5 changes: 3 additions & 2 deletions test/ir/inference/test_trt_convert_flip.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 @@ -75,7 +76,7 @@ def generate_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 self.dims == 4:
self.dynamic_shape.min_input_shape = {
Expand Down
12 changes: 7 additions & 5 deletions test/ir/inference/test_trt_convert_fused_conv2d_add_act.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 unittest
from functools import partial
from itertools import product
from typing import Any, Dict, List
from typing import Any

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand Down Expand Up @@ -53,15 +55,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
)

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

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

batch_options = [1, 2]
Expand Down Expand Up @@ -148,7 +150,7 @@ def generate_weight2(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):
input_groups = attrs[0]['groups'] * 3
self.dynamic_shape.min_input_shape = {
Expand Down
12 changes: 7 additions & 5 deletions test/ir/inference/test_trt_convert_fused_token_prune.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 @@ -30,13 +32,13 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_attn_or_mask(attrs: List[Dict[str, Any]]):
def generate_attn_or_mask(attrs: list[dict[str, Any]]):
return np.ones([4, 12, 64, 64]).astype(np.float32)

def generate_x(attrs: List[Dict[str, Any]]):
def generate_x(attrs: list[dict[str, Any]]):
return np.random.random([4, 64, 76]).astype(np.float32)

def generate_new_mask(attrs: List[Dict[str, Any]]):
def generate_new_mask(attrs: list[dict[str, Any]]):
return np.random.random([4, 12, 32, 32]).astype(np.float32)

for keep_first_token in [True, False]:
Expand Down Expand Up @@ -86,7 +88,7 @@ def generate_new_mask(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 = {
"attn": [4, 12, 64, 64],
Expand Down
Loading