Skip to content

Commit 425c2e8

Browse files
megeminilixcli
authored andcommitted
[Typing][C-55] Add type annotations for python/paddle/incubate/autotune.py (PaddlePaddle#66009)
1 parent 61352cc commit 425c2e8

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

python/paddle/incubate/autotune.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,39 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import json
1618
import warnings
19+
from typing import TYPE_CHECKING, TypedDict
1720

1821
import paddle
1922
from paddle.base import core
2023

24+
if TYPE_CHECKING:
25+
from typing_extensions import NotRequired
26+
27+
class _Kernel(TypedDict):
28+
enable: bool
29+
tuning_range: list[int] | tuple[int, int]
30+
31+
class _Layout(TypedDict):
32+
enable: bool
33+
34+
class _Dataloader(TypedDict):
35+
enable: bool
36+
tuning_steps: int
37+
38+
class _ConfigKernel(TypedDict):
39+
kernel: NotRequired[_Kernel]
40+
layout: NotRequired[_Layout]
41+
dataloader: NotRequired[_Dataloader]
42+
43+
2144
__all__ = ['set_config']
2245

2346

24-
def set_config(config=None):
47+
def set_config(config: _ConfigKernel | str | None = None) -> None:
2548
r"""
2649
Set the configuration for kernel, layout and dataloader auto-tuning.
2750
@@ -72,7 +95,7 @@ def set_config(config=None):
7295
... "enable": True,
7396
... }
7497
>>> }
75-
>>> paddle.incubate.autotune.set_config(config)
98+
>>> paddle.incubate.autotune.set_config(config) # type: ignore[arg-type]
7699
77100
>>> # config is the path of json file.
78101
>>> config_json = json.dumps(config)

0 commit comments

Comments
 (0)