Skip to content

Commit

Permalink
use pep563
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo committed Jan 27, 2024
1 parent 9700507 commit 5025687
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 37 deletions.
18 changes: 10 additions & 8 deletions test/ir/inference/test_trt_convert_batch_norm.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -29,7 +31,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:
if attrs[0]['data_layout'] == "NCHW":
return np.ones([batch, 3, 24, 24]).astype(np.float32)
Expand All @@ -40,19 +42,19 @@ def generate_input1(attrs: List[Dict[str, Any]], batch):
elif self.dims == 2:
return np.ones([batch, 3]).astype(np.float32)

def generate_bias(attrs: List[Dict[str, Any]], batch):
def generate_bias(attrs: list[dict[str, Any]], batch):
return np.full((3), 0.9).astype("float32")

def generate_mean(attrs: List[Dict[str, Any]], batch):
def generate_mean(attrs: list[dict[str, Any]], batch):
return np.full((3), 0.9).astype("float32")

def generate_scale(attrs: List[Dict[str, Any]], batch):
def generate_scale(attrs: list[dict[str, Any]], batch):
return np.full((3), 1.1).astype("float32")

def generate_variance(attrs: List[Dict[str, Any]], batch):
def generate_variance(attrs: list[dict[str, Any]], batch):
return np.full((3), 1.2).astype("float32")

def generate_MomentumTensor(attrs: List[Dict[str, Any]], batch):
def generate_MomentumTensor(attrs: list[dict[str, Any]], batch):
return np.full((3), 0.9).astype("float32")

for dims, num_input, batch, epsilon, data_layout, momentum in product(
Expand Down Expand Up @@ -156,7 +158,7 @@ def generate_MomentumTensor(attrs: List[Dict[str, Any]], batch):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
if self.dims == 4:
Expand Down
10 changes: 6 additions & 4 deletions test/ir/inference/test_trt_convert_depthwise_conv2d_transpose.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand Down Expand Up @@ -56,12 +58,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, attrs: List[Dict[str, Any]]):
def generate_input1(batch, attrs: list[dict[str, Any]]):
return np.ones([batch, attrs[0]['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([attrs[0]['groups'], 1, 3, 3]).astype(
np.float32
)
Expand Down Expand Up @@ -130,7 +132,7 @@ def generate_weight1(attrs: List[Dict[str, Any]]):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
Expand Down
8 changes: 5 additions & 3 deletions test/ir/inference/test_trt_convert_nearest_interp.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -42,7 +44,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, 64, 64]).astype(np.float32)

for (
Expand Down Expand Up @@ -97,7 +99,7 @@ def generate_input1(attrs: List[Dict[str, Any]]):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]}
Expand Down
6 changes: 4 additions & 2 deletions test/ir/inference/test_trt_convert_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# 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 itertools import product
from typing import Any, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand Down Expand Up @@ -205,7 +207,7 @@ def generate_b():
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
attrs = [
program_config.ops[i].attrs for i in range(len(program_config.ops))
Expand Down
12 changes: 7 additions & 5 deletions test/ir/inference/test_trt_convert_roi_align.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -29,13 +31,13 @@ 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, 256, 32, 32]).astype(np.float32)

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

def generate_input3(attrs: List[Dict[str, Any]], batch):
def generate_input3(attrs: list[dict[str, Any]], batch):
if batch == 1:
return np.array([3]).astype(np.int32)
if batch == 2:
Expand Down Expand Up @@ -136,7 +138,7 @@ def generate_lod(batch):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
if self.num_input == 0:
Expand Down
10 changes: 6 additions & 4 deletions test/ir/inference/test_trt_convert_scale.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -29,7 +31,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, is_int):
def generate_input1(attrs: list[dict[str, Any]], batch, is_int):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(
np.int32 if is_int else np.float32
Expand All @@ -47,7 +49,7 @@ def generate_input1(attrs: List[Dict[str, Any]], batch, is_int):
elif self.dims == 0:
return np.ones([]).astype(np.int32 if is_int else np.float32)

def generate_weight1(attrs: List[Dict[str, Any]], is_int):
def generate_weight1(attrs: list[dict[str, Any]], is_int):
return np.ones([1]).astype(np.int32 if is_int else np.float32)

for (
Expand Down Expand Up @@ -130,7 +132,7 @@ def generate_weight1(attrs: List[Dict[str, Any]], is_int):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
if self.dims == 4:
Expand Down
14 changes: 9 additions & 5 deletions test/ir/inference/test_trt_convert_strided_slice.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, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -34,7 +36,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([1, 56, 56, 192]).astype(np.float32)

for axes, starts, ends, decrease_axis, infer_flags, strides in product(
Expand Down Expand Up @@ -82,7 +84,7 @@ def generate_input1(attrs: List[Dict[str, Any]]):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
Expand Down Expand Up @@ -145,7 +147,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([1, 56, 56, 192]).astype(np.float32)

for axes in [[1, 2], [2, 3], [1, 3]]:
Expand Down Expand Up @@ -200,7 +202,9 @@ def generate_input1(attrs: List[Dict[str, Any]]):

def sample_predictor_configs(
self, program_config
) -> (paddle_infer.Config, List[int], float):
) -> Generator[
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape():
self.dynamic_shape.min_input_shape = {
"input_data": [1, 56, 56, 192]
Expand Down
7 changes: 5 additions & 2 deletions test/ir/inference/test_trt_convert_trans_layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
# 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 itertools import product
from typing import Any, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand Down Expand Up @@ -176,7 +179,7 @@ def conv2d_input_datagen(dics):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs, inputs):
conv2d_c = inputs['conv2d_input'].shape[1]
Expand Down
10 changes: 6 additions & 4 deletions test/ir/inference/test_trt_convert_yolo_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# 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 itertools import product
from typing import Any, Dict, Generator, List, Tuple
from typing import Any, Generator

import numpy as np
from program_config import ProgramConfig, TensorConfig
Expand All @@ -30,7 +32,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, channel):
def generate_input1(attrs: list[dict[str, Any]], batch, channel):
if attrs[0]['iou_aware']:
return np.ones([batch, 3 * (channel + 6), 13, 13]).astype(
np.float32
Expand All @@ -40,7 +42,7 @@ def generate_input1(attrs: List[Dict[str, Any]], batch, channel):
np.float32
)

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

for (
Expand Down Expand Up @@ -120,7 +122,7 @@ def generate_input2(attrs: List[Dict[str, Any]], batch):
def sample_predictor_configs(
self, program_config
) -> Generator[
Any, Any, Tuple[paddle_infer.Config, List[int], float] | None
Any, Any, tuple[paddle_infer.Config, list[int], float] | None
]:
def generate_dynamic_shape(attrs):
if attrs[0]['iou_aware']:
Expand Down

0 comments on commit 5025687

Please sign in to comment.