-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type annotations for numba and pytorch plugins (#5129)
Type annotations are added for numba and Pytorch plugins, covering the operators (Numba function and Torch Python function) available in the plugin module. Additionally, type annotations are added to Pytorch data iterators for DALI. The code is rearranged so the dictionaries reflect the actual module hierarchy and allow for inserting the interface .pyi files, rather than generating the modules at runtime (especially the `fn` ones). The operators annotations are based on mix of stubgen, `nvidia.dali._signatures._gen_fn/ops_signature` and existing operators annotations. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
- Loading branch information
Showing
16 changed files
with
507 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
dali/python/nvidia/dali/plugin/numba/experimental/__init__.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 typing import Any, Optional, Union, List, Sequence, Callable | ||
|
||
from nvidia.dali.data_node import DataNode | ||
|
||
from nvidia.dali.types import DALIDataType | ||
|
||
class NumbaFunction: | ||
"""Invokes a njit compiled Numba function. | ||
The run function should be a Python function that can be compiled in Numba ``nopython`` mode.""" | ||
|
||
def __init__( | ||
self, | ||
run_fn: Optional[Callable[..., None]] = None, | ||
out_types: Optional[List[DALIDataType]] = None, | ||
in_types: Optional[List[DALIDataType]] = None, | ||
outs_ndim: Optional[List[int]] = None, | ||
ins_ndim: Optional[List[int]] = None, | ||
setup_fn: Optional[ | ||
Callable[[Sequence[Sequence[Any]], Sequence[Sequence[Any]], None]] | ||
] = None, | ||
device: str = "cpu", | ||
batch_processing: bool = False, | ||
blocks: Optional[Sequence[int]] = None, | ||
threads_per_block: Optional[Sequence[int]] = None, | ||
bytes_per_sample_hint: Union[Sequence[int], int, None] = [0], | ||
seed: Optional[int] = -1, | ||
) -> None: ... | ||
def __call__( | ||
self, | ||
__input_0: DataNode, | ||
__input_1: Optional[DataNode] = None, | ||
__input_2: Optional[DataNode] = None, | ||
__input_3: Optional[DataNode] = None, | ||
__input_4: Optional[DataNode] = None, | ||
__input_5: Optional[DataNode] = None, | ||
/, | ||
*, | ||
run_fn: Optional[Callable[..., None]] = None, | ||
out_types: Optional[List[DALIDataType]] = None, | ||
in_types: Optional[List[DALIDataType]] = None, | ||
outs_ndim: Optional[List[int]] = None, | ||
ins_ndim: Optional[List[int]] = None, | ||
setup_fn: Optional[ | ||
Callable[[Sequence[Sequence[Any]], Sequence[Sequence[Any]], None]] | ||
] = None, | ||
device: str = "cpu", | ||
batch_processing: bool = False, | ||
blocks: Optional[Sequence[int]] = None, | ||
threads_per_block: Optional[Sequence[int]] = None, | ||
bytes_per_sample_hint: Union[Sequence[int], int, None] = [0], | ||
seed: Optional[int] = -1, | ||
) -> Union[DataNode, Sequence[DataNode]]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 . import experimental # noqa F401 |
13 changes: 13 additions & 0 deletions
13
dali/python/nvidia/dali/plugin/numba/fn/experimental/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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. |
48 changes: 48 additions & 0 deletions
48
dali/python/nvidia/dali/plugin/numba/fn/experimental/__init__.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 typing import Any, Optional, Union, List, Sequence, Callable | ||
|
||
from nvidia.dali.data_node import DataNode | ||
|
||
from nvidia.dali.types import DALIDataType | ||
|
||
def numba_function( | ||
__input_0: DataNode, | ||
__input_1: Optional[DataNode] = None, | ||
__input_2: Optional[DataNode] = None, | ||
__input_3: Optional[DataNode] = None, | ||
__input_4: Optional[DataNode] = None, | ||
__input_5: Optional[DataNode] = None, | ||
/, | ||
*, | ||
run_fn: Callable[..., None], | ||
out_types: List[DALIDataType], | ||
in_types: List[DALIDataType], | ||
outs_ndim: List[int], | ||
ins_ndim: List[int], | ||
setup_fn: Optional[Callable[[Sequence[Sequence[Any]], Sequence[Sequence[Any]], None]]] = None, | ||
batch_processing: bool = False, | ||
blocks: Optional[Sequence[int]] = None, | ||
threads_per_block: Optional[Sequence[int]] = None, | ||
bytes_per_sample_hint: Union[Sequence[int], int, None] = [0], | ||
preserve: Optional[bool] = False, | ||
seed: Optional[int] = -1, | ||
device: Optional[str] = None, | ||
name: Optional[str] = None, | ||
) -> Union[DataNode, Sequence[DataNode]]: | ||
"""Invokes a njit compiled Numba function. | ||
The run function should be a Python function that can be compiled in Numba ``nopython`` mode.""" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.