onnx-ir 0.0.1__tar.gz → 0.1.1__tar.gz

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.

Files changed (58) hide show
  1. onnx_ir-0.1.1/LICENSE +202 -0
  2. onnx_ir-0.1.1/PKG-INFO +53 -0
  3. onnx_ir-0.1.1/README.md +28 -0
  4. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/pyproject.toml +34 -19
  5. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/__init__.py +23 -10
  6. onnx_ir-0.0.1/src/onnx_ir/_convenience.py → onnx_ir-0.1.1/src/onnx_ir/_convenience/__init__.py +40 -102
  7. onnx_ir-0.1.1/src/onnx_ir/_convenience/_constructors.py +213 -0
  8. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_core.py +874 -257
  9. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_display.py +2 -2
  10. onnx_ir-0.1.1/src/onnx_ir/_enums.py +256 -0
  11. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_graph_comparison.py +2 -2
  12. onnx_ir-0.1.1/src/onnx_ir/_graph_containers.py +373 -0
  13. onnx_ir-0.1.1/src/onnx_ir/_io.py +97 -0
  14. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_linked_list.py +15 -7
  15. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_metadata.py +4 -3
  16. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_name_authority.py +2 -2
  17. onnx_ir-0.1.1/src/onnx_ir/_polyfill.py +26 -0
  18. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_protocols.py +31 -13
  19. onnx_ir-0.1.1/src/onnx_ir/_tape.py +211 -0
  20. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_thirdparty/asciichartpy.py +1 -4
  21. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/_type_casting.py +18 -3
  22. onnx_ir-0.0.1/src/onnx_ir/_internal/version_utils.py → onnx_ir-0.1.1/src/onnx_ir/_version_utils.py +2 -29
  23. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/convenience.py +4 -2
  24. onnx_ir-0.1.1/src/onnx_ir/external_data.py +401 -0
  25. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/passes/__init__.py +8 -2
  26. onnx_ir-0.1.1/src/onnx_ir/passes/_pass_infra.py +289 -0
  27. onnx_ir-0.1.1/src/onnx_ir/passes/common/__init__.py +40 -0
  28. onnx_ir-0.1.1/src/onnx_ir/passes/common/_c_api_utils.py +76 -0
  29. onnx_ir-0.1.1/src/onnx_ir/passes/common/clear_metadata_and_docstring.py +60 -0
  30. onnx_ir-0.1.1/src/onnx_ir/passes/common/common_subexpression_elimination.py +177 -0
  31. onnx_ir-0.1.1/src/onnx_ir/passes/common/constant_manipulation.py +217 -0
  32. onnx_ir-0.1.1/src/onnx_ir/passes/common/inliner.py +332 -0
  33. onnx_ir-0.1.1/src/onnx_ir/passes/common/onnx_checker.py +57 -0
  34. onnx_ir-0.1.1/src/onnx_ir/passes/common/shape_inference.py +112 -0
  35. onnx_ir-0.1.1/src/onnx_ir/passes/common/topological_sort.py +33 -0
  36. onnx_ir-0.1.1/src/onnx_ir/passes/common/unused_removal.py +196 -0
  37. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/serde.py +288 -124
  38. onnx_ir-0.1.1/src/onnx_ir/tape.py +15 -0
  39. onnx_ir-0.1.1/src/onnx_ir/tensor_adapters.py +122 -0
  40. onnx_ir-0.1.1/src/onnx_ir/testing.py +197 -0
  41. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir/traversal.py +4 -3
  42. onnx_ir-0.1.1/src/onnx_ir.egg-info/PKG-INFO +53 -0
  43. onnx_ir-0.1.1/src/onnx_ir.egg-info/SOURCES.txt +46 -0
  44. onnx_ir-0.0.1/LICENSE +0 -22
  45. onnx_ir-0.0.1/PKG-INFO +0 -73
  46. onnx_ir-0.0.1/README.md +0 -25
  47. onnx_ir-0.0.1/src/onnx_ir/_enums.py +0 -154
  48. onnx_ir-0.0.1/src/onnx_ir/_external_data.py +0 -323
  49. onnx_ir-0.0.1/src/onnx_ir/_io.py +0 -50
  50. onnx_ir-0.0.1/src/onnx_ir/_tape.py +0 -104
  51. onnx_ir-0.0.1/src/onnx_ir/passes/_pass_infra.py +0 -172
  52. onnx_ir-0.0.1/src/onnx_ir.egg-info/PKG-INFO +0 -73
  53. onnx_ir-0.0.1/src/onnx_ir.egg-info/SOURCES.txt +0 -30
  54. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/MANIFEST.in +0 -0
  55. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/setup.cfg +0 -0
  56. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir.egg-info/dependency_links.txt +0 -0
  57. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir.egg-info/requires.txt +0 -0
  58. {onnx_ir-0.0.1 → onnx_ir-0.1.1}/src/onnx_ir.egg-info/top_level.txt +0 -0
