|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import argparse |
| 18 | +from typing import Any |
| 19 | + |
15 | 20 | from paddlex.inference import PaddlePredictorOption |
16 | 21 | from paddlex.utils.device import get_default_device, parse_device |
17 | 22 |
|
|
28 | 33 | from ._utils.cli import str2bool |
29 | 34 |
|
30 | 35 |
|
31 | | -def parse_common_args(kwargs, *, default_enable_hpi): |
| 36 | +def parse_common_args(kwargs: dict[str, Any], *, default_enable_hpi: bool | None) -> dict[str, Any]: |
32 | 37 | default_vals = { |
33 | 38 | "device": DEFAULT_DEVICE, |
34 | 39 | "enable_hpi": default_enable_hpi, |
@@ -57,13 +62,13 @@ def parse_common_args(kwargs, *, default_enable_hpi): |
57 | 62 | return kwargs |
58 | 63 |
|
59 | 64 |
|
60 | | -def prepare_common_init_args(model_name, common_args): |
| 65 | +def prepare_common_init_args(model_name: str | None, common_args: dict[str, Any]) -> dict[str, Any]: |
61 | 66 | device = common_args["device"] |
62 | 67 | if device is None: |
63 | 68 | device = get_default_device() |
64 | 69 | device_type, _ = parse_device(device) |
65 | 70 |
|
66 | | - init_kwargs = {} |
| 71 | + init_kwargs: dict[str, Any] = {} |
67 | 72 | init_kwargs["device"] = device |
68 | 73 | init_kwargs["use_hpip"] = common_args["enable_hpi"] |
69 | 74 |
|
@@ -94,7 +99,7 @@ def prepare_common_init_args(model_name, common_args): |
94 | 99 | return init_kwargs |
95 | 100 |
|
96 | 101 |
|
97 | | -def add_common_cli_opts(parser, *, default_enable_hpi, allow_multiple_devices): |
| 102 | +def add_common_cli_opts(parser: argparse.ArgumentParser, *, default_enable_hpi: bool | None, allow_multiple_devices: bool) -> None: |
98 | 103 | if allow_multiple_devices: |
99 | 104 | help_ = "Device(s) to use for inference, e.g., `cpu`, `gpu`, `npu`, `gpu:0`, `gpu:0,1`. If multiple devices are specified, inference will be performed in parallel. Note that parallel inference is not always supported. By default, GPU 0 will be used if available; otherwise, the CPU will be used." |
100 | 105 | else: |
|
0 commit comments