onnxscript 0.1.0__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.
- onnxscript/__init__.py +131 -0
- onnxscript/_framework_apis/__init__.py +3 -0
- onnxscript/_framework_apis/torch_2_5.py +117 -0
- onnxscript/_framework_apis/torch_2_6.py +45 -0
- onnxscript/_internal/__init__.py +0 -0
- onnxscript/_internal/analysis.py +229 -0
- onnxscript/_internal/ast_utils.py +64 -0
- onnxscript/_internal/autocast.py +250 -0
- onnxscript/_internal/deprecation.py +78 -0
- onnxscript/_internal/param_manipulation.py +148 -0
- onnxscript/_internal/runtime_typing.py +43 -0
- onnxscript/_internal/utils.py +99 -0
- onnxscript/_internal/version_utils.py +118 -0
- onnxscript/_legacy_ir/__init__.py +341 -0
- onnxscript/_legacy_ir/visitor.py +937 -0
- onnxscript/_thirdparty/asciichartpy.py +313 -0
- onnxscript/backend/__init__.py +2 -0
- onnxscript/backend/onnx_backend.py +303 -0
- onnxscript/backend/onnx_export.py +885 -0
- onnxscript/converter.py +1470 -0
- onnxscript/evaluator.py +619 -0
- onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py +403 -0
- onnxscript/function_libs/tools/torch_lib/generate_aten_signatures.py +333 -0
- onnxscript/function_libs/tools/torch_lib/generate_prims_signatures.py +331 -0
- onnxscript/function_libs/torch_lib/__init__.py +12 -0
- onnxscript/function_libs/torch_lib/_constants.py +5 -0
- onnxscript/function_libs/torch_lib/_flags.py +58 -0
- onnxscript/function_libs/torch_lib/graph_building/__init__.py +56 -0
- onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py +723 -0
- onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py +1125 -0
- onnxscript/function_libs/torch_lib/ops/__init__.py +27 -0
- onnxscript/function_libs/torch_lib/ops/common.py +80 -0
- onnxscript/function_libs/torch_lib/ops/core.py +8935 -0
- onnxscript/function_libs/torch_lib/ops/fft.py +385 -0
- onnxscript/function_libs/torch_lib/ops/linalg.py +399 -0
- onnxscript/function_libs/torch_lib/ops/nested.py +25 -0
- onnxscript/function_libs/torch_lib/ops/nn.py +2713 -0
- onnxscript/function_libs/torch_lib/ops/prims.py +850 -0
- onnxscript/function_libs/torch_lib/ops/quantized_decomposed.py +63 -0
- onnxscript/function_libs/torch_lib/ops/sparse.py +23 -0
- onnxscript/function_libs/torch_lib/ops/special.py +387 -0
- onnxscript/function_libs/torch_lib/ops/vision.py +25 -0
- onnxscript/function_libs/torch_lib/registration.py +151 -0
- onnxscript/function_libs/torch_lib/tensor_typing.py +74 -0
- onnxscript/ir/__init__.py +153 -0
- onnxscript/ir/_convenience.py +447 -0
- onnxscript/ir/_core.py +3119 -0
- onnxscript/ir/_display.py +49 -0
- onnxscript/ir/_enums.py +163 -0
- onnxscript/ir/_graph_comparison.py +23 -0
- onnxscript/ir/_io.py +97 -0
- onnxscript/ir/_linked_list.py +276 -0
- onnxscript/ir/_metadata.py +44 -0
- onnxscript/ir/_name_authority.py +72 -0
- onnxscript/ir/_polyfill.py +25 -0
- onnxscript/ir/_protocols.py +598 -0
- onnxscript/ir/_schemas.py +548 -0
- onnxscript/ir/_tape.py +120 -0
- onnxscript/ir/_type_casting.py +106 -0
- onnxscript/ir/convenience.py +32 -0
- onnxscript/ir/external_data.py +396 -0
- onnxscript/ir/passes/__init__.py +33 -0
- onnxscript/ir/passes/_pass_infra.py +172 -0
- onnxscript/ir/serde.py +1620 -0
- onnxscript/ir/tensor_adapters.py +122 -0
- onnxscript/ir/traversal.py +82 -0
- onnxscript/irbuilder.py +542 -0
- onnxscript/main.py +167 -0
- onnxscript/onnx_opset/__init__.py +232 -0
- onnxscript/onnx_opset/_impl/opset1.py +4100 -0
- onnxscript/onnx_opset/_impl/opset10.py +1227 -0
- onnxscript/onnx_opset/_impl/opset11.py +4013 -0
- onnxscript/onnx_opset/_impl/opset12.py +1078 -0
- onnxscript/onnx_opset/_impl/opset13.py +3924 -0
- onnxscript/onnx_opset/_impl/opset14.py +999 -0
- onnxscript/onnx_opset/_impl/opset15.py +604 -0
- onnxscript/onnx_opset/_impl/opset16.py +1255 -0
- onnxscript/onnx_opset/_impl/opset17.py +561 -0
- onnxscript/onnx_opset/_impl/opset18.py +1803 -0
- onnxscript/onnx_opset/_impl/opset19.py +1942 -0
- onnxscript/onnx_opset/_impl/opset2.py +218 -0
- onnxscript/onnx_opset/_impl/opset20.py +675 -0
- onnxscript/onnx_opset/_impl/opset21.py +1976 -0
- onnxscript/onnx_opset/_impl/opset22.py +2588 -0
- onnxscript/onnx_opset/_impl/opset3.py +199 -0
- onnxscript/onnx_opset/_impl/opset4.py +77 -0
- onnxscript/onnx_opset/_impl/opset5.py +84 -0
- onnxscript/onnx_opset/_impl/opset6.py +944 -0
- onnxscript/onnx_opset/_impl/opset7.py +1243 -0
- onnxscript/onnx_opset/_impl/opset8.py +444 -0
- onnxscript/onnx_opset/_impl/opset9.py +1485 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_ml1.py +974 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_ml2.py +112 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_ml3.py +308 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_ml4.py +129 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_ml5.py +158 -0
- onnxscript/onnx_opset/_impl/opset_ai_onnx_preview_training1.py +577 -0
- onnxscript/onnx_types.py +229 -0
- onnxscript/optimizer/__init__.py +39 -0
- onnxscript/optimizer/_constant_folding.py +1083 -0
- onnxscript/optimizer/_inliner.py +312 -0
- onnxscript/optimizer/_legacy/_optimizer.py +98 -0
- onnxscript/optimizer/_legacy/_remove_unused_proto.py +144 -0
- onnxscript/optimizer/_legacy/_simple_function_folding.py +243 -0
- onnxscript/optimizer/_legacy/constant_folding.py +293 -0
- onnxscript/optimizer/_legacy/evaluator.py +439 -0
- onnxscript/optimizer/_optimizer.py +61 -0
- onnxscript/optimizer/_remove_unused.py +106 -0
- onnxscript/optimizer/_remove_unused_function.py +72 -0
- onnxscript/py.typed +1 -0
- onnxscript/rewriter/__init__.py +56 -0
- onnxscript/rewriter/_ir_utils.py +111 -0
- onnxscript/rewriter/broadcast_to_matmul.py +180 -0
- onnxscript/rewriter/cast_constant_of_shape.py +50 -0
- onnxscript/rewriter/collapse_slices.py +141 -0
- onnxscript/rewriter/erfgelu.py +27 -0
- onnxscript/rewriter/function_rule.py +232 -0
- onnxscript/rewriter/gemm_to_matmul_add.py +21 -0
- onnxscript/rewriter/generic_pattern.py +700 -0
- onnxscript/rewriter/llama_rule_sets.py +287 -0
- onnxscript/rewriter/no_op.py +56 -0
- onnxscript/rewriter/onnxruntime/__init__.py +50 -0
- onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py +99 -0
- onnxscript/rewriter/onnxruntime/fused_matmul_rule_sets.py +177 -0
- onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py +64 -0
- onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py +155 -0
- onnxscript/rewriter/onnxruntime/softmax.py +63 -0
- onnxscript/rewriter/onnxruntime/transformers/__init__.py +21 -0
- onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py +31 -0
- onnxscript/rewriter/onnxruntime/transformers/fastgelu.py +29 -0
- onnxscript/rewriter/onnxruntime/transformers/layernorm.py +47 -0
- onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py +715 -0
- onnxscript/rewriter/ort_fusions/__init__.py +9 -0
- onnxscript/rewriter/ort_fusions/_core.py +28 -0
- onnxscript/rewriter/ort_fusions/_smollm_1.py +253 -0
- onnxscript/rewriter/ort_fusions/_smollm_2.py +467 -0
- onnxscript/rewriter/ort_fusions/_test_models.py +122 -0
- onnxscript/rewriter/ort_fusions/_test_utils.py +42 -0
- onnxscript/rewriter/ort_fusions/cos_sin_cache.py +154 -0
- onnxscript/rewriter/ort_fusions/gqa.py +156 -0
- onnxscript/rewriter/ort_fusions/mha.py +198 -0
- onnxscript/rewriter/ort_fusions/rms_normalization.py +95 -0
- onnxscript/rewriter/ort_fusions/rotary_embedding.py +64 -0
- onnxscript/rewriter/ort_fusions/sdpa.py +75 -0
- onnxscript/rewriter/ort_fusions/skip_normalization.py +46 -0
- onnxscript/rewriter/pattern.py +1714 -0
- onnxscript/rewriter/testing.py +77 -0
- onnxscript/sourceinfo.py +59 -0
- onnxscript/tensor.py +227 -0
- onnxscript/testing/__init__.py +482 -0
- onnxscript/tools/__init__.py +4 -0
- onnxscript/tools/benchmark/__init__.py +23 -0
- onnxscript/tools/benchmark/benchmark_helpers.py +783 -0
- onnxscript/tools/benchmark/benchmark_run.py +140 -0
- onnxscript/tools/benchmark/export_model.py +207 -0
- onnxscript/tools/benchmark/export_model_batch.py +146 -0
- onnxscript/tools/memory_peak.py +244 -0
- onnxscript/tools/training_helper.py +50 -0
- onnxscript/tools/transformers_models/__init__.py +190 -0
- onnxscript/tools/transformers_models/llama.py +168 -0
- onnxscript/tools/transformers_models/mistral.py +238 -0
- onnxscript/tools/transformers_models/phi.py +248 -0
- onnxscript/tools/transformers_models/phi3.py +259 -0
- onnxscript/type_annotation.py +281 -0
- onnxscript/utils/__init__.py +0 -0
- onnxscript/utils/evaluation_utils.py +56 -0
- onnxscript/utils/timing_utils.py +33 -0
- onnxscript/utils/utils.py +84 -0
- onnxscript/values.py +790 -0
- onnxscript/version_converter/__init__.py +21 -0
- onnxscript/version_converter/_version_converter.py +314 -0
- onnxscript-0.1.0.dist-info/LICENSE +21 -0
- onnxscript-0.1.0.dist-info/METADATA +370 -0
- onnxscript-0.1.0.dist-info/RECORD +176 -0
- onnxscript-0.1.0.dist-info/WHEEL +5 -0
- onnxscript-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# ⚠️ WARNING - AUTO-GENERATED CODE - DO NOT EDIT ⚠️
|
|
3
|
+
# ⚙️ Generated by 'python -m opgen'
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=W0221,W0222,R0901,W0237
|
|
9
|
+
# mypy: disable-error-code=override
|
|
10
|
+
# ruff: noqa: N801,E741
|
|
11
|
+
# ruff: noqa: D214,D402,D405,D411,D412,D416,D417
|
|
12
|
+
# --------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Optional, Sequence, TypeVar, Union
|
|
17
|
+
|
|
18
|
+
from onnx.defs import get_schema
|
|
19
|
+
from typing_extensions import TypeAlias
|
|
20
|
+
|
|
21
|
+
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml1 import Opset_ai_onnx_ml1
|
|
22
|
+
from onnxscript.onnx_types import FLOAT, INT64, STRING
|
|
23
|
+
from onnxscript.values import Op, Opset
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Opset_ai_onnx_ml2(Opset_ai_onnx_ml1):
|
|
27
|
+
def __new__(cls):
|
|
28
|
+
return Opset.__new__(cls, "ai.onnx.ml", 2)
|
|
29
|
+
|
|
30
|
+
T1_LabelEncoder = TypeVar("T1_LabelEncoder", FLOAT, INT64, STRING)
|
|
31
|
+
|
|
32
|
+
T2_LabelEncoder: TypeAlias = Union[FLOAT, INT64, STRING]
|
|
33
|
+
|
|
34
|
+
def LabelEncoder(
|
|
35
|
+
self,
|
|
36
|
+
X: T1_LabelEncoder,
|
|
37
|
+
*,
|
|
38
|
+
default_float: float = -0.0,
|
|
39
|
+
default_int64: int = -1,
|
|
40
|
+
default_string: str = "_Unused",
|
|
41
|
+
keys_floats: Optional[Sequence[float]] = None,
|
|
42
|
+
keys_int64s: Optional[Sequence[int]] = None,
|
|
43
|
+
keys_strings: Optional[Sequence[str]] = None,
|
|
44
|
+
values_floats: Optional[Sequence[float]] = None,
|
|
45
|
+
values_int64s: Optional[Sequence[int]] = None,
|
|
46
|
+
values_strings: Optional[Sequence[str]] = None,
|
|
47
|
+
) -> T2_LabelEncoder:
|
|
48
|
+
r"""[🌐 ai.onnx.ml::LabelEncoder(2)](https://onnx.ai/onnx/operators/onnx_aionnxml_LabelEncoder.html#labelencoder-2 "Online Documentation")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
Maps each element in the input tensor to another value.
|
|
52
|
+
|
|
53
|
+
The mapping is determined by the two parallel attributes, 'keys_*' and
|
|
54
|
+
'values_*' attribute. The i-th value in the specified 'keys_*' attribute
|
|
55
|
+
would be mapped to the i-th value in the specified 'values_*' attribute. It
|
|
56
|
+
implies that input's element type and the element type of the specified
|
|
57
|
+
'keys_*' should be identical while the output type is identical to the
|
|
58
|
+
specified 'values_*' attribute. If an input element can not be found in the
|
|
59
|
+
specified 'keys_*' attribute, the 'default_*' that matches the specified
|
|
60
|
+
'values_*' attribute may be used as its output value.
|
|
61
|
+
|
|
62
|
+
Let's consider an example which maps a string tensor to an integer tensor.
|
|
63
|
+
Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6],
|
|
64
|
+
and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally",
|
|
65
|
+
"Sally"] would be mapped to [-1, 5, 5, 6, 6].
|
|
66
|
+
|
|
67
|
+
Since this operator is an one-to-one mapping, its input and output shapes
|
|
68
|
+
are the same. Notice that only one of 'keys_*'/'values_*' can be set.
|
|
69
|
+
|
|
70
|
+
For key look-up, bit-wise comparison is used so even a float NaN can be
|
|
71
|
+
mapped to a value in 'values_*' attribute.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
X: Input data. It can be either tensor or scalar.
|
|
77
|
+
|
|
78
|
+
default_float: A float.
|
|
79
|
+
|
|
80
|
+
default_int64: An integer.
|
|
81
|
+
|
|
82
|
+
default_string: A string.
|
|
83
|
+
|
|
84
|
+
keys_floats: A list of floats.
|
|
85
|
+
|
|
86
|
+
keys_int64s: A list of ints.
|
|
87
|
+
|
|
88
|
+
keys_strings: A list of strings. One and only one of 'keys_*'s should be
|
|
89
|
+
set.
|
|
90
|
+
|
|
91
|
+
values_floats: A list of floats.
|
|
92
|
+
|
|
93
|
+
values_int64s: A list of ints.
|
|
94
|
+
|
|
95
|
+
values_strings: A list of strings. One and only one of 'value_*'s should be
|
|
96
|
+
set.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
schema = get_schema("LabelEncoder", 2, "ai.onnx.ml")
|
|
100
|
+
op = Op(self, "LabelEncoder", schema)
|
|
101
|
+
return op(
|
|
102
|
+
*self._prepare_inputs(schema, X),
|
|
103
|
+
default_float=default_float,
|
|
104
|
+
default_int64=default_int64,
|
|
105
|
+
default_string=default_string,
|
|
106
|
+
keys_floats=keys_floats,
|
|
107
|
+
keys_int64s=keys_int64s,
|
|
108
|
+
keys_strings=keys_strings,
|
|
109
|
+
values_floats=values_floats,
|
|
110
|
+
values_int64s=values_int64s,
|
|
111
|
+
values_strings=values_strings,
|
|
112
|
+
)
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# ⚠️ WARNING - AUTO-GENERATED CODE - DO NOT EDIT ⚠️
|
|
3
|
+
# ⚙️ Generated by 'python -m opgen'
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=W0221,W0222,R0901,W0237
|
|
9
|
+
# mypy: disable-error-code=override
|
|
10
|
+
# ruff: noqa: N801,E741
|
|
11
|
+
# ruff: noqa: D214,D402,D405,D411,D412,D416,D417
|
|
12
|
+
# --------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Optional, Sequence, Tuple, TypeVar, Union
|
|
17
|
+
|
|
18
|
+
from onnx import TensorProto
|
|
19
|
+
from onnx.defs import get_schema
|
|
20
|
+
from typing_extensions import TypeAlias
|
|
21
|
+
|
|
22
|
+
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml2 import Opset_ai_onnx_ml2
|
|
23
|
+
from onnxscript.onnx_types import DOUBLE, FLOAT, INT32, INT64, STRING
|
|
24
|
+
from onnxscript.values import Op, Opset
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Opset_ai_onnx_ml3(Opset_ai_onnx_ml2):
|
|
28
|
+
def __new__(cls):
|
|
29
|
+
return Opset.__new__(cls, "ai.onnx.ml", 3)
|
|
30
|
+
|
|
31
|
+
T1_TreeEnsembleClassifier = TypeVar(
|
|
32
|
+
"T1_TreeEnsembleClassifier", DOUBLE, FLOAT, INT32, INT64
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
T2_TreeEnsembleClassifier: TypeAlias = Union[INT64, STRING]
|
|
36
|
+
|
|
37
|
+
def TreeEnsembleClassifier(
|
|
38
|
+
self,
|
|
39
|
+
X: T1_TreeEnsembleClassifier,
|
|
40
|
+
*,
|
|
41
|
+
base_values: Optional[Sequence[float]] = None,
|
|
42
|
+
base_values_as_tensor: Optional[TensorProto] = None,
|
|
43
|
+
class_ids: Optional[Sequence[int]] = None,
|
|
44
|
+
class_nodeids: Optional[Sequence[int]] = None,
|
|
45
|
+
class_treeids: Optional[Sequence[int]] = None,
|
|
46
|
+
class_weights: Optional[Sequence[float]] = None,
|
|
47
|
+
class_weights_as_tensor: Optional[TensorProto] = None,
|
|
48
|
+
classlabels_int64s: Optional[Sequence[int]] = None,
|
|
49
|
+
classlabels_strings: Optional[Sequence[str]] = None,
|
|
50
|
+
nodes_falsenodeids: Optional[Sequence[int]] = None,
|
|
51
|
+
nodes_featureids: Optional[Sequence[int]] = None,
|
|
52
|
+
nodes_hitrates: Optional[Sequence[float]] = None,
|
|
53
|
+
nodes_hitrates_as_tensor: Optional[TensorProto] = None,
|
|
54
|
+
nodes_missing_value_tracks_true: Optional[Sequence[int]] = None,
|
|
55
|
+
nodes_modes: Optional[Sequence[str]] = None,
|
|
56
|
+
nodes_nodeids: Optional[Sequence[int]] = None,
|
|
57
|
+
nodes_treeids: Optional[Sequence[int]] = None,
|
|
58
|
+
nodes_truenodeids: Optional[Sequence[int]] = None,
|
|
59
|
+
nodes_values: Optional[Sequence[float]] = None,
|
|
60
|
+
nodes_values_as_tensor: Optional[TensorProto] = None,
|
|
61
|
+
post_transform: str = "NONE",
|
|
62
|
+
) -> Tuple[T2_TreeEnsembleClassifier, FLOAT]:
|
|
63
|
+
r"""[🌐 ai.onnx.ml::TreeEnsembleClassifier(3)](https://onnx.ai/onnx/operators/onnx_aionnxml_TreeEnsembleClassifier.html#treeensembleclassifier-3 "Online Documentation")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
Tree Ensemble classifier. Returns the top class for each of N inputs.
|
|
67
|
+
|
|
68
|
+
The attributes named 'nodes_X' form a sequence of tuples, associated by
|
|
69
|
+
index into the sequences, which must all be of equal length. These tuples
|
|
70
|
+
define the nodes.
|
|
71
|
+
|
|
72
|
+
Similarly, all fields prefixed with 'class_' are tuples of votes at the leaves.
|
|
73
|
+
A leaf may have multiple votes, where each vote is weighted by
|
|
74
|
+
the associated class_weights index.
|
|
75
|
+
|
|
76
|
+
One and only one of classlabels_strings or classlabels_int64s
|
|
77
|
+
will be defined. The class_ids are indices into this list.
|
|
78
|
+
All fields ending with <i>_as_tensor</i> can be used instead of the
|
|
79
|
+
same parameter without the suffix if the element type is double and not float.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
X: Input of shape [N,F]
|
|
84
|
+
|
|
85
|
+
base_values: Base values for classification, added to final class score; the
|
|
86
|
+
size must be the same as the classes or can be left unassigned (assumed
|
|
87
|
+
0)
|
|
88
|
+
|
|
89
|
+
base_values_as_tensor: Base values for classification, added to final class
|
|
90
|
+
score; the size must be the same as the classes or can be left
|
|
91
|
+
unassigned (assumed 0)
|
|
92
|
+
|
|
93
|
+
class_ids: The index of the class list that each weight is for.
|
|
94
|
+
|
|
95
|
+
class_nodeids: node id that this weight is for.
|
|
96
|
+
|
|
97
|
+
class_treeids: The id of the tree that this node is in.
|
|
98
|
+
|
|
99
|
+
class_weights: The weight for the class in class_id.
|
|
100
|
+
|
|
101
|
+
class_weights_as_tensor: The weight for the class in class_id.
|
|
102
|
+
|
|
103
|
+
classlabels_int64s: Class labels if using integer labels.<br>One and only
|
|
104
|
+
one of the 'classlabels_*' attributes must be defined.
|
|
105
|
+
|
|
106
|
+
classlabels_strings: Class labels if using string labels.<br>One and only
|
|
107
|
+
one of the 'classlabels_*' attributes must be defined.
|
|
108
|
+
|
|
109
|
+
nodes_falsenodeids: Child node if expression is false.
|
|
110
|
+
|
|
111
|
+
nodes_featureids: Feature id for each node.
|
|
112
|
+
|
|
113
|
+
nodes_hitrates: Popularity of each node, used for performance and may be
|
|
114
|
+
omitted.
|
|
115
|
+
|
|
116
|
+
nodes_hitrates_as_tensor: Popularity of each node, used for performance and
|
|
117
|
+
may be omitted.
|
|
118
|
+
|
|
119
|
+
nodes_missing_value_tracks_true: For each node, define what to do in the
|
|
120
|
+
presence of a missing value: if a value is missing (NaN), use the 'true'
|
|
121
|
+
or 'false' branch based on the value in this array.<br>This attribute
|
|
122
|
+
may be left undefined, and the default value is false (0) for all nodes.
|
|
123
|
+
|
|
124
|
+
nodes_modes: The node kind, that is, the comparison to make at the node.
|
|
125
|
+
There is no comparison to make at a leaf node.<br>One of 'BRANCH_LEQ',
|
|
126
|
+
'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ',
|
|
127
|
+
'LEAF'
|
|
128
|
+
|
|
129
|
+
nodes_nodeids: Node id for each node. Ids may restart at zero for each tree,
|
|
130
|
+
but it not required to.
|
|
131
|
+
|
|
132
|
+
nodes_treeids: Tree id for each node.
|
|
133
|
+
|
|
134
|
+
nodes_truenodeids: Child node if expression is true.
|
|
135
|
+
|
|
136
|
+
nodes_values: Thresholds to do the splitting on for each node.
|
|
137
|
+
|
|
138
|
+
nodes_values_as_tensor: Thresholds to do the splitting on for each node.
|
|
139
|
+
|
|
140
|
+
post_transform: Indicates the transform to apply to the score. <br> One of
|
|
141
|
+
'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
schema = get_schema("TreeEnsembleClassifier", 3, "ai.onnx.ml")
|
|
145
|
+
op = Op(self, "TreeEnsembleClassifier", schema)
|
|
146
|
+
return op(
|
|
147
|
+
*self._prepare_inputs(schema, X),
|
|
148
|
+
base_values=base_values,
|
|
149
|
+
base_values_as_tensor=base_values_as_tensor,
|
|
150
|
+
class_ids=class_ids,
|
|
151
|
+
class_nodeids=class_nodeids,
|
|
152
|
+
class_treeids=class_treeids,
|
|
153
|
+
class_weights=class_weights,
|
|
154
|
+
class_weights_as_tensor=class_weights_as_tensor,
|
|
155
|
+
classlabels_int64s=classlabels_int64s,
|
|
156
|
+
classlabels_strings=classlabels_strings,
|
|
157
|
+
nodes_falsenodeids=nodes_falsenodeids,
|
|
158
|
+
nodes_featureids=nodes_featureids,
|
|
159
|
+
nodes_hitrates=nodes_hitrates,
|
|
160
|
+
nodes_hitrates_as_tensor=nodes_hitrates_as_tensor,
|
|
161
|
+
nodes_missing_value_tracks_true=nodes_missing_value_tracks_true,
|
|
162
|
+
nodes_modes=nodes_modes,
|
|
163
|
+
nodes_nodeids=nodes_nodeids,
|
|
164
|
+
nodes_treeids=nodes_treeids,
|
|
165
|
+
nodes_truenodeids=nodes_truenodeids,
|
|
166
|
+
nodes_values=nodes_values,
|
|
167
|
+
nodes_values_as_tensor=nodes_values_as_tensor,
|
|
168
|
+
post_transform=post_transform,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
T_TreeEnsembleRegressor = TypeVar("T_TreeEnsembleRegressor", DOUBLE, FLOAT, INT32, INT64)
|
|
172
|
+
|
|
173
|
+
def TreeEnsembleRegressor(
|
|
174
|
+
self,
|
|
175
|
+
X: T_TreeEnsembleRegressor,
|
|
176
|
+
*,
|
|
177
|
+
aggregate_function: str = "SUM",
|
|
178
|
+
base_values: Optional[Sequence[float]] = None,
|
|
179
|
+
base_values_as_tensor: Optional[TensorProto] = None,
|
|
180
|
+
n_targets: Optional[int] = None,
|
|
181
|
+
nodes_falsenodeids: Optional[Sequence[int]] = None,
|
|
182
|
+
nodes_featureids: Optional[Sequence[int]] = None,
|
|
183
|
+
nodes_hitrates: Optional[Sequence[float]] = None,
|
|
184
|
+
nodes_hitrates_as_tensor: Optional[TensorProto] = None,
|
|
185
|
+
nodes_missing_value_tracks_true: Optional[Sequence[int]] = None,
|
|
186
|
+
nodes_modes: Optional[Sequence[str]] = None,
|
|
187
|
+
nodes_nodeids: Optional[Sequence[int]] = None,
|
|
188
|
+
nodes_treeids: Optional[Sequence[int]] = None,
|
|
189
|
+
nodes_truenodeids: Optional[Sequence[int]] = None,
|
|
190
|
+
nodes_values: Optional[Sequence[float]] = None,
|
|
191
|
+
nodes_values_as_tensor: Optional[TensorProto] = None,
|
|
192
|
+
post_transform: str = "NONE",
|
|
193
|
+
target_ids: Optional[Sequence[int]] = None,
|
|
194
|
+
target_nodeids: Optional[Sequence[int]] = None,
|
|
195
|
+
target_treeids: Optional[Sequence[int]] = None,
|
|
196
|
+
target_weights: Optional[Sequence[float]] = None,
|
|
197
|
+
target_weights_as_tensor: Optional[TensorProto] = None,
|
|
198
|
+
) -> FLOAT:
|
|
199
|
+
r"""[🌐 ai.onnx.ml::TreeEnsembleRegressor(3)](https://onnx.ai/onnx/operators/onnx_aionnxml_TreeEnsembleRegressor.html#treeensembleregressor-3 "Online Documentation")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
Tree Ensemble regressor. Returns the regressed values for each input in N.
|
|
203
|
+
|
|
204
|
+
All args with nodes_ are fields of a tuple of tree nodes, and
|
|
205
|
+
it is assumed they are the same length, and an index i will decode the
|
|
206
|
+
tuple across these inputs. Each node id can appear only once
|
|
207
|
+
for each tree id.
|
|
208
|
+
|
|
209
|
+
All fields prefixed with target_ are tuples of votes at the leaves.
|
|
210
|
+
|
|
211
|
+
A leaf may have multiple votes, where each vote is weighted by
|
|
212
|
+
the associated target_weights index.
|
|
213
|
+
|
|
214
|
+
All fields ending with <i>_as_tensor</i> can be used instead of the
|
|
215
|
+
same parameter without the suffix if the element type is double and not float.
|
|
216
|
+
All trees must have their node ids start at 0 and increment by 1.
|
|
217
|
+
|
|
218
|
+
Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
X: Input of shape [N,F]
|
|
223
|
+
|
|
224
|
+
aggregate_function: Defines how to aggregate leaf values within a target.
|
|
225
|
+
<br>One of 'AVERAGE,' 'SUM,' 'MIN,' 'MAX.'
|
|
226
|
+
|
|
227
|
+
base_values: Base values for regression, added to final prediction after
|
|
228
|
+
applying aggregate_function; the size must be the same as the classes or
|
|
229
|
+
can be left unassigned (assumed 0)
|
|
230
|
+
|
|
231
|
+
base_values_as_tensor: Base values for regression, added to final prediction
|
|
232
|
+
after applying aggregate_function; the size must be the same as the
|
|
233
|
+
classes or can be left unassigned (assumed 0)
|
|
234
|
+
|
|
235
|
+
n_targets: The total number of targets.
|
|
236
|
+
|
|
237
|
+
nodes_falsenodeids: Child node if expression is false
|
|
238
|
+
|
|
239
|
+
nodes_featureids: Feature id for each node.
|
|
240
|
+
|
|
241
|
+
nodes_hitrates: Popularity of each node, used for performance and may be
|
|
242
|
+
omitted.
|
|
243
|
+
|
|
244
|
+
nodes_hitrates_as_tensor: Popularity of each node, used for performance and
|
|
245
|
+
may be omitted.
|
|
246
|
+
|
|
247
|
+
nodes_missing_value_tracks_true: For each node, define what to do in the
|
|
248
|
+
presence of a NaN: use the 'true' (if the attribute value is 1) or
|
|
249
|
+
'false' (if the attribute value is 0) branch based on the value in this
|
|
250
|
+
array.<br>This attribute may be left undefined and the default value is
|
|
251
|
+
false (0) for all nodes.
|
|
252
|
+
|
|
253
|
+
nodes_modes: The node kind, that is, the comparison to make at the node.
|
|
254
|
+
There is no comparison to make at a leaf node.<br>One of 'BRANCH_LEQ',
|
|
255
|
+
'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ',
|
|
256
|
+
'LEAF'
|
|
257
|
+
|
|
258
|
+
nodes_nodeids: Node id for each node. Node ids must restart at zero for each
|
|
259
|
+
tree and increase sequentially.
|
|
260
|
+
|
|
261
|
+
nodes_treeids: Tree id for each node.
|
|
262
|
+
|
|
263
|
+
nodes_truenodeids: Child node if expression is true
|
|
264
|
+
|
|
265
|
+
nodes_values: Thresholds to do the splitting on for each node.
|
|
266
|
+
|
|
267
|
+
nodes_values_as_tensor: Thresholds to do the splitting on for each node.
|
|
268
|
+
|
|
269
|
+
post_transform: Indicates the transform to apply to the score. <br>One of
|
|
270
|
+
'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
|
|
271
|
+
|
|
272
|
+
target_ids: The index of the target that each weight is for
|
|
273
|
+
|
|
274
|
+
target_nodeids: The node id of each weight
|
|
275
|
+
|
|
276
|
+
target_treeids: The id of the tree that each node is in.
|
|
277
|
+
|
|
278
|
+
target_weights: The weight for each target
|
|
279
|
+
|
|
280
|
+
target_weights_as_tensor: The weight for each target
|
|
281
|
+
"""
|
|
282
|
+
|
|
283
|
+
schema = get_schema("TreeEnsembleRegressor", 3, "ai.onnx.ml")
|
|
284
|
+
op = Op(self, "TreeEnsembleRegressor", schema)
|
|
285
|
+
return op(
|
|
286
|
+
*self._prepare_inputs(schema, X),
|
|
287
|
+
aggregate_function=aggregate_function,
|
|
288
|
+
base_values=base_values,
|
|
289
|
+
base_values_as_tensor=base_values_as_tensor,
|
|
290
|
+
n_targets=n_targets,
|
|
291
|
+
nodes_falsenodeids=nodes_falsenodeids,
|
|
292
|
+
nodes_featureids=nodes_featureids,
|
|
293
|
+
nodes_hitrates=nodes_hitrates,
|
|
294
|
+
nodes_hitrates_as_tensor=nodes_hitrates_as_tensor,
|
|
295
|
+
nodes_missing_value_tracks_true=nodes_missing_value_tracks_true,
|
|
296
|
+
nodes_modes=nodes_modes,
|
|
297
|
+
nodes_nodeids=nodes_nodeids,
|
|
298
|
+
nodes_treeids=nodes_treeids,
|
|
299
|
+
nodes_truenodeids=nodes_truenodeids,
|
|
300
|
+
nodes_values=nodes_values,
|
|
301
|
+
nodes_values_as_tensor=nodes_values_as_tensor,
|
|
302
|
+
post_transform=post_transform,
|
|
303
|
+
target_ids=target_ids,
|
|
304
|
+
target_nodeids=target_nodeids,
|
|
305
|
+
target_treeids=target_treeids,
|
|
306
|
+
target_weights=target_weights,
|
|
307
|
+
target_weights_as_tensor=target_weights_as_tensor,
|
|
308
|
+
)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# ⚠️ WARNING - AUTO-GENERATED CODE - DO NOT EDIT ⚠️
|
|
3
|
+
# ⚙️ Generated by 'python -m opgen'
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# --------------------------------------------------------------------------
|
|
8
|
+
# pylint: disable=W0221,W0222,R0901,W0237
|
|
9
|
+
# mypy: disable-error-code=override
|
|
10
|
+
# ruff: noqa: N801,E741
|
|
11
|
+
# ruff: noqa: D214,D402,D405,D411,D412,D416,D417
|
|
12
|
+
# --------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Optional, Sequence, TypeVar, Union
|
|
17
|
+
|
|
18
|
+
from onnx import TensorProto
|
|
19
|
+
from onnx.defs import get_schema
|
|
20
|
+
from typing_extensions import TypeAlias
|
|
21
|
+
|
|
22
|
+
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml3 import Opset_ai_onnx_ml3
|
|
23
|
+
from onnxscript.onnx_types import DOUBLE, FLOAT, INT16, INT32, INT64, STRING
|
|
24
|
+
from onnxscript.values import Op, Opset
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Opset_ai_onnx_ml4(Opset_ai_onnx_ml3):
|
|
28
|
+
def __new__(cls):
|
|
29
|
+
return Opset.__new__(cls, "ai.onnx.ml", 4)
|
|
30
|
+
|
|
31
|
+
T1_LabelEncoder = TypeVar("T1_LabelEncoder", DOUBLE, FLOAT, INT16, INT32, INT64, STRING)
|
|
32
|
+
|
|
33
|
+
T2_LabelEncoder: TypeAlias = Union[DOUBLE, FLOAT, INT16, INT32, INT64, STRING]
|
|
34
|
+
|
|
35
|
+
def LabelEncoder(
|
|
36
|
+
self,
|
|
37
|
+
X: T1_LabelEncoder,
|
|
38
|
+
*,
|
|
39
|
+
default_float: float = -0.0,
|
|
40
|
+
default_int64: int = -1,
|
|
41
|
+
default_string: str = "_Unused",
|
|
42
|
+
default_tensor: Optional[TensorProto] = None,
|
|
43
|
+
keys_floats: Optional[Sequence[float]] = None,
|
|
44
|
+
keys_int64s: Optional[Sequence[int]] = None,
|
|
45
|
+
keys_strings: Optional[Sequence[str]] = None,
|
|
46
|
+
keys_tensor: Optional[TensorProto] = None,
|
|
47
|
+
values_floats: Optional[Sequence[float]] = None,
|
|
48
|
+
values_int64s: Optional[Sequence[int]] = None,
|
|
49
|
+
values_strings: Optional[Sequence[str]] = None,
|
|
50
|
+
values_tensor: Optional[TensorProto] = None,
|
|
51
|
+
) -> T2_LabelEncoder:
|
|
52
|
+
r"""[🌐 ai.onnx.ml::LabelEncoder(4)](https://onnx.ai/onnx/operators/onnx_aionnxml_LabelEncoder.html#labelencoder-4 "Online Documentation")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Maps each element in the input tensor to another value.
|
|
56
|
+
|
|
57
|
+
The mapping is determined by the two parallel attributes, 'keys_*' and
|
|
58
|
+
'values_*' attribute. The i-th value in the specified 'keys_*' attribute
|
|
59
|
+
would be mapped to the i-th value in the specified 'values_*' attribute. It
|
|
60
|
+
implies that input's element type and the element type of the specified
|
|
61
|
+
'keys_*' should be identical while the output type is identical to the
|
|
62
|
+
specified 'values_*' attribute. Note that the 'keys_*' and 'values_*' attributes
|
|
63
|
+
must have the same length. If an input element can not be found in the
|
|
64
|
+
specified 'keys_*' attribute, the 'default_*' that matches the specified
|
|
65
|
+
'values_*' attribute may be used as its output value. The type of the 'default_*'
|
|
66
|
+
attribute must match the 'values_*' attribute chosen.
|
|
67
|
+
|
|
68
|
+
Let's consider an example which maps a string tensor to an integer tensor.
|
|
69
|
+
Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6],
|
|
70
|
+
and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally",
|
|
71
|
+
"Sally"] would be mapped to [-1, 5, 5, 6, 6].
|
|
72
|
+
|
|
73
|
+
Since this operator is an one-to-one mapping, its input and output shapes
|
|
74
|
+
are the same. Notice that only one of 'keys_*'/'values_*' can be set.
|
|
75
|
+
|
|
76
|
+
Float keys with value 'NaN' match any input 'NaN' value regardless of bit
|
|
77
|
+
value. If a key is repeated, the last key takes precedence.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
X: Input data. It must have the same element type as the keys_* attribute
|
|
82
|
+
set.
|
|
83
|
+
|
|
84
|
+
default_float: A float.
|
|
85
|
+
|
|
86
|
+
default_int64: An integer.
|
|
87
|
+
|
|
88
|
+
default_string: A string.
|
|
89
|
+
|
|
90
|
+
default_tensor: A default tensor. {"_Unused"} if values_* has string type,
|
|
91
|
+
{-1} if values_* has integral type, and {-0.f} if values_* has float
|
|
92
|
+
type.
|
|
93
|
+
|
|
94
|
+
keys_floats: A list of floats.
|
|
95
|
+
|
|
96
|
+
keys_int64s: A list of ints.
|
|
97
|
+
|
|
98
|
+
keys_strings: A list of strings.
|
|
99
|
+
|
|
100
|
+
keys_tensor: Keys encoded as a 1D tensor. One and only one of 'keys_*'s
|
|
101
|
+
should be set.
|
|
102
|
+
|
|
103
|
+
values_floats: A list of floats.
|
|
104
|
+
|
|
105
|
+
values_int64s: A list of ints.
|
|
106
|
+
|
|
107
|
+
values_strings: A list of strings.
|
|
108
|
+
|
|
109
|
+
values_tensor: Values encoded as a 1D tensor. One and only one of
|
|
110
|
+
'values_*'s should be set.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
schema = get_schema("LabelEncoder", 4, "ai.onnx.ml")
|
|
114
|
+
op = Op(self, "LabelEncoder", schema)
|
|
115
|
+
return op(
|
|
116
|
+
*self._prepare_inputs(schema, X),
|
|
117
|
+
default_float=default_float,
|
|
118
|
+
default_int64=default_int64,
|
|
119
|
+
default_string=default_string,
|
|
120
|
+
default_tensor=default_tensor,
|
|
121
|
+
keys_floats=keys_floats,
|
|
122
|
+
keys_int64s=keys_int64s,
|
|
123
|
+
keys_strings=keys_strings,
|
|
124
|
+
keys_tensor=keys_tensor,
|
|
125
|
+
values_floats=values_floats,
|
|
126
|
+
values_int64s=values_int64s,
|
|
127
|
+
values_strings=values_strings,
|
|
128
|
+
values_tensor=values_tensor,
|
|
129
|
+
)
|