onnx_ir-0.1.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
onnx_ir-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: onnx-ir
3
+ Version: 0.1.1
4
+ Summary: Efficient in-memory representation for ONNX
5
+ Author-email: ONNX Contributors <onnx-technical-discuss@lists.lfaidata.foundation>
6
+ License: Apache License v2.0
7
+ Project-URL: Homepage, https://onnx.ai/onnx-ir
8
+ Project-URL: Issues, https://github.com/onnx/onnx-ir/issues
9
+ Project-URL: Repository, https://github.com/onnx/onnx-ir
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy
21
+ Requires-Dist: onnx>=1.16
22
+ Requires-Dist: typing_extensions>=4.10
23
+ Requires-Dist: ml_dtypes
24
+ Dynamic: license-file
25
+
26
+ # ONNX IR
27
+
28
+ [![PyPI - Version](https://img.shields.io/pypi/v/onnx-ir.svg)](https://pypi.org/project/onnx-ir)
29
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/onnx-ir.svg)](https://pypi.org/project/onnx-ir)
30
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
31
+ [![codecov](https://codecov.io/gh/onnx/ir-py/graph/badge.svg?token=SPQ3G9T78Z)](https://codecov.io/gh/onnx/ir-py)
32
+ [![DeepWiki](https://img.shields.io/badge/DeepWiki-onnx%2Fir--py-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==)](https://deepwiki.com/onnx/ir-py)
33
+
34
+ An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
35
+
36
+ ## Features ✨
37
+
38
+ - Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them).
39
+ - Low memory footprint: mmap'ed external tensors; unified interface for ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size limitation. Zero copies.
40
+ - Straightforward access patterns: Access value information and traverse the graph topology at ease.
41
+ - Robust mutation: Create as many iterators as you like on the graph while mutating it.
42
+ - Speed: Performant graph manipulation, serialization/deserialization to Protobuf.
43
+ - Pythonic and familiar APIs: Classes define Pythonic apis and still map to ONNX protobuf concepts in an intuitive way.
44
+ - No protobuf dependency: The IR does not require protobuf once the model is converted to the IR representation, decoupling from the serialization format.
45
+
46
+ ## Code Organization 🗺️
47
+
48
+ - [`_protocols.py`](src/onnx_ir/_protocols.py): Interfaces defined for all entities in the IR.
49
+ - [`_core.py`](src/onnx_ir/_core.py): Implementation of the core entities in the IR, including `Model`, `Graph`, `Node`, `Value`, and others.
50
+ - [`_enums.py`](src/onnx_ir/_enums.py): Definition of the type enums that correspond to the `DataType` and `AttributeType` in `onnx.proto`.
51
+ - [`_name_authority.py`](src/onnx_ir/_name_authority.py): The authority for giving names to entities in the graph, used internally.
52
+ - [`_linked_list.py`](src/onnx_ir/_linked_list.py): The data structure as the node container in the graph that supports robust iteration and mutation. Internal.
53
+ - [`_metadata.py`](src/onnx_ir/_metadata.py): Metadata store for all entities in the IR.
@@ -0,0 +1,28 @@
1
+ # ONNX IR
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/onnx-ir.svg)](https://pypi.org/project/onnx-ir)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/onnx-ir.svg)](https://pypi.org/project/onnx-ir)
5
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
6
+ [![codecov](https://codecov.io/gh/onnx/ir-py/graph/badge.svg?token=SPQ3G9T78Z)](https://codecov.io/gh/onnx/ir-py)
7
+ [![DeepWiki](https://img.shields.io/badge/DeepWiki-onnx%2Fir--py-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==)](https://deepwiki.com/onnx/ir-py)
8
+
9
+ An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
10
+
11
+ ## Features ✨
12
+
13
+ - Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them).
14
+ - Low memory footprint: mmap'ed external tensors; unified interface for ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size limitation. Zero copies.
15
+ - Straightforward access patterns: Access value information and traverse the graph topology at ease.
16
+ - Robust mutation: Create as many iterators as you like on the graph while mutating it.
17
+ - Speed: Performant graph manipulation, serialization/deserialization to Protobuf.
18
+ - Pythonic and familiar APIs: Classes define Pythonic apis and still map to ONNX protobuf concepts in an intuitive way.
19
+ - No protobuf dependency: The IR does not require protobuf once the model is converted to the IR representation, decoupling from the serialization format.
20
+
21
+ ## Code Organization 🗺️
22
+
23
+ - [`_protocols.py`](src/onnx_ir/_protocols.py): Interfaces defined for all entities in the IR.
24
+ - [`_core.py`](src/onnx_ir/_core.py): Implementation of the core entities in the IR, including `Model`, `Graph`, `Node`, `Value`, and others.
25
+ - [`_enums.py`](src/onnx_ir/_enums.py): Definition of the type enums that correspond to the `DataType` and `AttributeType` in `onnx.proto`.
26
+ - [`_name_authority.py`](src/onnx_ir/_name_authority.py): The authority for giving names to entities in the graph, used internally.
27
+ - [`_linked_list.py`](src/onnx_ir/_linked_list.py): The data structure as the node container in the graph that supports robust iteration and mutation. Internal.
28
+ - [`_metadata.py`](src/onnx_ir/_metadata.py): Metadata store for all entities in the IR.
@@ -1,34 +1,55 @@
1
1
  [build-system]
2
- requires = ["setuptools"]
2
+ requires = ["setuptools>=70"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "onnx-ir"
7
- version = "0.0.1"
8
- authors = [{ name = "Justin Chu", email = "justinchu@microsoft.com" }]
7
+ dynamic = ["version"]
8
+ description = "Efficient in-memory representation for ONNX"
9
+ authors = [
10
+ {name = "ONNX Contributors", email = "onnx-technical-discuss@lists.lfaidata.foundation"},
11
+ ]
9
12
  readme = "README.md"
10
- requires-python = ">=3.8"
11
- license = { file = "LICENSE" }
13
+ requires-python = ">=3.9"
14
+ license = {text = "Apache License v2.0"}
12
15
  classifiers = [
13
16
  "Development Status :: 4 - Beta",
14
- "Environment :: Console",
15
- "Intended Audience :: Developers",
16
- "Operating System :: POSIX",
17
- "Operating System :: MacOS :: MacOS X",
18
- "Operating System :: Microsoft :: Windows",
19
- "Programming Language :: Python :: 3.8",
20
17
  "Programming Language :: Python :: 3.9",
21
18
  "Programming Language :: Python :: 3.10",
22
19
  "Programming Language :: Python :: 3.11",
23
20
  "Programming Language :: Python :: 3.12",
24
21
  "Programming Language :: Python :: 3.13",
25
- "License :: OSI Approved :: MIT License",
22
+ "License :: OSI Approved :: Apache Software License",
26
23
  ]
27
24
  dependencies = ["numpy", "onnx>=1.16", "typing_extensions>=4.10", "ml_dtypes"]
28
25
 
26
+ [project.urls]
27
+ Homepage = "https://onnx.ai/onnx-ir"
28
+ Issues = "https://github.com/onnx/onnx-ir/issues"
29
+ Repository = "https://github.com/onnx/onnx-ir"
30
+
31
+ [tool.setuptools.dynamic]
32
+ version = {attr = "onnx_ir.__version__"}
33
+
34
+ [tool.pytest.ini_options]
35
+ addopts = "--tb=short --color=yes"
36
+
37
+ [tool.mypy]
38
+ check_untyped_defs = true
39
+ disable_error_code = 'override,import-untyped'
40
+ disallow_any_generics = false
41
+ disallow_untyped_decorators = true
42
+ show_column_numbers = true
43
+ strict_optional = true
44
+ warn_incomplete_stub = true
45
+ warn_no_return = true
46
+ warn_redundant_casts = true
47
+ warn_unused_configs = true
48
+ warn_unused_ignores = false
49
+
29
50
  [tool.ruff]
30
51
  line-length = 95
31
- target-version = "py38"
52
+ target-version = "py39"
32
53
 
33
54
  [tool.ruff.lint]
34
55
  select = [
@@ -62,12 +83,7 @@ ignore = [
62
83
  "B9", # Opinionated bugbear rules
63
84
  "C408", # Sometimes it is preferable when we construct kwargs
64
85
  "D1", # D1 is for missing docstrings, which is not yet enforced.
65
- "D202", # D202 Too strict. "No blank lines allowed after function docstring"
66
- "D205", # D205 Too strict. "1 blank line required between summary line and description"
67
- "D212",
68
- "D400",
69
86
  "D401", # First line of docstring should be in imperative mood
70
- "D415", # D415 Not yet enforced. "First line should end with a period, question mark, or exclamation point"
71
87
  "E1", "E2", "E3", # Pycodestyle formatting rules that conflicts with the formatter
72
88
  "E501", # Line length. Not enforced because black will handle formatting
73
89
  "SIM103", # "Return the condition directly" obscures logic sometimes
@@ -88,7 +104,6 @@ ignore = [
88
104
  "SIM116", # Don't use dict lookup to replace if-else
89
105
  "TRY003", # Messages can be constructed in the exception
90
106
  ]
91
- ignore-init-module-imports = true
92
107
 
93
108
  [tool.ruff.lint.flake8-tidy-imports.banned-api]
94
109
  "pathlib".msg = "Using pathlib can impact performance. Use os.path instead"
@@ -1,14 +1,19 @@
1
- # Copyright (c) Microsoft Corporation.
2
- # Licensed under the MIT License.
1
+ # Copyright (c) ONNX Project Contributors
2
+ # SPDX-License-Identifier: Apache-2.0
3
3
  """In-memory intermediate representation for ONNX graphs."""
4
4
 
5
5
  __all__ = [
6
6
  # Modules
7
7
  "serde",
8
+ "traversal",
9
+ "convenience",
10
+ "external_data",
11
+ "tape",
8
12
  # IR classes
9
13
  "Tensor",
10
14
  "ExternalTensor",
11
15
  "StringTensor",
16
+ "LazyTensor",
12
17
  "SymbolicDim",
13
18
  "Shape",
14
19
  "TensorType",
@@ -66,19 +71,24 @@ __all__ = [
66
71
  "TensorProtoTensor",
67
72
  # Conversion functions
68
73
  "from_proto",
74
+ "from_onnx_text",
69
75
  "to_proto",
70
- # IR Tensor initializer
76
+ # Convenience constructors
71
77
  "tensor",
78
+ "node",
72
79
  # Pass infrastructure
73
80
  "passes",
74
- "traversal",
75
81
  # IO
76
82
  "load",
77
83
  "save",
84
+ # Flags
85
+ "DEBUG",
78
86
  ]
79
87
 
80
- from onnx_ir import passes, serde, traversal
81
- from onnx_ir._convenience import tensor
88
+ import types
89
+
90
+ from onnx_ir import convenience, external_data, passes, serde, tape, traversal
91
+ from onnx_ir._convenience._constructors import node, tensor
82
92
  from onnx_ir._core import (
83
93
  Attr,
84
94
  AttrFloat32,
@@ -100,6 +110,7 @@ from onnx_ir._core import (
100
110
  Graph,
101
111
  GraphView,
102
112
  Input,
113
+ LazyTensor,
103
114
  Model,
104
115
  Node,
105
116
  OptionalType,
@@ -138,17 +149,19 @@ from onnx_ir._protocols import (
138
149
  TypeProtocol,
139
150
  ValueProtocol,
140
151
  )
141
- from onnx_ir.serde import TensorProtoTensor, from_proto, to_proto
142
-
152
+ from onnx_ir.serde import TensorProtoTensor, from_onnx_text, from_proto, to_proto
143
153
 
144
- DEBUG: bool = False
154
+ DEBUG = False
145
155
 
146
156
 
147
157
  def __set_module() -> None:
148
158
  """Set the module of all functions in this module to this public module."""
149
159
  global_dict = globals()
150
160
  for name in __all__:
151
- global_dict[name].__module__ = __name__
161
+ obj = global_dict[name]
162
+ if hasattr(obj, "__module__") and not isinstance(obj, types.GenericAlias):
163
+ obj.__module__ = __name__
152
164
 
153
165
 
154
166
  __set_module()
167
+ __version__ = "0.1.1"