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.
Files changed (176) hide show
  1. onnxscript/__init__.py +131 -0
  2. onnxscript/_framework_apis/__init__.py +3 -0
  3. onnxscript/_framework_apis/torch_2_5.py +117 -0
  4. onnxscript/_framework_apis/torch_2_6.py +45 -0
  5. onnxscript/_internal/__init__.py +0 -0
  6. onnxscript/_internal/analysis.py +229 -0
  7. onnxscript/_internal/ast_utils.py +64 -0
  8. onnxscript/_internal/autocast.py +250 -0
  9. onnxscript/_internal/deprecation.py +78 -0
  10. onnxscript/_internal/param_manipulation.py +148 -0
  11. onnxscript/_internal/runtime_typing.py +43 -0
  12. onnxscript/_internal/utils.py +99 -0
  13. onnxscript/_internal/version_utils.py +118 -0
  14. onnxscript/_legacy_ir/__init__.py +341 -0
  15. onnxscript/_legacy_ir/visitor.py +937 -0
  16. onnxscript/_thirdparty/asciichartpy.py +313 -0
  17. onnxscript/backend/__init__.py +2 -0
  18. onnxscript/backend/onnx_backend.py +303 -0
  19. onnxscript/backend/onnx_export.py +885 -0
  20. onnxscript/converter.py +1470 -0
  21. onnxscript/evaluator.py +619 -0
  22. onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py +403 -0
  23. onnxscript/function_libs/tools/torch_lib/generate_aten_signatures.py +333 -0
  24. onnxscript/function_libs/tools/torch_lib/generate_prims_signatures.py +331 -0
  25. onnxscript/function_libs/torch_lib/__init__.py +12 -0
  26. onnxscript/function_libs/torch_lib/_constants.py +5 -0
  27. onnxscript/function_libs/torch_lib/_flags.py +58 -0
  28. onnxscript/function_libs/torch_lib/graph_building/__init__.py +56 -0
  29. onnxscript/function_libs/torch_lib/graph_building/_graph_building_ir.py +723 -0
  30. onnxscript/function_libs/torch_lib/graph_building/_graph_building_torch.py +1125 -0
  31. onnxscript/function_libs/torch_lib/ops/__init__.py +27 -0
  32. onnxscript/function_libs/torch_lib/ops/common.py +80 -0
  33. onnxscript/function_libs/torch_lib/ops/core.py +8935 -0
  34. onnxscript/function_libs/torch_lib/ops/fft.py +385 -0
  35. onnxscript/function_libs/torch_lib/ops/linalg.py +399 -0
  36. onnxscript/function_libs/torch_lib/ops/nested.py +25 -0
  37. onnxscript/function_libs/torch_lib/ops/nn.py +2713 -0
  38. onnxscript/function_libs/torch_lib/ops/prims.py +850 -0
  39. onnxscript/function_libs/torch_lib/ops/quantized_decomposed.py +63 -0
  40. onnxscript/function_libs/torch_lib/ops/sparse.py +23 -0
  41. onnxscript/function_libs/torch_lib/ops/special.py +387 -0
  42. onnxscript/function_libs/torch_lib/ops/vision.py +25 -0
  43. onnxscript/function_libs/torch_lib/registration.py +151 -0
  44. onnxscript/function_libs/torch_lib/tensor_typing.py +74 -0
  45. onnxscript/ir/__init__.py +153 -0
  46. onnxscript/ir/_convenience.py +447 -0
  47. onnxscript/ir/_core.py +3119 -0
  48. onnxscript/ir/_display.py +49 -0
  49. onnxscript/ir/_enums.py +163 -0
  50. onnxscript/ir/_graph_comparison.py +23 -0
  51. onnxscript/ir/_io.py +97 -0
  52. onnxscript/ir/_linked_list.py +276 -0
  53. onnxscript/ir/_metadata.py +44 -0
  54. onnxscript/ir/_name_authority.py +72 -0
  55. onnxscript/ir/_polyfill.py +25 -0
  56. onnxscript/ir/_protocols.py +598 -0
  57. onnxscript/ir/_schemas.py +548 -0
  58. onnxscript/ir/_tape.py +120 -0
  59. onnxscript/ir/_type_casting.py +106 -0
  60. onnxscript/ir/convenience.py +32 -0
  61. onnxscript/ir/external_data.py +396 -0
  62. onnxscript/ir/passes/__init__.py +33 -0
  63. onnxscript/ir/passes/_pass_infra.py +172 -0
  64. onnxscript/ir/serde.py +1620 -0
  65. onnxscript/ir/tensor_adapters.py +122 -0
  66. onnxscript/ir/traversal.py +82 -0
  67. onnxscript/irbuilder.py +542 -0
  68. onnxscript/main.py +167 -0
  69. onnxscript/onnx_opset/__init__.py +232 -0
  70. onnxscript/onnx_opset/_impl/opset1.py +4100 -0
  71. onnxscript/onnx_opset/_impl/opset10.py +1227 -0
  72. onnxscript/onnx_opset/_impl/opset11.py +4013 -0
  73. onnxscript/onnx_opset/_impl/opset12.py +1078 -0
  74. onnxscript/onnx_opset/_impl/opset13.py +3924 -0
  75. onnxscript/onnx_opset/_impl/opset14.py +999 -0
  76. onnxscript/onnx_opset/_impl/opset15.py +604 -0
  77. onnxscript/onnx_opset/_impl/opset16.py +1255 -0
  78. onnxscript/onnx_opset/_impl/opset17.py +561 -0
  79. onnxscript/onnx_opset/_impl/opset18.py +1803 -0
  80. onnxscript/onnx_opset/_impl/opset19.py +1942 -0
  81. onnxscript/onnx_opset/_impl/opset2.py +218 -0
  82. onnxscript/onnx_opset/_impl/opset20.py +675 -0
  83. onnxscript/onnx_opset/_impl/opset21.py +1976 -0
  84. onnxscript/onnx_opset/_impl/opset22.py +2588 -0
  85. onnxscript/onnx_opset/_impl/opset3.py +199 -0
  86. onnxscript/onnx_opset/_impl/opset4.py +77 -0
  87. onnxscript/onnx_opset/_impl/opset5.py +84 -0
  88. onnxscript/onnx_opset/_impl/opset6.py +944 -0
  89. onnxscript/onnx_opset/_impl/opset7.py +1243 -0
  90. onnxscript/onnx_opset/_impl/opset8.py +444 -0
  91. onnxscript/onnx_opset/_impl/opset9.py +1485 -0
  92. onnxscript/onnx_opset/_impl/opset_ai_onnx_ml1.py +974 -0
  93. onnxscript/onnx_opset/_impl/opset_ai_onnx_ml2.py +112 -0
  94. onnxscript/onnx_opset/_impl/opset_ai_onnx_ml3.py +308 -0
  95. onnxscript/onnx_opset/_impl/opset_ai_onnx_ml4.py +129 -0
  96. onnxscript/onnx_opset/_impl/opset_ai_onnx_ml5.py +158 -0
  97. onnxscript/onnx_opset/_impl/opset_ai_onnx_preview_training1.py +577 -0
  98. onnxscript/onnx_types.py +229 -0
  99. onnxscript/optimizer/__init__.py +39 -0
  100. onnxscript/optimizer/_constant_folding.py +1083 -0
  101. onnxscript/optimizer/_inliner.py +312 -0
  102. onnxscript/optimizer/_legacy/_optimizer.py +98 -0
  103. onnxscript/optimizer/_legacy/_remove_unused_proto.py +144 -0
  104. onnxscript/optimizer/_legacy/_simple_function_folding.py +243 -0
  105. onnxscript/optimizer/_legacy/constant_folding.py +293 -0
  106. onnxscript/optimizer/_legacy/evaluator.py +439 -0
  107. onnxscript/optimizer/_optimizer.py +61 -0
  108. onnxscript/optimizer/_remove_unused.py +106 -0
  109. onnxscript/optimizer/_remove_unused_function.py +72 -0
  110. onnxscript/py.typed +1 -0
  111. onnxscript/rewriter/__init__.py +56 -0
  112. onnxscript/rewriter/_ir_utils.py +111 -0
  113. onnxscript/rewriter/broadcast_to_matmul.py +180 -0
  114. onnxscript/rewriter/cast_constant_of_shape.py +50 -0
  115. onnxscript/rewriter/collapse_slices.py +141 -0
  116. onnxscript/rewriter/erfgelu.py +27 -0
  117. onnxscript/rewriter/function_rule.py +232 -0
  118. onnxscript/rewriter/gemm_to_matmul_add.py +21 -0
  119. onnxscript/rewriter/generic_pattern.py +700 -0
  120. onnxscript/rewriter/llama_rule_sets.py +287 -0
  121. onnxscript/rewriter/no_op.py +56 -0
  122. onnxscript/rewriter/onnxruntime/__init__.py +50 -0
  123. onnxscript/rewriter/onnxruntime/bfloat16_utils/bfloat16_converter.py +99 -0
  124. onnxscript/rewriter/onnxruntime/fused_matmul_rule_sets.py +177 -0
  125. onnxscript/rewriter/onnxruntime/group_normalization_merge_silu.py +64 -0
  126. onnxscript/rewriter/onnxruntime/instance_to_group_normalization.py +155 -0
  127. onnxscript/rewriter/onnxruntime/softmax.py +63 -0
  128. onnxscript/rewriter/onnxruntime/transformers/__init__.py +21 -0
  129. onnxscript/rewriter/onnxruntime/transformers/biassplitgelu.py +31 -0
  130. onnxscript/rewriter/onnxruntime/transformers/fastgelu.py +29 -0
  131. onnxscript/rewriter/onnxruntime/transformers/layernorm.py +47 -0
  132. onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py +715 -0
  133. onnxscript/rewriter/ort_fusions/__init__.py +9 -0
  134. onnxscript/rewriter/ort_fusions/_core.py +28 -0
  135. onnxscript/rewriter/ort_fusions/_smollm_1.py +253 -0
  136. onnxscript/rewriter/ort_fusions/_smollm_2.py +467 -0
  137. onnxscript/rewriter/ort_fusions/_test_models.py +122 -0
  138. onnxscript/rewriter/ort_fusions/_test_utils.py +42 -0
  139. onnxscript/rewriter/ort_fusions/cos_sin_cache.py +154 -0
  140. onnxscript/rewriter/ort_fusions/gqa.py +156 -0
  141. onnxscript/rewriter/ort_fusions/mha.py +198 -0
  142. onnxscript/rewriter/ort_fusions/rms_normalization.py +95 -0
  143. onnxscript/rewriter/ort_fusions/rotary_embedding.py +64 -0
  144. onnxscript/rewriter/ort_fusions/sdpa.py +75 -0
  145. onnxscript/rewriter/ort_fusions/skip_normalization.py +46 -0
  146. onnxscript/rewriter/pattern.py +1714 -0
  147. onnxscript/rewriter/testing.py +77 -0
  148. onnxscript/sourceinfo.py +59 -0
  149. onnxscript/tensor.py +227 -0
  150. onnxscript/testing/__init__.py +482 -0
  151. onnxscript/tools/__init__.py +4 -0
  152. onnxscript/tools/benchmark/__init__.py +23 -0
  153. onnxscript/tools/benchmark/benchmark_helpers.py +783 -0
  154. onnxscript/tools/benchmark/benchmark_run.py +140 -0
  155. onnxscript/tools/benchmark/export_model.py +207 -0
  156. onnxscript/tools/benchmark/export_model_batch.py +146 -0
  157. onnxscript/tools/memory_peak.py +244 -0
  158. onnxscript/tools/training_helper.py +50 -0
  159. onnxscript/tools/transformers_models/__init__.py +190 -0
  160. onnxscript/tools/transformers_models/llama.py +168 -0
  161. onnxscript/tools/transformers_models/mistral.py +238 -0
  162. onnxscript/tools/transformers_models/phi.py +248 -0
  163. onnxscript/tools/transformers_models/phi3.py +259 -0
  164. onnxscript/type_annotation.py +281 -0
  165. onnxscript/utils/__init__.py +0 -0
  166. onnxscript/utils/evaluation_utils.py +56 -0
  167. onnxscript/utils/timing_utils.py +33 -0
  168. onnxscript/utils/utils.py +84 -0
  169. onnxscript/values.py +790 -0
  170. onnxscript/version_converter/__init__.py +21 -0
  171. onnxscript/version_converter/_version_converter.py +314 -0
  172. onnxscript-0.1.0.dist-info/LICENSE +21 -0
  173. onnxscript-0.1.0.dist-info/METADATA +370 -0
  174. onnxscript-0.1.0.dist-info/RECORD +176 -0
  175. onnxscript-0.1.0.dist-info/WHEEL +5 -0
  176. onnxscript-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1227 @@
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
17
+
18
+ from onnx.defs import get_schema
19
+ from typing_extensions import TypeAlias
20
+
21
+ from onnxscript.onnx_opset._impl.opset9 import Opset9
22
+ from onnxscript.onnx_types import (
23
+ BOOL,
24
+ COMPLEX64,
25
+ COMPLEX128,
26
+ DOUBLE,
27
+ FLOAT,
28
+ FLOAT16,
29
+ INT8,
30
+ INT16,
31
+ INT32,
32
+ INT64,
33
+ STRING,
34
+ UINT8,
35
+ UINT16,
36
+ UINT32,
37
+ UINT64,
38
+ )
39
+ from onnxscript.values import Op, Opset
40
+
41
+
42
+ class Opset10(Opset9):
43
+ def __new__(cls):
44
+ return Opset.__new__(cls, "", 10)
45
+
46
+ T_AveragePool = TypeVar("T_AveragePool", DOUBLE, FLOAT, FLOAT16)
47
+
48
+ def AveragePool(
49
+ self,
50
+ X: T_AveragePool,
51
+ *,
52
+ auto_pad: str = "NOTSET",
53
+ ceil_mode: int = 0,
54
+ count_include_pad: int = 0,
55
+ kernel_shape: Sequence[int],
56
+ pads: Optional[Sequence[int]] = None,
57
+ strides: Optional[Sequence[int]] = None,
58
+ ) -> T_AveragePool:
59
+ r"""[🌐 AveragePool(10)](https://onnx.ai/onnx/operators/onnx__AveragePool.html#averagepool-10 "Online Documentation")
60
+
61
+
62
+ AveragePool consumes an input tensor X and applies average pooling across
63
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
64
+ average pooling consisting of computing the average on all values of a
65
+ subset of the input tensor according to the kernel size and downsampling the
66
+ data into the output tensor Y for further processing. The output spatial shape will be following:
67
+ ```
68
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
69
+ ```
70
+ or
71
+ ```
72
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
73
+ ```
74
+ if ceil_mode is enabled
75
+
76
+ ```
77
+ * pad_shape[i] is sum of pads along axis i
78
+ ```
79
+
80
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
81
+ ```
82
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])
83
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
84
+ ```
85
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
86
+ ```
87
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]
88
+ ```
89
+ The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
90
+
91
+
92
+ Args:
93
+ X: Input data tensor from the previous operator; dimensions for image case
94
+ are (N x C x H x W), where N is the batch size, C is the number of
95
+ channels, and H and W are the height and the width of the data. For non
96
+ image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn),
97
+ where N is the batch size. Optionally, if dimension denotation is in
98
+ effect, the operation expects the input data tensor to arrive with the
99
+ dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE,
100
+ DATA_FEATURE ...].
101
+
102
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
103
+ Where default value is NOTSET, which means explicit padding is used.
104
+ SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial
105
+ size match the input.In case of odd number add the extra padding at the
106
+ end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no
107
+ padding.
108
+
109
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
110
+ shape.
111
+
112
+ count_include_pad: Whether include pad pixels when calculating values for
113
+ the edges. Default is 0, doesn't count include pad.
114
+
115
+ kernel_shape: The size of the kernel along each axis.
116
+
117
+ pads: Padding for the beginning and ending along each spatial axis, it can
118
+ take any value greater than or equal to 0. The value represent the
119
+ number of pixels added to the beginning and end part of the
120
+ corresponding axis. `pads` format should be as follow [x1_begin,
121
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
122
+ added at the beginning of axis `i` and xi_end, the number of pixels
123
+ added at the end of axis `i`. This attribute cannot be used
124
+ simultaneously with auto_pad attribute. If not present, the padding
125
+ defaults to 0 along start and end of each spatial axis.
126
+
127
+ strides: Stride along each spatial axis.
128
+ """
129
+
130
+ schema = get_schema("AveragePool", 10, "")
131
+ op = Op(self, "AveragePool", schema)
132
+ return op(
133
+ *self._prepare_inputs(schema, X),
134
+ auto_pad=auto_pad,
135
+ ceil_mode=ceil_mode,
136
+ count_include_pad=count_include_pad,
137
+ kernel_shape=kernel_shape,
138
+ pads=pads,
139
+ strides=strides,
140
+ )
141
+
142
+ T1_ConvInteger = TypeVar("T1_ConvInteger", INT8, UINT8)
143
+
144
+ T2_ConvInteger = TypeVar("T2_ConvInteger", INT8, UINT8)
145
+
146
+ T3_ConvInteger: TypeAlias = INT32
147
+
148
+ def ConvInteger(
149
+ self,
150
+ x: T1_ConvInteger,
151
+ w: T2_ConvInteger,
152
+ x_zero_point: Optional[T1_ConvInteger] = None,
153
+ w_zero_point: Optional[T2_ConvInteger] = None,
154
+ *,
155
+ auto_pad: str = "NOTSET",
156
+ dilations: Optional[Sequence[int]] = None,
157
+ group: int = 1,
158
+ kernel_shape: Optional[Sequence[int]] = None,
159
+ pads: Optional[Sequence[int]] = None,
160
+ strides: Optional[Sequence[int]] = None,
161
+ ) -> T3_ConvInteger:
162
+ r"""[🌐 ConvInteger(10)](https://onnx.ai/onnx/operators/onnx__ConvInteger.html#convinteger-10 "Online Documentation")
163
+
164
+
165
+ The integer convolution operator consumes an input tensor, its zero-point, a filter, and its zero-point,
166
+ and computes the output. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits.
167
+
168
+
169
+ Args:
170
+ x: Input data tensor from previous layer; has size (N x C x H x W), where N
171
+ is the batch size, C is the number of channels, and H and W are the
172
+ height and width. Note that this is for the 2D image. Otherwise the size
173
+ is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in
174
+ effect, the operation expects input data tensor to arrive with the
175
+ dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE,
176
+ DATA_FEATURE ...].
177
+
178
+ w: The weight tensor that will be used in the convolutions; has size (M x
179
+ C/group x kH x kW), where C is the number of channels, and kH and kW are
180
+ the height and width of the kernel, and M is the number of feature maps.
181
+ For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x
182
+ k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel.
183
+ Optionally, if dimension denotation is in effect, the operation expects
184
+ the weight tensor to arrive with the dimension denotation of
185
+ [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL
186
+ ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based
187
+ indices for the shape array). Or in other words FILTER_IN_CHANNEL should
188
+ be equal to DATA_CHANNEL.
189
+
190
+ x_zero_point: (optional) Zero point tensor for input 'x'. It's optional and
191
+ default value is 0. It's a scalar, which means a per-tensor/layer
192
+ quantization.
193
+
194
+ w_zero_point: (optional) Zero point tensor for input 'w'. It's optional and
195
+ default value is 0. It could be a scalar or a 1-D tensor, which means a
196
+ per-tensor/layer or per output channel quantization. If it's a 1-D
197
+ tensor, its number of elements should be equal to the number of output
198
+ channels (M)
199
+
200
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
201
+ Where default value is NOTSET, which means explicit padding is used.
202
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
203
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
204
+ split between the two sides equally or almost equally (depending on
205
+ whether it is even or odd). In case the padding is an odd number, the
206
+ extra padding is added at the end for SAME_UPPER and at the beginning
207
+ for SAME_LOWER.
208
+
209
+ dilations: dilation value along each spatial axis of the filter. If not
210
+ present, the dilation defaults to 1 along each axis.
211
+
212
+ group: number of groups input channels and output channels are divided into.
213
+ default is 1.
214
+
215
+ kernel_shape: The shape of the convolution kernel. If not present, should be
216
+ inferred from input 'w'.
217
+
218
+ pads: Padding for the beginning and ending along each spatial axis, it can
219
+ take any value greater than or equal to 0.The value represent the number
220
+ of pixels added to the beginning and end part of the corresponding
221
+ axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end,
222
+ x2_end,...], where xi_begin the number ofpixels added at the beginning
223
+ of axis `i` and xi_end, the number of pixels added at the end of axis
224
+ `i`.This attribute cannot be used simultaneously with auto_pad
225
+ attribute. If not present, the padding defaultsto 0 along start and end
226
+ of each spatial axis.
227
+
228
+ strides: Stride along each spatial axis. If not present, the stride defaults
229
+ to 1 along each axis.
230
+ """
231
+
232
+ schema = get_schema("ConvInteger", 10, "")
233
+ op = Op(self, "ConvInteger", schema)
234
+ return op(
235
+ *self._prepare_inputs(schema, x, w, x_zero_point, w_zero_point),
236
+ auto_pad=auto_pad,
237
+ dilations=dilations,
238
+ group=group,
239
+ kernel_shape=kernel_shape,
240
+ pads=pads,
241
+ strides=strides,
242
+ )
243
+
244
+ T_DequantizeLinear = TypeVar("T_DequantizeLinear", INT32, INT8, UINT8)
245
+
246
+ def DequantizeLinear(
247
+ self,
248
+ x: T_DequantizeLinear,
249
+ x_scale: FLOAT,
250
+ x_zero_point: Optional[T_DequantizeLinear] = None,
251
+ ) -> FLOAT:
252
+ r"""[🌐 DequantizeLinear(10)](https://onnx.ai/onnx/operators/onnx__DequantizeLinear.html#dequantizelinear-10 "Online Documentation")
253
+
254
+
255
+ The linear dequantization operator. It consumes a quantized tensor, a scale, a zero point to compute the full precision tensor.
256
+ The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' are both scalars.
257
+ 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32,
258
+ there's no zero point (zero point is supposed to be 0).
259
+
260
+
261
+ Args:
262
+ x: N-D quantized input tensor to be de-quantized.
263
+
264
+ x_scale: Scale for input 'x'. It's a scalar, which means a per-tensor/layer
265
+ quantization.
266
+
267
+ x_zero_point: (optional) Zero point for input 'x'. It's a scalar, which
268
+ means a per-tensor/layer quantization. It's optional. 0 is the default
269
+ value when it's not specified.
270
+ """
271
+
272
+ schema = get_schema("DequantizeLinear", 10, "")
273
+ op = Op(self, "DequantizeLinear", schema)
274
+ return op(*self._prepare_inputs(schema, x, x_scale, x_zero_point))
275
+
276
+ T_Dropout = TypeVar("T_Dropout", DOUBLE, FLOAT, FLOAT16)
277
+
278
+ T1_Dropout: TypeAlias = BOOL
279
+
280
+ def Dropout(self, data: T_Dropout, *, ratio: float = 0.5) -> Tuple[T_Dropout, T1_Dropout]:
281
+ r"""[🌐 Dropout(10)](https://onnx.ai/onnx/operators/onnx__Dropout.html#dropout-10 "Online Documentation")
282
+
283
+
284
+ Dropout takes one input floating tensor and produces two tensor outputs,
285
+ output (floating tensor) and mask (`Tensor<bool>`). Depending on whether it is
286
+ in test mode or not, the output Y will either be a random dropout, or a simple
287
+ copy of the input. Note that our implementation of Dropout does scaling in
288
+ the training phase, so during testing nothing needs to be done.
289
+ This operator has **optional** inputs/outputs. See `ONNX <https://github.com/onnx/onnx/blob/master/docs/IR.md>`_ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
290
+
291
+
292
+ Args:
293
+ data: The input data as Tensor.
294
+
295
+ ratio: The ratio of random dropout
296
+ """
297
+
298
+ schema = get_schema("Dropout", 10, "")
299
+ op = Op(self, "Dropout", schema)
300
+ return op(*self._prepare_inputs(schema, data), ratio=ratio)
301
+
302
+ T1_IsInf = TypeVar("T1_IsInf", DOUBLE, FLOAT)
303
+
304
+ T2_IsInf: TypeAlias = BOOL
305
+
306
+ def IsInf(
307
+ self, X: T1_IsInf, *, detect_negative: int = 1, detect_positive: int = 1
308
+ ) -> T2_IsInf:
309
+ r"""[🌐 IsInf(10)](https://onnx.ai/onnx/operators/onnx__IsInf.html#isinf-10 "Online Documentation")
310
+
311
+ Map infinity to true and other values to false.
312
+
313
+ Args:
314
+ X: (non-differentiable) input
315
+
316
+ detect_negative: (Optional) Whether map negative infinity to true. Default
317
+ to 1 so that negative infinity induces true. Set this attribute to 0 if
318
+ negative infinity should be mapped to false.
319
+
320
+ detect_positive: (Optional) Whether map positive infinity to true. Default
321
+ to 1 so that positive infinity induces true. Set this attribute to 0 if
322
+ positive infinity should be mapped to false.
323
+ """
324
+
325
+ schema = get_schema("IsInf", 10, "")
326
+ op = Op(self, "IsInf", schema)
327
+ return op(
328
+ *self._prepare_inputs(schema, X),
329
+ detect_negative=detect_negative,
330
+ detect_positive=detect_positive,
331
+ )
332
+
333
+ T1_MatMulInteger = TypeVar("T1_MatMulInteger", INT8, UINT8)
334
+
335
+ T2_MatMulInteger = TypeVar("T2_MatMulInteger", INT8, UINT8)
336
+
337
+ T3_MatMulInteger: TypeAlias = INT32
338
+
339
+ def MatMulInteger(
340
+ self,
341
+ A: T1_MatMulInteger,
342
+ B: T2_MatMulInteger,
343
+ a_zero_point: Optional[T1_MatMulInteger] = None,
344
+ b_zero_point: Optional[T2_MatMulInteger] = None,
345
+ ) -> T3_MatMulInteger:
346
+ r"""[🌐 MatMulInteger(10)](https://onnx.ai/onnx/operators/onnx__MatMulInteger.html#matmulinteger-10 "Online Documentation")
347
+
348
+
349
+ Matrix product that behaves like [numpy.matmul](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html).
350
+ The production MUST never overflow. The accumulation may overflow if and only if in 32 bits.
351
+
352
+
353
+ Args:
354
+ A: (non-differentiable) N-dimensional matrix A
355
+
356
+ B: (non-differentiable) N-dimensional matrix B
357
+
358
+ a_zero_point: (optional, non-differentiable) Zero point tensor for input
359
+ 'A'. It's optional and default value is 0. It could be a scalar or N-D
360
+ tensor. Scalar refers to per tensor quantization whereas N-D refers to
361
+ per row quantization. If the input is 2D of shape [M, K] then zero point
362
+ tensor may be an M element vector [zp_1, zp_2, ..., zp_M]. If the input
363
+ is N-D tensor with shape [D1, D2, M, K] then zero point tensor may have
364
+ shape [D1, D2, M, 1].
365
+
366
+ b_zero_point: (optional, non-differentiable) Zero point tensor for input
367
+ 'B'. It's optional and default value is 0. It could be a scalar or a N-D
368
+ tensor, Scalar refers to per tensor quantization whereas N-D refers to
369
+ per col quantization. If the input is 2D of shape [K, N] then zero point
370
+ tensor may be an N element vector [zp_1, zp_2, ..., zp_N]. If the input
371
+ is N-D tensor with shape [D1, D2, K, N] then zero point tensor may have
372
+ shape [D1, D2, 1, N].
373
+ """
374
+
375
+ schema = get_schema("MatMulInteger", 10, "")
376
+ op = Op(self, "MatMulInteger", schema)
377
+ return op(*self._prepare_inputs(schema, A, B, a_zero_point, b_zero_point))
378
+
379
+ T_MaxPool = TypeVar("T_MaxPool", DOUBLE, FLOAT, FLOAT16)
380
+
381
+ I_MaxPool: TypeAlias = INT64
382
+
383
+ def MaxPool(
384
+ self,
385
+ X: T_MaxPool,
386
+ *,
387
+ auto_pad: str = "NOTSET",
388
+ ceil_mode: int = 0,
389
+ dilations: Optional[Sequence[int]] = None,
390
+ kernel_shape: Sequence[int],
391
+ pads: Optional[Sequence[int]] = None,
392
+ storage_order: int = 0,
393
+ strides: Optional[Sequence[int]] = None,
394
+ ) -> Tuple[T_MaxPool, I_MaxPool]:
395
+ r"""[🌐 MaxPool(10)](https://onnx.ai/onnx/operators/onnx__MaxPool.html#maxpool-10 "Online Documentation")
396
+
397
+
398
+ MaxPool consumes an input tensor X and applies max pooling across
399
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
400
+ max pooling consisting of computing the max on all values of a
401
+ subset of the input tensor according to the kernel size and downsampling the
402
+ data into the output tensor Y for further processing. The output spatial shape will be following:
403
+ ```
404
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1)
405
+ ```
406
+ or
407
+ ```
408
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1)
409
+ ```
410
+ if ceil_mode is enabled
411
+
412
+ ```
413
+ * pad_shape[i] is sum of pads along axis i
414
+ ```
415
+
416
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
417
+ ```
418
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])
419
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
420
+ ```
421
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
422
+ ```
423
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]
424
+ ```
425
+ The output of each pooling window is maximum number of elements exclude pad.
426
+
427
+
428
+ Args:
429
+ X: Input data tensor from the previous operator; dimensions for image case
430
+ are (N x C x H x W), where N is the batch size, C is the number of
431
+ channels, and H and W are the height and the width of the data. For non
432
+ image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn),
433
+ where N is the batch size. Optionally, if dimension denotation is in
434
+ effect, the operation expects the input data tensor to arrive with the
435
+ dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE,
436
+ DATA_FEATURE ...].
437
+
438
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
439
+ Where default value is NOTSET, which means explicit padding is used.
440
+ SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial
441
+ size match the input.In case of odd number add the extra padding at the
442
+ end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no
443
+ padding.
444
+
445
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
446
+ shape.
447
+
448
+ dilations: Dilation value along each spatial axis of filter.
449
+
450
+ kernel_shape: The size of the kernel along each axis.
451
+
452
+ pads: Padding for the beginning and ending along each spatial axis, it can
453
+ take any value greater than or equal to 0. The value represent the
454
+ number of pixels added to the beginning and end part of the
455
+ corresponding axis. `pads` format should be as follow [x1_begin,
456
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
457
+ added at the beginning of axis `i` and xi_end, the number of pixels
458
+ added at the end of axis `i`. This attribute cannot be used
459
+ simultaneously with auto_pad attribute. If not present, the padding
460
+ defaults to 0 along start and end of each spatial axis.
461
+
462
+ storage_order: The storage order of the tensor. 0 is row major, and 1 is
463
+ column major.
464
+
465
+ strides: Stride along each spatial axis.
466
+ """
467
+
468
+ schema = get_schema("MaxPool", 10, "")
469
+ op = Op(self, "MaxPool", schema)
470
+ return op(
471
+ *self._prepare_inputs(schema, X),
472
+ auto_pad=auto_pad,
473
+ ceil_mode=ceil_mode,
474
+ dilations=dilations,
475
+ kernel_shape=kernel_shape,
476
+ pads=pads,
477
+ storage_order=storage_order,
478
+ strides=strides,
479
+ )
480
+
481
+ T_Mod = TypeVar(
482
+ "T_Mod",
483
+ DOUBLE,
484
+ FLOAT,
485
+ FLOAT16,
486
+ INT16,
487
+ INT32,
488
+ INT64,
489
+ INT8,
490
+ UINT16,
491
+ UINT32,
492
+ UINT64,
493
+ UINT8,
494
+ )
495
+
496
+ def Mod(self, A: T_Mod, B: T_Mod, *, fmod: int = 0) -> T_Mod:
497
+ r"""[🌐 Mod(10)](https://onnx.ai/onnx/operators/onnx__Mod.html#mod-10 "Online Documentation")
498
+
499
+
500
+ Performs element-wise binary modulus (with Numpy-style broadcasting support).
501
+ The sign of the remainder is the same as that of the Divisor.
502
+
503
+ Mod operator can also behave like C fmod() or numpy.fmod. In this case, the sign of the remainder however, will be the same as the Dividend
504
+ (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided.
505
+ This attribute is set to 0 by default causing the behavior to be like integer mod.
506
+ Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod().
507
+
508
+ If the input type is floating point, then `fmod` attribute must be set to 1.
509
+
510
+ In case of dividend being zero, the results will be platform dependent.
511
+
512
+ This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check `Broadcasting in ONNX <https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md>`_.
513
+
514
+
515
+ Args:
516
+ A: Dividend tensor
517
+
518
+ B: Divisor tensor
519
+
520
+ fmod: Whether the operator should behave like fmod (default=0 meaning it
521
+ will do integer mods); Set this to 1 to force fmod treatment
522
+ """
523
+
524
+ schema = get_schema("Mod", 10, "")
525
+ op = Op(self, "Mod", schema)
526
+ return op(*self._prepare_inputs(schema, A, B), fmod=fmod)
527
+
528
+ def NonMaxSuppression(
529
+ self,
530
+ boxes: FLOAT,
531
+ scores: FLOAT,
532
+ max_output_boxes_per_class: Optional[INT64] = None,
533
+ iou_threshold: Optional[FLOAT] = None,
534
+ score_threshold: Optional[FLOAT] = None,
535
+ *,
536
+ center_point_box: int = 0,
537
+ ) -> INT64:
538
+ r"""[🌐 NonMaxSuppression(10)](https://onnx.ai/onnx/operators/onnx__NonMaxSuppression.html#nonmaxsuppression-10 "Online Documentation")
539
+
540
+
541
+ Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.
542
+ Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.
543
+ Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to
544
+ orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system
545
+ result in the same boxes being selected by the algorithm.
546
+ The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes.
547
+ The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation.
548
+
549
+
550
+ Args:
551
+ boxes: An input tensor with shape [num_batches, spatial_dimension, 4]. The
552
+ single box data format is indicated by center_point_box.
553
+
554
+ scores: An input tensor with shape [num_batches, num_classes,
555
+ spatial_dimension]
556
+
557
+ max_output_boxes_per_class: (optional) Integer representing the maximum
558
+ number of boxes to be selected per batch per class. It is a scalar.
559
+ Default to 0, which means no output.
560
+
561
+ iou_threshold: (optional) Float representing the threshold for deciding
562
+ whether boxes overlap too much with respect to IOU. It is scalar. Value
563
+ range [0, 1]. Default to 0.
564
+
565
+ score_threshold: (optional) Float representing the threshold for deciding
566
+ when to remove boxes based on score. It is a scalar.
567
+
568
+ center_point_box: Integer indicate the format of the box data. The default
569
+ is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1)
570
+ and (y2, x2) are the coordinates of any diagonal pair of box corners and
571
+ the coordinates can be provided as normalized (i.e., lying in the
572
+ interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box
573
+ data is supplied as [x_center, y_center, width, height]. Mostly used for
574
+ Pytorch models.
575
+ """
576
+
577
+ schema = get_schema("NonMaxSuppression", 10, "")
578
+ op = Op(self, "NonMaxSuppression", schema)
579
+ return op(
580
+ *self._prepare_inputs(
581
+ schema,
582
+ boxes,
583
+ scores,
584
+ max_output_boxes_per_class,
585
+ iou_threshold,
586
+ score_threshold,
587
+ ),
588
+ center_point_box=center_point_box,
589
+ )
590
+
591
+ T1_QLinearConv = TypeVar("T1_QLinearConv", INT8, UINT8)
592
+
593
+ T2_QLinearConv = TypeVar("T2_QLinearConv", INT8, UINT8)
594
+
595
+ T3_QLinearConv = TypeVar("T3_QLinearConv", INT8, UINT8)
596
+
597
+ T4_QLinearConv: TypeAlias = INT32
598
+
599
+ def QLinearConv(
600
+ self,
601
+ x: T1_QLinearConv,
602
+ x_scale: FLOAT,
603
+ x_zero_point: T1_QLinearConv,
604
+ w: T2_QLinearConv,
605
+ w_scale: FLOAT,
606
+ w_zero_point: T2_QLinearConv,
607
+ y_scale: FLOAT,
608
+ y_zero_point: T3_QLinearConv,
609
+ B: Optional[T4_QLinearConv] = None,
610
+ *,
611
+ auto_pad: str = "NOTSET",
612
+ dilations: Optional[Sequence[int]] = None,
613
+ group: int = 1,
614
+ kernel_shape: Optional[Sequence[int]] = None,
615
+ pads: Optional[Sequence[int]] = None,
616
+ strides: Optional[Sequence[int]] = None,
617
+ ) -> T3_QLinearConv:
618
+ r"""[🌐 QLinearConv(10)](https://onnx.ai/onnx/operators/onnx__QLinearConv.html#qlinearconv-10 "Online Documentation")
619
+
620
+
621
+ The convolution operator consumes a quantized input tensor, its scale and zero point,
622
+ a quantized filter, its scale and zero point, and output's scale and zero point,
623
+ and computes the quantized output. Each scale and zero-point pair must have same shape.
624
+ It means they must be either scalars (per tensor) or 1-D tensors (per output channel).
625
+ Each input or output and its related zero point must have same type.
626
+ When bias is present it must be quantized using scale = input scale * weight scale and
627
+ zero point as 0.
628
+
629
+
630
+ Args:
631
+ x: Input data tensor from previous layer; has size (N x C x H x W), where N
632
+ is the batch size, C is the number of channels, and H and W are the
633
+ height and width. Note that this is for the 2D image. Otherwise the size
634
+ is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in
635
+ effect, the operation expects input data tensor to arrive with the
636
+ dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE,
637
+ DATA_FEATURE ...].
638
+
639
+ x_scale: Scale tensor for input 'x'. It's a scalar, which means a
640
+ per-tensor/layer quantization.
641
+
642
+ x_zero_point: Zero point tensor for input 'x'. It's a scalar, which means a
643
+ per-tensor/layer quantization.
644
+
645
+ w: The weight tensor that will be used in the convolutions; has size (M x
646
+ C/group x kH x kW), where C is the number of channels, and kH and kW are
647
+ the height and width of the kernel, and M is the number of feature maps.
648
+ For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x
649
+ k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel.
650
+ Optionally, if dimension denotation is in effect, the operation expects
651
+ the weight tensor to arrive with the dimension denotation of
652
+ [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL
653
+ ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based
654
+ indices for the shape array). Or in other words FILTER_IN_CHANNEL should
655
+ be equal to DATA_CHANNEL.
656
+
657
+ w_scale: Scale tensor for input 'w'. It could be a scalar or a 1-D tensor,
658
+ which means a per-tensor/layer or per output channel quantization. If
659
+ it's a 1-D tensor, its number of elements should be equal to the number
660
+ of output channels (M).
661
+
662
+ w_zero_point: Zero point tensor for input 'w'. It could be a scalar or a 1-D
663
+ tensor, which means a per-tensor/layer or per output channel
664
+ quantization. If it's a 1-D tensor, its number of elements should be
665
+ equal to the number of output channels (M).
666
+
667
+ y_scale: Scale tensor for output 'y'. It's a scalar, which means a
668
+ per-tensor/layer quantization.
669
+
670
+ y_zero_point: Zero point tensor for output 'y'. It's a scalar, which means a
671
+ per-tensor/layer quantization.
672
+
673
+ B: (optional) Optional 1D bias to be added to the convolution, has size of
674
+ M. Bias must be quantized using scale = x_scale * w_scale and zero_point
675
+ = 0
676
+
677
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
678
+ Where default value is NOTSET, which means explicit padding is used.
679
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
680
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
681
+ split between the two sides equally or almost equally (depending on
682
+ whether it is even or odd). In case the padding is an odd number, the
683
+ extra padding is added at the end for SAME_UPPER and at the beginning
684
+ for SAME_LOWER.
685
+
686
+ dilations: dilation value along each spatial axis of the filter. If not
687
+ present, the dilation defaults to 1 along each spatial axis.
688
+
689
+ group: number of groups input channels and output channels are divided into.
690
+ default is 1.
691
+
692
+ kernel_shape: The shape of the convolution kernel. If not present, should be
693
+ inferred from input 'w'.
694
+
695
+ pads: Padding for the beginning and ending along each spatial axis, it can
696
+ take any value greater than or equal to 0.The value represent the number
697
+ of pixels added to the beginning and end part of the corresponding
698
+ axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end,
699
+ x2_end,...], where xi_begin the number ofpixels added at the beginning
700
+ of axis `i` and xi_end, the number of pixels added at the end of axis
701
+ `i`.This attribute cannot be used simultaneously with auto_pad
702
+ attribute. If not present, the padding defaultsto 0 along start and end
703
+ of each spatial axis.
704
+
705
+ strides: Stride along each spatial axis. If not present, the stride defaults
706
+ to 1 along each spatial axis.
707
+ """
708
+
709
+ schema = get_schema("QLinearConv", 10, "")
710
+ op = Op(self, "QLinearConv", schema)
711
+ return op(
712
+ *self._prepare_inputs(
713
+ schema,
714
+ x,
715
+ x_scale,
716
+ x_zero_point,
717
+ w,
718
+ w_scale,
719
+ w_zero_point,
720
+ y_scale,
721
+ y_zero_point,
722
+ B,
723
+ ),
724
+ auto_pad=auto_pad,
725
+ dilations=dilations,
726
+ group=group,
727
+ kernel_shape=kernel_shape,
728
+ pads=pads,
729
+ strides=strides,
730
+ )
731
+
732
+ T1_QLinearMatMul = TypeVar("T1_QLinearMatMul", INT8, UINT8)
733
+
734
+ T2_QLinearMatMul = TypeVar("T2_QLinearMatMul", INT8, UINT8)
735
+
736
+ T3_QLinearMatMul = TypeVar("T3_QLinearMatMul", INT8, UINT8)
737
+
738
+ def QLinearMatMul(
739
+ self,
740
+ a: T1_QLinearMatMul,
741
+ a_scale: FLOAT,
742
+ a_zero_point: T1_QLinearMatMul,
743
+ b: T2_QLinearMatMul,
744
+ b_scale: FLOAT,
745
+ b_zero_point: T2_QLinearMatMul,
746
+ y_scale: FLOAT,
747
+ y_zero_point: T3_QLinearMatMul,
748
+ ) -> T3_QLinearMatMul:
749
+ r"""[🌐 QLinearMatMul(10)](https://onnx.ai/onnx/operators/onnx__QLinearMatMul.html#qlinearmatmul-10 "Online Documentation")
750
+
751
+
752
+ Matrix product that behaves like [numpy.matmul](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html).
753
+ It consumes two quantized input tensors, their scales and zero points, scale and zero point of output,
754
+ and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point).
755
+ For (x / y_scale), it is rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details.
756
+ Scale and zero point must have same shape. They must be either scalar (per tensor) or N-D tensor
757
+ (per row for 'a' and per column for 'b'). Scalar refers to per tensor quantization whereas N-D refers to per row
758
+ or per column quantization. If the input is 2D of shape [M, K] then zero point and scale tensor may be
759
+ an M element vector [v_1, v_2, ..., v_M] for per row quantization and K element vector of shape [v_1, v_2, ..., v_K]
760
+ for per column quantization. If the input is N-D tensor with shape [D1, D2, M, K] then zero point and scale tensor may
761
+ have shape [D1, D2, M, 1] for per row quantization and shape [D1, D2, 1, K] for per column quantization.
762
+ Production must never overflow, and accumulation may overflow if and only if in 32 bits.
763
+
764
+
765
+ Args:
766
+ a: (non-differentiable) N-dimensional quantized matrix a
767
+
768
+ a_scale: (non-differentiable) scale of quantized input a
769
+
770
+ a_zero_point: (non-differentiable) zero point of quantized input a
771
+
772
+ b: (non-differentiable) N-dimensional quantized matrix b
773
+
774
+ b_scale: (non-differentiable) scale of quantized input b
775
+
776
+ b_zero_point: (non-differentiable) zero point of quantized input b
777
+
778
+ y_scale: (non-differentiable) scale of quantized output y
779
+
780
+ y_zero_point: (non-differentiable) zero point of quantized output y
781
+ """
782
+
783
+ schema = get_schema("QLinearMatMul", 10, "")
784
+ op = Op(self, "QLinearMatMul", schema)
785
+ return op(
786
+ *self._prepare_inputs(
787
+ schema,
788
+ a,
789
+ a_scale,
790
+ a_zero_point,
791
+ b,
792
+ b_scale,
793
+ b_zero_point,
794
+ y_scale,
795
+ y_zero_point,
796
+ )
797
+ )
798
+
799
+ T1_QuantizeLinear = TypeVar("T1_QuantizeLinear", FLOAT, INT32)
800
+
801
+ T2_QuantizeLinear = TypeVar("T2_QuantizeLinear", INT8, UINT8)
802
+
803
+ def QuantizeLinear(
804
+ self,
805
+ x: T1_QuantizeLinear,
806
+ y_scale: FLOAT,
807
+ y_zero_point: Optional[T2_QuantizeLinear] = None,
808
+ ) -> T2_QuantizeLinear:
809
+ r"""[🌐 QuantizeLinear(10)](https://onnx.ai/onnx/operators/onnx__QuantizeLinear.html#quantizelinear-10 "Online Documentation")
810
+
811
+
812
+ The linear per-tensor/layer quantization operator. It consumes a high precision tensor, a scale, a zero point to compute the low precision / quantized tensor.
813
+ The quantization formula is y = saturate ((x / y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8.
814
+ For (x / y_scale), it's rounding to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and 'y' must have same type.
815
+
816
+
817
+ Args:
818
+ x: N-D full precision Input tensor to be quantized.
819
+
820
+ y_scale: Scale for doing quantization to get 'y'. It's a scalar, which means
821
+ a per-tensor/layer quantization.
822
+
823
+ y_zero_point: (optional) Zero point for doing quantization to get 'y'. It's
824
+ a scalar, which means a per-tensor/layer quantization. Default value is
825
+ uint8 typed 0 if it's not specified.
826
+ """
827
+
828
+ schema = get_schema("QuantizeLinear", 10, "")
829
+ op = Op(self, "QuantizeLinear", schema)
830
+ return op(*self._prepare_inputs(schema, x, y_scale, y_zero_point))
831
+
832
+ T_Resize = TypeVar(
833
+ "T_Resize",
834
+ BOOL,
835
+ COMPLEX128,
836
+ COMPLEX64,
837
+ DOUBLE,
838
+ FLOAT,
839
+ FLOAT16,
840
+ INT16,
841
+ INT32,
842
+ INT64,
843
+ INT8,
844
+ STRING,
845
+ UINT16,
846
+ UINT32,
847
+ UINT64,
848
+ UINT8,
849
+ )
850
+
851
+ def Resize(self, X: T_Resize, scales: FLOAT, *, mode: str = "nearest") -> T_Resize:
852
+ r"""[🌐 Resize(10)](https://onnx.ai/onnx/operators/onnx__Resize.html#resize-10 "Online Documentation")
853
+
854
+
855
+ Resize the input tensor.
856
+ Each dimension value of the output tensor is:
857
+ output_dimension = floor(input_dimension * scale).
858
+
859
+
860
+ Args:
861
+ X: N-D tensor
862
+
863
+ scales: The scale array along each dimension. It takes value greater than 0.
864
+ If it's less than 1, it's sampling down, otherwise, it's upsampling. The
865
+ number of elements of 'scales' should be the same as the rank of input
866
+ 'X'.
867
+
868
+ mode: Two interpolation modes: nearest (default), and linear (including
869
+ bilinear, trilinear, etc)
870
+ """
871
+
872
+ schema = get_schema("Resize", 10, "")
873
+ op = Op(self, "Resize", schema)
874
+ return op(*self._prepare_inputs(schema, X, scales), mode=mode)
875
+
876
+ T_ReverseSequence = TypeVar(
877
+ "T_ReverseSequence",
878
+ BOOL,
879
+ COMPLEX128,
880
+ COMPLEX64,
881
+ DOUBLE,
882
+ FLOAT,
883
+ FLOAT16,
884
+ INT16,
885
+ INT32,
886
+ INT64,
887
+ INT8,
888
+ STRING,
889
+ UINT16,
890
+ UINT32,
891
+ UINT64,
892
+ UINT8,
893
+ )
894
+
895
+ def ReverseSequence(
896
+ self,
897
+ input: T_ReverseSequence,
898
+ sequence_lens: INT64,
899
+ *,
900
+ batch_axis: int = 1,
901
+ time_axis: int = 0,
902
+ ) -> T_ReverseSequence:
903
+ r"""[🌐 ReverseSequence(10)](https://onnx.ai/onnx/operators/onnx__ReverseSequence.html#reversesequence-10 "Online Documentation")
904
+
905
+
906
+ Reverse batch of sequences having different lengths specified by `sequence_lens`.
907
+
908
+ For each slice i iterating on batch axis, the operator reverses the first sequence_lens[i] elements on time axis,
909
+ and copies elements whose index's beyond sequence_lens[i] to the output. So the output slice i contains reversed
910
+ sequences on the first sequence_lens[i] elements, then have original values copied for the other elements.
911
+
912
+ Example 1:
913
+ input = [[0.0, 4.0, 8.0, 12.0],
914
+ [1.0, 5.0, 9.0, 13.0],
915
+ [2.0, 6.0, 10.0, 14.0],
916
+ [3.0, 7.0, 11.0, 15.0]]
917
+ sequence_lens = [4, 3, 2, 1]
918
+ time_axis = 0
919
+ batch_axis = 1
920
+
921
+ output = [[3.0, 6.0, 9.0, 12.0],
922
+ [2.0, 5.0, 8.0, 13.0],
923
+ [1.0, 4.0, 10.0, 14.0],
924
+ [0.0, 7.0, 11.0, 15.0]]
925
+
926
+ Example 2:
927
+ input = [[0.0, 1.0, 2.0, 3.0 ],
928
+ [4.0, 5.0, 6.0, 7.0 ],
929
+ [8.0, 9.0, 10.0, 11.0],
930
+ [12.0, 13.0, 14.0, 15.0]]
931
+ sequence_lens = [1, 2, 3, 4]
932
+ time_axis = 1
933
+ batch_axis = 0
934
+
935
+ output = [[0.0, 1.0, 2.0, 3.0 ],
936
+ [5.0, 4.0, 6.0, 7.0 ],
937
+ [10.0, 9.0, 8.0, 11.0],
938
+ [15.0, 14.0, 13.0, 12.0]]
939
+
940
+
941
+ Args:
942
+ input: Tensor of rank r >= 2.
943
+
944
+ sequence_lens: Tensor specifying lengths of the sequences in a batch. It has
945
+ shape `[batch_size]`.
946
+
947
+ batch_axis: (Optional) Specify which axis is batch axis. Must be one of 1
948
+ (default), or 0.
949
+
950
+ time_axis: (Optional) Specify which axis is time axis. Must be one of 0
951
+ (default), or 1.
952
+ """
953
+
954
+ schema = get_schema("ReverseSequence", 10, "")
955
+ op = Op(self, "ReverseSequence", schema)
956
+ return op(
957
+ *self._prepare_inputs(schema, input, sequence_lens),
958
+ batch_axis=batch_axis,
959
+ time_axis=time_axis,
960
+ )
961
+
962
+ T1_RoiAlign = TypeVar("T1_RoiAlign", DOUBLE, FLOAT, FLOAT16)
963
+
964
+ T2_RoiAlign: TypeAlias = INT64
965
+
966
+ def RoiAlign(
967
+ self,
968
+ X: T1_RoiAlign,
969
+ rois: T1_RoiAlign,
970
+ batch_indices: T2_RoiAlign,
971
+ *,
972
+ mode: str = "avg",
973
+ output_height: int = 1,
974
+ output_width: int = 1,
975
+ sampling_ratio: int = 0,
976
+ spatial_scale: float = 1.0,
977
+ ) -> T1_RoiAlign:
978
+ r"""[🌐 RoiAlign(10)](https://onnx.ai/onnx/operators/onnx__RoiAlign.html#roialign-10 "Online Documentation")
979
+
980
+
981
+ Region of Interest (RoI) align operation described in the
982
+ [Mask R-CNN paper](https://arxiv.org/abs/1703.06870).
983
+ RoiAlign consumes an input tensor X and region of interests (rois)
984
+ to apply pooling across each RoI; it produces a 4-D tensor of shape
985
+ (num_rois, C, output_height, output_width).
986
+
987
+ RoiAlign is proposed to avoid the misalignment by removing
988
+ quantizations while converting from original image into feature
989
+ map and from feature map into RoI feature; in each ROI bin,
990
+ the value of the sampled locations are computed directly
991
+ through bilinear interpolation.
992
+
993
+
994
+ Args:
995
+ X: Input data tensor from the previous operator; 4-D feature map of shape
996
+ (N, C, H, W), where N is the batch size, C is the number of channels,
997
+ and H and W are the height and the width of the data.
998
+
999
+ rois: RoIs (Regions of Interest) to pool over; rois is 2-D input of shape
1000
+ (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates
1001
+ are in the coordinate system of the input image. Each coordinate set has
1002
+ a 1:1 correspondence with the 'batch_indices' input.
1003
+
1004
+ batch_indices: 1-D tensor of shape (num_rois,) with each element denoting
1005
+ the index of the corresponding image in the batch.
1006
+
1007
+ mode: The pooling method. Two modes are supported: 'avg' and 'max'. Default
1008
+ is 'avg'.
1009
+
1010
+ output_height: default 1; Pooled output Y's height.
1011
+
1012
+ output_width: default 1; Pooled output Y's width.
1013
+
1014
+ sampling_ratio: Number of sampling points in the interpolation grid used to
1015
+ compute the output value of each pooled output bin. If > 0, then exactly
1016
+ sampling_ratio x sampling_ratio grid points are used. If == 0, then an
1017
+ adaptive number of grid points are used (computed as ceil(roi_width /
1018
+ output_width), and likewise for height). Default is 0.
1019
+
1020
+ spatial_scale: Multiplicative spatial scale factor to translate ROI
1021
+ coordinates from their input spatial scale to the scale used when
1022
+ pooling, i.e., spatial scale of the input feature map X relative to the
1023
+ input image. E.g.; default is 1.0f.
1024
+ """
1025
+
1026
+ schema = get_schema("RoiAlign", 10, "")
1027
+ op = Op(self, "RoiAlign", schema)
1028
+ return op(
1029
+ *self._prepare_inputs(schema, X, rois, batch_indices),
1030
+ mode=mode,
1031
+ output_height=output_height,
1032
+ output_width=output_width,
1033
+ sampling_ratio=sampling_ratio,
1034
+ spatial_scale=spatial_scale,
1035
+ )
1036
+
1037
+ T_Slice = TypeVar(
1038
+ "T_Slice",
1039
+ BOOL,
1040
+ COMPLEX128,
1041
+ COMPLEX64,
1042
+ DOUBLE,
1043
+ FLOAT,
1044
+ FLOAT16,
1045
+ INT16,
1046
+ INT32,
1047
+ INT64,
1048
+ INT8,
1049
+ STRING,
1050
+ UINT16,
1051
+ UINT32,
1052
+ UINT64,
1053
+ UINT8,
1054
+ )
1055
+
1056
+ Tind_Slice = TypeVar("Tind_Slice", INT32, INT64)
1057
+
1058
+ def Slice(
1059
+ self,
1060
+ data: T_Slice,
1061
+ starts: Tind_Slice,
1062
+ ends: Tind_Slice,
1063
+ axes: Optional[Tind_Slice] = None,
1064
+ steps: Optional[Tind_Slice] = None,
1065
+ ) -> T_Slice:
1066
+ r"""[🌐 Slice(10)](https://onnx.ai/onnx/operators/onnx__Slice.html#slice-10 "Online Documentation")
1067
+
1068
+
1069
+ Produces a slice of the input tensor along multiple axes. Similar to numpy:
1070
+ https://numpy.org/doc/stable/reference/routines.indexing.html
1071
+ Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end
1072
+ dimension and step for each axis in the list of axes, it uses this information to
1073
+ slice the input `data` tensor. If a negative value is passed for any of the
1074
+ start or end indices, it represent number of elements before the end of that
1075
+ dimension. If the value passed to start or end is larger than the `n` (the
1076
+ number of elements in this dimension), it represents `n`. For slicing to the
1077
+ end of a dimension with unknown size, it is recommended to pass in `INT_MAX`.
1078
+ If a negative value is passed for step, it represents slicing backward.
1079
+ If `axes` are omitted, they are set to `[0, ..., ndim-1]`.
1080
+ If `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)`
1081
+ Example 1:
1082
+ data = [
1083
+ [1, 2, 3, 4],
1084
+ [5, 6, 7, 8],
1085
+ ]
1086
+ axes = [0, 1]
1087
+ starts = [1, 0]
1088
+ ends = [2, 3]
1089
+ steps = [1, 2]
1090
+ result = [
1091
+ [5, 7],
1092
+ ]
1093
+ Example 2:
1094
+ data = [
1095
+ [1, 2, 3, 4],
1096
+ [5, 6, 7, 8],
1097
+ ]
1098
+ starts = [0, 1]
1099
+ ends = [-1, 1000]
1100
+ result = [
1101
+ [2, 3, 4],
1102
+ ]
1103
+
1104
+
1105
+ Args:
1106
+ data: Tensor of data to extract slices from.
1107
+
1108
+ starts: 1-D tensor of starting indices of corresponding axis in `axes`
1109
+
1110
+ ends: 1-D tensor of ending indices (exclusive) of corresponding axis in
1111
+ `axes`
1112
+
1113
+ axes: (optional) 1-D tensor of axes that `starts` and `ends` apply to.
1114
+
1115
+ steps: (optional) 1-D tensor of slice step of corresponding axis in `axes`.
1116
+ Default to 1.
1117
+ """
1118
+
1119
+ schema = get_schema("Slice", 10, "")
1120
+ op = Op(self, "Slice", schema)
1121
+ return op(*self._prepare_inputs(schema, data, starts, ends, axes, steps))
1122
+
1123
+ def StringNormalizer(
1124
+ self,
1125
+ X: STRING,
1126
+ *,
1127
+ case_change_action: str = "NONE",
1128
+ is_case_sensitive: int = 0,
1129
+ locale: Optional[str] = None,
1130
+ stopwords: Optional[Sequence[str]] = None,
1131
+ ) -> STRING:
1132
+ r"""[🌐 StringNormalizer(10)](https://onnx.ai/onnx/operators/onnx__StringNormalizer.html#stringnormalizer-10 "Online Documentation")
1133
+
1134
+
1135
+ StringNormalization performs string operations for basic cleaning.
1136
+ This operator has only one input (denoted by X) and only one output
1137
+ (denoted by Y). This operator first examines the elements in the X,
1138
+ and removes elements specified in "stopwords" attribute.
1139
+ After removing stop words, the intermediate result can be further lowercased,
1140
+ uppercased, or just returned depending the "case_change_action" attribute.
1141
+ This operator only accepts [C]- and [1, C]-tensor.
1142
+ If all elements in X are dropped, the output will be the empty value of string tensor with shape [1]
1143
+ if input shape is [C] and shape [1, 1] if input shape is [1, C].
1144
+
1145
+
1146
+ Args:
1147
+ X: UTF-8 strings to normalize
1148
+
1149
+ case_change_action: string enum that cases output to be
1150
+ lowercased/uppercases/unchanged. Valid values are "LOWER", "UPPER",
1151
+ "NONE". Default is "NONE"
1152
+
1153
+ is_case_sensitive: Boolean. Whether the identification of stop words in X is
1154
+ case-sensitive. Default is false
1155
+
1156
+ locale: Environment dependent string that denotes the locale according to
1157
+ which output strings needs to be upper/lowercased.Default en_US or
1158
+ platform specific equivalent as decided by the implementation.
1159
+
1160
+ stopwords: List of stop words. If not set, no word would be removed from X.
1161
+ """
1162
+
1163
+ schema = get_schema("StringNormalizer", 10, "")
1164
+ op = Op(self, "StringNormalizer", schema)
1165
+ return op(
1166
+ *self._prepare_inputs(schema, X),
1167
+ case_change_action=case_change_action,
1168
+ is_case_sensitive=is_case_sensitive,
1169
+ locale=locale,
1170
+ stopwords=stopwords,
1171
+ )
1172
+
1173
+ T_ThresholdedRelu = TypeVar("T_ThresholdedRelu", DOUBLE, FLOAT, FLOAT16)
1174
+
1175
+ def ThresholdedRelu(
1176
+ self, X: T_ThresholdedRelu, *, alpha: float = 1.0
1177
+ ) -> T_ThresholdedRelu:
1178
+ r"""[🌐 ThresholdedRelu(10)](https://onnx.ai/onnx/operators/onnx__ThresholdedRelu.html#thresholdedrelu-10 "Online Documentation")
1179
+
1180
+
1181
+ ThresholdedRelu takes one input data (Tensor<T>) and produces one output data
1182
+ (Tensor<T>) where the rectified linear function, y = x for x > alpha, y = 0 otherwise,
1183
+ is applied to the tensor elementwise.
1184
+
1185
+
1186
+ Args:
1187
+ X: (differentiable) Input tensor
1188
+
1189
+ alpha: Threshold value
1190
+ """
1191
+
1192
+ schema = get_schema("ThresholdedRelu", 10, "")
1193
+ op = Op(self, "ThresholdedRelu", schema)
1194
+ return op(*self._prepare_inputs(schema, X), alpha=alpha)
1195
+
1196
+ T_TopK = TypeVar("T_TopK", DOUBLE, FLOAT, FLOAT16)
1197
+
1198
+ I_TopK: TypeAlias = INT64
1199
+
1200
+ def TopK(self, X: T_TopK, K: INT64, *, axis: int = -1) -> Tuple[T_TopK, I_TopK]:
1201
+ r"""[🌐 TopK(10)](https://onnx.ai/onnx/operators/onnx__TopK.html#topk-10 "Online Documentation")
1202
+
1203
+
1204
+ Retrieve the top-K elements along a specified axis. Given an input tensor of
1205
+ shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
1206
+ -Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
1207
+ which contains the values of the top k elements along the specified axis
1208
+ -Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
1209
+ contains the indices of the top k elements (original indices from the input
1210
+ tensor).
1211
+
1212
+ Given two equivalent values, this operator uses the indices along the axis as
1213
+ a tiebreaker. That is, the element with the lower index will appear first.
1214
+
1215
+
1216
+ Args:
1217
+ X: Tensor of shape [a_0, a_1, ..., a_{n-1}]
1218
+
1219
+ K: A 1-D tensor containing a single positive value corresponding to the
1220
+ number of top elements to retrieve
1221
+
1222
+ axis: Dimension on which to do the sort.
1223
+ """
1224
+
1225
+ schema = get_schema("TopK", 10, "")
1226
+ op = Op(self, "TopK", schema)
1227
+ return op(*self._prepare_inputs(schema, X, K), axis=axis)