onnx-ir 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of onnx-ir might be problematic. Click here for more details.

onnx_ir/traversal.py ADDED
@@ -0,0 +1,82 @@
1
+ # Copyright (c) Microsoft Corporation.
2
+ # Licensed under the MIT License.
3
+ """Utilities for traversing the IR graph."""
4
+
5
+ from __future__ import annotations
6
+
7
+ __all__ = [
8
+ "RecursiveGraphIterator",
9
+ ]
10
+
11
+ from typing import Callable, Iterator, Reversible, Union
12
+
13
+ from typing_extensions import Self
14
+
15
+ from onnx_ir import _core, _enums
16
+
17
+ GraphLike = Union[_core.Graph, _core.Function, _core.GraphView]
18
+
19
+
20
+ class RecursiveGraphIterator(Iterator[_core.Node], Reversible[_core.Node]):
21
+ def __init__(
22
+ self,
23
+ graph_like: GraphLike,
24
+ *,
25
+ recursive: Callable[[_core.Node], bool] | None = None,
26
+ reverse: bool = False,
27
+ ):
28
+ """Iterate over the nodes in the graph, recursively visiting subgraphs.
29
+
30
+ Args:
31
+ graph_like: The graph to traverse.
32
+ recursive: A callback that determines whether to recursively visit the subgraphs
33
+ contained in a node. If not provided, all nodes in subgraphs are visited.
34
+ reverse: Whether to iterate in reverse order.
35
+ """
36
+ self._graph = graph_like
37
+ self._recursive = recursive
38
+ self._reverse = reverse
39
+ self._iterator = self._recursive_node_iter(graph_like)
40
+
41
+ def __iter__(self) -> Self:
42
+ self._iterator = self._recursive_node_iter(self._graph)
43
+ return self
44
+
45
+ def __next__(self) -> _core.Node:
46
+ return next(self._iterator)
47
+
48
+ def _recursive_node_iter(
49
+ self, graph: _core.Graph | _core.Function | _core.GraphView
50
+ ) -> Iterator[_core.Node]:
51
+ iterable = reversed(graph) if self._reverse else graph
52
+ for node in iterable: # type: ignore[union-attr]
53
+ yield node
54
+ if self._recursive is not None and not self._recursive(node):
55
+ continue
56
+ yield from self._iterate_subgraphs(node)
57
+
58
+ def _iterate_subgraphs(self, node: _core.Node):
59
+ for attr in node.attributes.values():
60
+ if not isinstance(attr, _core.Attr):
61
+ continue
62
+ if attr.type == _enums.AttributeType.GRAPH:
63
+ yield from RecursiveGraphIterator(
64
+ attr.value,
65
+ recursive=self._recursive,
66
+ reverse=self._reverse,
67
+ )
68
+ elif attr.type == _enums.AttributeType.GRAPHS:
69
+ graphs = reversed(attr.value) if self._reverse else attr.value
70
+ for graph in graphs:
71
+ yield from RecursiveGraphIterator(
72
+ graph,
73
+ recursive=self._recursive,
74
+ reverse=self._reverse,
75
+ )
76
+
77
+ def __reversed__(self) -> Iterator[_core.Node]:
78
+ return RecursiveGraphIterator(
79
+ self._graph,
80
+ recursive=self._recursive,
81
+ reverse=not self._reverse,
82
+ )
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Justin Chu
4
+ Copyright (c) Microsoft Corporation
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.2
2
+ Name: onnx-ir
3
+ Version: 0.0.1
4
+ Author-email: Justin Chu <justinchu@microsoft.com>
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 Justin Chu
8
+ Copyright (c) Microsoft Corporation
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Classifier: Development Status :: 4 - Beta
29
+ Classifier: Environment :: Console
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: Operating System :: POSIX
32
+ Classifier: Operating System :: MacOS :: MacOS X
33
+ Classifier: Operating System :: Microsoft :: Windows
34
+ Classifier: Programming Language :: Python :: 3.8
35
+ Classifier: Programming Language :: Python :: 3.9
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Requires-Python: >=3.8
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Requires-Dist: numpy
45
+ Requires-Dist: onnx>=1.16
46
+ Requires-Dist: typing_extensions>=4.10
47
+ Requires-Dist: ml_dtypes
48
+
49
+ # ONNX IR
50
+
51
+ > [!NOTE]
52
+ > This is an adaptation of the `onnxscript.ir` module from the ONNX Script project: https://github.com/microsoft/onnxscript/tree/main/onnxscript/ir
53
+
54
+ An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
55
+
56
+ ## Features ✨
57
+
58
+ - Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them).
59
+ - Low memory footprint: mmap'ed external tensors; unified interface for ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size limitation. Zero copies.
60
+ - Straightforward access patterns: Access value information and traverse the graph topology at ease.
61
+ - Robust mutation: Create as many iterators as you like on the graph while mutating it.
62
+ - Speed: Performant graph manipulation, serialization/deserialization to Protobuf.
63
+ - Pythonic and familiar APIs: Classes define Pythonic apis and still map to ONNX protobuf concepts in an intuitive way.
64
+ - No protobuf dependency: The IR does not require protobuf once the model is converted to the IR representation, decoupling from the serialization format.
65
+
66
+ ## Code Organization 🗺️
67
+
68
+ - [`_protocols.py`](_protocols.py): Interfaces defined for all entities in the IR.
69
+ - [`_core.py`](_core.py): Implementation of the core entities in the IR, including `Model`, `Graph`, `Node`, `Value`, and others.
70
+ - [`_enums.py`](_enums.py): Definition of the type enums that correspond to the `DataType` and `AttributeType` in `onnx.proto`.
71
+ - [`_name_authority.py`](_name_authority.py): The authority for giving names to entities in the graph, used internally.
72
+ - [`_linked_list.py`](_linked_list.py): The data structure as the node container in the graph that supports robust iteration and mutation. Internal.
73
+ - [`_metadata.py`](_metadata.py): Metadata store for all entities in the IR.
@@ -0,0 +1,26 @@
1
+ onnx_ir/__init__.py,sha256=Lj7uEV33mcR9dLgvA0Qs-pFkE3faJoLZLtJGC-QphjM,2993
2
+ onnx_ir/_convenience.py,sha256=G7uDrvbKYpk65-f-wYqORKuP0roxMQ-miMiGEMnHDG8,16467
3
+ onnx_ir/_core.py,sha256=0TS4bzBvsChq-uDueFLMU32azRIxY8HDF9oIXRCnDGw,103991
4
+ onnx_ir/_display.py,sha256=6x5QQwpA4ugEhbCZ8ZzFGMNcpNlnjXQIftJrT-cb61c,1293
5
+ onnx_ir/_enums.py,sha256=0Q-1ee0XzM0EDwX-CbfS_i48XjLErtwDVz7H34vDUFg,4127
6
+ onnx_ir/_external_data.py,sha256=xV4Fi_jBXcbvMRzfbdeFH5rZMAi2bym2E9NdCqtABQM,13747
7
+ onnx_ir/_graph_comparison.py,sha256=wGkD4HLfC4JOcvOSxNM1dLMpc1QPEy_uCnasL5Z_2RY,720
8
+ onnx_ir/_io.py,sha256=Nnid_zzuA7G0a5IhJHvI6smLqYtftXpC6ILKtHpWhp8,1703
9
+ onnx_ir/_linked_list.py,sha256=rTog1WP4YFfXkOtvc63X7zzKvFydneVn3I3W2vv9JEc,10344
10
+ onnx_ir/_metadata.py,sha256=4SL4m-GiRO3z0fcOfXzye-5QwFwKxFacqoVx3_AzyVI,1510
11
+ onnx_ir/_name_authority.py,sha256=B7fS92M1zTz0iSwTbxzYt1fbaOuQ2kv7-wRZC8zkqoQ,3029
12
+ onnx_ir/_protocols.py,sha256=PgrWncyCERua4fMVnmwPJnfD08i-9y8dYCNdqY2fA3I,20818
13
+ onnx_ir/_tape.py,sha256=bRg7LipHIZr62TbLbAB-rjjomDDkwoupDuWj27_vGv0,3417
14
+ onnx_ir/_type_casting.py,sha256=K8W6NEwbsQWQ-BSl9j928-vz6Posy0mUnMGBjX2ZAj0,2848
15
+ onnx_ir/convenience.py,sha256=QRVmuU8OSS4mu-VOjv0MjHHxpQC5VOKAGnwHjWmvOJ4,810
16
+ onnx_ir/serde.py,sha256=YXJD7146RERbPK5SQBJe-lYlhgs-0Ir71hmw7SdZc1g,62852
17
+ onnx_ir/traversal.py,sha256=8zw8XvxUefzbWfGcK28c9h4XTnc7IqNgKYCZnIB0Q-U,2829
18
+ onnx_ir/_internal/version_utils.py,sha256=fDJMHm5lxv-Q1Iz4KJ8kM9pmFFUymz1zi0a_uDF0Js4,3281
19
+ onnx_ir/_thirdparty/asciichartpy.py,sha256=wgqaJBjSZRvftSzQO8TPyldnYt5wUlApKAc9GxFVZpw,10599
20
+ onnx_ir/passes/__init__.py,sha256=O2uRd8pbRhYYMzlKJ4CnWNq3MR2JXzQCv_lFFIZHc4A,645
21
+ onnx_ir/passes/_pass_infra.py,sha256=ygI2Ptq5Moleq2pr23OPnVmQVY4e0LyupQY0c6-BRwM,5366
22
+ onnx_ir-0.0.1.dist-info/LICENSE,sha256=mwKiiaO6cDOyDz3J5_ApIDbydWOxYwi8jD2WOVHrJX4,1103
23
+ onnx_ir-0.0.1.dist-info/METADATA,sha256=6IJ-7WF9AB4Sl3WHRV9LnPz74MY-9ylIJB-kIB0LQYQ,4076
24
+ onnx_ir-0.0.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
25
+ onnx_ir-0.0.1.dist-info/top_level.txt,sha256=W5tROO93YjO0XRxIdjMy4wocp-5st5GiI2ukvW7UhDo,8
26
+ onnx_ir-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ onnx_ir