onnx-ir 0.0.1__py3-none-any.whl → 0.1.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/__init__.py +23 -10
- onnx_ir/{_convenience.py → _convenience/__init__.py} +40 -102
- onnx_ir/_convenience/_constructors.py +213 -0
- onnx_ir/_core.py +874 -257
- onnx_ir/_display.py +2 -2
- onnx_ir/_enums.py +107 -5
- onnx_ir/_graph_comparison.py +2 -2
- onnx_ir/_graph_containers.py +373 -0
- onnx_ir/_io.py +57 -10
- onnx_ir/_linked_list.py +15 -7
- onnx_ir/_metadata.py +4 -3
- onnx_ir/_name_authority.py +2 -2
- onnx_ir/_polyfill.py +26 -0
- onnx_ir/_protocols.py +31 -13
- onnx_ir/_tape.py +139 -32
- onnx_ir/_thirdparty/asciichartpy.py +1 -4
- onnx_ir/_type_casting.py +18 -3
- onnx_ir/{_internal/version_utils.py → _version_utils.py} +2 -29
- onnx_ir/convenience.py +4 -2
- onnx_ir/external_data.py +401 -0
- onnx_ir/passes/__init__.py +8 -2
- onnx_ir/passes/_pass_infra.py +173 -56
- onnx_ir/passes/common/__init__.py +40 -0
- onnx_ir/passes/common/_c_api_utils.py +76 -0
- onnx_ir/passes/common/clear_metadata_and_docstring.py +60 -0
- onnx_ir/passes/common/common_subexpression_elimination.py +177 -0
- onnx_ir/passes/common/constant_manipulation.py +217 -0
- onnx_ir/passes/common/inliner.py +332 -0
- onnx_ir/passes/common/onnx_checker.py +57 -0
- onnx_ir/passes/common/shape_inference.py +112 -0
- onnx_ir/passes/common/topological_sort.py +33 -0
- onnx_ir/passes/common/unused_removal.py +196 -0
- onnx_ir/serde.py +288 -124
- onnx_ir/tape.py +15 -0
- onnx_ir/tensor_adapters.py +122 -0
- onnx_ir/testing.py +197 -0
- onnx_ir/traversal.py +4 -3
- onnx_ir-0.1.1.dist-info/METADATA +53 -0
- onnx_ir-0.1.1.dist-info/RECORD +42 -0
- {onnx_ir-0.0.1.dist-info → onnx_ir-0.1.1.dist-info}/WHEEL +1 -1
- onnx_ir-0.1.1.dist-info/licenses/LICENSE +202 -0
- onnx_ir/_external_data.py +0 -323
- onnx_ir-0.0.1.dist-info/LICENSE +0 -22
- onnx_ir-0.0.1.dist-info/METADATA +0 -73
- onnx_ir-0.0.1.dist-info/RECORD +0 -26
- {onnx_ir-0.0.1.dist-info → onnx_ir-0.1.1.dist-info}/top_level.txt +0 -0
onnx_ir/_external_data.py
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Microsoft Corporation.
|
|
2
|
-
# Licensed under the MIT License.
|
|
3
|
-
"""External data related utilities."""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
__all__ = ["set_base_dir"]
|
|
8
|
-
|
|
9
|
-
import dataclasses
|
|
10
|
-
import os
|
|
11
|
-
from typing import Iterator, Sequence
|
|
12
|
-
|
|
13
|
-
from onnx_ir import _core, _enums, _protocols, traversal
|
|
14
|
-
|
|
15
|
-
# Note: If needed in future, add these as parameters to the function calls
|
|
16
|
-
# align_offset: Offset will always be page aligned and alloction granularity aligned for mmap support. This is done by padding previous tensor data with zeros keeping same length. Tensor data will be aligned if > align_threshold
|
|
17
|
-
_ALIGN_OFFSET = True
|
|
18
|
-
# align_threshold: Alignment threshold for size of data. Having a low threshold will waste file space for small initializers. Only when tensor's data is > the page_align_threshold it will be force aligned.
|
|
19
|
-
_ALIGN_THRESHOLD = 1048576 # 1MB
|
|
20
|
-
# allocation_granularity: The allocation Granularity for mmap() support. Typically 64KB for Windows & 4KB for other OSes.
|
|
21
|
-
_ALLOCATION_GRANULARITY = 65536 # 64KB
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@dataclasses.dataclass
|
|
25
|
-
class _ExternalDataInfo:
|
|
26
|
-
"""
|
|
27
|
-
A class that stores information about a tensor that is to be stored as external data.
|
|
28
|
-
|
|
29
|
-
Attributes:
|
|
30
|
-
name: The name of the tensor that is to be stored as external data.
|
|
31
|
-
offset: The offset is used to determine where exactly in the file the external data is written to.
|
|
32
|
-
length: Stores the size of the tensor.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
name: str | None
|
|
36
|
-
offset: int
|
|
37
|
-
length: int
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _all_tensors(
|
|
41
|
-
graph: _core.Graph | _core.GraphView, include_attributes: bool = False
|
|
42
|
-
) -> Iterator[_protocols.TensorProtocol]:
|
|
43
|
-
"""Iterate over all tensors in the graph.
|
|
44
|
-
|
|
45
|
-
Args:
|
|
46
|
-
graph: The graph to traverse tensors on.
|
|
47
|
-
include_attributes: Whether to include tensors in attributes.
|
|
48
|
-
|
|
49
|
-
Yields:
|
|
50
|
-
Tensors in the graph.
|
|
51
|
-
"""
|
|
52
|
-
# Yield all tensors in initializers
|
|
53
|
-
for value in graph.initializers.values():
|
|
54
|
-
if value.const_value is not None:
|
|
55
|
-
yield value.const_value
|
|
56
|
-
if not include_attributes:
|
|
57
|
-
return
|
|
58
|
-
# Look at constant attributes in nodes
|
|
59
|
-
for node in traversal.RecursiveGraphIterator(graph):
|
|
60
|
-
for attr in node.attributes.values():
|
|
61
|
-
if isinstance(attr, _core.RefAttr):
|
|
62
|
-
continue
|
|
63
|
-
if attr.type == _enums.AttributeType.TENSOR and attr.value is not None:
|
|
64
|
-
yield attr.value
|
|
65
|
-
elif attr.type == _enums.AttributeType.TENSORS and attr.value is not None:
|
|
66
|
-
yield from attr.value
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def set_base_dir(graph: _core.Graph | _core.GraphView, base_dir: str | os.PathLike) -> None:
|
|
70
|
-
"""Set the base directory for external data in a graph.
|
|
71
|
-
|
|
72
|
-
Args:
|
|
73
|
-
graph: The graph to traverse tensors on.
|
|
74
|
-
base_dir: The base directory. This is the directory where the ONNX file is.
|
|
75
|
-
"""
|
|
76
|
-
for tensor in _all_tensors(graph, include_attributes=True):
|
|
77
|
-
if isinstance(tensor, _core.ExternalTensor):
|
|
78
|
-
tensor.base_dir = base_dir
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _load_external_data_file(
|
|
82
|
-
tensors: Sequence[_protocols.TensorProtocol],
|
|
83
|
-
base_path: str | os.PathLike,
|
|
84
|
-
relative_path: str | os.PathLike,
|
|
85
|
-
) -> list[_protocols.TensorProtocol]:
|
|
86
|
-
"""Load all external data that is at relative_path into memory for the provided model.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
tensors: Tensors to be converted to external tensors. They can be external tensors themselves.
|
|
90
|
-
base_path: Path of base directory.
|
|
91
|
-
relative_path: Path to which external data is to be stored, relative to the ONNX file.
|
|
92
|
-
|
|
93
|
-
Returns:
|
|
94
|
-
A list of ir.Tensor values.
|
|
95
|
-
"""
|
|
96
|
-
updated_tensors: list[_protocols.TensorProtocol] = []
|
|
97
|
-
for tensor in tensors:
|
|
98
|
-
if isinstance(tensor, _core.ExternalTensor):
|
|
99
|
-
external_tensor = tensor
|
|
100
|
-
if os.path.samefile(tensor.path, os.path.join(base_path, relative_path)):
|
|
101
|
-
# Copy the data as the .numpy() call references data from a file whose data is eventually modified
|
|
102
|
-
tensor_data = external_tensor.numpy().copy()
|
|
103
|
-
external_tensor.release()
|
|
104
|
-
tensor = _core.Tensor(
|
|
105
|
-
tensor_data, name=external_tensor.name, dtype=external_tensor.dtype
|
|
106
|
-
)
|
|
107
|
-
updated_tensors.append(tensor)
|
|
108
|
-
return updated_tensors
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def _compute_new_offset(
|
|
112
|
-
current_offset: int,
|
|
113
|
-
tensor_size: int,
|
|
114
|
-
align_offset: bool = _ALIGN_OFFSET,
|
|
115
|
-
align_threshold: int = _ALIGN_THRESHOLD,
|
|
116
|
-
allocation_granularity: int = _ALLOCATION_GRANULARITY,
|
|
117
|
-
) -> int:
|
|
118
|
-
"""Compute the offset to align the tensor data based on the current offset.
|
|
119
|
-
|
|
120
|
-
Args:
|
|
121
|
-
current_offset: Current location in the file at which tensor data will be written to.
|
|
122
|
-
tensor_size: Size of the tensor data to be written to file.
|
|
123
|
-
align_offset: Offset will always be page aligned and alloction granularity aligned for mmap support. This is done by padding previous tensor data with zeros keeping same length. Tensor data will be aligned if > align_threshold
|
|
124
|
-
align_threshold: Alignment threshold for size of data. Having a low threshold will waste file space for small initializers. Only when tensor's data is > the page_align_threshold it will be force aligned.
|
|
125
|
-
allocation_granularity: The allocation Granularity for mmap() support. Typically 64KB for Windows & 4KB for other OSes.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
The updated offset value.
|
|
129
|
-
"""
|
|
130
|
-
if align_offset and tensor_size > align_threshold:
|
|
131
|
-
alignment_factor = max(4096, allocation_granularity)
|
|
132
|
-
# Align to the next page or alloc granularity
|
|
133
|
-
return (current_offset + alignment_factor - 1) // alignment_factor * alignment_factor
|
|
134
|
-
return current_offset
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _compute_external_data_info(
|
|
138
|
-
tensor: _protocols.TensorProtocol,
|
|
139
|
-
current_offset: int,
|
|
140
|
-
) -> _ExternalDataInfo:
|
|
141
|
-
"""Capture information about a tensor that is to be stored as external data."""
|
|
142
|
-
tensor_size = tensor.nbytes
|
|
143
|
-
# Calculate updated offset and align tensors
|
|
144
|
-
current_offset = _compute_new_offset(current_offset, tensor_size)
|
|
145
|
-
# Store offset and tensor size as ExternalDataInfo
|
|
146
|
-
external_data_info = _ExternalDataInfo(
|
|
147
|
-
tensor.name,
|
|
148
|
-
current_offset,
|
|
149
|
-
tensor_size,
|
|
150
|
-
)
|
|
151
|
-
return external_data_info
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def _save_external_data(
|
|
155
|
-
external_data_info: list[tuple[_protocols.TensorProtocol, _ExternalDataInfo]],
|
|
156
|
-
file_path: str | os.PathLike,
|
|
157
|
-
) -> None:
|
|
158
|
-
"""Write tensor data to an external file according to information stored in ExternalDataInfo objects.
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
external_data_info: A collection of external data information stored for each tensor to be written as external data.
|
|
162
|
-
file_path: Location to which external data is to be stored.
|
|
163
|
-
"""
|
|
164
|
-
with open(file_path, "wb") as data_file:
|
|
165
|
-
for tensor, tensor_info in external_data_info:
|
|
166
|
-
current_offset = tensor_info.offset
|
|
167
|
-
assert tensor is not None
|
|
168
|
-
raw_data = tensor.tobytes()
|
|
169
|
-
if isinstance(tensor, _core.ExternalTensor):
|
|
170
|
-
tensor.release()
|
|
171
|
-
# Pad file to required offset if needed
|
|
172
|
-
file_size = data_file.tell()
|
|
173
|
-
if current_offset > file_size:
|
|
174
|
-
data_file.write(b"\0" * (current_offset - file_size))
|
|
175
|
-
data_file.write(raw_data)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def _convert_as_external_tensors(
|
|
179
|
-
external_data_info: list[tuple[_protocols.TensorProtocol, _ExternalDataInfo]],
|
|
180
|
-
base_path: str | os.PathLike,
|
|
181
|
-
relative_path: str | os.PathLike,
|
|
182
|
-
) -> list[_core.ExternalTensor]:
|
|
183
|
-
"""Convert the tensors (stored within the values) written as external data to _core.ExternalTensor types.
|
|
184
|
-
|
|
185
|
-
Args:
|
|
186
|
-
external_data_info: A collection of external data information stored for each tensor to be written as external data.
|
|
187
|
-
base_path: Path of base directory.
|
|
188
|
-
relative_path: Path to which external data is to be stored, relative to the ONNX file.
|
|
189
|
-
|
|
190
|
-
Returns:
|
|
191
|
-
A list of external tensors.
|
|
192
|
-
"""
|
|
193
|
-
external_tensors: list[_core.ExternalTensor] = []
|
|
194
|
-
for tensor, tensor_info in external_data_info:
|
|
195
|
-
assert tensor is not None
|
|
196
|
-
external_tensor = _core.ExternalTensor(
|
|
197
|
-
os.path.normpath(relative_path),
|
|
198
|
-
tensor_info.offset,
|
|
199
|
-
tensor_info.length,
|
|
200
|
-
tensor.dtype, # type: ignore[arg-type]
|
|
201
|
-
shape=tensor.shape, # type: ignore[arg-type]
|
|
202
|
-
name=tensor.name, # type: ignore[arg-type]
|
|
203
|
-
base_dir=os.path.normpath(base_path),
|
|
204
|
-
)
|
|
205
|
-
external_tensors.append(external_tensor)
|
|
206
|
-
return external_tensors
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
def convert_tensors_to_external(
|
|
210
|
-
tensors: Sequence[_protocols.TensorProtocol],
|
|
211
|
-
base_path: str | os.PathLike,
|
|
212
|
-
relative_path: str | os.PathLike,
|
|
213
|
-
load_external_to_memory: bool = False,
|
|
214
|
-
) -> list[_core.ExternalTensor]:
|
|
215
|
-
"""Convert a sequence of any TensorProtocol tensors to external tensors.
|
|
216
|
-
|
|
217
|
-
Args:
|
|
218
|
-
tensors: Tensors to be converted to external tensors. They can be external tensors themselves.
|
|
219
|
-
base_path: Path of base directory.
|
|
220
|
-
relative_path: Path to which external data is to be stored, relative to the ONNX file.
|
|
221
|
-
load_external_to_memory: If set to true, loads external tensors present in the same file path as destination path to memory.
|
|
222
|
-
|
|
223
|
-
Returns:
|
|
224
|
-
A list of external tensors derived from a list of input tensors.
|
|
225
|
-
"""
|
|
226
|
-
path = os.path.join(base_path, relative_path)
|
|
227
|
-
# Check if file path is valid, and create subsequent subdirectories within the path if they don't exist
|
|
228
|
-
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
229
|
-
tmp_file_created = False
|
|
230
|
-
# Check if file exists. Load pre-existing external data if it does.
|
|
231
|
-
if os.path.exists(path):
|
|
232
|
-
# Check if any tensor in the model is using the destination file
|
|
233
|
-
file_used = False
|
|
234
|
-
for tensor in tensors:
|
|
235
|
-
if isinstance(tensor, _core.ExternalTensor) and os.path.samefile(
|
|
236
|
-
path, tensor.path
|
|
237
|
-
):
|
|
238
|
-
# FIXME(shubhambhokare1): If there is a non-initializer tensor that is referring to this file, that tensor is now invalid. This is a special case we are ok not handling right now.
|
|
239
|
-
file_used = True
|
|
240
|
-
if file_used:
|
|
241
|
-
if load_external_to_memory:
|
|
242
|
-
tensors = _load_external_data_file(tensors, base_path, relative_path)
|
|
243
|
-
else:
|
|
244
|
-
tmp_path = os.path.join(base_path, "tmp")
|
|
245
|
-
os.makedirs(tmp_path, exist_ok=True)
|
|
246
|
-
# If exisiting external tensors are not loaded to memory, copy the external data to a temporary location
|
|
247
|
-
os.rename(path, os.path.join(tmp_path, relative_path))
|
|
248
|
-
tmp_file_created = True
|
|
249
|
-
for tensor in tensors:
|
|
250
|
-
if (
|
|
251
|
-
isinstance(tensor, _core.ExternalTensor)
|
|
252
|
-
and tensor.location == relative_path
|
|
253
|
-
):
|
|
254
|
-
tensor.base_dir = tmp_path
|
|
255
|
-
|
|
256
|
-
external_data_info: list[tuple[_protocols.TensorProtocol, _ExternalDataInfo]] = []
|
|
257
|
-
# Sort all tensors based on tensor sizes, in order to avoid unneccesarry alignment.
|
|
258
|
-
# All the smaller tensors are written earlier and alignment is performed for the larger tensors.
|
|
259
|
-
sorted_indices = sorted(range(len(tensors)), key=lambda i: tensors[i].nbytes)
|
|
260
|
-
sorted_tensors = [tensors[i] for i in sorted_indices]
|
|
261
|
-
|
|
262
|
-
current_offset = 0
|
|
263
|
-
for tensor in sorted_tensors:
|
|
264
|
-
tensor_info = _compute_external_data_info(tensor, current_offset)
|
|
265
|
-
external_data_info.append((tensor, tensor_info))
|
|
266
|
-
current_offset = tensor_info.offset + tensor_info.length
|
|
267
|
-
_save_external_data(external_data_info, path)
|
|
268
|
-
|
|
269
|
-
# Convert initializers to ExternalTensors
|
|
270
|
-
external_tensors = _convert_as_external_tensors(
|
|
271
|
-
external_data_info, base_path, relative_path
|
|
272
|
-
)
|
|
273
|
-
# Sort external_tensors based on original key order
|
|
274
|
-
external_tensors = [
|
|
275
|
-
external_tensors[i]
|
|
276
|
-
for i in sorted(range(len(external_tensors)), key=lambda i: sorted_indices[i])
|
|
277
|
-
]
|
|
278
|
-
|
|
279
|
-
# Clean-up temporary file if it is created
|
|
280
|
-
tmp_path = os.path.join(base_path, "tmp", relative_path)
|
|
281
|
-
if os.path.exists(tmp_path) and tmp_file_created:
|
|
282
|
-
os.remove(tmp_path)
|
|
283
|
-
|
|
284
|
-
return external_tensors
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
def to_external_data(
|
|
288
|
-
model: _core.Model,
|
|
289
|
-
base_path: str | os.PathLike,
|
|
290
|
-
relative_path: str | os.PathLike,
|
|
291
|
-
load_external_to_memory: bool = False,
|
|
292
|
-
) -> _core.Model:
|
|
293
|
-
"""Set all tensors with raw data as external data.
|
|
294
|
-
|
|
295
|
-
Args:
|
|
296
|
-
model: Model to process.
|
|
297
|
-
base_path: Path of base directory.
|
|
298
|
-
relative_path: Path to which external data is to be stored, relative to the ONNX file.
|
|
299
|
-
load_external_to_memory: If set to true, loads external tensors present in the same file path as destination path to memory. Otherwise, the external tensors are appended to file.
|
|
300
|
-
|
|
301
|
-
Returns:
|
|
302
|
-
An ir.Model with all tensors with raw data converted to external tensors.
|
|
303
|
-
"""
|
|
304
|
-
|
|
305
|
-
# Get all the tensors in the graph which are to be stored as external data.
|
|
306
|
-
# Iterate through all the tensors, and extract the external data information such as
|
|
307
|
-
# name, offset and length.
|
|
308
|
-
# TODO: Currently attributes not handled, eventually try to use _all_tensors to include attrs
|
|
309
|
-
tensors: list[_protocols.TensorProtocol] = []
|
|
310
|
-
for value in model.graph.initializers.values():
|
|
311
|
-
if value.const_value is not None:
|
|
312
|
-
tensors.append(value.const_value)
|
|
313
|
-
|
|
314
|
-
external_tensors = convert_tensors_to_external(
|
|
315
|
-
tensors,
|
|
316
|
-
base_path,
|
|
317
|
-
relative_path,
|
|
318
|
-
load_external_to_memory=load_external_to_memory,
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
for value, external_tensor in zip(model.graph.initializers.values(), external_tensors):
|
|
322
|
-
value.const_value = external_tensor
|
|
323
|
-
return model
|
onnx_ir-0.0.1.dist-info/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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.
|
onnx_ir-0.0.1.dist-info/METADATA
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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.
|
onnx_ir-0.0.1.dist-info/RECORD
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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,,
|
|
File without changes
|