onnx-ir 0.1.1__py3-none-any.whl → 0.1.3__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 +5 -2
- onnx_ir/_convenience/__init__.py +130 -4
- onnx_ir/_convenience/_constructors.py +6 -2
- onnx_ir/_core.py +283 -39
- onnx_ir/_enums.py +37 -25
- onnx_ir/_graph_containers.py +2 -2
- onnx_ir/_io.py +40 -4
- onnx_ir/_type_casting.py +2 -1
- onnx_ir/_version_utils.py +5 -48
- onnx_ir/convenience.py +3 -1
- onnx_ir/external_data.py +43 -3
- onnx_ir/passes/_pass_infra.py +1 -1
- onnx_ir/passes/common/__init__.py +4 -0
- onnx_ir/passes/common/_c_api_utils.py +1 -1
- onnx_ir/passes/common/common_subexpression_elimination.py +104 -75
- onnx_ir/passes/common/initializer_deduplication.py +56 -0
- onnx_ir/passes/common/onnx_checker.py +1 -1
- onnx_ir/passes/common/shape_inference.py +1 -1
- onnx_ir/passes/common/unused_removal.py +1 -1
- onnx_ir/serde.py +176 -6
- onnx_ir/tensor_adapters.py +62 -7
- {onnx_ir-0.1.1.dist-info → onnx_ir-0.1.3.dist-info}/METADATA +22 -4
- onnx_ir-0.1.3.dist-info/RECORD +43 -0
- onnx_ir-0.1.1.dist-info/RECORD +0 -42
- {onnx_ir-0.1.1.dist-info → onnx_ir-0.1.3.dist-info}/WHEEL +0 -0
- {onnx_ir-0.1.1.dist-info → onnx_ir-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {onnx_ir-0.1.1.dist-info → onnx_ir-0.1.3.dist-info}/top_level.txt +0 -0
onnx_ir/serde.py
CHANGED
|
@@ -37,6 +37,7 @@ __all__ = [
|
|
|
37
37
|
"deserialize_value_info_proto",
|
|
38
38
|
# Serialization
|
|
39
39
|
"to_proto",
|
|
40
|
+
"to_onnx_text",
|
|
40
41
|
"serialize_attribute_into",
|
|
41
42
|
"serialize_attribute",
|
|
42
43
|
"serialize_dimension_into",
|
|
@@ -62,14 +63,14 @@ __all__ = [
|
|
|
62
63
|
import collections
|
|
63
64
|
import logging
|
|
64
65
|
import os
|
|
65
|
-
from collections.abc import Mapping, Sequence
|
|
66
|
+
from collections.abc import Iterable, Mapping, Sequence
|
|
66
67
|
from typing import Any, Callable
|
|
67
68
|
|
|
68
69
|
import numpy as np
|
|
69
|
-
import onnx
|
|
70
|
-
import onnx.external_data_helper
|
|
70
|
+
import onnx # noqa: TID251
|
|
71
|
+
import onnx.external_data_helper # noqa: TID251
|
|
71
72
|
|
|
72
|
-
from onnx_ir import _core, _enums, _protocols, _type_casting
|
|
73
|
+
from onnx_ir import _convenience, _core, _enums, _protocols, _type_casting
|
|
73
74
|
|
|
74
75
|
if typing.TYPE_CHECKING:
|
|
75
76
|
import google.protobuf.internal.containers as proto_containers
|
|
@@ -190,13 +191,69 @@ def from_proto(proto: object) -> object:
|
|
|
190
191
|
)
|
|
191
192
|
|
|
192
193
|
|
|
193
|
-
def from_onnx_text(
|
|
194
|
+
def from_onnx_text(
|
|
195
|
+
model_text: str,
|
|
196
|
+
/,
|
|
197
|
+
initializers: Iterable[_protocols.TensorProtocol] | None = None,
|
|
198
|
+
) -> _core.Model:
|
|
194
199
|
"""Convert the ONNX textual representation to an IR model.
|
|
195
200
|
|
|
196
201
|
Read more about the textual representation at: https://onnx.ai/onnx/repo-docs/Syntax.html
|
|
202
|
+
|
|
203
|
+
.. versionchanged:: 0.1.2
|
|
204
|
+
Added the ``initializers`` argument.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
model_text: The ONNX textual representation of the model.
|
|
208
|
+
initializers: Tensors to be added as initializers. If provided, these tensors
|
|
209
|
+
will be added to the model as initializers. If a name does not exist in the model,
|
|
210
|
+
a ValueError will be raised.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
The IR model corresponding to the ONNX textual representation.
|
|
214
|
+
|
|
215
|
+
Raises:
|
|
216
|
+
ValueError: If a tensor name in `initializers` does not match any value in the model.
|
|
197
217
|
"""
|
|
198
218
|
proto = onnx.parser.parse_model(model_text)
|
|
199
|
-
|
|
219
|
+
model = deserialize_model(proto)
|
|
220
|
+
values = _convenience.create_value_mapping(model.graph)
|
|
221
|
+
if initializers:
|
|
222
|
+
# Add initializers to the model
|
|
223
|
+
for tensor in initializers:
|
|
224
|
+
name = tensor.name
|
|
225
|
+
if not name:
|
|
226
|
+
raise ValueError(
|
|
227
|
+
"Initializer tensor must have a name. "
|
|
228
|
+
f"Please provide a name for the initializer: {tensor}"
|
|
229
|
+
)
|
|
230
|
+
if name not in values:
|
|
231
|
+
raise ValueError(f"Value '{name}' does not exist in model.")
|
|
232
|
+
initializer = values[name]
|
|
233
|
+
initializer.const_value = tensor
|
|
234
|
+
model.graph.register_initializer(initializer)
|
|
235
|
+
return model
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def to_onnx_text(
|
|
239
|
+
model: _protocols.ModelProtocol, /, exclude_initializers: bool = False
|
|
240
|
+
) -> str:
|
|
241
|
+
"""Convert the IR model to the ONNX textual representation.
|
|
242
|
+
|
|
243
|
+
.. versionadded:: 0.1.2
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
model: The IR model to convert.
|
|
247
|
+
exclude_initializers: If True, the initializers will not be included in the output.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
The ONNX textual representation of the model.
|
|
251
|
+
"""
|
|
252
|
+
proto = serialize_model(model)
|
|
253
|
+
if exclude_initializers:
|
|
254
|
+
del proto.graph.initializer[:]
|
|
255
|
+
text = onnx.printer.to_text(proto)
|
|
256
|
+
return text
|
|
200
257
|
|
|
201
258
|
|
|
202
259
|
@typing.overload
|
|
@@ -462,6 +519,14 @@ def _get_field(proto: Any, field: str) -> Any:
|
|
|
462
519
|
def deserialize_opset_import(
|
|
463
520
|
protos: Sequence[onnx.OperatorSetIdProto],
|
|
464
521
|
) -> dict[str, int]:
|
|
522
|
+
"""Deserialize a sequence of OperatorSetIdProto to opset imports mapping.
|
|
523
|
+
|
|
524
|
+
Args:
|
|
525
|
+
protos: The sequence of ONNX OperatorSetIdProto objects.
|
|
526
|
+
|
|
527
|
+
Returns:
|
|
528
|
+
A dictionary mapping domain strings to version integers.
|
|
529
|
+
"""
|
|
465
530
|
return {opset.domain: opset.version for opset in protos}
|
|
466
531
|
|
|
467
532
|
|
|
@@ -495,6 +560,14 @@ def _parse_experimental_function_value_info_name(
|
|
|
495
560
|
|
|
496
561
|
|
|
497
562
|
def deserialize_model(proto: onnx.ModelProto) -> _core.Model:
|
|
563
|
+
"""Deserialize an ONNX ModelProto into an IR Model.
|
|
564
|
+
|
|
565
|
+
Args:
|
|
566
|
+
proto: The ONNX ModelProto to deserialize.
|
|
567
|
+
|
|
568
|
+
Returns:
|
|
569
|
+
An IR Model object representing the ONNX model.
|
|
570
|
+
"""
|
|
498
571
|
graph = _deserialize_graph(proto.graph, [])
|
|
499
572
|
graph.opset_imports.update(deserialize_opset_import(proto.opset_import))
|
|
500
573
|
|
|
@@ -699,6 +772,14 @@ def _deserialize_graph(
|
|
|
699
772
|
|
|
700
773
|
@_capture_errors(lambda proto: proto.name)
|
|
701
774
|
def deserialize_function(proto: onnx.FunctionProto) -> _core.Function:
|
|
775
|
+
"""Deserialize an ONNX FunctionProto into an IR Function.
|
|
776
|
+
|
|
777
|
+
Args:
|
|
778
|
+
proto: The ONNX FunctionProto to deserialize.
|
|
779
|
+
|
|
780
|
+
Returns:
|
|
781
|
+
An IR Function object representing the ONNX function.
|
|
782
|
+
"""
|
|
702
783
|
inputs = [_core.Input(name) for name in proto.input]
|
|
703
784
|
values: dict[str, _core.Value] = {v.name: v for v in inputs} # type: ignore[misc]
|
|
704
785
|
value_info = {info.name: info for info in getattr(proto, "value_info", [])}
|
|
@@ -741,6 +822,15 @@ def deserialize_function(proto: onnx.FunctionProto) -> _core.Function:
|
|
|
741
822
|
def deserialize_value_info_proto(
|
|
742
823
|
proto: onnx.ValueInfoProto, value: _core.Value | None
|
|
743
824
|
) -> _core.Value:
|
|
825
|
+
"""Deserialize an ONNX ValueInfoProto into an IR Value.
|
|
826
|
+
|
|
827
|
+
Args:
|
|
828
|
+
proto: The ONNX ValueInfoProto to deserialize.
|
|
829
|
+
value: An existing Value to update, or None to create a new one.
|
|
830
|
+
|
|
831
|
+
Returns:
|
|
832
|
+
An IR Value object with type and shape information populated from the proto.
|
|
833
|
+
"""
|
|
744
834
|
if value is None:
|
|
745
835
|
value = _core.Value(name=proto.name)
|
|
746
836
|
value.shape = deserialize_type_proto_for_shape(proto.type)
|
|
@@ -767,6 +857,14 @@ def _deserialize_quantization_annotation(
|
|
|
767
857
|
|
|
768
858
|
@_capture_errors(str)
|
|
769
859
|
def deserialize_tensor_shape(proto: onnx.TensorShapeProto) -> _core.Shape:
|
|
860
|
+
"""Deserialize an ONNX TensorShapeProto into an IR Shape.
|
|
861
|
+
|
|
862
|
+
Args:
|
|
863
|
+
proto: The ONNX TensorShapeProto to deserialize.
|
|
864
|
+
|
|
865
|
+
Returns:
|
|
866
|
+
An IR Shape object representing the tensor shape.
|
|
867
|
+
"""
|
|
770
868
|
# This logic handles when the shape is [] as well
|
|
771
869
|
dim_protos = proto.dim
|
|
772
870
|
deserialized_dim_denotations = [
|
|
@@ -779,6 +877,14 @@ def deserialize_tensor_shape(proto: onnx.TensorShapeProto) -> _core.Shape:
|
|
|
779
877
|
|
|
780
878
|
@_capture_errors(str)
|
|
781
879
|
def deserialize_type_proto_for_shape(proto: onnx.TypeProto) -> _core.Shape | None:
|
|
880
|
+
"""Extract and deserialize shape information from an ONNX TypeProto.
|
|
881
|
+
|
|
882
|
+
Args:
|
|
883
|
+
proto: The ONNX TypeProto to extract shape from.
|
|
884
|
+
|
|
885
|
+
Returns:
|
|
886
|
+
An IR Shape object if shape information is present, None otherwise.
|
|
887
|
+
"""
|
|
782
888
|
if proto.HasField("tensor_type"):
|
|
783
889
|
if (shape_proto := _get_field(proto.tensor_type, "shape")) is None:
|
|
784
890
|
return None
|
|
@@ -806,6 +912,14 @@ def deserialize_type_proto_for_shape(proto: onnx.TypeProto) -> _core.Shape | Non
|
|
|
806
912
|
def deserialize_type_proto_for_type(
|
|
807
913
|
proto: onnx.TypeProto,
|
|
808
914
|
) -> _protocols.TypeProtocol | None:
|
|
915
|
+
"""Extract and deserialize type information from an ONNX TypeProto.
|
|
916
|
+
|
|
917
|
+
Args:
|
|
918
|
+
proto: The ONNX TypeProto to extract type from.
|
|
919
|
+
|
|
920
|
+
Returns:
|
|
921
|
+
An IR type object (TensorType, SequenceType, etc.) if type information is present, None otherwise.
|
|
922
|
+
"""
|
|
809
923
|
denotation = _get_field(proto, "denotation")
|
|
810
924
|
if proto.HasField("tensor_type"):
|
|
811
925
|
if (elem_type := _get_field(proto.tensor_type, "elem_type")) is None:
|
|
@@ -906,6 +1020,14 @@ _deserialize_string_string_maps = deserialize_metadata_props
|
|
|
906
1020
|
|
|
907
1021
|
|
|
908
1022
|
def deserialize_attribute(proto: onnx.AttributeProto) -> _core.Attr:
|
|
1023
|
+
"""Deserialize an ONNX AttributeProto into an IR Attribute.
|
|
1024
|
+
|
|
1025
|
+
Args:
|
|
1026
|
+
proto: The ONNX AttributeProto to deserialize.
|
|
1027
|
+
|
|
1028
|
+
Returns:
|
|
1029
|
+
An IR Attribute object representing the ONNX attribute.
|
|
1030
|
+
"""
|
|
909
1031
|
return _deserialize_attribute(proto, [])
|
|
910
1032
|
|
|
911
1033
|
|
|
@@ -979,6 +1101,14 @@ def _deserialize_attribute(
|
|
|
979
1101
|
|
|
980
1102
|
|
|
981
1103
|
def deserialize_node(proto: onnx.NodeProto) -> _core.Node:
|
|
1104
|
+
"""Deserialize an ONNX NodeProto into an IR Node.
|
|
1105
|
+
|
|
1106
|
+
Args:
|
|
1107
|
+
proto: The ONNX NodeProto to deserialize.
|
|
1108
|
+
|
|
1109
|
+
Returns:
|
|
1110
|
+
An IR Node object representing the ONNX node.
|
|
1111
|
+
"""
|
|
982
1112
|
return _deserialize_node(
|
|
983
1113
|
proto, scoped_values=[{}], value_info={}, quantization_annotations={}
|
|
984
1114
|
)
|
|
@@ -1097,6 +1227,14 @@ def _deserialize_node(
|
|
|
1097
1227
|
|
|
1098
1228
|
|
|
1099
1229
|
def serialize_model(model: _protocols.ModelProtocol) -> onnx.ModelProto:
|
|
1230
|
+
"""Serialize an IR Model to an ONNX ModelProto.
|
|
1231
|
+
|
|
1232
|
+
Args:
|
|
1233
|
+
model: The IR Model to serialize.
|
|
1234
|
+
|
|
1235
|
+
Returns:
|
|
1236
|
+
The serialized ONNX ModelProto object.
|
|
1237
|
+
"""
|
|
1100
1238
|
return serialize_model_into(onnx.ModelProto(), from_=model)
|
|
1101
1239
|
|
|
1102
1240
|
|
|
@@ -1418,6 +1556,14 @@ def serialize_function_into(
|
|
|
1418
1556
|
|
|
1419
1557
|
|
|
1420
1558
|
def serialize_node(node: _protocols.NodeProtocol) -> onnx.NodeProto:
|
|
1559
|
+
"""Serialize an IR Node to an ONNX NodeProto.
|
|
1560
|
+
|
|
1561
|
+
Args:
|
|
1562
|
+
node: The IR Node to serialize.
|
|
1563
|
+
|
|
1564
|
+
Returns:
|
|
1565
|
+
The serialized ONNX NodeProto object.
|
|
1566
|
+
"""
|
|
1421
1567
|
node_proto = onnx.NodeProto()
|
|
1422
1568
|
serialize_node_into(node_proto, from_=node)
|
|
1423
1569
|
return node_proto
|
|
@@ -1472,6 +1618,14 @@ def serialize_node_into(node_proto: onnx.NodeProto, from_: _protocols.NodeProtoc
|
|
|
1472
1618
|
|
|
1473
1619
|
|
|
1474
1620
|
def serialize_tensor(tensor: _protocols.TensorProtocol) -> onnx.TensorProto:
|
|
1621
|
+
"""Serialize an IR Tensor to an ONNX TensorProto.
|
|
1622
|
+
|
|
1623
|
+
Args:
|
|
1624
|
+
tensor: The IR Tensor to serialize.
|
|
1625
|
+
|
|
1626
|
+
Returns:
|
|
1627
|
+
The serialized ONNX TensorProto object.
|
|
1628
|
+
"""
|
|
1475
1629
|
tensor_proto = onnx.TensorProto()
|
|
1476
1630
|
serialize_tensor_into(tensor_proto, from_=tensor)
|
|
1477
1631
|
return tensor_proto
|
|
@@ -1514,6 +1668,14 @@ def serialize_tensor_into(
|
|
|
1514
1668
|
|
|
1515
1669
|
|
|
1516
1670
|
def serialize_attribute(attribute: _protocols.AttributeProtocol) -> onnx.AttributeProto:
|
|
1671
|
+
"""Serialize an IR Attribute to an ONNX AttributeProto.
|
|
1672
|
+
|
|
1673
|
+
Args:
|
|
1674
|
+
attribute: The IR Attribute to serialize.
|
|
1675
|
+
|
|
1676
|
+
Returns:
|
|
1677
|
+
The serialized ONNX AttributeProto object.
|
|
1678
|
+
"""
|
|
1517
1679
|
attribute_proto = onnx.AttributeProto()
|
|
1518
1680
|
serialize_attribute_into(attribute_proto, from_=attribute)
|
|
1519
1681
|
return attribute_proto
|
|
@@ -1678,6 +1840,14 @@ def serialize_type_into(type_proto: onnx.TypeProto, from_: _protocols.TypeProtoc
|
|
|
1678
1840
|
|
|
1679
1841
|
|
|
1680
1842
|
def serialize_type(type_protocol: _protocols.TypeProtocol) -> onnx.TypeProto:
|
|
1843
|
+
"""Serialize an IR Type to an ONNX TypeProto.
|
|
1844
|
+
|
|
1845
|
+
Args:
|
|
1846
|
+
type_protocol: The IR Type to serialize.
|
|
1847
|
+
|
|
1848
|
+
Returns:
|
|
1849
|
+
The serialized ONNX TypeProto object.
|
|
1850
|
+
"""
|
|
1681
1851
|
type_proto = onnx.TypeProto()
|
|
1682
1852
|
serialize_type_into(type_proto, from_=type_protocol)
|
|
1683
1853
|
return type_proto
|
onnx_ir/tensor_adapters.py
CHANGED
|
@@ -29,6 +29,8 @@ Example::
|
|
|
29
29
|
from __future__ import annotations
|
|
30
30
|
|
|
31
31
|
__all__ = [
|
|
32
|
+
"from_torch_dtype",
|
|
33
|
+
"to_torch_dtype",
|
|
32
34
|
"TorchTensor",
|
|
33
35
|
]
|
|
34
36
|
|
|
@@ -44,14 +46,17 @@ if TYPE_CHECKING:
|
|
|
44
46
|
import torch
|
|
45
47
|
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
_TORCH_DTYPE_TO_ONNX: dict[torch.dtype, ir.DataType] | None = None
|
|
50
|
+
_ONNX_DTYPE_TO_TORCH: dict[ir.DataType, torch.dtype] | None = None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def from_torch_dtype(dtype: torch.dtype) -> ir.DataType:
|
|
54
|
+
"""Convert a PyTorch dtype to an ONNX IR DataType."""
|
|
55
|
+
global _TORCH_DTYPE_TO_ONNX
|
|
56
|
+
if _TORCH_DTYPE_TO_ONNX is None:
|
|
52
57
|
import torch
|
|
53
58
|
|
|
54
|
-
_TORCH_DTYPE_TO_ONNX
|
|
59
|
+
_TORCH_DTYPE_TO_ONNX = {
|
|
55
60
|
torch.bfloat16: ir.DataType.BFLOAT16,
|
|
56
61
|
torch.bool: ir.DataType.BOOL,
|
|
57
62
|
torch.complex128: ir.DataType.COMPLEX128,
|
|
@@ -72,8 +77,58 @@ class TorchTensor(_core.Tensor):
|
|
|
72
77
|
torch.uint32: ir.DataType.UINT32,
|
|
73
78
|
torch.uint64: ir.DataType.UINT64,
|
|
74
79
|
}
|
|
80
|
+
if dtype not in _TORCH_DTYPE_TO_ONNX:
|
|
81
|
+
raise TypeError(
|
|
82
|
+
f"Unsupported PyTorch dtype '{dtype}'. "
|
|
83
|
+
"Please use a supported dtype from the list: "
|
|
84
|
+
f"{list(_TORCH_DTYPE_TO_ONNX.keys())}"
|
|
85
|
+
)
|
|
86
|
+
return _TORCH_DTYPE_TO_ONNX[dtype]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def to_torch_dtype(dtype: ir.DataType) -> torch.dtype:
|
|
90
|
+
"""Convert an ONNX IR DataType to a PyTorch dtype."""
|
|
91
|
+
global _ONNX_DTYPE_TO_TORCH
|
|
92
|
+
if _ONNX_DTYPE_TO_TORCH is None:
|
|
93
|
+
import torch
|
|
94
|
+
|
|
95
|
+
_ONNX_DTYPE_TO_TORCH = {
|
|
96
|
+
ir.DataType.BFLOAT16: torch.bfloat16,
|
|
97
|
+
ir.DataType.BOOL: torch.bool,
|
|
98
|
+
ir.DataType.COMPLEX128: torch.complex128,
|
|
99
|
+
ir.DataType.COMPLEX64: torch.complex64,
|
|
100
|
+
ir.DataType.FLOAT16: torch.float16,
|
|
101
|
+
ir.DataType.FLOAT: torch.float32,
|
|
102
|
+
ir.DataType.DOUBLE: torch.float64,
|
|
103
|
+
ir.DataType.FLOAT8E4M3FN: torch.float8_e4m3fn,
|
|
104
|
+
ir.DataType.FLOAT8E4M3FNUZ: torch.float8_e4m3fnuz,
|
|
105
|
+
ir.DataType.FLOAT8E5M2: torch.float8_e5m2,
|
|
106
|
+
ir.DataType.FLOAT8E5M2FNUZ: torch.float8_e5m2fnuz,
|
|
107
|
+
ir.DataType.INT16: torch.int16,
|
|
108
|
+
ir.DataType.INT32: torch.int32,
|
|
109
|
+
ir.DataType.INT64: torch.int64,
|
|
110
|
+
ir.DataType.INT8: torch.int8,
|
|
111
|
+
ir.DataType.UINT8: torch.uint8,
|
|
112
|
+
ir.DataType.UINT16: torch.uint16,
|
|
113
|
+
ir.DataType.UINT32: torch.uint32,
|
|
114
|
+
ir.DataType.UINT64: torch.uint64,
|
|
115
|
+
}
|
|
116
|
+
if dtype not in _ONNX_DTYPE_TO_TORCH:
|
|
117
|
+
raise TypeError(
|
|
118
|
+
f"Unsupported conversion from ONNX dtype '{dtype}' to torch. "
|
|
119
|
+
"Please use a supported dtype from the list: "
|
|
120
|
+
f"{list(_ONNX_DTYPE_TO_TORCH.keys())}"
|
|
121
|
+
)
|
|
122
|
+
return _ONNX_DTYPE_TO_TORCH[dtype]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class TorchTensor(_core.Tensor):
|
|
126
|
+
def __init__(
|
|
127
|
+
self, tensor: torch.Tensor, name: str | None = None, doc_string: str | None = None
|
|
128
|
+
):
|
|
129
|
+
# Pass the tensor as the raw data to ir.Tensor's constructor
|
|
75
130
|
super().__init__(
|
|
76
|
-
tensor, dtype=
|
|
131
|
+
tensor, dtype=from_torch_dtype(tensor.dtype), name=name, doc_string=doc_string
|
|
77
132
|
)
|
|
78
133
|
|
|
79
134
|
def numpy(self) -> npt.NDArray:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: onnx-ir
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Efficient in-memory representation for ONNX
|
|
5
5
|
Author-email: ONNX Contributors <onnx-technical-discuss@lists.lfaidata.foundation>
|
|
6
6
|
License: Apache License v2.0
|
|
7
|
-
Project-URL: Homepage, https://onnx.ai/
|
|
8
|
-
Project-URL: Issues, https://github.com/onnx/
|
|
9
|
-
Project-URL: Repository, https://github.com/onnx/
|
|
7
|
+
Project-URL: Homepage, https://onnx.ai/ir-py
|
|
8
|
+
Project-URL: Issues, https://github.com/onnx/ir-py/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/onnx/ir-py
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -33,6 +33,24 @@ Dynamic: license-file
|
|
|
33
33
|
|
|
34
34
|
An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
|
|
35
35
|
|
|
36
|
+
## Getting Started
|
|
37
|
+
|
|
38
|
+
[onnx-ir documentation](https://onnx.ai/ir-py/)
|
|
39
|
+
|
|
40
|
+
### Installation
|
|
41
|
+
|
|
42
|
+
Via pip:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
pip install onnx-ir
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or from source:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
pip install git+https://github.com/onnx/ir-py.git
|
|
52
|
+
```
|
|
53
|
+
|
|
36
54
|
## Features ✨
|
|
37
55
|
|
|
38
56
|
- Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
onnx_ir/__init__.py,sha256=5KP1Ngl2qyWiqb5S0Ol5owYsbU0geo4LFwGwN8EXTIk,3424
|
|
2
|
+
onnx_ir/_core.py,sha256=-9BpVTZHuHQ9jsms33wqu4NjMEaDF_M57sIuVxYcM1I,137964
|
|
3
|
+
onnx_ir/_display.py,sha256=230bMN_hVy47Ug3HkA4o5Tf5Hr21AnBEoq5w0fxjyTs,1300
|
|
4
|
+
onnx_ir/_enums.py,sha256=4lmm_DFKEtz6PqNw6gt6GcqrBYHisctgKMsUbQCm5N8,8252
|
|
5
|
+
onnx_ir/_graph_comparison.py,sha256=8_D1gu547eCDotEUqxfIJhUGU_Ufhfji7sfsSraOj3g,727
|
|
6
|
+
onnx_ir/_graph_containers.py,sha256=PRKrshRZ5rzWCgRs1TefzJq9n8wyo7OqeKy3XxMhyys,14265
|
|
7
|
+
onnx_ir/_io.py,sha256=GWwA4XOZ-ZX1cgibgaYD0K0O5d9LX21ZwcBN02Wrh04,5205
|
|
8
|
+
onnx_ir/_linked_list.py,sha256=PXVcbHLMXHLZ6DxZnElnJLWfhBPvYcXUxM8Y3K4J7lM,10592
|
|
9
|
+
onnx_ir/_metadata.py,sha256=lzmCaYy4kAJrPW-PSGKF4a78LisxF0hiofySNQ3Mwhg,1544
|
|
10
|
+
onnx_ir/_name_authority.py,sha256=PnoV9TRgMLussZNufWavJXosDWx5avPfldVjMWEEz18,3036
|
|
11
|
+
onnx_ir/_polyfill.py,sha256=LzAGBKQbVDlURC0tgQgaxgkYU4rESgCYnqVs-u-Vsx8,887
|
|
12
|
+
onnx_ir/_protocols.py,sha256=M29sIOAvtdlis3QtBvCQPH4pnvSwhJCQNCvs3IrN9FY,21276
|
|
13
|
+
onnx_ir/_tape.py,sha256=nEGY6VZVKuB8FDyXeYr0MTq8j7E4HKOE2yN8qpz4ia0,7007
|
|
14
|
+
onnx_ir/_type_casting.py,sha256=8iZDVrNAx_FwRVt48G4tkzIOFu3I6AsETpH3fdxcyEI,3387
|
|
15
|
+
onnx_ir/_version_utils.py,sha256=bZThuE7meVHFOY1DLsmss9WshVIp9iig7udGfDbVaK4,1333
|
|
16
|
+
onnx_ir/convenience.py,sha256=0B1epuXZCSmY4FbW2vaYfR-t5ubxBZ1UruiytHs-zFw,917
|
|
17
|
+
onnx_ir/external_data.py,sha256=rXHtRU-9tjAt10Iervhr5lsI6Dtv-EhR7J4brxppImA,18079
|
|
18
|
+
onnx_ir/serde.py,sha256=YkbYfQMwn0YAzTd3tVDSWJ-NBiSVsG-74T6xk3e5iTU,75073
|
|
19
|
+
onnx_ir/tape.py,sha256=4FyfAHmVhQoMsfHMYnBwP2azi6UF6b6pj--ercObqZs,350
|
|
20
|
+
onnx_ir/tensor_adapters.py,sha256=dXuapwfFcpLhjKC6AOqCXbtY3WvDaEHoCNPwjnUK7_o,6565
|
|
21
|
+
onnx_ir/testing.py,sha256=WTrjf2joWizDWaYMJlV1KjZMQw7YmZ8NvuBTVn1uY6s,8803
|
|
22
|
+
onnx_ir/traversal.py,sha256=Z69wzYBNljn1S7PhVTYgwMftrfsdEBLoa0JYteOhLL0,2863
|
|
23
|
+
onnx_ir/_convenience/__init__.py,sha256=DQ-Bz1wTiZJEARCFxDqZvYexWviGmwvDzE_1hR-vp0Q,19182
|
|
24
|
+
onnx_ir/_convenience/_constructors.py,sha256=5GhlYy_xCE2ng7l_4cNx06WQsNDyvS-0U1HgOpPKJEk,8347
|
|
25
|
+
onnx_ir/_thirdparty/asciichartpy.py,sha256=afQ0fsqko2uYRPAR4TZBrQxvCb4eN8lxZ2yDFbVQq_s,10533
|
|
26
|
+
onnx_ir/passes/__init__.py,sha256=M_Tcl_-qGSNPluFIvOoeDyh0qAwNayaYyXDS5UJUJPQ,764
|
|
27
|
+
onnx_ir/passes/_pass_infra.py,sha256=xIOw_zZIuOqD4Z_wZ4OvsqXfh2IZMoMlDp1xQ_MPQlc,9567
|
|
28
|
+
onnx_ir/passes/common/__init__.py,sha256=GrrscfBekrIjxrYusgvTgP80OrgY1GMJwZMInRQmcL4,1467
|
|
29
|
+
onnx_ir/passes/common/_c_api_utils.py,sha256=g6riA6xNGVWaO5YjVHZ0krrfslWHmRlryRkwB8X56cg,2907
|
|
30
|
+
onnx_ir/passes/common/clear_metadata_and_docstring.py,sha256=YwouLfsNFSaTuGd7uMOGjdvVwG9yHQTkSphUgDlM0ME,2365
|
|
31
|
+
onnx_ir/passes/common/common_subexpression_elimination.py,sha256=wZ1zEPdCshYB_ifP9fCAVfzQkesE6uhCfzCuL2qO5fA,7948
|
|
32
|
+
onnx_ir/passes/common/constant_manipulation.py,sha256=_fGDwn0Axl2Q8APfc2m_mLMH28T-Mc9kIlpzBXoe3q4,8779
|
|
33
|
+
onnx_ir/passes/common/initializer_deduplication.py,sha256=4CIVFYfdXUlmF2sAx560c_pTwYVXtX5hcSwWzUKm5uc,2061
|
|
34
|
+
onnx_ir/passes/common/inliner.py,sha256=wBoO6yXt6F1AObQjYZHMQ0wn3YH681N4HQQVyaMAYd4,13702
|
|
35
|
+
onnx_ir/passes/common/onnx_checker.py,sha256=_sPmJ2ff9pDB1g9q7082BL6fyubomRaj6svE0cCyDew,1691
|
|
36
|
+
onnx_ir/passes/common/shape_inference.py,sha256=LVdvxjeKtcIEbPcb6mKisxoPJOOawzsm3tzk5j9xqeM,3992
|
|
37
|
+
onnx_ir/passes/common/topological_sort.py,sha256=Vcu1YhBdfRX4LROr0NScjB1Pwz2DjBFD0Z_GxqaxPF8,999
|
|
38
|
+
onnx_ir/passes/common/unused_removal.py,sha256=cBNqaqGnUVyCWxsD7hBzYk4qSglVPo3SmHAvkUo5-Oc,7613
|
|
39
|
+
onnx_ir-0.1.3.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
40
|
+
onnx_ir-0.1.3.dist-info/METADATA,sha256=vKG8o_nAUJfjM05rahv0g-FCeHkHXIwCAcuYzSY6PH8,4782
|
|
41
|
+
onnx_ir-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
42
|
+
onnx_ir-0.1.3.dist-info/top_level.txt,sha256=W5tROO93YjO0XRxIdjMy4wocp-5st5GiI2ukvW7UhDo,8
|
|
43
|
+
onnx_ir-0.1.3.dist-info/RECORD,,
|
onnx_ir-0.1.1.dist-info/RECORD
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
onnx_ir/__init__.py,sha256=0fD02tkU7-bC9BfPS68TP2500619oJ8NZyGx3CdGmVk,3352
|
|
2
|
-
onnx_ir/_core.py,sha256=7nufz-9r8J3d6R4BzmRKq0DwmWosOZp3ICNr9MfMG0E,128316
|
|
3
|
-
onnx_ir/_display.py,sha256=230bMN_hVy47Ug3HkA4o5Tf5Hr21AnBEoq5w0fxjyTs,1300
|
|
4
|
-
onnx_ir/_enums.py,sha256=zMvRvYyxOg0Rf3DCQ5Sn1TyZ5znj4NuGO-OAOKZCiDM,7880
|
|
5
|
-
onnx_ir/_graph_comparison.py,sha256=8_D1gu547eCDotEUqxfIJhUGU_Ufhfji7sfsSraOj3g,727
|
|
6
|
-
onnx_ir/_graph_containers.py,sha256=hK3R3OrQTMXF8_z9Kx1DBtJriq_NQx8MUAFy7GpTZ2U,14154
|
|
7
|
-
onnx_ir/_io.py,sha256=XmVqvM2lyX7QtXGr0KcV4bboRGTOPJ8BP4YtQ-jh4dg,3886
|
|
8
|
-
onnx_ir/_linked_list.py,sha256=PXVcbHLMXHLZ6DxZnElnJLWfhBPvYcXUxM8Y3K4J7lM,10592
|
|
9
|
-
onnx_ir/_metadata.py,sha256=lzmCaYy4kAJrPW-PSGKF4a78LisxF0hiofySNQ3Mwhg,1544
|
|
10
|
-
onnx_ir/_name_authority.py,sha256=PnoV9TRgMLussZNufWavJXosDWx5avPfldVjMWEEz18,3036
|
|
11
|
-
onnx_ir/_polyfill.py,sha256=LzAGBKQbVDlURC0tgQgaxgkYU4rESgCYnqVs-u-Vsx8,887
|
|
12
|
-
onnx_ir/_protocols.py,sha256=M29sIOAvtdlis3QtBvCQPH4pnvSwhJCQNCvs3IrN9FY,21276
|
|
13
|
-
onnx_ir/_tape.py,sha256=nEGY6VZVKuB8FDyXeYr0MTq8j7E4HKOE2yN8qpz4ia0,7007
|
|
14
|
-
onnx_ir/_type_casting.py,sha256=evx6P4A0lI_V68SfKLqTN8pH7Q8GZb0So5wvf1eKCNw,3315
|
|
15
|
-
onnx_ir/_version_utils.py,sha256=A51xvGq4I81vV4VuvDx7zc4Xe0XPSp0CTjsh_M7yX4A,2669
|
|
16
|
-
onnx_ir/convenience.py,sha256=48mqMeva9Sb39P_9IUOud8V1Zc79wZUNcQEuMv-fT-Y,871
|
|
17
|
-
onnx_ir/external_data.py,sha256=Aul9O5j7zNCayFP77sMHUU-FrUnwK9BL7mXm8wJmgHY,16511
|
|
18
|
-
onnx_ir/serde.py,sha256=xtMaSdOW_JfSkvM_cdYzVx1By6Z-R9NVsVEZNECIvL8,70131
|
|
19
|
-
onnx_ir/tape.py,sha256=4FyfAHmVhQoMsfHMYnBwP2azi6UF6b6pj--ercObqZs,350
|
|
20
|
-
onnx_ir/tensor_adapters.py,sha256=J2z0gxkxwZqBrob1pYT53lgz1XQ1r7kCxhoSZa5NHaQ,4469
|
|
21
|
-
onnx_ir/testing.py,sha256=WTrjf2joWizDWaYMJlV1KjZMQw7YmZ8NvuBTVn1uY6s,8803
|
|
22
|
-
onnx_ir/traversal.py,sha256=Z69wzYBNljn1S7PhVTYgwMftrfsdEBLoa0JYteOhLL0,2863
|
|
23
|
-
onnx_ir/_convenience/__init__.py,sha256=szllgzSyKafBsmrTFRazkxURjUYVjIEzwQRA593uSo4,14389
|
|
24
|
-
onnx_ir/_convenience/_constructors.py,sha256=nA0tytizoFhQeN6gpxVx3khJQXq-tRtIh0UBM0CdTOg,8174
|
|
25
|
-
onnx_ir/_thirdparty/asciichartpy.py,sha256=afQ0fsqko2uYRPAR4TZBrQxvCb4eN8lxZ2yDFbVQq_s,10533
|
|
26
|
-
onnx_ir/passes/__init__.py,sha256=M_Tcl_-qGSNPluFIvOoeDyh0qAwNayaYyXDS5UJUJPQ,764
|
|
27
|
-
onnx_ir/passes/_pass_infra.py,sha256=HEzxDbXjIUPVubv4pxsPTFXiCDPoiM_tPEoEH1mHO70,9560
|
|
28
|
-
onnx_ir/passes/common/__init__.py,sha256=aHjx2y7L7LJChixmKsSUCdiaTP1u-zSmcmEISduqeG4,1335
|
|
29
|
-
onnx_ir/passes/common/_c_api_utils.py,sha256=cr0vOhnZ-0lOcZV_mOS3Gn-cUK73CPzjAjfbYA-PJuQ,2891
|
|
30
|
-
onnx_ir/passes/common/clear_metadata_and_docstring.py,sha256=YwouLfsNFSaTuGd7uMOGjdvVwG9yHQTkSphUgDlM0ME,2365
|
|
31
|
-
onnx_ir/passes/common/common_subexpression_elimination.py,sha256=WMsTAI-12A3iVqptmWw0tiBmGwVKsls5VNxZEbjvp2A,6527
|
|
32
|
-
onnx_ir/passes/common/constant_manipulation.py,sha256=_fGDwn0Axl2Q8APfc2m_mLMH28T-Mc9kIlpzBXoe3q4,8779
|
|
33
|
-
onnx_ir/passes/common/inliner.py,sha256=wBoO6yXt6F1AObQjYZHMQ0wn3YH681N4HQQVyaMAYd4,13702
|
|
34
|
-
onnx_ir/passes/common/onnx_checker.py,sha256=4RdWgleYHs36pRRiUCbojkBrw80b1LX88xmj5NLclMg,1675
|
|
35
|
-
onnx_ir/passes/common/shape_inference.py,sha256=J5VWsLbx9dPwV1JTuaRBObliiVHEb978AxHq_9dOGII,3976
|
|
36
|
-
onnx_ir/passes/common/topological_sort.py,sha256=Vcu1YhBdfRX4LROr0NScjB1Pwz2DjBFD0Z_GxqaxPF8,999
|
|
37
|
-
onnx_ir/passes/common/unused_removal.py,sha256=n1Vr8kSv3HGZyxFin_Kyx79GasfmhlQRVdJ0hGeZnv0,7597
|
|
38
|
-
onnx_ir-0.1.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
39
|
-
onnx_ir-0.1.1.dist-info/METADATA,sha256=W3i284mv7QuWNNkjRy7x_zHEsMwgUpXvmoux6VE0vZQ,4586
|
|
40
|
-
onnx_ir-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
41
|
-
onnx_ir-0.1.1.dist-info/top_level.txt,sha256=W5tROO93YjO0XRxIdjMy4wocp-5st5GiI2ukvW7UhDo,8
|
|
42
|
-
onnx_ir-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|