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,1803 @@
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.opset17 import Opset17
22
+ from onnxscript.onnx_types import (
23
+ BFLOAT16,
24
+ BOOL,
25
+ COMPLEX64,
26
+ COMPLEX128,
27
+ DOUBLE,
28
+ FLOAT,
29
+ FLOAT16,
30
+ INT8,
31
+ INT16,
32
+ INT32,
33
+ INT64,
34
+ STRING,
35
+ UINT8,
36
+ UINT16,
37
+ UINT32,
38
+ UINT64,
39
+ )
40
+ from onnxscript.values import Op, Opset
41
+
42
+
43
+ class Opset18(Opset17):
44
+ def __new__(cls):
45
+ return Opset.__new__(cls, "", 18)
46
+
47
+ T_BitwiseAnd = TypeVar(
48
+ "T_BitwiseAnd", INT16, INT32, INT64, INT8, UINT16, UINT32, UINT64, UINT8
49
+ )
50
+
51
+ def BitwiseAnd(self, A: T_BitwiseAnd, B: T_BitwiseAnd) -> T_BitwiseAnd:
52
+ r"""[🌐 BitwiseAnd(18)](https://onnx.ai/onnx/operators/onnx__BitwiseAnd.html#bitwiseand-18 "Online Documentation")
53
+
54
+
55
+ Returns the tensor resulting from performing the bitwise `and` operation
56
+ elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).
57
+
58
+ 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>`_.
59
+
60
+
61
+ Args:
62
+ A: (non-differentiable) First input operand for the bitwise operator.
63
+
64
+ B: (non-differentiable) Second input operand for the bitwise operator.
65
+ """
66
+
67
+ schema = get_schema("BitwiseAnd", 18, "")
68
+ op = Op(self, "BitwiseAnd", schema)
69
+ return op(*self._prepare_inputs(schema, A, B))
70
+
71
+ T_BitwiseNot = TypeVar(
72
+ "T_BitwiseNot", INT16, INT32, INT64, INT8, UINT16, UINT32, UINT64, UINT8
73
+ )
74
+
75
+ def BitwiseNot(self, X: T_BitwiseNot) -> T_BitwiseNot:
76
+ r"""[🌐 BitwiseNot(18)](https://onnx.ai/onnx/operators/onnx__BitwiseNot.html#bitwisenot-18 "Online Documentation")
77
+
78
+
79
+ Returns the bitwise not of the input tensor element-wise.
80
+
81
+
82
+ Args:
83
+ X: (non-differentiable) Input tensor
84
+ """
85
+
86
+ schema = get_schema("BitwiseNot", 18, "")
87
+ op = Op(self, "BitwiseNot", schema)
88
+ return op(*self._prepare_inputs(schema, X))
89
+
90
+ T_BitwiseOr = TypeVar(
91
+ "T_BitwiseOr", INT16, INT32, INT64, INT8, UINT16, UINT32, UINT64, UINT8
92
+ )
93
+
94
+ def BitwiseOr(self, A: T_BitwiseOr, B: T_BitwiseOr) -> T_BitwiseOr:
95
+ r"""[🌐 BitwiseOr(18)](https://onnx.ai/onnx/operators/onnx__BitwiseOr.html#bitwiseor-18 "Online Documentation")
96
+
97
+
98
+ Returns the tensor resulting from performing the bitwise `or` operation
99
+ elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).
100
+
101
+ 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>`_.
102
+
103
+
104
+ Args:
105
+ A: (non-differentiable) First input operand for the bitwise operator.
106
+
107
+ B: (non-differentiable) Second input operand for the bitwise operator.
108
+ """
109
+
110
+ schema = get_schema("BitwiseOr", 18, "")
111
+ op = Op(self, "BitwiseOr", schema)
112
+ return op(*self._prepare_inputs(schema, A, B))
113
+
114
+ T_BitwiseXor = TypeVar(
115
+ "T_BitwiseXor", INT16, INT32, INT64, INT8, UINT16, UINT32, UINT64, UINT8
116
+ )
117
+
118
+ def BitwiseXor(self, A: T_BitwiseXor, B: T_BitwiseXor) -> T_BitwiseXor:
119
+ r"""[🌐 BitwiseXor(18)](https://onnx.ai/onnx/operators/onnx__BitwiseXor.html#bitwisexor-18 "Online Documentation")
120
+
121
+
122
+ Returns the tensor resulting from performing the bitwise `xor` operation
123
+ elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).
124
+
125
+ 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>`_.
126
+
127
+
128
+ Args:
129
+ A: (non-differentiable) First input operand for the bitwise operator.
130
+
131
+ B: (non-differentiable) Second input operand for the bitwise operator.
132
+ """
133
+
134
+ schema = get_schema("BitwiseXor", 18, "")
135
+ op = Op(self, "BitwiseXor", schema)
136
+ return op(*self._prepare_inputs(schema, A, B))
137
+
138
+ T_CenterCropPad = TypeVar(
139
+ "T_CenterCropPad",
140
+ BFLOAT16,
141
+ BOOL,
142
+ COMPLEX128,
143
+ COMPLEX64,
144
+ DOUBLE,
145
+ FLOAT,
146
+ FLOAT16,
147
+ INT16,
148
+ INT32,
149
+ INT64,
150
+ INT8,
151
+ STRING,
152
+ UINT16,
153
+ UINT32,
154
+ UINT64,
155
+ UINT8,
156
+ )
157
+
158
+ Tind_CenterCropPad = TypeVar("Tind_CenterCropPad", INT32, INT64)
159
+
160
+ def CenterCropPad(
161
+ self,
162
+ input_data: T_CenterCropPad,
163
+ shape: Tind_CenterCropPad,
164
+ *,
165
+ axes: Optional[Sequence[int]] = None,
166
+ ) -> T_CenterCropPad:
167
+ r"""[🌐 CenterCropPad(18)](https://onnx.ai/onnx/operators/onnx__CenterCropPad.html#centercroppad-18 "Online Documentation")
168
+
169
+
170
+ Center crop or pad an input to given dimensions.
171
+
172
+ The crop/pad dimensions can be specified for a subset of the `axes`. Non-specified dimensions will not be
173
+ cropped or padded.
174
+
175
+ If the input dimensions are bigger than the crop shape, a centered cropping window is extracted from the input.
176
+ If the input dimensions are smaller than the crop shape, the input is padded on each side equally,
177
+ so that the input is centered in the output.
178
+
179
+
180
+ Args:
181
+ input_data: (differentiable) Input to extract the centered crop from.
182
+
183
+ shape: (non-differentiable) 1-D tensor representing the cropping window
184
+ dimensions.
185
+
186
+ axes: If provided, it specifies a subset of axes that 'shape' refer to. If
187
+ not provided, all axes are assumed [0, 1, ..., r-1], where r =
188
+ rank(data). Negative value means counting dimensions from the back.
189
+ Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined
190
+ if an axis is repeated.
191
+ """
192
+
193
+ schema = get_schema("CenterCropPad", 18, "")
194
+ op = Op(self, "CenterCropPad", schema)
195
+ return op(*self._prepare_inputs(schema, input_data, shape), axes=axes)
196
+
197
+ T_Col2Im = TypeVar(
198
+ "T_Col2Im",
199
+ BFLOAT16,
200
+ BOOL,
201
+ COMPLEX128,
202
+ COMPLEX64,
203
+ DOUBLE,
204
+ FLOAT,
205
+ FLOAT16,
206
+ INT16,
207
+ INT32,
208
+ INT64,
209
+ INT8,
210
+ STRING,
211
+ UINT16,
212
+ UINT32,
213
+ UINT64,
214
+ UINT8,
215
+ )
216
+
217
+ def Col2Im(
218
+ self,
219
+ input: T_Col2Im,
220
+ image_shape: INT64,
221
+ block_shape: INT64,
222
+ *,
223
+ dilations: Optional[Sequence[int]] = None,
224
+ pads: Optional[Sequence[int]] = None,
225
+ strides: Optional[Sequence[int]] = None,
226
+ ) -> T_Col2Im:
227
+ r"""[🌐 Col2Im(18)](https://onnx.ai/onnx/operators/onnx__Col2Im.html#col2im-18 "Online Documentation")
228
+
229
+
230
+ The operator rearranges column blocks back into a multidimensional image
231
+
232
+ Col2Im behaves similarly to PyTorch's fold https://pytorch.org/docs/stable/generated/torch.nn.Fold.html,
233
+ but it only supports *batched* multi-dimensional image tensors.
234
+ Another implementation in Python with N-dimension support can be found at https://github.com/f-dangel/unfoldNd/.
235
+
236
+ NOTE:
237
+ Although specifying image_shape looks redundant because it could be calculated from
238
+ convolution formulas, it is required as input for more advanced scenarios as explained
239
+ at PyTorch's implementation (https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10)
240
+
241
+
242
+ Args:
243
+ input: (differentiable) Input data tensor to be rearranged from column
244
+ blocks back into an image. This is a 3-dimensional tensor containing [N,
245
+ C * n-ary-product(block_shape), L], where N is batch dimension, C is
246
+ image channel dimension and L is number of blocks.The blocks are
247
+ enumerated in increasing lexicographic-order of their indices.For
248
+ example, with an image-size 10*20 and block-size 9*18, there would be
249
+ 2*3 blocks, enumerated in the order block(0, 0), block(0, 1), block(0,
250
+ 2), block(1, 0), block(1, 1), block(1, 2).
251
+
252
+ image_shape: (non-differentiable) The shape of the spatial dimensions of the
253
+ image after rearranging the column blocks.This is a 1-dimensional tensor
254
+ with size of at least 2, containing the value [H_img, W_img] for a 2-D
255
+ image or [dim_i1, dim_i2, ..., dim_iN] for a N-D image.
256
+
257
+ block_shape: (non-differentiable) The shape of the block to apply on the
258
+ input.This is a 1-dimensional tensor of size of at least 2, containing
259
+ the value [H_block, W_block] for a 2-D image or [dim_b1, dim_b2, ...,
260
+ dim_bN] for a N-D block.This is the block-shape before dilation is
261
+ applied to it.
262
+
263
+ dilations: 1-dimensional tensor with dilation value along each spatial axis
264
+ of the image. If not present, the dilation defaults to 1 along each
265
+ spatial axis of the image.
266
+
267
+ pads: 1-dimensional tensor with padding value for the beginning and ending
268
+ along each spatial axis, it can take any value greater than or equal to
269
+ 0. The value represent the number of pixels added to the beginning and
270
+ end part of the corresponding axis. `pads` format should be as follow
271
+ [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin is the number
272
+ of pixels added at the beginning of axis `i` and xi_end is the number of
273
+ pixels added at the end of axis `i`. If not present, the padding
274
+ defaults to 0 along start and end of each spatial axis.
275
+
276
+ strides: 1-dimensional tensor with stride value along each spatial axis. If
277
+ not present, the stride defaults to 1 along each spatial axis.
278
+ """
279
+
280
+ schema = get_schema("Col2Im", 18, "")
281
+ op = Op(self, "Col2Im", schema)
282
+ return op(
283
+ *self._prepare_inputs(schema, input, image_shape, block_shape),
284
+ dilations=dilations,
285
+ pads=pads,
286
+ strides=strides,
287
+ )
288
+
289
+ T_GroupNormalization = TypeVar("T_GroupNormalization", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
290
+
291
+ def GroupNormalization(
292
+ self,
293
+ X: T_GroupNormalization,
294
+ scale: T_GroupNormalization,
295
+ bias: T_GroupNormalization,
296
+ *,
297
+ epsilon: float = 9.999999747378752e-06,
298
+ num_groups: int,
299
+ ) -> T_GroupNormalization:
300
+ r"""[🌐 GroupNormalization(18)](https://onnx.ai/onnx/operators/onnx__GroupNormalization.html#groupnormalization-18 "Online Documentation")
301
+
302
+
303
+ A GroupNormalization function. Carries out group normalization as described in
304
+ the paper https://arxiv.org/abs/1803.08494
305
+
306
+ This operator transforms input according to
307
+ ::
308
+
309
+ y = scale * (x - mean) / sqrt(variance + epsilon) + bias,
310
+
311
+
312
+ where the mean and variance are computed per instance per group of channels, and
313
+ `scale` and `bias` should be specified for each group of channels. The number of
314
+ groups `num_groups` should be divisible by the number of channels so that there are
315
+ an equal number of channels per group.
316
+
317
+ When the number of groups is the same as the number of channels, this operator is
318
+ equivalent to InstanceNormalization. When there is only one group, this operator
319
+ is equivalent to LayerNormalization.
320
+
321
+
322
+ Args:
323
+ X: (differentiable) Input data tensor. Dimensions for image cases are `(N x
324
+ C x H x W)`, where `N` is the batch size, `C` is the number of channels,
325
+ and `H` and `W` are the height and width of the data. Statistics are
326
+ computed for every group of channels over `C`, `H`, and `W`. For
327
+ non-image cases, the dimensions are in the form of `(N x C x D1 x D2 ...
328
+ Dn)`.
329
+
330
+ scale: (differentiable) Scale tensor of shape `(num_groups)`.
331
+
332
+ bias: (differentiable) Bias tensor of shape `(num_groups)`.
333
+
334
+ epsilon: The epsilon value to use to avoid division by zero.
335
+
336
+ num_groups: The number of groups of channels. It should be a divisor of the
337
+ number of channels `C`.
338
+ """
339
+
340
+ schema = get_schema("GroupNormalization", 18, "")
341
+ op = Op(self, "GroupNormalization", schema)
342
+ return op(
343
+ *self._prepare_inputs(schema, X, scale, bias),
344
+ epsilon=epsilon,
345
+ num_groups=num_groups,
346
+ )
347
+
348
+ T_LpPool = TypeVar("T_LpPool", DOUBLE, FLOAT, FLOAT16)
349
+
350
+ def LpPool(
351
+ self,
352
+ X: T_LpPool,
353
+ *,
354
+ auto_pad: str = "NOTSET",
355
+ ceil_mode: int = 0,
356
+ dilations: Optional[Sequence[int]] = None,
357
+ kernel_shape: Sequence[int],
358
+ p: int = 2,
359
+ pads: Optional[Sequence[int]] = None,
360
+ strides: Optional[Sequence[int]] = None,
361
+ ) -> T_LpPool:
362
+ r"""[🌐 LpPool(18)](https://onnx.ai/onnx/operators/onnx__LpPool.html#lppool-18 "Online Documentation")
363
+
364
+
365
+ LpPool consumes an input tensor X and applies Lp pooling across
366
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
367
+ Lp pooling consisting of computing the Lp norm on all values of a subset
368
+ of the input tensor according to the kernel size and downsampling the
369
+ data into the output tensor Y for further processing. The output spatial shape will be following:
370
+ ```
371
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
372
+ ```
373
+ or
374
+ ```
375
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
376
+ ```
377
+ if ceil_mode is enabled `pad_shape[i]` is the sum of pads along axis `i`.
378
+
379
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
380
+ ```
381
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i])
382
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
383
+ ```
384
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
385
+ ```
386
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i]
387
+ ```
388
+
389
+ Args:
390
+ X: (differentiable) Input data tensor from the previous operator; dimensions
391
+ for image case are (N x C x H x W), where N is the batch size, C is the
392
+ number of channels, and H and W are the height and the width of the
393
+ data. For non image case, the dimensions are in the form of (N x C x D1
394
+ x D2 ... Dn), where N is the batch size.
395
+
396
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
397
+ Where default value is NOTSET, which means explicit padding is used.
398
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
399
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
400
+ split between the two sides equally or almost equally (depending on
401
+ whether it is even or odd). In case the padding is an odd number, the
402
+ extra padding is added at the end for SAME_UPPER and at the beginning
403
+ for SAME_LOWER.
404
+
405
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
406
+ shape.
407
+
408
+ dilations: dilation value along each spatial axis of the filter. If not
409
+ present, the dilation defaults is 1 along each spatial axis.
410
+
411
+ kernel_shape: The size of the kernel along each axis.
412
+
413
+ p: p value of the Lp norm used to pool over the input data.
414
+
415
+ pads: Padding for the beginning and ending along each spatial axis, it can
416
+ take any value greater than or equal to 0. The value represent the
417
+ number of pixels added to the beginning and end part of the
418
+ corresponding axis. `pads` format should be as follow [x1_begin,
419
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
420
+ added at the beginning of axis `i` and xi_end, the number of pixels
421
+ added at the end of axis `i`. This attribute cannot be used
422
+ simultaneously with auto_pad attribute. If not present, the padding
423
+ defaults to 0 along start and end of each spatial axis.
424
+
425
+ strides: Stride along each spatial axis. If not present, the stride defaults
426
+ to 1 along each spatial axis.
427
+ """
428
+
429
+ schema = get_schema("LpPool", 18, "")
430
+ op = Op(self, "LpPool", schema)
431
+ return op(
432
+ *self._prepare_inputs(schema, X),
433
+ auto_pad=auto_pad,
434
+ ceil_mode=ceil_mode,
435
+ dilations=dilations,
436
+ kernel_shape=kernel_shape,
437
+ p=p,
438
+ pads=pads,
439
+ strides=strides,
440
+ )
441
+
442
+ T_Mish = TypeVar("T_Mish", DOUBLE, FLOAT, FLOAT16)
443
+
444
+ def Mish(self, X: T_Mish) -> T_Mish:
445
+ r"""[🌐 Mish(18)](https://onnx.ai/onnx/operators/onnx__Mish.html#mish-18 "Online Documentation")
446
+
447
+
448
+ Mish: A Self Regularized Non-Monotonic Neural Activation Function.
449
+
450
+ Perform the linear unit element-wise on the input tensor X using formula:
451
+
452
+ ::
453
+
454
+ mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))
455
+
456
+
457
+
458
+
459
+ Args:
460
+ X: (differentiable) Input tensor
461
+ """
462
+
463
+ schema = get_schema("Mish", 18, "")
464
+ op = Op(self, "Mish", schema)
465
+ return op(*self._prepare_inputs(schema, X))
466
+
467
+ O_OptionalGetElement = TypeVar(
468
+ "O_OptionalGetElement",
469
+ Optional[Sequence[BOOL]],
470
+ Optional[Sequence[COMPLEX128]],
471
+ Optional[Sequence[COMPLEX64]],
472
+ Optional[Sequence[DOUBLE]],
473
+ Optional[Sequence[FLOAT]],
474
+ Optional[Sequence[FLOAT16]],
475
+ Optional[Sequence[INT16]],
476
+ Optional[Sequence[INT32]],
477
+ Optional[Sequence[INT64]],
478
+ Optional[Sequence[INT8]],
479
+ Optional[Sequence[STRING]],
480
+ Optional[Sequence[UINT16]],
481
+ Optional[Sequence[UINT32]],
482
+ Optional[Sequence[UINT64]],
483
+ Optional[Sequence[UINT8]],
484
+ Optional[BOOL],
485
+ Optional[COMPLEX128],
486
+ Optional[COMPLEX64],
487
+ Optional[DOUBLE],
488
+ Optional[FLOAT],
489
+ Optional[FLOAT16],
490
+ Optional[INT16],
491
+ Optional[INT32],
492
+ Optional[INT64],
493
+ Optional[INT8],
494
+ Optional[STRING],
495
+ Optional[UINT16],
496
+ Optional[UINT32],
497
+ Optional[UINT64],
498
+ Optional[UINT8],
499
+ Sequence[BOOL],
500
+ Sequence[COMPLEX128],
501
+ Sequence[COMPLEX64],
502
+ Sequence[DOUBLE],
503
+ Sequence[FLOAT],
504
+ Sequence[FLOAT16],
505
+ Sequence[INT16],
506
+ Sequence[INT32],
507
+ Sequence[INT64],
508
+ Sequence[INT8],
509
+ Sequence[STRING],
510
+ Sequence[UINT16],
511
+ Sequence[UINT32],
512
+ Sequence[UINT64],
513
+ Sequence[UINT8],
514
+ BOOL,
515
+ COMPLEX128,
516
+ COMPLEX64,
517
+ DOUBLE,
518
+ FLOAT,
519
+ FLOAT16,
520
+ INT16,
521
+ INT32,
522
+ INT64,
523
+ INT8,
524
+ STRING,
525
+ UINT16,
526
+ UINT32,
527
+ UINT64,
528
+ UINT8,
529
+ )
530
+
531
+ V_OptionalGetElement: TypeAlias = Union[
532
+ Sequence[BOOL],
533
+ Sequence[COMPLEX128],
534
+ Sequence[COMPLEX64],
535
+ Sequence[DOUBLE],
536
+ Sequence[FLOAT],
537
+ Sequence[FLOAT16],
538
+ Sequence[INT16],
539
+ Sequence[INT32],
540
+ Sequence[INT64],
541
+ Sequence[INT8],
542
+ Sequence[STRING],
543
+ Sequence[UINT16],
544
+ Sequence[UINT32],
545
+ Sequence[UINT64],
546
+ Sequence[UINT8],
547
+ BOOL,
548
+ COMPLEX128,
549
+ COMPLEX64,
550
+ DOUBLE,
551
+ FLOAT,
552
+ FLOAT16,
553
+ INT16,
554
+ INT32,
555
+ INT64,
556
+ INT8,
557
+ STRING,
558
+ UINT16,
559
+ UINT32,
560
+ UINT64,
561
+ UINT8,
562
+ ]
563
+
564
+ def OptionalGetElement(self, input: O_OptionalGetElement) -> V_OptionalGetElement:
565
+ r"""[🌐 OptionalGetElement(18)](https://onnx.ai/onnx/operators/onnx__OptionalGetElement.html#optionalgetelement-18 "Online Documentation")
566
+
567
+
568
+ If the input is a tensor or sequence type, it returns the input.
569
+ If the input is an optional type, it outputs the element in the input.
570
+ It is an error if the input is an empty optional-type (i.e. does not have an element) and the behavior is undefined in this case.
571
+
572
+
573
+ Args:
574
+ input: The optional input.
575
+ """
576
+
577
+ schema = get_schema("OptionalGetElement", 18, "")
578
+ op = Op(self, "OptionalGetElement", schema)
579
+ return op(*self._prepare_inputs(schema, input))
580
+
581
+ O_OptionalHasElement = TypeVar(
582
+ "O_OptionalHasElement",
583
+ Optional[Sequence[BOOL]],
584
+ Optional[Sequence[COMPLEX128]],
585
+ Optional[Sequence[COMPLEX64]],
586
+ Optional[Sequence[DOUBLE]],
587
+ Optional[Sequence[FLOAT]],
588
+ Optional[Sequence[FLOAT16]],
589
+ Optional[Sequence[INT16]],
590
+ Optional[Sequence[INT32]],
591
+ Optional[Sequence[INT64]],
592
+ Optional[Sequence[INT8]],
593
+ Optional[Sequence[STRING]],
594
+ Optional[Sequence[UINT16]],
595
+ Optional[Sequence[UINT32]],
596
+ Optional[Sequence[UINT64]],
597
+ Optional[Sequence[UINT8]],
598
+ Optional[BOOL],
599
+ Optional[COMPLEX128],
600
+ Optional[COMPLEX64],
601
+ Optional[DOUBLE],
602
+ Optional[FLOAT],
603
+ Optional[FLOAT16],
604
+ Optional[INT16],
605
+ Optional[INT32],
606
+ Optional[INT64],
607
+ Optional[INT8],
608
+ Optional[STRING],
609
+ Optional[UINT16],
610
+ Optional[UINT32],
611
+ Optional[UINT64],
612
+ Optional[UINT8],
613
+ Sequence[BOOL],
614
+ Sequence[COMPLEX128],
615
+ Sequence[COMPLEX64],
616
+ Sequence[DOUBLE],
617
+ Sequence[FLOAT],
618
+ Sequence[FLOAT16],
619
+ Sequence[INT16],
620
+ Sequence[INT32],
621
+ Sequence[INT64],
622
+ Sequence[INT8],
623
+ Sequence[STRING],
624
+ Sequence[UINT16],
625
+ Sequence[UINT32],
626
+ Sequence[UINT64],
627
+ Sequence[UINT8],
628
+ BOOL,
629
+ COMPLEX128,
630
+ COMPLEX64,
631
+ DOUBLE,
632
+ FLOAT,
633
+ FLOAT16,
634
+ INT16,
635
+ INT32,
636
+ INT64,
637
+ INT8,
638
+ STRING,
639
+ UINT16,
640
+ UINT32,
641
+ UINT64,
642
+ UINT8,
643
+ )
644
+
645
+ B_OptionalHasElement: TypeAlias = BOOL
646
+
647
+ def OptionalHasElement(
648
+ self, input: Optional[O_OptionalHasElement] = None
649
+ ) -> B_OptionalHasElement:
650
+ r"""[🌐 OptionalHasElement(18)](https://onnx.ai/onnx/operators/onnx__OptionalHasElement.html#optionalhaselement-18 "Online Documentation")
651
+
652
+
653
+ Returns true if (1) the input is an optional-type and contains an element,
654
+ or, (2) the input is a tensor or sequence type.
655
+ If the input is not provided or is an empty optional-type, this op returns false.
656
+
657
+
658
+ Args:
659
+ input: (optional) The optional input.
660
+ """
661
+
662
+ schema = get_schema("OptionalHasElement", 18, "")
663
+ op = Op(self, "OptionalHasElement", schema)
664
+ return op(*self._prepare_inputs(schema, input))
665
+
666
+ T_Pad = TypeVar(
667
+ "T_Pad",
668
+ BFLOAT16,
669
+ BOOL,
670
+ COMPLEX128,
671
+ COMPLEX64,
672
+ DOUBLE,
673
+ FLOAT,
674
+ FLOAT16,
675
+ INT16,
676
+ INT32,
677
+ INT64,
678
+ INT8,
679
+ STRING,
680
+ UINT16,
681
+ UINT32,
682
+ UINT64,
683
+ UINT8,
684
+ )
685
+
686
+ Tind_Pad = TypeVar("Tind_Pad", INT32, INT64)
687
+
688
+ def Pad(
689
+ self,
690
+ data: T_Pad,
691
+ pads: INT64,
692
+ constant_value: Optional[T_Pad] = None,
693
+ axes: Optional[Tind_Pad] = None,
694
+ *,
695
+ mode: str = "constant",
696
+ ) -> T_Pad:
697
+ r"""[🌐 Pad(18)](https://onnx.ai/onnx/operators/onnx__Pad.html#pad-18 "Online Documentation")
698
+
699
+
700
+ Given a tensor containing the data to be padded (`data`), a tensor containing the number of start and end pad values for axis (`pads`), (optionally) a `mode`, and (optionally) `constant_value`,
701
+ a padded tensor (`output`) is generated.
702
+
703
+ The three supported `modes` are (similar to corresponding modes supported by `numpy.pad`):
704
+
705
+ 1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0, empty string, or False)
706
+
707
+ 2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis
708
+
709
+ 3) `edge` - pads with the edge values of array
710
+
711
+
712
+ Example 1 (`constant` mode):
713
+
714
+ Insert 0 pads to the beginning of the second dimension.
715
+
716
+ ::
717
+
718
+ data = [
719
+ [1.0, 1.2],
720
+ [2.3, 3.4],
721
+ [4.5, 5.7],
722
+ ]
723
+
724
+ pads = [0, 2, 0, 0]
725
+
726
+ mode = 'constant'
727
+
728
+ constant_value = 0.0
729
+
730
+ output = [
731
+ [0.0, 0.0, 1.0, 1.2],
732
+ [0.0, 0.0, 2.3, 3.4],
733
+ [0.0, 0.0, 4.5, 5.7],
734
+ ]
735
+
736
+
737
+
738
+ Example 2 (`reflect` mode):
739
+
740
+ ::
741
+
742
+ data = [
743
+ [1.0, 1.2],
744
+ [2.3, 3.4],
745
+ [4.5, 5.7],
746
+ ]
747
+
748
+ pads = [0, 2, 0, 0]
749
+
750
+ mode = 'reflect'
751
+
752
+ output = [
753
+ [1.0, 1.2, 1.0, 1.2],
754
+ [2.3, 3.4, 2.3, 3.4],
755
+ [4.5, 5.7, 4.5, 5.7],
756
+ ]
757
+
758
+
759
+
760
+ Example 3 (`edge` mode):
761
+
762
+ ::
763
+
764
+ data = [
765
+ [1.0, 1.2],
766
+ [2.3, 3.4],
767
+ [4.5, 5.7],
768
+ ]
769
+
770
+ pads = [0, 2, 0, 0]
771
+
772
+ mode = 'edge'
773
+
774
+ output = [
775
+ [1.0, 1.0, 1.0, 1.2],
776
+ [2.3, 2.3, 2.3, 3.4],
777
+ [4.5, 4.5, 4.5, 5.7],
778
+ ]
779
+
780
+
781
+
782
+
783
+ Args:
784
+ data: (differentiable) Input tensor.
785
+
786
+ pads: (non-differentiable) Tensor of integers indicating the number of
787
+ padding elements to add or remove (if negative) at the beginning and end
788
+ of each axis. For 2D input tensor, it is the number of pixels. `pads`
789
+ should be a 1D tensor of shape [2 * num_axes] where `num_axes` refers to
790
+ the number of elements in the `axes` input or the input rank if `axes`
791
+ are not provided explicitly. `pads` format should be: [x1_begin,
792
+ x2_begin, ..., x1_end, x2_end,...], where xi_begin is the number of pad
793
+ values added at the beginning of axis `axes[i]` and xi_end, the number
794
+ of pad values added at the end of axis `axes[i]`.
795
+
796
+ constant_value: (optional, non-differentiable) (Optional) A scalar value to
797
+ be used if the mode chosen is `constant` (by default it is 0, empty
798
+ string or False).
799
+
800
+ axes: (optional, non-differentiable) 1-D tensor of axes that `pads` apply
801
+ to. Negative value means counting dimensions from the back. Accepted
802
+ range is [-r, r-1] where r = rank(data). Behavior is undefined if an
803
+ axis is repeated. If not provided, all axes are assumed (`[0, 1, ...,
804
+ input_rank-1]`).
805
+
806
+ mode: Supported modes: `constant`(default), `reflect`, `edge`
807
+ """
808
+
809
+ schema = get_schema("Pad", 18, "")
810
+ op = Op(self, "Pad", schema)
811
+ return op(*self._prepare_inputs(schema, data, pads, constant_value, axes), mode=mode)
812
+
813
+ T_ReduceL1 = TypeVar(
814
+ "T_ReduceL1", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
815
+ )
816
+
817
+ def ReduceL1(
818
+ self,
819
+ data: T_ReduceL1,
820
+ axes: Optional[INT64] = None,
821
+ *,
822
+ keepdims: int = 1,
823
+ noop_with_empty_axes: int = 0,
824
+ ) -> T_ReduceL1:
825
+ r"""[🌐 ReduceL1(18)](https://onnx.ai/onnx/operators/onnx__ReduceL1.html#reducel1-18 "Online Documentation")
826
+
827
+
828
+ Computes the L1 norm of the input tensor's elements along the provided axes. The resulting
829
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
830
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
831
+ valid. Reduction over an empty set of values yields 0.
832
+
833
+
834
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
835
+ to `False` instead of `True`.
836
+
837
+ Args:
838
+ data: (differentiable) An input tensor.
839
+
840
+ axes: (optional, non-differentiable) Optional input list of integers, along
841
+ which to reduce. The default is to reduce over all the dimensions of the
842
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
843
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
844
+ where r = rank(data).
845
+
846
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
847
+ dimension.
848
+
849
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
850
+ with 'false' is to reduce all axes. When axes is empty and this
851
+ attribute is set to true, input tensor will not be reduced,and the
852
+ output tensor would be equivalent to input tensor.
853
+ """
854
+
855
+ schema = get_schema("ReduceL1", 18, "")
856
+ op = Op(self, "ReduceL1", schema)
857
+ return op(
858
+ *self._prepare_inputs(schema, data, axes),
859
+ keepdims=keepdims,
860
+ noop_with_empty_axes=noop_with_empty_axes,
861
+ )
862
+
863
+ T_ReduceL2 = TypeVar(
864
+ "T_ReduceL2", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
865
+ )
866
+
867
+ def ReduceL2(
868
+ self,
869
+ data: T_ReduceL2,
870
+ axes: Optional[INT64] = None,
871
+ *,
872
+ keepdims: int = 1,
873
+ noop_with_empty_axes: int = 0,
874
+ ) -> T_ReduceL2:
875
+ r"""[🌐 ReduceL2(18)](https://onnx.ai/onnx/operators/onnx__ReduceL2.html#reducel2-18 "Online Documentation")
876
+
877
+
878
+ Computes the L2 norm of the input tensor's elements along the provided axes. The resulting
879
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
880
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
881
+ valid. Reduction over an empty set of values yields 0.
882
+
883
+
884
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
885
+ to `False` instead of `True`.
886
+
887
+ Args:
888
+ data: (differentiable) An input tensor.
889
+
890
+ axes: (optional, non-differentiable) Optional input list of integers, along
891
+ which to reduce. The default is to reduce over all the dimensions of the
892
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
893
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
894
+ where r = rank(data).
895
+
896
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
897
+ dimension.
898
+
899
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
900
+ with 'false' is to reduce all axes. When axes is empty and this
901
+ attribute is set to true, input tensor will not be reduced,and the
902
+ output tensor would be equivalent to input tensor.
903
+ """
904
+
905
+ schema = get_schema("ReduceL2", 18, "")
906
+ op = Op(self, "ReduceL2", schema)
907
+ return op(
908
+ *self._prepare_inputs(schema, data, axes),
909
+ keepdims=keepdims,
910
+ noop_with_empty_axes=noop_with_empty_axes,
911
+ )
912
+
913
+ T_ReduceLogSum = TypeVar(
914
+ "T_ReduceLogSum", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
915
+ )
916
+
917
+ def ReduceLogSum(
918
+ self,
919
+ data: T_ReduceLogSum,
920
+ axes: Optional[INT64] = None,
921
+ *,
922
+ keepdims: int = 1,
923
+ noop_with_empty_axes: int = 0,
924
+ ) -> T_ReduceLogSum:
925
+ r"""[🌐 ReduceLogSum(18)](https://onnx.ai/onnx/operators/onnx__ReduceLogSum.html#reducelogsum-18 "Online Documentation")
926
+
927
+
928
+ Computes the log sum of the input tensor's elements along the provided axes. The resulting
929
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
930
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
931
+ valid. Reduction over an empty set of values yields minus infinity (if supported by the datatype) or undefined otherwise.
932
+
933
+
934
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
935
+ to `False` instead of `True`.
936
+
937
+ Args:
938
+ data: (differentiable) An input tensor.
939
+
940
+ axes: (optional, non-differentiable) Optional input list of integers, along
941
+ which to reduce. The default is to reduce over all the dimensions of the
942
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
943
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
944
+ where r = rank(data).
945
+
946
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
947
+ dimension.
948
+
949
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
950
+ with 'false' is to reduce all axes. When axes is empty and this
951
+ attribute is set to true, input tensor will not be reduced,and the
952
+ output tensor would be equivalent to input tensor.
953
+ """
954
+
955
+ schema = get_schema("ReduceLogSum", 18, "")
956
+ op = Op(self, "ReduceLogSum", schema)
957
+ return op(
958
+ *self._prepare_inputs(schema, data, axes),
959
+ keepdims=keepdims,
960
+ noop_with_empty_axes=noop_with_empty_axes,
961
+ )
962
+
963
+ T_ReduceLogSumExp = TypeVar(
964
+ "T_ReduceLogSumExp", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
965
+ )
966
+
967
+ def ReduceLogSumExp(
968
+ self,
969
+ data: T_ReduceLogSumExp,
970
+ axes: Optional[INT64] = None,
971
+ *,
972
+ keepdims: int = 1,
973
+ noop_with_empty_axes: int = 0,
974
+ ) -> T_ReduceLogSumExp:
975
+ r"""[🌐 ReduceLogSumExp(18)](https://onnx.ai/onnx/operators/onnx__ReduceLogSumExp.html#reducelogsumexp-18 "Online Documentation")
976
+
977
+
978
+ Computes the log sum exponent of the input tensor's elements along the provided axes. The resulting
979
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
980
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
981
+ valid. Reduction over an empty set of values yields minus infinity (if supported by the datatype) or undefined otherwise.
982
+
983
+
984
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
985
+ to `False` instead of `True`.
986
+
987
+ Args:
988
+ data: (differentiable) An input tensor.
989
+
990
+ axes: (optional, non-differentiable) Optional input list of integers, along
991
+ which to reduce. The default is to reduce over all the dimensions of the
992
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
993
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
994
+ where r = rank(data).
995
+
996
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
997
+ dimension.
998
+
999
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1000
+ with 'false' is to reduce all axes. When axes is empty and this
1001
+ attribute is set to true, input tensor will not be reduced,and the
1002
+ output tensor would be equivalent to input tensor.
1003
+ """
1004
+
1005
+ schema = get_schema("ReduceLogSumExp", 18, "")
1006
+ op = Op(self, "ReduceLogSumExp", schema)
1007
+ return op(
1008
+ *self._prepare_inputs(schema, data, axes),
1009
+ keepdims=keepdims,
1010
+ noop_with_empty_axes=noop_with_empty_axes,
1011
+ )
1012
+
1013
+ T_ReduceMax = TypeVar(
1014
+ "T_ReduceMax",
1015
+ BFLOAT16,
1016
+ DOUBLE,
1017
+ FLOAT,
1018
+ FLOAT16,
1019
+ INT32,
1020
+ INT64,
1021
+ INT8,
1022
+ UINT32,
1023
+ UINT64,
1024
+ UINT8,
1025
+ )
1026
+
1027
+ def ReduceMax(
1028
+ self,
1029
+ data: T_ReduceMax,
1030
+ axes: Optional[INT64] = None,
1031
+ *,
1032
+ keepdims: int = 1,
1033
+ noop_with_empty_axes: int = 0,
1034
+ ) -> T_ReduceMax:
1035
+ r"""[🌐 ReduceMax(18)](https://onnx.ai/onnx/operators/onnx__ReduceMax.html#reducemax-18 "Online Documentation")
1036
+
1037
+
1038
+ Computes the max of the input tensor's elements along the provided axes. The resulting
1039
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
1040
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
1041
+ valid. Reduction over an empty set of values yields minus infinity (if supported by the datatype) or the minimum value of the data type otherwise.
1042
+
1043
+
1044
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
1045
+ to `False` instead of `True`.
1046
+
1047
+ Args:
1048
+ data: (differentiable) An input tensor.
1049
+
1050
+ axes: (optional, non-differentiable) Optional input list of integers, along
1051
+ which to reduce. The default is to reduce over all the dimensions of the
1052
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
1053
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
1054
+ where r = rank(data).
1055
+
1056
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
1057
+ dimension.
1058
+
1059
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1060
+ with 'false' is to reduce all axes. When axes is empty and this
1061
+ attribute is set to true, input tensor will not be reduced,and the
1062
+ output tensor would be equivalent to input tensor.
1063
+ """
1064
+
1065
+ schema = get_schema("ReduceMax", 18, "")
1066
+ op = Op(self, "ReduceMax", schema)
1067
+ return op(
1068
+ *self._prepare_inputs(schema, data, axes),
1069
+ keepdims=keepdims,
1070
+ noop_with_empty_axes=noop_with_empty_axes,
1071
+ )
1072
+
1073
+ T_ReduceMean = TypeVar(
1074
+ "T_ReduceMean", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
1075
+ )
1076
+
1077
+ def ReduceMean(
1078
+ self,
1079
+ data: T_ReduceMean,
1080
+ axes: Optional[INT64] = None,
1081
+ *,
1082
+ keepdims: int = 1,
1083
+ noop_with_empty_axes: int = 0,
1084
+ ) -> T_ReduceMean:
1085
+ r"""[🌐 ReduceMean(18)](https://onnx.ai/onnx/operators/onnx__ReduceMean.html#reducemean-18 "Online Documentation")
1086
+
1087
+
1088
+ Computes the mean of the input tensor's elements along the provided axes. The resulting
1089
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
1090
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
1091
+ valid. Reduction over an empty set of values yields undefined.
1092
+
1093
+
1094
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
1095
+ to `False` instead of `True`.
1096
+
1097
+ Args:
1098
+ data: (differentiable) An input tensor.
1099
+
1100
+ axes: (optional, non-differentiable) Optional input list of integers, along
1101
+ which to reduce. The default is to reduce over all the dimensions of the
1102
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
1103
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
1104
+ where r = rank(data).
1105
+
1106
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
1107
+ dimension.
1108
+
1109
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1110
+ with 'false' is to reduce all axes. When axes is empty and this
1111
+ attribute is set to true, input tensor will not be reduced,and the
1112
+ output tensor would be equivalent to input tensor.
1113
+ """
1114
+
1115
+ schema = get_schema("ReduceMean", 18, "")
1116
+ op = Op(self, "ReduceMean", schema)
1117
+ return op(
1118
+ *self._prepare_inputs(schema, data, axes),
1119
+ keepdims=keepdims,
1120
+ noop_with_empty_axes=noop_with_empty_axes,
1121
+ )
1122
+
1123
+ T_ReduceMin = TypeVar(
1124
+ "T_ReduceMin",
1125
+ BFLOAT16,
1126
+ DOUBLE,
1127
+ FLOAT,
1128
+ FLOAT16,
1129
+ INT32,
1130
+ INT64,
1131
+ INT8,
1132
+ UINT32,
1133
+ UINT64,
1134
+ UINT8,
1135
+ )
1136
+
1137
+ def ReduceMin(
1138
+ self,
1139
+ data: T_ReduceMin,
1140
+ axes: Optional[INT64] = None,
1141
+ *,
1142
+ keepdims: int = 1,
1143
+ noop_with_empty_axes: int = 0,
1144
+ ) -> T_ReduceMin:
1145
+ r"""[🌐 ReduceMin(18)](https://onnx.ai/onnx/operators/onnx__ReduceMin.html#reducemin-18 "Online Documentation")
1146
+
1147
+
1148
+ Computes the min of the input tensor's elements along the provided axes. The resulting
1149
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
1150
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
1151
+ valid. Reduction over an empty set of values yields plus infinity (if supported by the datatype) or the maximum value of the data type otherwise.
1152
+
1153
+
1154
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
1155
+ to `False` instead of `True`.
1156
+
1157
+ Args:
1158
+ data: (differentiable) An input tensor.
1159
+
1160
+ axes: (optional, non-differentiable) Optional input list of integers, along
1161
+ which to reduce. The default is to reduce over all the dimensions of the
1162
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
1163
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
1164
+ where r = rank(data).
1165
+
1166
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
1167
+ dimension.
1168
+
1169
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1170
+ with 'false' is to reduce all axes. When axes is empty and this
1171
+ attribute is set to true, input tensor will not be reduced,and the
1172
+ output tensor would be equivalent to input tensor.
1173
+ """
1174
+
1175
+ schema = get_schema("ReduceMin", 18, "")
1176
+ op = Op(self, "ReduceMin", schema)
1177
+ return op(
1178
+ *self._prepare_inputs(schema, data, axes),
1179
+ keepdims=keepdims,
1180
+ noop_with_empty_axes=noop_with_empty_axes,
1181
+ )
1182
+
1183
+ T_ReduceProd = TypeVar(
1184
+ "T_ReduceProd", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
1185
+ )
1186
+
1187
+ def ReduceProd(
1188
+ self,
1189
+ data: T_ReduceProd,
1190
+ axes: Optional[INT64] = None,
1191
+ *,
1192
+ keepdims: int = 1,
1193
+ noop_with_empty_axes: int = 0,
1194
+ ) -> T_ReduceProd:
1195
+ r"""[🌐 ReduceProd(18)](https://onnx.ai/onnx/operators/onnx__ReduceProd.html#reduceprod-18 "Online Documentation")
1196
+
1197
+
1198
+ Computes the product of the input tensor's elements along the provided axes. The resulting
1199
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
1200
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
1201
+ valid. Reduction over an empty set of values yields 1.
1202
+
1203
+
1204
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
1205
+ to `False` instead of `True`.
1206
+
1207
+ Args:
1208
+ data: (differentiable) An input tensor.
1209
+
1210
+ axes: (optional, non-differentiable) Optional input list of integers, along
1211
+ which to reduce. The default is to reduce over all the dimensions of the
1212
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
1213
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
1214
+ where r = rank(data).
1215
+
1216
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
1217
+ dimension.
1218
+
1219
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1220
+ with 'false' is to reduce all axes. When axes is empty and this
1221
+ attribute is set to true, input tensor will not be reduced,and the
1222
+ output tensor would be equivalent to input tensor.
1223
+ """
1224
+
1225
+ schema = get_schema("ReduceProd", 18, "")
1226
+ op = Op(self, "ReduceProd", schema)
1227
+ return op(
1228
+ *self._prepare_inputs(schema, data, axes),
1229
+ keepdims=keepdims,
1230
+ noop_with_empty_axes=noop_with_empty_axes,
1231
+ )
1232
+
1233
+ T_ReduceSumSquare = TypeVar(
1234
+ "T_ReduceSumSquare", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT32, INT64, UINT32, UINT64
1235
+ )
1236
+
1237
+ def ReduceSumSquare(
1238
+ self,
1239
+ data: T_ReduceSumSquare,
1240
+ axes: Optional[INT64] = None,
1241
+ *,
1242
+ keepdims: int = 1,
1243
+ noop_with_empty_axes: int = 0,
1244
+ ) -> T_ReduceSumSquare:
1245
+ r"""[🌐 ReduceSumSquare(18)](https://onnx.ai/onnx/operators/onnx__ReduceSumSquare.html#reducesumsquare-18 "Online Documentation")
1246
+
1247
+
1248
+ Computes the sum square of the input tensor's elements along the provided axes. The resulting
1249
+ tensor has the same rank as the input if `keepdims` equals 1. If `keepdims` equals 0, then
1250
+ the resulting tensor has the reduced dimension pruned. Input tensors of rank zero are
1251
+ valid. Reduction over an empty set of values yields 0.
1252
+
1253
+
1254
+ The above behavior is similar to numpy, with the exception that numpy defaults `keepdims`
1255
+ to `False` instead of `True`.
1256
+
1257
+ Args:
1258
+ data: (differentiable) An input tensor.
1259
+
1260
+ axes: (optional, non-differentiable) Optional input list of integers, along
1261
+ which to reduce. The default is to reduce over all the dimensions of the
1262
+ input tensor if 'noop_with_empty_axes' is false, else act as an Identity
1263
+ op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
1264
+ where r = rank(data).
1265
+
1266
+ keepdims: Keep the reduced dimension or not, default 1 means keep reduced
1267
+ dimension.
1268
+
1269
+ noop_with_empty_axes: Defines behavior if 'axes' is empty. Default behavior
1270
+ with 'false' is to reduce all axes. When axes is empty and this
1271
+ attribute is set to true, input tensor will not be reduced,and the
1272
+ output tensor would be equivalent to input tensor.
1273
+ """
1274
+
1275
+ schema = get_schema("ReduceSumSquare", 18, "")
1276
+ op = Op(self, "ReduceSumSquare", schema)
1277
+ return op(
1278
+ *self._prepare_inputs(schema, data, axes),
1279
+ keepdims=keepdims,
1280
+ noop_with_empty_axes=noop_with_empty_axes,
1281
+ )
1282
+
1283
+ T1_Resize = TypeVar(
1284
+ "T1_Resize",
1285
+ BFLOAT16,
1286
+ BOOL,
1287
+ COMPLEX128,
1288
+ COMPLEX64,
1289
+ DOUBLE,
1290
+ FLOAT,
1291
+ FLOAT16,
1292
+ INT16,
1293
+ INT32,
1294
+ INT64,
1295
+ INT8,
1296
+ STRING,
1297
+ UINT16,
1298
+ UINT32,
1299
+ UINT64,
1300
+ UINT8,
1301
+ )
1302
+
1303
+ T2_Resize = TypeVar("T2_Resize", DOUBLE, FLOAT, FLOAT16)
1304
+
1305
+ def Resize(
1306
+ self,
1307
+ X: T1_Resize,
1308
+ roi: Optional[T2_Resize] = None,
1309
+ scales: Optional[FLOAT] = None,
1310
+ sizes: Optional[INT64] = None,
1311
+ *,
1312
+ antialias: int = 0,
1313
+ axes: Optional[Sequence[int]] = None,
1314
+ coordinate_transformation_mode: str = "half_pixel",
1315
+ cubic_coeff_a: float = -0.75,
1316
+ exclude_outside: int = 0,
1317
+ extrapolation_value: float = 0.0,
1318
+ keep_aspect_ratio_policy: str = "stretch",
1319
+ mode: str = "nearest",
1320
+ nearest_mode: str = "round_prefer_floor",
1321
+ ) -> T1_Resize:
1322
+ r"""[🌐 Resize(18)](https://onnx.ai/onnx/operators/onnx__Resize.html#resize-18 "Online Documentation")
1323
+
1324
+
1325
+ Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor.
1326
+ Each dimension value of the output tensor is: <br/>
1327
+ `output_dimension = floor(input_dimension * (roi_end - roi_start) * scale)` <br/>
1328
+ if input \"sizes\" is not specified.
1329
+
1330
+
1331
+ Args:
1332
+ X: (differentiable) N-D tensor
1333
+
1334
+ roi: (optional, non-differentiable) 1-D tensor given as [start1, ...,
1335
+ startN, end1, ..., endN], where N is the rank of X or the length of
1336
+ axes, if provided. The RoIs' coordinates are normalized in the
1337
+ coordinate system of the input image. It only takes effect when
1338
+ coordinate_transformation_mode is "tf_crop_and_resize"
1339
+
1340
+ scales: (optional, non-differentiable) The scale array along each dimension.
1341
+ It takes value greater than 0. If it's less than 1, it's sampling down,
1342
+ otherwise, it's upsampling. The number of elements of 'scales' should be
1343
+ the same as the rank of input 'X' or the length of 'axes', if provided.
1344
+ One of 'scales' and 'sizes' MUST be specified and it is an error if both
1345
+ are specified. If 'sizes' is needed, the user can use an empty string as
1346
+ the name of 'scales' in this operator's input list.
1347
+
1348
+ sizes: (optional, non-differentiable) Target size of the output tensor. Its
1349
+ interpretation depends on the 'keep_aspect_ratio_policy' value.The
1350
+ number of elements of 'sizes' should be the same as the rank of input
1351
+ 'X', or the length of 'axes', if provided. Only one of 'scales' and
1352
+ 'sizes' can be specified.
1353
+
1354
+ antialias: If set to 1, "linear" and "cubic" interpolation modes will use an
1355
+ antialiasing filter when downscaling. Antialiasing is achieved by
1356
+ stretching the resampling filter by a factor max(1, 1 / scale), which
1357
+ means that when downsampling, more input pixels contribute to an output
1358
+ pixel.
1359
+
1360
+ axes: If provided, it specifies a subset of axes that 'roi', 'scales' and
1361
+ 'sizes' refer to. If not provided, all axes are assumed [0, 1, ...,
1362
+ r-1], where r = rank(data). Non-specified dimensions are interpreted as
1363
+ non-resizable. Negative value means counting dimensions from the back.
1364
+ Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined
1365
+ if an axis is repeated.
1366
+
1367
+ coordinate_transformation_mode:
1368
+ This attribute describes how to transform
1369
+ the coordinate in the resized tensor to the coordinate in the original
1370
+ tensor. <br/>
1371
+
1372
+ The coordinate of each dimension is transformed
1373
+ individually. Let's describe a case using axis x as an example.
1374
+ Denote
1375
+ x_resized as the coordinate of axis x in the resized tensor, x_original
1376
+ as the coordinate of axis x in the original tensor, `length_original` as
1377
+ the length of the original tensor in axis x, length_resized as the
1378
+ length of the resized tensor in axis x, roi_x = (start_x, end_x) of the
1379
+ axis x in input "roi", `scale = length_resized / length_original`, <br/>
1380
+ if coordinate_transformation_mode is `"half_pixel"`, <br/>
1381
+ `x_original =
1382
+ (x_resized + 0.5) / scale - 0.5` <br/>
1383
+
1384
+ if
1385
+ coordinate_transformation_mode is `"pytorch_half_pixel"`, <br/>
1386
+ `x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0`
1387
+ <br/>
1388
+
1389
+ if coordinate_transformation_mode is `"align_corners"`, <br/>
1390
+ `x_original = x_resized * (length_original - 1) / (length_resized - 1)`
1391
+ <br/>
1392
+
1393
+ if coordinate_transformation_mode is `"asymmetric"`, <br/>
1394
+ `x_original = x_resized / scale` <br/>
1395
+
1396
+ if
1397
+ coordinate_transformation_mode is `"tf_crop_and_resize"`, <br/>
1398
+ `x_original = length_resized > 1 ? start_x * (length_original - 1) +
1399
+ x_resized * (end_x - start_x) * (length_original - 1) / (length_resized
1400
+ - 1) : 0.5 * (start_x + end_x) * (length_original - 1)`
1401
+ .
1402
+
1403
+ cubic_coeff_a: The coefficient 'a' used in cubic interpolation. Two common
1404
+ choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch).
1405
+ Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711
1406
+ for the details. This attribute is valid only if mode is "cubic".
1407
+
1408
+ exclude_outside: If set to 1, the weight of sampling locations outside the
1409
+ tensor will be set to 0 and the weight will be renormalized so that
1410
+ their sum is 1.0. The default value is 0.
1411
+
1412
+ extrapolation_value: When coordinate_transformation_mode is
1413
+ "tf_crop_and_resize" and x_original is outside the range [0,
1414
+ length_original - 1], this value is used as the corresponding output
1415
+ value. Default is 0.0f.
1416
+
1417
+ keep_aspect_ratio_policy:
1418
+ This attribute describes how to interpret the
1419
+ `sizes` input with regard to keeping the original aspect ratio of the
1420
+ input, and it is not applicable when
1421
+ the `scales` input is used. <br/>
1422
+ Given a set of `sizes`, associated with a subset of `axes` (explicitly
1423
+ provided or default), and assuming `d = axes[i]`, with `i` being the
1424
+ index of the provided `sizes`. <br/>
1425
+
1426
+ If `keep_aspect_ratio_policy` is
1427
+ `"stretch"`, the original aspect ratio is disregarded, and the input is
1428
+ resized to the specified size: <br/>
1429
+ `out_size[d] = sizes[i]` <br/>
1430
+
1431
+ If
1432
+ `keep_aspect_ratio_policy` is `"not_larger"`, the sizes are adjusted so
1433
+ that no extent of the output is larger than the specified size, while
1434
+ keeping the original aspect ratio: <br/>
1435
+ `scale = Min(sizes[i] /
1436
+ in_size[d])` <br/>
1437
+ `out_size[d] = round_int(scale * in_size[i])` <br/>
1438
+ If `keep_aspect_ratio_policy` is `"not_smaller"`, the sizes are adjusted
1439
+ so that no extent of the output is smaller than the specified size,
1440
+ while keeping the original aspect ratio: <br/>
1441
+ `scale = Max(sizes[i] /
1442
+ in_size[d])` <br/>
1443
+ `out_size[d] = round_int(scale * in_size[i])` <br/>
1444
+ For non-resizable axes (those not specified in `axes`), the output size
1445
+ will be equal to the input size.
1446
+
1447
+ Note: `round_int` stands for computing
1448
+ the nearest integer value, rounding halfway cases up.
1449
+
1450
+ mode: Three interpolation modes: "nearest" (default), "linear" and "cubic".
1451
+ The "linear" mode includes linear interpolation for 1D tensor and
1452
+ N-linear interpolation for N-D tensor (for example, bilinear
1453
+ interpolation for 2D tensor). The "cubic" mode includes cubic
1454
+ interpolation for 1D tensor and N-cubic interpolation for N-D tensor
1455
+ (for example, bicubic interpolation for 2D tensor).
1456
+
1457
+ nearest_mode: Four modes: "round_prefer_floor" (default, as known as round
1458
+ half down), "round_prefer_ceil" (as known as round half up), "floor",
1459
+ "ceil". Only used by nearest interpolation. It indicates how to get
1460
+ "nearest" pixel in input tensor from x_original, so this attribute is
1461
+ valid only if "mode" is "nearest".
1462
+ """
1463
+
1464
+ schema = get_schema("Resize", 18, "")
1465
+ op = Op(self, "Resize", schema)
1466
+ return op(
1467
+ *self._prepare_inputs(schema, X, roi, scales, sizes),
1468
+ antialias=antialias,
1469
+ axes=axes,
1470
+ coordinate_transformation_mode=coordinate_transformation_mode,
1471
+ cubic_coeff_a=cubic_coeff_a,
1472
+ exclude_outside=exclude_outside,
1473
+ extrapolation_value=extrapolation_value,
1474
+ keep_aspect_ratio_policy=keep_aspect_ratio_policy,
1475
+ mode=mode,
1476
+ nearest_mode=nearest_mode,
1477
+ )
1478
+
1479
+ T_ScatterElements = TypeVar(
1480
+ "T_ScatterElements",
1481
+ BFLOAT16,
1482
+ BOOL,
1483
+ COMPLEX128,
1484
+ COMPLEX64,
1485
+ DOUBLE,
1486
+ FLOAT,
1487
+ FLOAT16,
1488
+ INT16,
1489
+ INT32,
1490
+ INT64,
1491
+ INT8,
1492
+ STRING,
1493
+ UINT16,
1494
+ UINT32,
1495
+ UINT64,
1496
+ UINT8,
1497
+ )
1498
+
1499
+ Tind_ScatterElements = TypeVar("Tind_ScatterElements", INT32, INT64)
1500
+
1501
+ def ScatterElements(
1502
+ self,
1503
+ data: T_ScatterElements,
1504
+ indices: Tind_ScatterElements,
1505
+ updates: T_ScatterElements,
1506
+ *,
1507
+ axis: int = 0,
1508
+ reduction: str = "none",
1509
+ ) -> T_ScatterElements:
1510
+ r"""[🌐 ScatterElements(18)](https://onnx.ai/onnx/operators/onnx__ScatterElements.html#scatterelements-18 "Online Documentation")
1511
+
1512
+
1513
+ ScatterElements takes three inputs `data`, `updates`, and `indices` of the same
1514
+ rank r >= 1 and an optional attribute axis that identifies an axis of `data`
1515
+ (by default, the outer-most axis, that is axis 0). The output of the operation
1516
+ is produced by creating a copy of the input `data`, and then updating its value
1517
+ to values specified by `updates` at specific index positions specified by
1518
+ `indices`. Its output shape is the same as the shape of `data`.
1519
+
1520
+ For each entry in `updates`, the target index in `data` is obtained by combining
1521
+ the corresponding entry in `indices` with the index of the entry itself: the
1522
+ index-value for dimension = axis is obtained from the value of the corresponding
1523
+ entry in `indices` and the index-value for dimension != axis is obtained from the
1524
+ index of the entry itself.
1525
+
1526
+ `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates`
1527
+ tensor into `output` at the specified `indices`.
1528
+ In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,
1529
+ then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update
1530
+ corresponding to the [i][j] entry is performed as below:
1531
+ ::
1532
+
1533
+ output[indices[i][j]][j] = updates[i][j] if axis = 0,
1534
+ output[i][indices[i][j]] = updates[i][j] if axis = 1,
1535
+
1536
+
1537
+ When `reduction` is set to some reduction function `f`, the update corresponding to the [i][j] entry is performed as below:
1538
+ ::
1539
+
1540
+ output[indices[i][j]][j] = f(output[indices[i][j]][j], updates[i][j]) if axis = 0,
1541
+ output[i][indices[i][j]] = f(output[i][indices[i][j]], updates[i][j]) if axis = 1,
1542
+
1543
+
1544
+ where the `f` is `+`, `*`, `max` or `min` as specified.
1545
+
1546
+ This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.
1547
+
1548
+ (Opset 18 change): Adds max/min to the set of allowed reduction ops.
1549
+
1550
+ Example 1:
1551
+ ::
1552
+
1553
+ data = [
1554
+ [0.0, 0.0, 0.0],
1555
+ [0.0, 0.0, 0.0],
1556
+ [0.0, 0.0, 0.0],
1557
+ ]
1558
+ indices = [
1559
+ [1, 0, 2],
1560
+ [0, 2, 1],
1561
+ ]
1562
+ updates = [
1563
+ [1.0, 1.1, 1.2],
1564
+ [2.0, 2.1, 2.2],
1565
+ ]
1566
+ output = [
1567
+ [2.0, 1.1, 0.0]
1568
+ [1.0, 0.0, 2.2]
1569
+ [0.0, 2.1, 1.2]
1570
+ ]
1571
+
1572
+
1573
+ Example 2:
1574
+ ::
1575
+
1576
+ data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
1577
+ indices = [[1, 3]]
1578
+ updates = [[1.1, 2.1]]
1579
+ axis = 1
1580
+ output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
1581
+
1582
+
1583
+
1584
+
1585
+ Args:
1586
+ data: (differentiable) Tensor of rank r >= 1.
1587
+
1588
+ indices: (non-differentiable) Tensor of int32/int64 indices, of r >= 1 (same
1589
+ rank as input). All index values are expected to be within bounds [-s,
1590
+ s-1] along axis of size s. It is an error if any of the index values are
1591
+ out of bounds.
1592
+
1593
+ updates: (differentiable) Tensor of rank r >=1 (same rank and shape as
1594
+ indices)
1595
+
1596
+ axis: Which axis to scatter on. Negative value means counting dimensions
1597
+ from the back. Accepted range is [-r, r-1] where r = rank(data).
1598
+
1599
+ reduction: Type of reduction to apply: none (default), add, mul, max, min.
1600
+ 'none': no reduction applied. 'add': reduction using the addition
1601
+ operation. 'mul': reduction using the multiplication operation.'max':
1602
+ reduction using the maximum operation.'min': reduction using the minimum
1603
+ operation.
1604
+ """
1605
+
1606
+ schema = get_schema("ScatterElements", 18, "")
1607
+ op = Op(self, "ScatterElements", schema)
1608
+ return op(
1609
+ *self._prepare_inputs(schema, data, indices, updates),
1610
+ axis=axis,
1611
+ reduction=reduction,
1612
+ )
1613
+
1614
+ T_ScatterND = TypeVar(
1615
+ "T_ScatterND",
1616
+ BFLOAT16,
1617
+ BOOL,
1618
+ COMPLEX128,
1619
+ COMPLEX64,
1620
+ DOUBLE,
1621
+ FLOAT,
1622
+ FLOAT16,
1623
+ INT16,
1624
+ INT32,
1625
+ INT64,
1626
+ INT8,
1627
+ STRING,
1628
+ UINT16,
1629
+ UINT32,
1630
+ UINT64,
1631
+ UINT8,
1632
+ )
1633
+
1634
+ def ScatterND(
1635
+ self,
1636
+ data: T_ScatterND,
1637
+ indices: INT64,
1638
+ updates: T_ScatterND,
1639
+ *,
1640
+ reduction: str = "none",
1641
+ ) -> T_ScatterND:
1642
+ r"""[🌐 ScatterND(18)](https://onnx.ai/onnx/operators/onnx__ScatterND.html#scatternd-18 "Online Documentation")
1643
+
1644
+
1645
+ ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1,
1646
+ and `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation
1647
+ is produced by creating a copy of the input `data`, and then updating its value to values
1648
+ specified by `updates` at specific index positions specified by `indices`. Its output shape
1649
+ is the same as the shape of `data`.
1650
+
1651
+ `indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`.
1652
+ `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`.
1653
+ Hence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an
1654
+ update to a single element of the tensor. When k is less than rank(data) each update entry specifies an
1655
+ update to a slice of the tensor. Index values are allowed to be negative, as per the usual
1656
+ convention for counting backwards from the end, but are expected in the valid range.
1657
+
1658
+ `updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the
1659
+ first (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape.
1660
+ The remaining dimensions of `updates` correspond to the dimensions of the
1661
+ replacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor,
1662
+ corresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates`
1663
+ must equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation
1664
+ of shapes.
1665
+
1666
+ The `output` is calculated via the following equation:
1667
+
1668
+ ::
1669
+
1670
+ output = np.copy(data)
1671
+ update_indices = indices.shape[:-1]
1672
+ for idx in np.ndindex(update_indices):
1673
+ output[indices[idx]] = updates[idx]
1674
+
1675
+
1676
+
1677
+ The order of iteration in the above loop is not specified.
1678
+ In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].
1679
+ This ensures that the output value does not depend on the iteration order.
1680
+
1681
+ `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates`
1682
+ tensor into `output` at the specified `indices`.
1683
+ In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,
1684
+ then indices[idx1] != indices[idx2]. This ensures that the output value does not depend on the iteration order.
1685
+ When `reduction` is set to some reduction function `f`, `output` is calculated as follows:
1686
+
1687
+ ::
1688
+
1689
+ output = np.copy(data)
1690
+ update_indices = indices.shape[:-1]
1691
+ for idx in np.ndindex(update_indices):
1692
+ output[indices[idx]] = f(output[indices[idx]], updates[idx])
1693
+
1694
+
1695
+
1696
+ where the `f` is `+`, `*`, `max` or `min` as specified.
1697
+
1698
+ This operator is the inverse of GatherND.
1699
+
1700
+ (Opset 18 change): Adds max/min to the set of allowed reduction ops.
1701
+
1702
+ Example 1:
1703
+ ::
1704
+
1705
+ data = [1, 2, 3, 4, 5, 6, 7, 8]
1706
+ indices = [[4], [3], [1], [7]]
1707
+ updates = [9, 10, 11, 12]
1708
+ output = [1, 11, 3, 10, 9, 6, 7, 12]
1709
+
1710
+
1711
+
1712
+ Example 2:
1713
+ ::
1714
+
1715
+ data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
1716
+ [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
1717
+ [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
1718
+ [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
1719
+ indices = [[0], [2]]
1720
+ updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
1721
+ [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
1722
+ output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
1723
+ [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
1724
+ [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
1725
+ [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
1726
+
1727
+
1728
+
1729
+
1730
+ Args:
1731
+ data: (differentiable) Tensor of rank r >= 1.
1732
+
1733
+ indices: (non-differentiable) Tensor of rank q >= 1.
1734
+
1735
+ updates: (differentiable) Tensor of rank q + r - indices_shape[-1] - 1.
1736
+
1737
+ reduction: Type of reduction to apply: none (default), add, mul, max, min.
1738
+ 'none': no reduction applied. 'add': reduction using the addition
1739
+ operation. 'mul': reduction using the addition operation. 'max':
1740
+ reduction using the maximum operation.'min': reduction using the minimum
1741
+ operation.
1742
+ """
1743
+
1744
+ schema = get_schema("ScatterND", 18, "")
1745
+ op = Op(self, "ScatterND", schema)
1746
+ return op(*self._prepare_inputs(schema, data, indices, updates), reduction=reduction)
1747
+
1748
+ T_Split = TypeVar(
1749
+ "T_Split",
1750
+ BFLOAT16,
1751
+ BOOL,
1752
+ COMPLEX128,
1753
+ COMPLEX64,
1754
+ DOUBLE,
1755
+ FLOAT,
1756
+ FLOAT16,
1757
+ INT16,
1758
+ INT32,
1759
+ INT64,
1760
+ INT8,
1761
+ STRING,
1762
+ UINT16,
1763
+ UINT32,
1764
+ UINT64,
1765
+ UINT8,
1766
+ )
1767
+
1768
+ def Split(
1769
+ self,
1770
+ input: T_Split,
1771
+ split: Optional[INT64] = None,
1772
+ *,
1773
+ axis: int = 0,
1774
+ num_outputs: Optional[int] = None,
1775
+ ) -> T_Split:
1776
+ r"""[🌐 Split(18)](https://onnx.ai/onnx/operators/onnx__Split.html#split-18 "Online Documentation")
1777
+
1778
+ Split a tensor into a list of tensors, along the specified 'axis'.
1779
+ Either input 'split' or the attribute 'num_outputs' should be specified, but not both.
1780
+ If the attribute 'num_outputs' is specified, then the tensor is split into equal sized parts.
1781
+ If the tensor is not evenly splittable into `num_outputs`, the last chunk will be smaller.
1782
+ If the input 'split' is specified, it indicates the sizes of each output in the split.
1783
+
1784
+
1785
+ Args:
1786
+ input: (differentiable) The tensor to split
1787
+
1788
+ split: (optional, non-differentiable) Optional length of each output. Values
1789
+ should be >= 0.Sum of the values must be equal to the dim value at
1790
+ 'axis' specified.
1791
+
1792
+ axis: Which axis to split on. A negative value means counting dimensions
1793
+ from the back. Accepted range is [-rank, rank-1] where r = rank(input).
1794
+
1795
+ num_outputs: Number of outputs to split parts of the tensor into. If the
1796
+ tensor is not evenly splittable the last chunk will be smaller.
1797
+ """
1798
+
1799
+ schema = get_schema("Split", 18, "")
1800
+ op = Op(self, "Split", schema)
1801
+ return op(
1802
+ *self._prepare_inputs(schema, input, split), axis=axis, num_outputs=num_outputs
1803
+ )