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,2588 @@
1
+ # --------------------------------------------------------------------------
2
+ # ⚠️ WARNING - AUTO-GENERATED CODE - DO NOT EDIT ⚠️
3
+ # ⚙️ Generated by 'python -m opgen'
4
+ # --------------------------------------------------------------------------
5
+ # Copyright (c) Microsoft Corporation. All rights reserved.
6
+ # Licensed under the MIT License.
7
+ # --------------------------------------------------------------------------
8
+ # pylint: disable=W0221,W0222,R0901,W0237
9
+ # mypy: disable-error-code=override
10
+ # ruff: noqa: N801,E741
11
+ # ruff: noqa: D214,D402,D405,D411,D412,D416,D417
12
+ # --------------------------------------------------------------------------
13
+
14
+ from __future__ import annotations
15
+
16
+ from typing import Optional, Sequence, Tuple, TypeVar, Union
17
+
18
+ from onnx.defs import get_schema
19
+ from typing_extensions import TypeAlias
20
+
21
+ from onnxscript.onnx_opset._impl.opset21 import Opset21
22
+ from onnxscript.onnx_types import (
23
+ BFLOAT16,
24
+ BOOL,
25
+ COMPLEX64,
26
+ COMPLEX128,
27
+ DOUBLE,
28
+ FLOAT,
29
+ FLOAT8E4M3FN,
30
+ FLOAT8E4M3FNUZ,
31
+ FLOAT8E5M2,
32
+ FLOAT8E5M2FNUZ,
33
+ FLOAT16,
34
+ INT8,
35
+ INT16,
36
+ INT32,
37
+ INT64,
38
+ STRING,
39
+ UINT8,
40
+ UINT16,
41
+ UINT32,
42
+ UINT64,
43
+ )
44
+ from onnxscript.values import Op, Opset
45
+
46
+
47
+ class Opset22(Opset21):
48
+ def __new__(cls):
49
+ return Opset.__new__(cls, "", 22)
50
+
51
+ T_Acos = TypeVar("T_Acos", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
52
+
53
+ def Acos(self, input: T_Acos) -> T_Acos:
54
+ r"""[🌐 Acos(22)](https://onnx.ai/onnx/operators/onnx__Acos.html#acos-22 "Online Documentation")
55
+
56
+
57
+ Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise.
58
+
59
+
60
+ Args:
61
+ input: (differentiable) Input tensor
62
+ """
63
+
64
+ schema = get_schema("Acos", 22, "")
65
+ op = Op(self, "Acos", schema)
66
+ return op(*self._prepare_inputs(schema, input))
67
+
68
+ T_Acosh = TypeVar("T_Acosh", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
69
+
70
+ def Acosh(self, input: T_Acosh) -> T_Acosh:
71
+ r"""[🌐 Acosh(22)](https://onnx.ai/onnx/operators/onnx__Acosh.html#acosh-22 "Online Documentation")
72
+
73
+
74
+ Calculates the hyperbolic arccosine of the given input tensor element-wise.
75
+
76
+
77
+ Args:
78
+ input: (differentiable) Input tensor
79
+ """
80
+
81
+ schema = get_schema("Acosh", 22, "")
82
+ op = Op(self, "Acosh", schema)
83
+ return op(*self._prepare_inputs(schema, input))
84
+
85
+ T_Asin = TypeVar("T_Asin", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
86
+
87
+ def Asin(self, input: T_Asin) -> T_Asin:
88
+ r"""[🌐 Asin(22)](https://onnx.ai/onnx/operators/onnx__Asin.html#asin-22 "Online Documentation")
89
+
90
+
91
+ Calculates the arcsine (inverse of sine) of the given input tensor, element-wise.
92
+
93
+
94
+ Args:
95
+ input: (differentiable) Input tensor
96
+ """
97
+
98
+ schema = get_schema("Asin", 22, "")
99
+ op = Op(self, "Asin", schema)
100
+ return op(*self._prepare_inputs(schema, input))
101
+
102
+ T_Asinh = TypeVar("T_Asinh", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
103
+
104
+ def Asinh(self, input: T_Asinh) -> T_Asinh:
105
+ r"""[🌐 Asinh(22)](https://onnx.ai/onnx/operators/onnx__Asinh.html#asinh-22 "Online Documentation")
106
+
107
+
108
+ Calculates the hyperbolic arcsine of the given input tensor element-wise.
109
+
110
+
111
+ Args:
112
+ input: (differentiable) Input tensor
113
+ """
114
+
115
+ schema = get_schema("Asinh", 22, "")
116
+ op = Op(self, "Asinh", schema)
117
+ return op(*self._prepare_inputs(schema, input))
118
+
119
+ T_Atan = TypeVar("T_Atan", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
120
+
121
+ def Atan(self, input: T_Atan) -> T_Atan:
122
+ r"""[🌐 Atan(22)](https://onnx.ai/onnx/operators/onnx__Atan.html#atan-22 "Online Documentation")
123
+
124
+
125
+ Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise.
126
+
127
+
128
+ Args:
129
+ input: (differentiable) Input tensor
130
+ """
131
+
132
+ schema = get_schema("Atan", 22, "")
133
+ op = Op(self, "Atan", schema)
134
+ return op(*self._prepare_inputs(schema, input))
135
+
136
+ T_Atanh = TypeVar("T_Atanh", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
137
+
138
+ def Atanh(self, input: T_Atanh) -> T_Atanh:
139
+ r"""[🌐 Atanh(22)](https://onnx.ai/onnx/operators/onnx__Atanh.html#atanh-22 "Online Documentation")
140
+
141
+
142
+ Calculates the hyperbolic arctangent of the given input tensor element-wise.
143
+
144
+
145
+ Args:
146
+ input: (differentiable) Input tensor
147
+ """
148
+
149
+ schema = get_schema("Atanh", 22, "")
150
+ op = Op(self, "Atanh", schema)
151
+ return op(*self._prepare_inputs(schema, input))
152
+
153
+ T_AveragePool = TypeVar("T_AveragePool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
154
+
155
+ def AveragePool(
156
+ self,
157
+ X: T_AveragePool,
158
+ *,
159
+ auto_pad: str = "NOTSET",
160
+ ceil_mode: int = 0,
161
+ count_include_pad: int = 0,
162
+ dilations: Optional[Sequence[int]] = None,
163
+ kernel_shape: Sequence[int],
164
+ pads: Optional[Sequence[int]] = None,
165
+ strides: Optional[Sequence[int]] = None,
166
+ ) -> T_AveragePool:
167
+ r"""[🌐 AveragePool(22)](https://onnx.ai/onnx/operators/onnx__AveragePool.html#averagepool-22 "Online Documentation")
168
+
169
+
170
+ AveragePool consumes an input tensor X and applies average pooling across
171
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
172
+ average pooling consisting of computing the average on all values of a
173
+ subset of the input tensor according to the kernel size and downsampling the
174
+ data into the output tensor Y for further processing. The output spatial shape is calculated differently
175
+ depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized.
176
+ With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d):
177
+ ```
178
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
179
+ ```
180
+ or
181
+ ```
182
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
183
+ ```
184
+ if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`. Sliding windows that would start in the right padded region are ignored.
185
+
186
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled:
187
+ ```
188
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])
189
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
190
+ ```
191
+ or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D):
192
+ ```
193
+ VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1
194
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1
195
+ ```
196
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
197
+ ```
198
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]
199
+ ```
200
+ The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
201
+
202
+
203
+ Args:
204
+ X: (differentiable) Input data tensor from the previous operator; dimensions
205
+ for image case are (N x C x H x W), where N is the batch size, C is the
206
+ number of channels, and H and W are the height and the width of the
207
+ data. For non image case, the dimensions are in the form of (N x C x D1
208
+ x D2 ... Dn), where N is the batch size. Optionally, if dimension
209
+ denotation is in effect, the operation expects the input data tensor to
210
+ arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL,
211
+ DATA_FEATURE, DATA_FEATURE ...].
212
+
213
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
214
+ Where default value is NOTSET, which means explicit padding is used.
215
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
216
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
217
+ split between the two sides equally or almost equally (depending on
218
+ whether it is even or odd). In case the padding is an odd number, the
219
+ extra padding is added at the end for SAME_UPPER and at the beginning
220
+ for SAME_LOWER.
221
+
222
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
223
+ shape.
224
+
225
+ count_include_pad: Whether include pad pixels when calculating values for
226
+ the edges. Default is 0, doesn't count include pad.
227
+
228
+ dilations: Dilation value along each spatial axis of filter. If not present,
229
+ the dilation defaults to 1 along each spatial axis.
230
+
231
+ kernel_shape: The size of the kernel along each axis.
232
+
233
+ pads: Padding for the beginning and ending along each spatial axis, it can
234
+ take any value greater than or equal to 0. The value represent the
235
+ number of pixels added to the beginning and end part of the
236
+ corresponding axis. `pads` format should be as follow [x1_begin,
237
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
238
+ added at the beginning of axis `i` and xi_end, the number of pixels
239
+ added at the end of axis `i`. This attribute cannot be used
240
+ simultaneously with auto_pad attribute. If not present, the padding
241
+ defaults to 0 along start and end of each spatial axis.
242
+
243
+ strides: Stride along each spatial axis. If not present, the stride defaults
244
+ to 1 along each spatial axis.
245
+ """
246
+
247
+ schema = get_schema("AveragePool", 22, "")
248
+ op = Op(self, "AveragePool", schema)
249
+ return op(
250
+ *self._prepare_inputs(schema, X),
251
+ auto_pad=auto_pad,
252
+ ceil_mode=ceil_mode,
253
+ count_include_pad=count_include_pad,
254
+ dilations=dilations,
255
+ kernel_shape=kernel_shape,
256
+ pads=pads,
257
+ strides=strides,
258
+ )
259
+
260
+ T1_Bernoulli = TypeVar("T1_Bernoulli", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
261
+
262
+ T2_Bernoulli: TypeAlias = Union[
263
+ BFLOAT16,
264
+ BOOL,
265
+ DOUBLE,
266
+ FLOAT,
267
+ FLOAT16,
268
+ INT16,
269
+ INT32,
270
+ INT64,
271
+ INT8,
272
+ UINT16,
273
+ UINT32,
274
+ UINT64,
275
+ UINT8,
276
+ ]
277
+
278
+ def Bernoulli(
279
+ self, input: T1_Bernoulli, *, dtype: Optional[int] = None, seed: Optional[float] = None
280
+ ) -> T2_Bernoulli:
281
+ r"""[🌐 Bernoulli(22)](https://onnx.ai/onnx/operators/onnx__Bernoulli.html#bernoulli-22 "Online Documentation")
282
+
283
+
284
+ Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor
285
+ containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number,
286
+ where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p).
287
+
288
+ This operator is non-deterministic and may not produce the same values in different
289
+ implementations (even if a seed is specified).
290
+
291
+
292
+ Args:
293
+ input: All values in input have to be in the range:[0, 1].
294
+
295
+ dtype: The data type for the elements of the output tensor. if not
296
+ specified, we will use the data type of the input tensor.
297
+
298
+ seed: (Optional) Seed to the random generator, if not specified we will auto
299
+ generate one.
300
+ """
301
+
302
+ schema = get_schema("Bernoulli", 22, "")
303
+ op = Op(self, "Bernoulli", schema)
304
+ return op(*self._prepare_inputs(schema, input), dtype=dtype, seed=seed)
305
+
306
+ T_Conv = TypeVar("T_Conv", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
307
+
308
+ def Conv(
309
+ self,
310
+ X: T_Conv,
311
+ W: T_Conv,
312
+ B: Optional[T_Conv] = None,
313
+ *,
314
+ auto_pad: str = "NOTSET",
315
+ dilations: Optional[Sequence[int]] = None,
316
+ group: int = 1,
317
+ kernel_shape: Optional[Sequence[int]] = None,
318
+ pads: Optional[Sequence[int]] = None,
319
+ strides: Optional[Sequence[int]] = None,
320
+ ) -> T_Conv:
321
+ r"""[🌐 Conv(22)](https://onnx.ai/onnx/operators/onnx__Conv.html#conv-22 "Online Documentation")
322
+
323
+
324
+ The convolution operator consumes an input tensor and a filter, and
325
+ computes the output.
326
+
327
+ Args:
328
+ X: (differentiable) Input data tensor from previous layer; has size (N x C x
329
+ H x W), where N is the batch size, C is the number of channels, and H
330
+ and W are the height and width. Note that this is for the 2D image.
331
+ Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if
332
+ dimension denotation is in effect, the operation expects input data
333
+ tensor to arrive with the dimension denotation of [DATA_BATCH,
334
+ DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
335
+
336
+ W: (differentiable) The weight tensor that will be used in the convolutions;
337
+ has size (M x C/group x kH x kW), where C is the number of channels, and
338
+ kH and kW are the height and width of the kernel, and M is the number of
339
+ feature maps. For more than 2 dimensions, the kernel shape will be (M x
340
+ C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension
341
+ of the kernel. Optionally, if dimension denotation is in effect, the
342
+ operation expects the weight tensor to arrive with the dimension
343
+ denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL,
344
+ FILTER_SPATIAL ...]. Assuming zero based indices for the shape array,
345
+ X.shape[1] == (W.shape[1] * group) == C and W.shape[0] mod G == 0. Or in
346
+ other words FILTER_IN_CHANNEL multiplied by the number of groups should
347
+ be equal to DATA_CHANNEL and the number of feature maps M should be a
348
+ multiple of the number of groups G.
349
+
350
+ B: (optional, differentiable) Optional 1D bias to be added to the
351
+ convolution, has size of M.
352
+
353
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
354
+ Where default value is NOTSET, which means explicit padding is used.
355
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
356
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
357
+ split between the two sides equally or almost equally (depending on
358
+ whether it is even or odd). In case the padding is an odd number, the
359
+ extra padding is added at the end for SAME_UPPER and at the beginning
360
+ for SAME_LOWER.
361
+
362
+ dilations: dilation value along each spatial axis of the filter. If not
363
+ present, the dilation defaults is 1 along each spatial axis.
364
+
365
+ group: number of groups input channels and output channels are divided into.
366
+
367
+ kernel_shape: The shape of the convolution kernel. If not present, should be
368
+ inferred from input W.
369
+
370
+ pads: Padding for the beginning and ending along each spatial axis, it can
371
+ take any value greater than or equal to 0. The value represent the
372
+ number of pixels added to the beginning and end part of the
373
+ corresponding axis. `pads` format should be as follow [x1_begin,
374
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
375
+ added at the beginning of axis `i` and xi_end, the number of pixels
376
+ added at the end of axis `i`. This attribute cannot be used
377
+ simultaneously with auto_pad attribute. If not present, the padding
378
+ defaults to 0 along start and end of each spatial axis.
379
+
380
+ strides: Stride along each spatial axis. If not present, the stride defaults
381
+ is 1 along each spatial axis.
382
+ """
383
+
384
+ schema = get_schema("Conv", 22, "")
385
+ op = Op(self, "Conv", schema)
386
+ return op(
387
+ *self._prepare_inputs(schema, X, W, B),
388
+ auto_pad=auto_pad,
389
+ dilations=dilations,
390
+ group=group,
391
+ kernel_shape=kernel_shape,
392
+ pads=pads,
393
+ strides=strides,
394
+ )
395
+
396
+ T_ConvTranspose = TypeVar("T_ConvTranspose", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
397
+
398
+ def ConvTranspose(
399
+ self,
400
+ X: T_ConvTranspose,
401
+ W: T_ConvTranspose,
402
+ B: Optional[T_ConvTranspose] = None,
403
+ *,
404
+ auto_pad: str = "NOTSET",
405
+ dilations: Optional[Sequence[int]] = None,
406
+ group: int = 1,
407
+ kernel_shape: Optional[Sequence[int]] = None,
408
+ output_padding: Optional[Sequence[int]] = None,
409
+ output_shape: Optional[Sequence[int]] = None,
410
+ pads: Optional[Sequence[int]] = None,
411
+ strides: Optional[Sequence[int]] = None,
412
+ ) -> T_ConvTranspose:
413
+ r"""[🌐 ConvTranspose(22)](https://onnx.ai/onnx/operators/onnx__ConvTranspose.html#convtranspose-22 "Online Documentation")
414
+
415
+
416
+ The convolution transpose operator consumes an input tensor and a filter,
417
+ and computes the output.
418
+
419
+ If the pads parameter is provided the shape of the output is calculated via the following equation:
420
+
421
+ output_shape[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - pads[start_i] - pads[end_i]
422
+
423
+ output_shape can also be explicitly specified in which case pads values are auto generated using these equations:
424
+
425
+ total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]
426
+ If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)
427
+ Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2).
428
+
429
+
430
+
431
+ Args:
432
+ X: (differentiable) Input data tensor from previous layer; has size (N x C x
433
+ H x W), where N is the batch size, C is the number of channels, and H
434
+ and W are the height and width. Note that this is for the 2D image.
435
+ Otherwise the size is (N x C x D1 x D2 ... x Dn)
436
+
437
+ W: (differentiable) The weight tensor that will be used in the convolutions;
438
+ has size (C x M/group x kH x kW), where C is the number of channels, and
439
+ kH and kW are the height and width of the kernel, and M is the number of
440
+ feature maps. For more than 2 dimensions, the weight shape will be (C x
441
+ M/group x k1 x k2 x ... x kn), where (k1 x k2 x ... x kn) is the
442
+ dimension of the kernel. The number of channels in the output should be
443
+ equal to W.shape[1] * group (assuming zero based indices of the shape
444
+ array)
445
+
446
+ B: (optional, differentiable) Optional 1D bias to be added to the
447
+ convolution, has size of M.
448
+
449
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
450
+ Where default value is NOTSET, which means explicit padding is used.
451
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
452
+ input_shape[i] * strides[i]` for each axis `i`. The padding is split
453
+ between the two sides equally or almost equally (depending on whether it
454
+ is even or odd). In case the padding is an odd number, the extra padding
455
+ is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
456
+
457
+ dilations: dilation value along each spatial axis of the filter. If not
458
+ present, the dilation defaults to 1 along each spatial axis.
459
+
460
+ group: number of groups input channels and output channels are divided into.
461
+
462
+ kernel_shape: The shape of the convolution kernel. If not present, should be
463
+ inferred from input W.
464
+
465
+ output_padding: Additional elements added to the side with higher coordinate
466
+ indices in the output. Each padding value in "output_padding" must be
467
+ less than the corresponding stride/dilation dimension. By default, this
468
+ attribute is a zero vector. Note that this attribute doesn't directly
469
+ affect the computed output values. It only controls the selection of the
470
+ computed values, so changing this attribute only adds or removes output
471
+ elements. If "output_shape" is explicitly provided, "output_padding"
472
+ does not contribute additional size to "output_shape" but participates
473
+ in the computation of the needed padding amount. This is also called
474
+ adjs or adjustment in some frameworks.
475
+
476
+ output_shape: The shape of the output can be explicitly set which will cause
477
+ pads values to be auto generated. If output_shape is specified pads
478
+ values are ignored. See doc for details for equations to generate pads.
479
+ Note that the output_shape attribute value should not include dimensions
480
+ for batch size and channels, which are automatically inferred.
481
+
482
+ pads: Padding for the beginning and ending along each spatial axis, it can
483
+ take any value greater than or equal to 0. The value represent the
484
+ number of pixels added to the beginning and end part of the
485
+ corresponding axis. `pads` format should be as follow [x1_begin,
486
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
487
+ added at the beginning of axis `i` and xi_end, the number of pixels
488
+ added at the end of axis `i`. This attribute cannot be used
489
+ simultaneously with auto_pad attribute. If not present, the padding
490
+ defaults to 0 along start and end of each spatial axis.
491
+
492
+ strides: Stride along each spatial axis. If not present, the stride defaults
493
+ to 1 along each spatial axis.
494
+ """
495
+
496
+ schema = get_schema("ConvTranspose", 22, "")
497
+ op = Op(self, "ConvTranspose", schema)
498
+ return op(
499
+ *self._prepare_inputs(schema, X, W, B),
500
+ auto_pad=auto_pad,
501
+ dilations=dilations,
502
+ group=group,
503
+ kernel_shape=kernel_shape,
504
+ output_padding=output_padding,
505
+ output_shape=output_shape,
506
+ pads=pads,
507
+ strides=strides,
508
+ )
509
+
510
+ T_Cos = TypeVar("T_Cos", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
511
+
512
+ def Cos(self, input: T_Cos) -> T_Cos:
513
+ r"""[🌐 Cos(22)](https://onnx.ai/onnx/operators/onnx__Cos.html#cos-22 "Online Documentation")
514
+
515
+
516
+ Calculates the cosine of the given input tensor, element-wise.
517
+
518
+
519
+ Args:
520
+ input: (differentiable) Input tensor
521
+ """
522
+
523
+ schema = get_schema("Cos", 22, "")
524
+ op = Op(self, "Cos", schema)
525
+ return op(*self._prepare_inputs(schema, input))
526
+
527
+ T_Cosh = TypeVar("T_Cosh", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
528
+
529
+ def Cosh(self, input: T_Cosh) -> T_Cosh:
530
+ r"""[🌐 Cosh(22)](https://onnx.ai/onnx/operators/onnx__Cosh.html#cosh-22 "Online Documentation")
531
+
532
+
533
+ Calculates the hyperbolic cosine of the given input tensor element-wise.
534
+
535
+
536
+ Args:
537
+ input: (differentiable) Input tensor
538
+ """
539
+
540
+ schema = get_schema("Cosh", 22, "")
541
+ op = Op(self, "Cosh", schema)
542
+ return op(*self._prepare_inputs(schema, input))
543
+
544
+ T_DeformConv = TypeVar("T_DeformConv", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
545
+
546
+ def DeformConv(
547
+ self,
548
+ X: T_DeformConv,
549
+ W: T_DeformConv,
550
+ offset: T_DeformConv,
551
+ B: Optional[T_DeformConv] = None,
552
+ mask: Optional[T_DeformConv] = None,
553
+ *,
554
+ dilations: Optional[Sequence[int]] = None,
555
+ group: int = 1,
556
+ kernel_shape: Optional[Sequence[int]] = None,
557
+ offset_group: int = 1,
558
+ pads: Optional[Sequence[int]] = None,
559
+ strides: Optional[Sequence[int]] = None,
560
+ ) -> T_DeformConv:
561
+ r"""[🌐 DeformConv(22)](https://onnx.ai/onnx/operators/onnx__DeformConv.html#deformconv-22 "Online Documentation")
562
+
563
+
564
+ Performs deformable convolution as described in https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168.
565
+ This operator specification supports the general N-D case. Note that most common use cases have 2D or 3D data.
566
+
567
+
568
+ Args:
569
+ X: Input data tensor. For 2D image data, it has shape (N, C, H, W) where N
570
+ is the batch size, C is the number of input channels, and H and W are
571
+ the height and width. In general, the shape is (N, C, D1, D2, ... , Dn)
572
+ for n-dimensional data, where D1 to Dn are the spatial dimension sizes.
573
+ Most common use cases have n = 2 or 3.
574
+
575
+ W: Weight tensor that will be used in the convolutions. It has shape (oC,
576
+ C/group, kH, kW), where oC is the number of output channels and kH and
577
+ kW are the kernel height and width. For more than 2 dimensions, it has
578
+ shape (oC, C/group, k1, k2, ... , kn).
579
+
580
+ offset: Offset tensor denoting the offset for the sampling locations in the
581
+ convolution kernel. It has shape (N, offset_group * kH * kW * 2, oH, oW)
582
+ for 2D data or (N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... ,
583
+ on) for nD data. Use linear interpolationfor fractional offset values.
584
+ Sampling locations outside of the padded input tensor gives zero.
585
+
586
+ B: (optional) Optional 1D bias of length oC to be added to the convolution.
587
+ Default is a tensor of zeros.
588
+
589
+ mask: (optional) The mask tensor to be applied to each position in the
590
+ convolution kernel. It has shape (N, offset_group * kH * kW, oH, oW) for
591
+ 2D data or (N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on)
592
+ for nD data. Default is a tensor of ones.
593
+
594
+ dilations: Dilation value along each spatial axis of the kernel. Default is
595
+ 1 along each axis.
596
+
597
+ group: Number of groups the input and output channels, C and oC, are divided
598
+ into. C and oC must both be divisible by group. Default is 1.
599
+
600
+ kernel_shape: Shape of the convolution kernel. If not present, it is
601
+ inferred from the shape of input W.
602
+
603
+ offset_group: Number of groups of offset. C must be divisible by
604
+ offset_group. Default is 1.
605
+
606
+ pads: Padding for the beginning and end along each spatial axis. The values
607
+ represent the number of pixels added to the beginning and end of the
608
+ corresponding axis and can take any nonnegative value. The format should
609
+ be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where
610
+ xi_begin is the number of pixels added at the beginning of axis `i` and
611
+ xi_end is the number of pixels added at the end of axis `i`. Default is
612
+ 0 along each axis.
613
+
614
+ strides: Stride along each spatial axis. Default is 1 along each axis.
615
+ """
616
+
617
+ schema = get_schema("DeformConv", 22, "")
618
+ op = Op(self, "DeformConv", schema)
619
+ return op(
620
+ *self._prepare_inputs(schema, X, W, offset, B, mask),
621
+ dilations=dilations,
622
+ group=group,
623
+ kernel_shape=kernel_shape,
624
+ offset_group=offset_group,
625
+ pads=pads,
626
+ strides=strides,
627
+ )
628
+
629
+ T_Det = TypeVar("T_Det", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
630
+
631
+ def Det(self, X: T_Det) -> T_Det:
632
+ r"""[🌐 Det(22)](https://onnx.ai/onnx/operators/onnx__Det.html#det-22 "Online Documentation")
633
+
634
+
635
+ Det calculates determinant of a square matrix or batches of square matrices.
636
+ Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions,
637
+ and the inner-most 2 dimensions form square matrices.
638
+ The output is a tensor of shape `[*]`, containing the determinants of all input submatrices.
639
+ e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`).
640
+
641
+
642
+ Args:
643
+ X: (differentiable) Input tensor
644
+ """
645
+
646
+ schema = get_schema("Det", 22, "")
647
+ op = Op(self, "Det", schema)
648
+ return op(*self._prepare_inputs(schema, X))
649
+
650
+ T_Dropout = TypeVar(
651
+ "T_Dropout",
652
+ BFLOAT16,
653
+ DOUBLE,
654
+ FLOAT,
655
+ FLOAT16,
656
+ FLOAT8E4M3FN,
657
+ FLOAT8E4M3FNUZ,
658
+ FLOAT8E5M2,
659
+ FLOAT8E5M2FNUZ,
660
+ )
661
+
662
+ T1_Dropout = TypeVar(
663
+ "T1_Dropout",
664
+ BFLOAT16,
665
+ DOUBLE,
666
+ FLOAT,
667
+ FLOAT16,
668
+ FLOAT8E4M3FN,
669
+ FLOAT8E4M3FNUZ,
670
+ FLOAT8E5M2,
671
+ FLOAT8E5M2FNUZ,
672
+ )
673
+
674
+ T2_Dropout: TypeAlias = BOOL
675
+
676
+ def Dropout(
677
+ self,
678
+ data: T_Dropout,
679
+ ratio: Optional[T1_Dropout] = None,
680
+ training_mode: Optional[T2_Dropout] = None,
681
+ *,
682
+ seed: Optional[int] = None,
683
+ ) -> Tuple[T_Dropout, T2_Dropout]:
684
+ r"""[🌐 Dropout(22)](https://onnx.ai/onnx/operators/onnx__Dropout.html#dropout-22 "Online Documentation")
685
+
686
+
687
+ Dropout takes an input floating-point tensor, an optional input ratio (floating-point scalar) and an optional input training_mode (boolean scalar). It produces two tensor outputs,
688
+ output (floating-point tensor) and mask (optional `Tensor<bool>`). If `training_mode` is true then the output Y will be a random dropout;
689
+ Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode,
690
+ the user can simply not pass `training_mode` input or set it to false.
691
+ ::
692
+
693
+ output = scale * data * mask,
694
+
695
+
696
+ where
697
+ ::
698
+
699
+ scale = 1. / (1. - ratio).
700
+
701
+
702
+ 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.
703
+
704
+
705
+ Args:
706
+ data: (differentiable) The input data as Tensor.
707
+
708
+ ratio: (optional, non-differentiable) The ratio of random dropout, with
709
+ value in [0, 1). If this input was not set, or if it was set to 0, the
710
+ output would be a simple copy of the input. If it's non-zero, output
711
+ will be a random dropout of the scaled input, which is typically the
712
+ case during training. It is an optional value, if not specified it will
713
+ default to 0.5.
714
+
715
+ training_mode: (optional, non-differentiable) If set to true then it
716
+ indicates dropout is being used for training. It is an optional value
717
+ hence unless specified explicitly, it is false. If it is false, ratio is
718
+ ignored and the operation mimics inference mode where nothing will be
719
+ dropped from the input data and if mask is requested as output it will
720
+ contain all ones.
721
+
722
+ seed: (Optional) Seed to the random generator, if not specified we will auto
723
+ generate one.
724
+ """
725
+
726
+ schema = get_schema("Dropout", 22, "")
727
+ op = Op(self, "Dropout", schema)
728
+ return op(*self._prepare_inputs(schema, data, ratio, training_mode), seed=seed)
729
+
730
+ T_Elu = TypeVar("T_Elu", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
731
+
732
+ def Elu(self, X: T_Elu, *, alpha: float = 1.0) -> T_Elu:
733
+ r"""[🌐 Elu(22)](https://onnx.ai/onnx/operators/onnx__Elu.html#elu-22 "Online Documentation")
734
+
735
+
736
+ Elu takes one input data (Tensor<T>) and produces one output data
737
+ (Tensor<T>) where the function `f(x) = alpha * (exp(x) - 1.) for x <
738
+ 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise.
739
+
740
+
741
+
742
+ Args:
743
+ X: (differentiable) 1D input tensor
744
+
745
+ alpha: Coefficient of ELU.
746
+ """
747
+
748
+ schema = get_schema("Elu", 22, "")
749
+ op = Op(self, "Elu", schema)
750
+ return op(*self._prepare_inputs(schema, X), alpha=alpha)
751
+
752
+ T1_EyeLike = TypeVar(
753
+ "T1_EyeLike",
754
+ BFLOAT16,
755
+ BOOL,
756
+ DOUBLE,
757
+ FLOAT,
758
+ FLOAT16,
759
+ INT16,
760
+ INT32,
761
+ INT64,
762
+ INT8,
763
+ UINT16,
764
+ UINT32,
765
+ UINT64,
766
+ UINT8,
767
+ )
768
+
769
+ T2_EyeLike: TypeAlias = Union[
770
+ BFLOAT16,
771
+ BOOL,
772
+ DOUBLE,
773
+ FLOAT,
774
+ FLOAT16,
775
+ INT16,
776
+ INT32,
777
+ INT64,
778
+ INT8,
779
+ UINT16,
780
+ UINT32,
781
+ UINT64,
782
+ UINT8,
783
+ ]
784
+
785
+ def EyeLike(
786
+ self, input: T1_EyeLike, *, dtype: Optional[int] = None, k: int = 0
787
+ ) -> T2_EyeLike:
788
+ r"""[🌐 EyeLike(22)](https://onnx.ai/onnx/operators/onnx__EyeLike.html#eyelike-22 "Online Documentation")
789
+
790
+
791
+ Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D
792
+ tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the
793
+ same as the input tensor. The data type can be specified by the 'dtype' argument. If
794
+ 'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal
795
+ is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals.
796
+ The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the
797
+ TensorProto message and be valid as an output type.
798
+
799
+
800
+ Args:
801
+ input: 2D input tensor to copy shape, and optionally, type information from.
802
+
803
+ dtype: (Optional) The data type for the elements of the output tensor. If
804
+ not specified,the data type of the input tensor T1 is used. If input
805
+ tensor T1 is also notspecified, then type defaults to 'float'.
806
+
807
+ k: (Optional) Index of the diagonal to be populated with ones. Default is 0.
808
+ If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the
809
+ main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a
810
+ lower diagonal.
811
+ """
812
+
813
+ schema = get_schema("EyeLike", 22, "")
814
+ op = Op(self, "EyeLike", schema)
815
+ return op(*self._prepare_inputs(schema, input), dtype=dtype, k=k)
816
+
817
+ T_GRU = TypeVar("T_GRU", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
818
+
819
+ T1_GRU: TypeAlias = INT32
820
+
821
+ def GRU(
822
+ self,
823
+ X: T_GRU,
824
+ W: T_GRU,
825
+ R: T_GRU,
826
+ B: Optional[T_GRU] = None,
827
+ sequence_lens: Optional[T1_GRU] = None,
828
+ initial_h: Optional[T_GRU] = None,
829
+ *,
830
+ activation_alpha: Optional[Sequence[float]] = None,
831
+ activation_beta: Optional[Sequence[float]] = None,
832
+ activations: Optional[Sequence[str]] = None,
833
+ clip: Optional[float] = None,
834
+ direction: str = "forward",
835
+ hidden_size: Optional[int] = None,
836
+ layout: int = 0,
837
+ linear_before_reset: int = 0,
838
+ ) -> Tuple[T_GRU, T_GRU]:
839
+ r"""[🌐 GRU(22)](https://onnx.ai/onnx/operators/onnx__GRU.html#gru-22 "Online Documentation")
840
+
841
+
842
+ Computes an one-layer GRU. This operator is usually supported via some custom
843
+ implementation such as CuDNN.
844
+
845
+ Notations:
846
+
847
+ * `X` - input tensor
848
+ * `z` - update gate
849
+ * `r` - reset gate
850
+ * `h` - hidden gate
851
+ * `t` - time step (t-1 means previous time step)
852
+ * `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates
853
+ * `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates
854
+ * `Wb[zrh]` - W bias vectors for update, reset, and hidden gates
855
+ * `Rb[zrh]` - R bias vectors for update, reset, and hidden gates
856
+ * `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates
857
+ * `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates
858
+ * `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates
859
+ * `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates
860
+ * `H` - Hidden state
861
+ * `num_directions` - 2 if direction == bidirectional else 1
862
+
863
+ Activation functions:
864
+
865
+ * Relu(x) - max(0, x)
866
+ * Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
867
+ * Sigmoid(x) - 1/(1 + e^{-x})
868
+
869
+ NOTE:
870
+ Below are optional
871
+
872
+ * Affine(x) - alpha * x + beta
873
+ * LeakyRelu(x) - x if x >= 0 else alpha * x
874
+ * ThresholdedRelu(x) - x if x >= alpha else 0
875
+ * ScaledTanh(x) - alpha * Tanh(beta * x)
876
+ * HardSigmoid(x) - min(max(alpha * x + beta, 0), 1)
877
+ * Elu(x) - x if x >= 0 else alpha * (e^x - 1)
878
+ * Softsign(x) - x/(1 + |x|)
879
+ * Softplus(x) - log(1 + e^x)
880
+
881
+ Equations (Default: f=Sigmoid, g=Tanh):
882
+
883
+ * zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz)
884
+ * rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr)
885
+ * ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0
886
+ * ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0
887
+ * Ht = (1 - zt) (.) ht + zt (.) Ht-1
888
+ 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.
889
+
890
+
891
+ Args:
892
+ X: (differentiable) The input sequences packed (and potentially padded) into
893
+ one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
894
+
895
+ W: (differentiable) The weight tensor for the gates. Concatenation of
896
+ `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor
897
+ has shape `[num_directions, 3*hidden_size, input_size]`.
898
+
899
+ R: (differentiable) The recurrence weight tensor. Concatenation of `R[zrh]`
900
+ and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has
901
+ shape `[num_directions, 3*hidden_size, hidden_size]`.
902
+
903
+ B: (optional, differentiable) The bias tensor for the gates. Concatenation
904
+ of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional)
905
+ along dimension 0. This tensor has shape `[num_directions,
906
+ 6*hidden_size]`. Optional: If not specified - assumed to be 0
907
+
908
+ sequence_lens: (optional, non-differentiable) Optional tensor specifying
909
+ lengths of the sequences in a batch. If not specified - assumed all
910
+ sequences in the batch to have length `seq_length`. It has shape
911
+ `[batch_size]`.
912
+
913
+ initial_h: (optional, non-differentiable) Optional initial value of the
914
+ hidden. If not specified - assumed to be 0. It has shape
915
+ `[num_directions, batch_size, hidden_size]`.
916
+
917
+ activation_alpha: Optional scaling values used by some activation functions.
918
+ The values are consumed in the order of activation functions, for
919
+ example (f, g, h) in LSTM. Default values are the same as of
920
+ corresponding ONNX operators.For example with LeakyRelu, the default
921
+ alpha is 0.01.
922
+
923
+ activation_beta: Optional scaling values used by some activation functions.
924
+ The values are consumed in the order of activation functions, for
925
+ example (f, g, h) in LSTM. Default values are the same as of
926
+ corresponding ONNX operators.
927
+
928
+ activations: A list of 2 (or 4 if bidirectional) activation functions for
929
+ update, reset, and hidden gates. The activation functions must be one of
930
+ the activation functions specified above. Optional: See the equations
931
+ for default if not specified.
932
+
933
+ clip: Cell clip threshold. Clipping bounds the elements of a tensor in the
934
+ range of [-threshold, +threshold] and is applied to the input of
935
+ activations. No clip if not specified.
936
+
937
+ direction: Specify if the RNN is forward, reverse, or bidirectional. Must be
938
+ one of forward (default), reverse, or bidirectional.
939
+
940
+ hidden_size: Number of neurons in the hidden layer
941
+
942
+ layout: The shape format of inputs X, initial_h and outputs Y, Y_h. If 0,
943
+ the following shapes are expected: X.shape = [seq_length, batch_size,
944
+ input_size], Y.shape = [seq_length, num_directions, batch_size,
945
+ hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size,
946
+ hidden_size]. If 1, the following shapes are expected: X.shape =
947
+ [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length,
948
+ num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size,
949
+ num_directions, hidden_size].
950
+
951
+ linear_before_reset: When computing the output of the hidden gate, apply the
952
+ linear transformation before multiplying by the output of the reset
953
+ gate.
954
+ """
955
+
956
+ schema = get_schema("GRU", 22, "")
957
+ op = Op(self, "GRU", schema)
958
+ return op(
959
+ *self._prepare_inputs(schema, X, W, R, B, sequence_lens, initial_h),
960
+ activation_alpha=activation_alpha,
961
+ activation_beta=activation_beta,
962
+ activations=activations,
963
+ clip=clip,
964
+ direction=direction,
965
+ hidden_size=hidden_size,
966
+ layout=layout,
967
+ linear_before_reset=linear_before_reset,
968
+ )
969
+
970
+ T_GlobalAveragePool = TypeVar("T_GlobalAveragePool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
971
+
972
+ def GlobalAveragePool(self, X: T_GlobalAveragePool) -> T_GlobalAveragePool:
973
+ r"""[🌐 GlobalAveragePool(22)](https://onnx.ai/onnx/operators/onnx__GlobalAveragePool.html#globalaveragepool-22 "Online Documentation")
974
+
975
+
976
+ GlobalAveragePool consumes an input tensor X and applies average pooling across
977
+ the values in the same channel. This is equivalent to AveragePool with kernel size
978
+ equal to the spatial dimension of input tensor.
979
+
980
+ Args:
981
+ X: (differentiable) Input data tensor from the previous operator; dimensions
982
+ for image case are (N x C x H x W), where N is the batch size, C is the
983
+ number of channels, and H and W are the height and the width of the
984
+ data. For non image case, the dimensions are in the form of (N x C x D1
985
+ x D2 ... Dn), where N is the batch size.
986
+ """
987
+
988
+ schema = get_schema("GlobalAveragePool", 22, "")
989
+ op = Op(self, "GlobalAveragePool", schema)
990
+ return op(*self._prepare_inputs(schema, X))
991
+
992
+ T_GlobalLpPool = TypeVar("T_GlobalLpPool", DOUBLE, FLOAT, FLOAT16)
993
+
994
+ def GlobalLpPool(self, X: T_GlobalLpPool, *, p: int = 2) -> T_GlobalLpPool:
995
+ r"""[🌐 GlobalLpPool(22)](https://onnx.ai/onnx/operators/onnx__GlobalLpPool.html#globallppool-22 "Online Documentation")
996
+
997
+
998
+ GlobalLpPool consumes an input tensor X and applies lp pool pooling across
999
+ the values in the same channel. This is equivalent to LpPool with kernel size
1000
+ equal to the spatial dimension of input tensor.
1001
+
1002
+ Args:
1003
+ X: (differentiable) Input data tensor from the previous operator; dimensions
1004
+ for image case are (N x C x H x W), where N is the batch size, C is the
1005
+ number of channels, and H and W are the height and the width of the
1006
+ data. For non image case, the dimensions are in the form of (N x C x D1
1007
+ x D2 ... Dn), where N is the batch size.
1008
+
1009
+ p: p value of the Lp norm used to pool over the input data.
1010
+ """
1011
+
1012
+ schema = get_schema("GlobalLpPool", 22, "")
1013
+ op = Op(self, "GlobalLpPool", schema)
1014
+ return op(*self._prepare_inputs(schema, X), p=p)
1015
+
1016
+ T_GlobalMaxPool = TypeVar("T_GlobalMaxPool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1017
+
1018
+ def GlobalMaxPool(self, X: T_GlobalMaxPool) -> T_GlobalMaxPool:
1019
+ r"""[🌐 GlobalMaxPool(22)](https://onnx.ai/onnx/operators/onnx__GlobalMaxPool.html#globalmaxpool-22 "Online Documentation")
1020
+
1021
+
1022
+ GlobalMaxPool consumes an input tensor X and applies max pooling across
1023
+ the values in the same channel. This is equivalent to MaxPool with kernel size
1024
+ equal to the spatial dimension of input tensor.
1025
+
1026
+ Args:
1027
+ X: (differentiable) Input data tensor from the previous operator; dimensions
1028
+ for image case are (N x C x H x W), where N is the batch size, C is the
1029
+ number of channels, and H and W are the height and the width of the
1030
+ data. For non image case, the dimensions are in the form of (N x C x D1
1031
+ x D2 ... Dn), where N is the batch size.
1032
+ """
1033
+
1034
+ schema = get_schema("GlobalMaxPool", 22, "")
1035
+ op = Op(self, "GlobalMaxPool", schema)
1036
+ return op(*self._prepare_inputs(schema, X))
1037
+
1038
+ T1_GridSample = TypeVar(
1039
+ "T1_GridSample",
1040
+ BFLOAT16,
1041
+ BOOL,
1042
+ COMPLEX128,
1043
+ COMPLEX64,
1044
+ DOUBLE,
1045
+ FLOAT,
1046
+ FLOAT16,
1047
+ INT16,
1048
+ INT32,
1049
+ INT64,
1050
+ INT8,
1051
+ STRING,
1052
+ UINT16,
1053
+ UINT32,
1054
+ UINT64,
1055
+ UINT8,
1056
+ )
1057
+
1058
+ T2_GridSample = TypeVar("T2_GridSample", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1059
+
1060
+ def GridSample(
1061
+ self,
1062
+ X: T1_GridSample,
1063
+ grid: T2_GridSample,
1064
+ *,
1065
+ align_corners: int = 0,
1066
+ mode: str = "linear",
1067
+ padding_mode: str = "zeros",
1068
+ ) -> T1_GridSample:
1069
+ r"""[🌐 GridSample(22)](https://onnx.ai/onnx/operators/onnx__GridSample.html#gridsample-22 "Online Documentation")
1070
+
1071
+
1072
+ Given an input `X` and a flow-field `grid`, computes the output `Y` using `X` values and pixel locations from the `grid`.
1073
+ For spatial input `X` with shape (N, C, H, W), the `grid` will have shape (N, H_out, W_out, 2),
1074
+ the output `Y` will have shape (N, C, H_out, W_out). For volumetric input `X` with shape (N, C, D, H, W),
1075
+ the `grid` will have shape (N, D_out, H_out, W_out, 3), the output `Y` will have shape (N, C, D_out, H_out, W_out).
1076
+ More generally, for an input `X` of rank r+2 with shape (N, C, d1, d2, ..., dr),
1077
+ the `grid` will have shape (N, D1_out, D2_out, ..., Dr_out, r), the output `Y` will have shape (N, C, D1_out, D2_out, ..., Dr_out).
1078
+
1079
+ The tensor `X` contains values at centers of square pixels (voxels, etc) locations such as (n, c, d1_in, d2_in, ..., dr_in).
1080
+ The (n, d1_out, d2_out, ..., dr_out, :) values from the tensor `grid` are the normalized positions for interpolating the values
1081
+ at the (n, c, d1_out, d2_out, ..., dr_out) locations from the output tensor `Y` using a specified interpolation method (the mode)
1082
+ and a padding mode (for `grid` positions falling outside the 2-dimensional image).
1083
+
1084
+ For example, the values in `grid[n, h_out, w_out, :]` are size-2 vectors specifying normalized positions in the 2-dimensional space of `X`.
1085
+ They are used to interpolate output values of `Y[n, c, h_out, w_out]`.
1086
+
1087
+ The GridSample operator is often used in doing grid generator and sampler in the
1088
+ [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025).
1089
+ See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html).
1090
+
1091
+
1092
+ Args:
1093
+ X: (differentiable) Input tensor of rank r+2 that has shape (N, C, D1, D2,
1094
+ ..., Dr), where N is the batch size, C is the number of channels, D1,
1095
+ D2, ..., Dr are the spatial dimensions.
1096
+
1097
+ grid: (non-differentiable) Input offset of shape (N, D1_out, D2_out, ...,
1098
+ Dr_out, r), where D1_out, D2_out, ..., Dr_out are the spatial dimensions
1099
+ of the grid and output, and r is the number of spatial dimensions. Grid
1100
+ specifies the sampling locations normalized by the input spatial
1101
+ dimensions. Therefore, it should have most values in the range of [-1,
1102
+ 1]. If the grid has values outside the range of [-1, 1], the
1103
+ corresponding outputs will be handled as defined by padding_mode.
1104
+ Following computer vision convention, the coordinates in the length-r
1105
+ location vector are listed from the innermost tensor dimension to the
1106
+ outermost, the opposite of regular tensor indexing.
1107
+
1108
+ align_corners: If align_corners=1, the extrema (-1 and 1) are considered as
1109
+ referring to the center points of the input's corner pixels (voxels,
1110
+ etc.). If align_corners=0, they are instead considered as referring to
1111
+ the corner points of the input's corner pixels (voxels, etc.), making
1112
+ the sampling more resolution agnostic.
1113
+
1114
+ mode: Three interpolation modes: linear (default), nearest and cubic. The
1115
+ "linear" mode includes linear and N-linear interpolation modes depending
1116
+ on the number of spatial dimensions of the input tensor (i.e. linear for
1117
+ 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The
1118
+ "cubic" mode also includes N-cubic interpolation modes following the
1119
+ same rules. The "nearest" mode rounds to the nearest even index when the
1120
+ sampling point falls halfway between two indices.
1121
+
1122
+ padding_mode: Support padding modes for outside grid values:
1123
+ `zeros`(default), `border`, `reflection`. zeros: use 0 for out-of-bound
1124
+ grid locations, border: use border values for out-of-bound grid
1125
+ locations, reflection: use values at locations reflected by the border
1126
+ for out-of-bound grid locations. If index 0 represents the margin pixel,
1127
+ the reflected value at index -1 will be the same as the value at index
1128
+ 1. For location far away from the border, it will keep being reflected
1129
+ until becoming in bound. If pixel location x = -3.5 reflects by border
1130
+ -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' =
1131
+ 0.5.
1132
+ """
1133
+
1134
+ schema = get_schema("GridSample", 22, "")
1135
+ op = Op(self, "GridSample", schema)
1136
+ return op(
1137
+ *self._prepare_inputs(schema, X, grid),
1138
+ align_corners=align_corners,
1139
+ mode=mode,
1140
+ padding_mode=padding_mode,
1141
+ )
1142
+
1143
+ T_HardSigmoid = TypeVar("T_HardSigmoid", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1144
+
1145
+ def HardSigmoid(
1146
+ self, X: T_HardSigmoid, *, alpha: float = 0.20000000298023224, beta: float = 0.5
1147
+ ) -> T_HardSigmoid:
1148
+ r"""[🌐 HardSigmoid(22)](https://onnx.ai/onnx/operators/onnx__HardSigmoid.html#hardsigmoid-22 "Online Documentation")
1149
+
1150
+
1151
+ HardSigmoid takes one input data (Tensor<T>) and produces one output data
1152
+ (Tensor<T>) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)),
1153
+ is applied to the tensor elementwise.
1154
+
1155
+
1156
+ Args:
1157
+ X: (differentiable) Input tensor
1158
+
1159
+ alpha: Value of alpha.
1160
+
1161
+ beta: Value of beta.
1162
+ """
1163
+
1164
+ schema = get_schema("HardSigmoid", 22, "")
1165
+ op = Op(self, "HardSigmoid", schema)
1166
+ return op(*self._prepare_inputs(schema, X), alpha=alpha, beta=beta)
1167
+
1168
+ T_HardSwish = TypeVar("T_HardSwish", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1169
+
1170
+ def HardSwish(self, X: T_HardSwish) -> T_HardSwish:
1171
+ r"""[🌐 HardSwish(22)](https://onnx.ai/onnx/operators/onnx__HardSwish.html#hardswish-22 "Online Documentation")
1172
+
1173
+
1174
+ HardSwish takes one input data (Tensor<T>) and produces one output data (Tensor<T>) where
1175
+ the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid<alpha, beta>(x),
1176
+ where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise.
1177
+
1178
+
1179
+ Args:
1180
+ X: (differentiable) Input tensor
1181
+ """
1182
+
1183
+ schema = get_schema("HardSwish", 22, "")
1184
+ op = Op(self, "HardSwish", schema)
1185
+ return op(*self._prepare_inputs(schema, X))
1186
+
1187
+ T_InstanceNormalization = TypeVar(
1188
+ "T_InstanceNormalization", BFLOAT16, DOUBLE, FLOAT, FLOAT16
1189
+ )
1190
+
1191
+ def InstanceNormalization(
1192
+ self,
1193
+ input: T_InstanceNormalization,
1194
+ scale: T_InstanceNormalization,
1195
+ B: T_InstanceNormalization,
1196
+ *,
1197
+ epsilon: float = 9.999999747378752e-06,
1198
+ ) -> T_InstanceNormalization:
1199
+ r"""[🌐 InstanceNormalization(22)](https://onnx.ai/onnx/operators/onnx__InstanceNormalization.html#instancenormalization-22 "Online Documentation")
1200
+
1201
+
1202
+ Carries out instance normalization as described in the paper
1203
+ https://arxiv.org/abs/1607.08022.
1204
+
1205
+ y = scale * (x - mean) / sqrt(variance + epsilon) + B,
1206
+ where mean and variance are computed per instance per channel.
1207
+
1208
+
1209
+
1210
+ Args:
1211
+ input: (differentiable) Input data tensor from the previous operator;
1212
+ dimensions for image case are (N x C x H x W), where N is the batch
1213
+ size, C is the number of channels, and H and W are the height and the
1214
+ width of the data. For non image case, the dimensions are in the form of
1215
+ (N x C x D1 x D2 ... Dn), where N is the batch size.
1216
+
1217
+ scale: (differentiable) The input 1-dimensional scale tensor of size C.
1218
+
1219
+ B: (differentiable) The input 1-dimensional bias tensor of size C.
1220
+
1221
+ epsilon: The epsilon value to use to avoid division by zero.
1222
+ """
1223
+
1224
+ schema = get_schema("InstanceNormalization", 22, "")
1225
+ op = Op(self, "InstanceNormalization", schema)
1226
+ return op(*self._prepare_inputs(schema, input, scale, B), epsilon=epsilon)
1227
+
1228
+ T_LSTM = TypeVar("T_LSTM", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1229
+
1230
+ T1_LSTM: TypeAlias = INT32
1231
+
1232
+ def LSTM(
1233
+ self,
1234
+ X: T_LSTM,
1235
+ W: T_LSTM,
1236
+ R: T_LSTM,
1237
+ B: Optional[T_LSTM] = None,
1238
+ sequence_lens: Optional[T1_LSTM] = None,
1239
+ initial_h: Optional[T_LSTM] = None,
1240
+ initial_c: Optional[T_LSTM] = None,
1241
+ P: Optional[T_LSTM] = None,
1242
+ *,
1243
+ activation_alpha: Optional[Sequence[float]] = None,
1244
+ activation_beta: Optional[Sequence[float]] = None,
1245
+ activations: Optional[Sequence[str]] = None,
1246
+ clip: Optional[float] = None,
1247
+ direction: str = "forward",
1248
+ hidden_size: Optional[int] = None,
1249
+ input_forget: int = 0,
1250
+ layout: int = 0,
1251
+ ) -> Tuple[T_LSTM, T_LSTM, T_LSTM]:
1252
+ r"""[🌐 LSTM(22)](https://onnx.ai/onnx/operators/onnx__LSTM.html#lstm-22 "Online Documentation")
1253
+
1254
+
1255
+ Computes an one-layer LSTM. This operator is usually supported via some
1256
+ custom implementation such as CuDNN.
1257
+
1258
+ Notations:
1259
+
1260
+ * `X` - input tensor
1261
+ * `i` - input gate
1262
+ * `o` - output gate
1263
+ * `f` - forget gate
1264
+ * `c` - cell gate
1265
+ * `t` - time step (t-1 means previous time step)
1266
+ * `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates
1267
+ * `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates
1268
+ * `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates
1269
+ * `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates
1270
+ * `P[iof]` - P peephole weight vector for input, output, and forget gates
1271
+ * `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates
1272
+ * `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates
1273
+ * `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates
1274
+ * `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates
1275
+ * `PB[iof]` - P peephole weight vector for backward input, output, and forget gates
1276
+ * `H` - Hidden state
1277
+ * `num_directions` - 2 if direction == bidirectional else 1
1278
+
1279
+ Activation functions:
1280
+
1281
+ * Relu(x) - max(0, x)
1282
+ * Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
1283
+ * Sigmoid(x) - 1/(1 + e^{-x})
1284
+
1285
+ NOTE: Below are optional
1286
+
1287
+ * Affine(x) - alpha*x + beta
1288
+ * LeakyRelu(x) - x if x >= 0 else alpha * x
1289
+ * ThresholdedRelu(x) - x if x >= alpha else 0
1290
+ * ScaledTanh(x) - alpha*Tanh(beta*x)
1291
+ * HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)
1292
+ * Elu(x) - x if x >= 0 else alpha*(e^x - 1)
1293
+ * Softsign(x) - x/(1 + |x|)
1294
+ * Softplus(x) - log(1 + e^x)
1295
+
1296
+ Equations (Default: f=Sigmoid, g=Tanh, h=Tanh):
1297
+
1298
+ * it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi)
1299
+ * ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf)
1300
+ * ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc)
1301
+ * Ct = ft (.) Ct-1 + it (.) ct
1302
+ * ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo)
1303
+ * Ht = ot (.) h(Ct)
1304
+ 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.
1305
+
1306
+
1307
+ Args:
1308
+ X: (differentiable) The input sequences packed (and potentially padded) into
1309
+ one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
1310
+
1311
+ W: (differentiable) The weight tensor for the gates. Concatenation of
1312
+ `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The
1313
+ tensor has shape `[num_directions, 4*hidden_size, input_size]`.
1314
+
1315
+ R: (differentiable) The recurrence weight tensor. Concatenation of `R[iofc]`
1316
+ and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has
1317
+ shape `[num_directions, 4*hidden_size, hidden_size]`.
1318
+
1319
+ B: (optional, differentiable) The bias tensor for input gate. Concatenation
1320
+ of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if
1321
+ bidirectional) along dimension 0. This tensor has shape
1322
+ `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed
1323
+ to be 0.
1324
+
1325
+ sequence_lens: (optional, non-differentiable) Optional tensor specifying
1326
+ lengths of the sequences in a batch. If not specified - assumed all
1327
+ sequences in the batch to have length `seq_length`. It has shape
1328
+ `[batch_size]`.
1329
+
1330
+ initial_h: (optional, non-differentiable) Optional initial value of the
1331
+ hidden. If not specified - assumed to be 0. It has shape
1332
+ `[num_directions, batch_size, hidden_size]`.
1333
+
1334
+ initial_c: (optional, non-differentiable) Optional initial value of the
1335
+ cell. If not specified - assumed to be 0. It has shape `[num_directions,
1336
+ batch_size, hidden_size]`.
1337
+
1338
+ P: (optional, differentiable) The weight tensor for peepholes. Concatenation
1339
+ of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has
1340
+ shape `[num_directions, 3*hidde_size]`. Optional: If not specified -
1341
+ assumed to be 0.
1342
+
1343
+ activation_alpha: Optional scaling values used by some activation functions.
1344
+ The values are consumed in the order of activation functions, for
1345
+ example (f, g, h) in LSTM. Default values are the same as of
1346
+ corresponding ONNX operators.For example with LeakyRelu, the default
1347
+ alpha is 0.01.
1348
+
1349
+ activation_beta: Optional scaling values used by some activation functions.
1350
+ The values are consumed in the order of activation functions, for
1351
+ example (f, g, h) in LSTM. Default values are the same as of
1352
+ corresponding ONNX operators.
1353
+
1354
+ activations: A list of 3 (or 6 if bidirectional) activation functions for
1355
+ input, output, forget, cell, and hidden. The activation functions must
1356
+ be one of the activation functions specified above. Optional: See the
1357
+ equations for default if not specified.
1358
+
1359
+ clip: Cell clip threshold. Clipping bounds the elements of a tensor in the
1360
+ range of [-threshold, +threshold] and is applied to the input of
1361
+ activations. No clip if not specified.
1362
+
1363
+ direction: Specify if the RNN is forward, reverse, or bidirectional. Must be
1364
+ one of forward (default), reverse, or bidirectional.
1365
+
1366
+ hidden_size: Number of neurons in the hidden layer
1367
+
1368
+ input_forget: Couple the input and forget gates if 1.
1369
+
1370
+ layout: The shape format of inputs X, initial_h, initial_c and outputs Y,
1371
+ Y_h, Y_c. If 0, the following shapes are expected: X.shape =
1372
+ [seq_length, batch_size, input_size], Y.shape = [seq_length,
1373
+ num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape =
1374
+ initial_c.shape = Y_c.shape = [num_directions, batch_size, hidden_size].
1375
+ If 1, the following shapes are expected: X.shape = [batch_size,
1376
+ seq_length, input_size], Y.shape = [batch_size, seq_length,
1377
+ num_directions, hidden_size], initial_h.shape = Y_h.shape =
1378
+ initial_c.shape = Y_c.shape = [batch_size, num_directions, hidden_size].
1379
+ """
1380
+
1381
+ schema = get_schema("LSTM", 22, "")
1382
+ op = Op(self, "LSTM", schema)
1383
+ return op(
1384
+ *self._prepare_inputs(schema, X, W, R, B, sequence_lens, initial_h, initial_c, P),
1385
+ activation_alpha=activation_alpha,
1386
+ activation_beta=activation_beta,
1387
+ activations=activations,
1388
+ clip=clip,
1389
+ direction=direction,
1390
+ hidden_size=hidden_size,
1391
+ input_forget=input_forget,
1392
+ layout=layout,
1393
+ )
1394
+
1395
+ T_LpNormalization = TypeVar("T_LpNormalization", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1396
+
1397
+ def LpNormalization(
1398
+ self, input: T_LpNormalization, *, axis: int = -1, p: int = 2
1399
+ ) -> T_LpNormalization:
1400
+ r"""[🌐 LpNormalization(22)](https://onnx.ai/onnx/operators/onnx__LpNormalization.html#lpnormalization-22 "Online Documentation")
1401
+
1402
+
1403
+ Given a matrix, apply Lp-normalization along the provided axis.
1404
+
1405
+
1406
+ Args:
1407
+ input: (differentiable) Input matrix
1408
+
1409
+ axis: The axis on which to apply normalization, -1 mean last axis.
1410
+
1411
+ p: The order of the normalization, only 1 or 2 are supported.
1412
+ """
1413
+
1414
+ schema = get_schema("LpNormalization", 22, "")
1415
+ op = Op(self, "LpNormalization", schema)
1416
+ return op(*self._prepare_inputs(schema, input), axis=axis, p=p)
1417
+
1418
+ T_LpPool = TypeVar("T_LpPool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1419
+
1420
+ def LpPool(
1421
+ self,
1422
+ X: T_LpPool,
1423
+ *,
1424
+ auto_pad: str = "NOTSET",
1425
+ ceil_mode: int = 0,
1426
+ dilations: Optional[Sequence[int]] = None,
1427
+ kernel_shape: Sequence[int],
1428
+ p: int = 2,
1429
+ pads: Optional[Sequence[int]] = None,
1430
+ strides: Optional[Sequence[int]] = None,
1431
+ ) -> T_LpPool:
1432
+ r"""[🌐 LpPool(22)](https://onnx.ai/onnx/operators/onnx__LpPool.html#lppool-22 "Online Documentation")
1433
+
1434
+
1435
+ LpPool consumes an input tensor X and applies Lp pooling across
1436
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
1437
+ Lp pooling consisting of computing the Lp norm on all values of a subset
1438
+ of the input tensor according to the kernel size and downsampling the
1439
+ data into the output tensor Y for further processing. The output spatial shape will be following:
1440
+ ```
1441
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
1442
+ ```
1443
+ or
1444
+ ```
1445
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
1446
+ ```
1447
+ if ceil_mode is enabled `pad_shape[i]` is the sum of pads along axis `i`.
1448
+
1449
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
1450
+ ```
1451
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i])
1452
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
1453
+ ```
1454
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
1455
+ ```
1456
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i]
1457
+ ```
1458
+
1459
+ Args:
1460
+ X: (differentiable) Input data tensor from the previous operator; dimensions
1461
+ for image case are (N x C x H x W), where N is the batch size, C is the
1462
+ number of channels, and H and W are the height and the width of the
1463
+ data. For non image case, the dimensions are in the form of (N x C x D1
1464
+ x D2 ... Dn), where N is the batch size.
1465
+
1466
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
1467
+ Where default value is NOTSET, which means explicit padding is used.
1468
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
1469
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
1470
+ split between the two sides equally or almost equally (depending on
1471
+ whether it is even or odd). In case the padding is an odd number, the
1472
+ extra padding is added at the end for SAME_UPPER and at the beginning
1473
+ for SAME_LOWER.
1474
+
1475
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
1476
+ shape.
1477
+
1478
+ dilations: dilation value along each spatial axis of the filter. If not
1479
+ present, the dilation defaults is 1 along each spatial axis.
1480
+
1481
+ kernel_shape: The size of the kernel along each axis.
1482
+
1483
+ p: p value of the Lp norm used to pool over the input data.
1484
+
1485
+ pads: Padding for the beginning and ending along each spatial axis, it can
1486
+ take any value greater than or equal to 0. The value represent the
1487
+ number of pixels added to the beginning and end part of the
1488
+ corresponding axis. `pads` format should be as follow [x1_begin,
1489
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
1490
+ added at the beginning of axis `i` and xi_end, the number of pixels
1491
+ added at the end of axis `i`. This attribute cannot be used
1492
+ simultaneously with auto_pad attribute. If not present, the padding
1493
+ defaults to 0 along start and end of each spatial axis.
1494
+
1495
+ strides: Stride along each spatial axis. If not present, the stride defaults
1496
+ to 1 along each spatial axis.
1497
+ """
1498
+
1499
+ schema = get_schema("LpPool", 22, "")
1500
+ op = Op(self, "LpPool", schema)
1501
+ return op(
1502
+ *self._prepare_inputs(schema, X),
1503
+ auto_pad=auto_pad,
1504
+ ceil_mode=ceil_mode,
1505
+ dilations=dilations,
1506
+ kernel_shape=kernel_shape,
1507
+ p=p,
1508
+ pads=pads,
1509
+ strides=strides,
1510
+ )
1511
+
1512
+ T_MaxPool = TypeVar("T_MaxPool", BFLOAT16, DOUBLE, FLOAT, FLOAT16, INT8, UINT8)
1513
+
1514
+ I_MaxPool: TypeAlias = INT64
1515
+
1516
+ def MaxPool(
1517
+ self,
1518
+ X: T_MaxPool,
1519
+ *,
1520
+ auto_pad: str = "NOTSET",
1521
+ ceil_mode: int = 0,
1522
+ dilations: Optional[Sequence[int]] = None,
1523
+ kernel_shape: Sequence[int],
1524
+ pads: Optional[Sequence[int]] = None,
1525
+ storage_order: int = 0,
1526
+ strides: Optional[Sequence[int]] = None,
1527
+ ) -> Tuple[T_MaxPool, I_MaxPool]:
1528
+ r"""[🌐 MaxPool(22)](https://onnx.ai/onnx/operators/onnx__MaxPool.html#maxpool-22 "Online Documentation")
1529
+
1530
+
1531
+ MaxPool consumes an input tensor X and applies max pooling across
1532
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
1533
+ max pooling consisting of computing the max on all values of a
1534
+ subset of the input tensor according to the kernel size and downsampling the
1535
+ data into the output tensor Y for further processing. The output spatial shape is calculated differently
1536
+ depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized.
1537
+ With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d):
1538
+ ```
1539
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
1540
+ ```
1541
+ or
1542
+ ```
1543
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
1544
+ ```
1545
+ if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`. Sliding windows that would start in the right padded region are ignored.
1546
+
1547
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled:
1548
+ ```
1549
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])
1550
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
1551
+ ```
1552
+ or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D):
1553
+ ```
1554
+ VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1
1555
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1
1556
+ ```
1557
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
1558
+ ```
1559
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]
1560
+ ```
1561
+ The output of each pooling window is maximum number of elements exclude pad.
1562
+
1563
+
1564
+ Args:
1565
+ X: (differentiable) Input data tensor from the previous operator; dimensions
1566
+ for image case are (N x C x H x W), where N is the batch size, C is the
1567
+ number of channels, and H and W are the height and the width of the
1568
+ data. For non image case, the dimensions are in the form of (N x C x D1
1569
+ x D2 ... Dn), where N is the batch size. Optionally, if dimension
1570
+ denotation is in effect, the operation expects the input data tensor to
1571
+ arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL,
1572
+ DATA_FEATURE, DATA_FEATURE ...].
1573
+
1574
+ auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
1575
+ Where default value is NOTSET, which means explicit padding is used.
1576
+ SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] =
1577
+ ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is
1578
+ split between the two sides equally or almost equally (depending on
1579
+ whether it is even or odd). In case the padding is an odd number, the
1580
+ extra padding is added at the end for SAME_UPPER and at the beginning
1581
+ for SAME_LOWER.
1582
+
1583
+ ceil_mode: Whether to use ceil or floor (default) to compute the output
1584
+ shape.
1585
+
1586
+ dilations: Dilation value along each spatial axis of filter. If not present,
1587
+ the dilation defaults to 1 along each spatial axis.
1588
+
1589
+ kernel_shape: The size of the kernel along each axis.
1590
+
1591
+ pads: Padding for the beginning and ending along each spatial axis, it can
1592
+ take any value greater than or equal to 0. The value represent the
1593
+ number of pixels added to the beginning and end part of the
1594
+ corresponding axis. `pads` format should be as follow [x1_begin,
1595
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
1596
+ added at the beginning of axis `i` and xi_end, the number of pixels
1597
+ added at the end of axis `i`. This attribute cannot be used
1598
+ simultaneously with auto_pad attribute. If not present, the padding
1599
+ defaults to 0 along start and end of each spatial axis.
1600
+
1601
+ storage_order: The storage order of the tensor. 0 is row major, and 1 is
1602
+ column major. This attribute is used only to convert an n-tuple index
1603
+ value into a single integer value for producing the second output.
1604
+
1605
+ strides: Stride along each spatial axis. If not present, the stride defaults
1606
+ to 1 along each spatial axis.
1607
+ """
1608
+
1609
+ schema = get_schema("MaxPool", 22, "")
1610
+ op = Op(self, "MaxPool", schema)
1611
+ return op(
1612
+ *self._prepare_inputs(schema, X),
1613
+ auto_pad=auto_pad,
1614
+ ceil_mode=ceil_mode,
1615
+ dilations=dilations,
1616
+ kernel_shape=kernel_shape,
1617
+ pads=pads,
1618
+ storage_order=storage_order,
1619
+ strides=strides,
1620
+ )
1621
+
1622
+ T_MaxRoiPool = TypeVar("T_MaxRoiPool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1623
+
1624
+ def MaxRoiPool(
1625
+ self,
1626
+ X: T_MaxRoiPool,
1627
+ rois: T_MaxRoiPool,
1628
+ *,
1629
+ pooled_shape: Sequence[int],
1630
+ spatial_scale: float = 1.0,
1631
+ ) -> T_MaxRoiPool:
1632
+ r"""[🌐 MaxRoiPool(22)](https://onnx.ai/onnx/operators/onnx__MaxRoiPool.html#maxroipool-22 "Online Documentation")
1633
+
1634
+
1635
+ ROI max pool consumes an input tensor X and region of interests (RoIs) to
1636
+ apply max pooling across each RoI, to produce output 4-D tensor of shape
1637
+ (num_rois, channels, pooled_shape[0], pooled_shape[1]).
1638
+
1639
+ Args:
1640
+ X: (differentiable) Input data tensor from the previous operator; dimensions
1641
+ for image case are (N x C x H x W), where N is the batch size, C is the
1642
+ number of channels, and H and W are the height and the width of the
1643
+ data.
1644
+
1645
+ rois: (non-differentiable) RoIs (Regions of Interest) to pool over. Should
1646
+ be a 2-D tensor of shape (num_rois, 5) given as [[batch_id, x1, y1, x2,
1647
+ y2], ...].
1648
+
1649
+ pooled_shape: ROI pool output shape (height, width).
1650
+
1651
+ spatial_scale: Multiplicative spatial scale factor to translate ROI
1652
+ coordinates from their input scale to the scale used when pooling.
1653
+ """
1654
+
1655
+ schema = get_schema("MaxRoiPool", 22, "")
1656
+ op = Op(self, "MaxRoiPool", schema)
1657
+ return op(
1658
+ *self._prepare_inputs(schema, X, rois),
1659
+ pooled_shape=pooled_shape,
1660
+ spatial_scale=spatial_scale,
1661
+ )
1662
+
1663
+ T1_MaxUnpool = TypeVar("T1_MaxUnpool", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1664
+
1665
+ T2_MaxUnpool: TypeAlias = INT64
1666
+
1667
+ def MaxUnpool(
1668
+ self,
1669
+ X: T1_MaxUnpool,
1670
+ I: T2_MaxUnpool,
1671
+ output_shape: Optional[T2_MaxUnpool] = None,
1672
+ *,
1673
+ kernel_shape: Sequence[int],
1674
+ pads: Optional[Sequence[int]] = None,
1675
+ strides: Optional[Sequence[int]] = None,
1676
+ ) -> T1_MaxUnpool:
1677
+ r"""[🌐 MaxUnpool(22)](https://onnx.ai/onnx/operators/onnx__MaxUnpool.html#maxunpool-22 "Online Documentation")
1678
+
1679
+
1680
+ MaxUnpool essentially computes the partial inverse of the MaxPool op.
1681
+ The input information to this op is typically the output information from a MaxPool op. The first
1682
+ input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output)
1683
+ from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corresponding
1684
+ to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op.
1685
+ The third (optional) input is a tensor that specifies the output size of the unpooling operation.
1686
+
1687
+ MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal
1688
+ values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling
1689
+ the result of an unpooling operation should give back the original input to the unpooling op.
1690
+
1691
+ MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous.
1692
+ The third input argument, output_size, is meant to disambiguate the op and produce output tensor of
1693
+ known/predictable size.
1694
+
1695
+ In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads,
1696
+ which define the exact unpooling op. The attributes typically have the same values as the corresponding
1697
+ pooling op that the unpooling op is trying to invert.
1698
+
1699
+
1700
+ Args:
1701
+ X: (differentiable) Input data tensor that has to be unpooled. This tensor
1702
+ is typically the first output of the MaxPool op.Dimensions for image
1703
+ case are (N x C x H x W), where N is the batch size, C is the number of
1704
+ channels, and H and W are the height and the width of the data. For
1705
+ non-image case, the dimensions are in the form of (N x C x D1 x D2 ...
1706
+ Dn), where N is the batch size. Optionally, if dimension denotation is
1707
+ in effect, the operation expects the input data tensor to arrive with
1708
+ the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE,
1709
+ DATA_FEATURE ...].
1710
+
1711
+ I: (non-differentiable) Input data tensor containing the indices
1712
+ corresponding to elements in the first input tensor X.This tensor is
1713
+ typically the second output of the MaxPool op.Dimensions must be the
1714
+ same as input tensor X. The indices are linear, i.e. computed
1715
+ considering the tensor as flattened 1-D tensor, assuming row-major
1716
+ storage. Also, the linear indices should not consider padding. So the
1717
+ values in indices are in the range [0, N x C x D1 x ... x Dn).
1718
+
1719
+ output_shape: (optional, non-differentiable) The shape of the output can be
1720
+ explicitly set which will cause pads values to be auto generated. If
1721
+ 'output_shape' is specified, 'pads' values are ignored.
1722
+
1723
+ kernel_shape: The size of the kernel along each axis.
1724
+
1725
+ pads: Padding for the beginning and ending along each spatial axis, it can
1726
+ take any value greater than or equal to 0. The value represent the
1727
+ number of pixels added to the beginning and end part of the
1728
+ corresponding axis. `pads` format should be as follow [x1_begin,
1729
+ x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels
1730
+ added at the beginning of axis `i` and xi_end, the number of pixels
1731
+ added at the end of axis `i`. This attribute cannot be used
1732
+ simultaneously with auto_pad attribute. If not present, the padding
1733
+ defaults to 0 along start and end of each spatial axis.
1734
+
1735
+ strides: Stride along each spatial axis. If not present, the stride defaults
1736
+ to 1 along each spatial axis.
1737
+ """
1738
+
1739
+ schema = get_schema("MaxUnpool", 22, "")
1740
+ op = Op(self, "MaxUnpool", schema)
1741
+ return op(
1742
+ *self._prepare_inputs(schema, X, I, output_shape),
1743
+ kernel_shape=kernel_shape,
1744
+ pads=pads,
1745
+ strides=strides,
1746
+ )
1747
+
1748
+ T_Mish = TypeVar("T_Mish", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1749
+
1750
+ def Mish(self, X: T_Mish) -> T_Mish:
1751
+ r"""[🌐 Mish(22)](https://onnx.ai/onnx/operators/onnx__Mish.html#mish-22 "Online Documentation")
1752
+
1753
+
1754
+ Mish: A Self Regularized Non-Monotonic Neural Activation Function.
1755
+
1756
+ Perform the linear unit element-wise on the input tensor X using formula:
1757
+
1758
+ ::
1759
+
1760
+ mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))
1761
+
1762
+
1763
+
1764
+
1765
+ Args:
1766
+ X: (differentiable) Input tensor
1767
+ """
1768
+
1769
+ schema = get_schema("Mish", 22, "")
1770
+ op = Op(self, "Mish", schema)
1771
+ return op(*self._prepare_inputs(schema, X))
1772
+
1773
+ T1_Multinomial = TypeVar("T1_Multinomial", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1774
+
1775
+ T2_Multinomial: TypeAlias = Union[INT32, INT64]
1776
+
1777
+ def Multinomial(
1778
+ self,
1779
+ input: T1_Multinomial,
1780
+ *,
1781
+ dtype: int = 6,
1782
+ sample_size: int = 1,
1783
+ seed: Optional[float] = None,
1784
+ ) -> T2_Multinomial:
1785
+ r"""[🌐 Multinomial(22)](https://onnx.ai/onnx/operators/onnx__Multinomial.html#multinomial-22 "Online Documentation")
1786
+
1787
+
1788
+ Generate a tensor of samples from a multinomial distribution according to the probabilities
1789
+ of each of the possible outcomes.
1790
+
1791
+
1792
+ Args:
1793
+ input: Input tensor with shape [batch_size, class_size], where class_size is
1794
+ the number of all possible outcomes. Each value along the axis zero
1795
+ represents the unnormalized log-probability of each corresponding
1796
+ outcome in a batch.
1797
+
1798
+ dtype: (Optional) The data type for the elements of the output tensor, if
1799
+ not specified, we will use int32.
1800
+
1801
+ sample_size: Number of times to sample.
1802
+
1803
+ seed: (Optional) Seed to the random generator, if not specified we will auto
1804
+ generate one.
1805
+ """
1806
+
1807
+ schema = get_schema("Multinomial", 22, "")
1808
+ op = Op(self, "Multinomial", schema)
1809
+ return op(
1810
+ *self._prepare_inputs(schema, input),
1811
+ dtype=dtype,
1812
+ sample_size=sample_size,
1813
+ seed=seed,
1814
+ )
1815
+
1816
+ T_NegativeLogLikelihoodLoss = TypeVar(
1817
+ "T_NegativeLogLikelihoodLoss", BFLOAT16, DOUBLE, FLOAT, FLOAT16
1818
+ )
1819
+
1820
+ Tind_NegativeLogLikelihoodLoss = TypeVar("Tind_NegativeLogLikelihoodLoss", INT32, INT64)
1821
+
1822
+ def NegativeLogLikelihoodLoss(
1823
+ self,
1824
+ input: T_NegativeLogLikelihoodLoss,
1825
+ target: Tind_NegativeLogLikelihoodLoss,
1826
+ weight: Optional[T_NegativeLogLikelihoodLoss] = None,
1827
+ *,
1828
+ ignore_index: Optional[int] = None,
1829
+ reduction: str = "mean",
1830
+ ) -> T_NegativeLogLikelihoodLoss:
1831
+ r"""[🌐 NegativeLogLikelihoodLoss(22)](https://onnx.ai/onnx/operators/onnx__NegativeLogLikelihoodLoss.html#negativeloglikelihoodloss-22 "Online Documentation")
1832
+
1833
+
1834
+ A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss.
1835
+ Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0.
1836
+ The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C).
1837
+ The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes)
1838
+ or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples.
1839
+ The loss value for input[n, :, d_1, d_2,...d_k] being classified as class c = target[n][d_1][d_2]...[d_k] is computed as:
1840
+
1841
+ ::
1842
+
1843
+ loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k].
1844
+
1845
+
1846
+
1847
+ When an optional "weight" is provided, the sample loss is calculated as:
1848
+
1849
+ ::
1850
+
1851
+ loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c].
1852
+
1853
+
1854
+
1855
+ loss is zero for the case when target-value equals ignore_index.
1856
+
1857
+ ::
1858
+
1859
+ loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index
1860
+
1861
+
1862
+
1863
+ If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk).
1864
+ If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged:
1865
+
1866
+ ::
1867
+
1868
+ mean(loss), if "weight" is not provided,
1869
+
1870
+
1871
+
1872
+ or if weight is provided,
1873
+
1874
+ ::
1875
+
1876
+ sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples.
1877
+
1878
+
1879
+
1880
+ If "reduction" attribute is set to "sum", the output is a scalar: `sum(loss)`.
1881
+
1882
+ See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss.
1883
+
1884
+ Example 1:
1885
+
1886
+ ::
1887
+
1888
+ // negative log likelihood loss, "none" reduction
1889
+ N, C, d1 = 2, 3, 2
1890
+ input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
1891
+ [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]
1892
+ target = [[2, 1], [0, 2]]
1893
+
1894
+ loss = np.zeros((N, d1))
1895
+ for n in range(N):
1896
+ for d_1 in range(d1):
1897
+ c = target[n][d_1]
1898
+ loss[n][d_1] = -input[n][c][d_1]
1899
+
1900
+ // print(loss)
1901
+ // [[-3. -2.]
1902
+ // [-0. -2.]]
1903
+
1904
+
1905
+
1906
+ Example 2:
1907
+
1908
+ ::
1909
+
1910
+ // weighted negative log likelihood loss, sum reduction
1911
+ N, C, d1 = 2, 3, 2
1912
+ input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
1913
+ [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]
1914
+ target = [[2, 1], [0, 2]]
1915
+ weight = [0.2, 0.3, 0.1]
1916
+ loss = np.zeros((N, d1))
1917
+ for n in range(N):
1918
+ for d_1 in range(d1):
1919
+ c = target[n][d_1]
1920
+ loss[n][d_1] = -input[n][c][d_1] * weight[c]
1921
+
1922
+ loss = np.sum(loss)
1923
+ // print(loss)
1924
+ // -1.1
1925
+
1926
+
1927
+
1928
+ Example 3:
1929
+
1930
+ ::
1931
+
1932
+ // weighted negative log likelihood loss, mean reduction
1933
+ N, C, d1 = 2, 3, 2
1934
+ input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
1935
+ [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]
1936
+ target = [[2, 1], [0, 2]]
1937
+ weight = [0.2, 0.3, 0.1]
1938
+ loss = np.zeros((N, d1))
1939
+ weight_total = 0
1940
+ for n in range(N):
1941
+ for d_1 in range(d1):
1942
+ c = target[n][d_1]
1943
+ loss[n][d_1] = -input[n][c][d_1] * weight[c]
1944
+ weight_total = weight_total + weight[c]
1945
+
1946
+ loss = np.sum(loss) / weight_total
1947
+ // print(loss)
1948
+ // -1.57
1949
+
1950
+
1951
+
1952
+
1953
+ Args:
1954
+ input: (differentiable) Input tensor of shape (N, C) or (N, C, d1, d2, ...,
1955
+ dk).
1956
+
1957
+ target: (non-differentiable) Target tensor of shape (N) or (N, d1, d2, ...,
1958
+ dk). Target element value shall be in range of [0, C). If ignore_index
1959
+ is specified, it may have a value outside [0, C) and the target values
1960
+ should either be in the range [0, C) or have the value ignore_index.
1961
+
1962
+ weight: (optional, non-differentiable) Optional rescaling weight tensor. If
1963
+ given, it has to be a tensor of size C. Otherwise, it is treated as if
1964
+ having all ones.
1965
+
1966
+ ignore_index: Specifies a target value that is ignored and does not
1967
+ contribute to the input gradient. It's an optional value.
1968
+
1969
+ reduction: Type of reduction to apply to loss: none, sum, mean (default).
1970
+ 'none': the output is the loss for each sample. 'sum': the output will
1971
+ be summed. 'mean': the sum of the output will be divided by the sum of
1972
+ applied weights.
1973
+ """
1974
+
1975
+ schema = get_schema("NegativeLogLikelihoodLoss", 22, "")
1976
+ op = Op(self, "NegativeLogLikelihoodLoss", schema)
1977
+ return op(
1978
+ *self._prepare_inputs(schema, input, target, weight),
1979
+ ignore_index=ignore_index,
1980
+ reduction=reduction,
1981
+ )
1982
+
1983
+ T_RNN = TypeVar("T_RNN", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
1984
+
1985
+ T1_RNN: TypeAlias = INT32
1986
+
1987
+ def RNN(
1988
+ self,
1989
+ X: T_RNN,
1990
+ W: T_RNN,
1991
+ R: T_RNN,
1992
+ B: Optional[T_RNN] = None,
1993
+ sequence_lens: Optional[T1_RNN] = None,
1994
+ initial_h: Optional[T_RNN] = None,
1995
+ *,
1996
+ activation_alpha: Optional[Sequence[float]] = None,
1997
+ activation_beta: Optional[Sequence[float]] = None,
1998
+ activations: Sequence[str] = ("Tanh", "Tanh"),
1999
+ clip: Optional[float] = None,
2000
+ direction: str = "forward",
2001
+ hidden_size: Optional[int] = None,
2002
+ layout: int = 0,
2003
+ ) -> Tuple[T_RNN, T_RNN]:
2004
+ r"""[🌐 RNN(22)](https://onnx.ai/onnx/operators/onnx__RNN.html#rnn-22 "Online Documentation")
2005
+
2006
+
2007
+ Computes an one-layer simple RNN. This operator is usually supported
2008
+ via some custom implementation such as CuDNN.
2009
+
2010
+ Notations:
2011
+
2012
+ * `X` - input tensor
2013
+ * `i` - input gate
2014
+ * `t` - time step (t-1 means previous time step)
2015
+ * `Wi` - W parameter weight matrix for input gate
2016
+ * `Ri` - R recurrence weight matrix for input gate
2017
+ * `Wbi` - W parameter bias vector for input gate
2018
+ * `Rbi` - R parameter bias vector for input gate
2019
+ * `WBi` - W parameter weight matrix for backward input gate
2020
+ * `RBi` - R recurrence weight matrix for backward input gate
2021
+ * `WBbi` - WR bias vectors for backward input gate
2022
+ * `RBbi` - RR bias vectors for backward input gate
2023
+ * `H` - Hidden state
2024
+ * `num_directions` - 2 if direction == bidirectional else 1
2025
+
2026
+ Activation functions:
2027
+
2028
+ * Relu(x) - max(0, x)
2029
+ * Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
2030
+ * Sigmoid(x) - 1/(1 + e^{-x})
2031
+
2032
+ NOTE: Below are optional
2033
+
2034
+ * Affine(x) - alpha*x + beta
2035
+ * LeakyRelu(x) - x if x >= 0 else alpha * x
2036
+ * ThresholdedRelu(x) - x if x >= alpha else 0
2037
+ * ScaledTanh(x) - alpha*Tanh(beta*x)
2038
+ * HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)
2039
+ * Elu(x) - x if x >= 0 else alpha*(e^x - 1)
2040
+ * Softsign(x) - x/(1 + |x|)
2041
+ * Softplus(x) - log(1 + e^x)
2042
+
2043
+ Equations (Default: f=Tanh):
2044
+
2045
+ * Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)
2046
+ 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.
2047
+
2048
+
2049
+ Args:
2050
+ X: (differentiable) The input sequences packed (and potentially padded) into
2051
+ one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
2052
+
2053
+ W: (differentiable) The weight tensor for input gate. Concatenation of `Wi`
2054
+ and `WBi` (if bidirectional). The tensor has shape `[num_directions,
2055
+ hidden_size, input_size]`.
2056
+
2057
+ R: (differentiable) The recurrence weight tensor. Concatenation of `Ri` and
2058
+ `RBi` (if bidirectional). The tensor has shape `[num_directions,
2059
+ hidden_size, hidden_size]`.
2060
+
2061
+ B: (optional, differentiable) The bias tensor for input gate. Concatenation
2062
+ of `[Wbi, Rbi]` and `[WBbi, RBbi]` (if bidirectional). The tensor has
2063
+ shape `[num_directions, 2*hidden_size]`. Optional: If not specified -
2064
+ assumed to be 0.
2065
+
2066
+ sequence_lens: (optional, non-differentiable) Optional tensor specifying
2067
+ lengths of the sequences in a batch. If not specified - assumed all
2068
+ sequences in the batch to have length `seq_length`. It has shape
2069
+ `[batch_size]`.
2070
+
2071
+ initial_h: (optional, non-differentiable) Optional initial value of the
2072
+ hidden. If not specified - assumed to be 0. It has shape
2073
+ `[num_directions, batch_size, hidden_size]`.
2074
+
2075
+ activation_alpha: Optional scaling values used by some activation functions.
2076
+ The values are consumed in the order of activation functions, for
2077
+ example (f, g, h) in LSTM. Default values are the same as of
2078
+ corresponding ONNX operators.For example with LeakyRelu, the default
2079
+ alpha is 0.01.
2080
+
2081
+ activation_beta: Optional scaling values used by some activation functions.
2082
+ The values are consumed in the order of activation functions, for
2083
+ example (f, g, h) in LSTM. Default values are the same as of
2084
+ corresponding ONNX operators.
2085
+
2086
+ activations: One (or two if bidirectional) activation function for input
2087
+ gate. The activation function must be one of the activation functions
2088
+ specified above. Optional: Default `Tanh` if not specified.
2089
+
2090
+ clip: Cell clip threshold. Clipping bounds the elements of a tensor in the
2091
+ range of [-threshold, +threshold] and is applied to the input of
2092
+ activations. No clip if not specified.
2093
+
2094
+ direction: Specify if the RNN is forward, reverse, or bidirectional. Must be
2095
+ one of forward (default), reverse, or bidirectional.
2096
+
2097
+ hidden_size: Number of neurons in the hidden layer
2098
+
2099
+ layout: The shape format of inputs X, initial_h and outputs Y, Y_h. If 0,
2100
+ the following shapes are expected: X.shape = [seq_length, batch_size,
2101
+ input_size], Y.shape = [seq_length, num_directions, batch_size,
2102
+ hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size,
2103
+ hidden_size]. If 1, the following shapes are expected: X.shape =
2104
+ [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length,
2105
+ num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size,
2106
+ num_directions, hidden_size].
2107
+ """
2108
+
2109
+ schema = get_schema("RNN", 22, "")
2110
+ op = Op(self, "RNN", schema)
2111
+ return op(
2112
+ *self._prepare_inputs(schema, X, W, R, B, sequence_lens, initial_h),
2113
+ activation_alpha=activation_alpha,
2114
+ activation_beta=activation_beta,
2115
+ activations=activations,
2116
+ clip=clip,
2117
+ direction=direction,
2118
+ hidden_size=hidden_size,
2119
+ layout=layout,
2120
+ )
2121
+
2122
+ T_RandomNormal: TypeAlias = Union[BFLOAT16, DOUBLE, FLOAT, FLOAT16]
2123
+
2124
+ def RandomNormal(
2125
+ self,
2126
+ *,
2127
+ dtype: int = 1,
2128
+ mean: float = 0.0,
2129
+ scale: float = 1.0,
2130
+ seed: Optional[float] = None,
2131
+ shape: Sequence[int],
2132
+ ) -> T_RandomNormal:
2133
+ r"""[🌐 RandomNormal(22)](https://onnx.ai/onnx/operators/onnx__RandomNormal.html#randomnormal-22 "Online Documentation")
2134
+
2135
+
2136
+ Generate a tensor with random values drawn from a normal distribution. The shape
2137
+ of the tensor is specified by the `shape` argument and the parameter of the normal distribution
2138
+ specified by `mean` and `scale`.
2139
+
2140
+ The data type is specified by the 'dtype' argument. The 'dtype' argument must
2141
+ be one of the data types specified in the 'DataType' enum field in the
2142
+ TensorProto message.
2143
+
2144
+
2145
+ Args:
2146
+ dtype: The data type for the elements of the output tensor. Default is
2147
+ TensorProto::FLOAT.
2148
+
2149
+ mean: The mean of the normal distribution.
2150
+
2151
+ scale: The standard deviation of the normal distribution.
2152
+
2153
+ seed: (Optional) Seed to the random generator, if not specified we will auto
2154
+ generate one.
2155
+
2156
+ shape: The shape of the output tensor.
2157
+ """
2158
+
2159
+ schema = get_schema("RandomNormal", 22, "")
2160
+ op = Op(self, "RandomNormal", schema)
2161
+ return op(dtype=dtype, mean=mean, scale=scale, seed=seed, shape=shape)
2162
+
2163
+ T1_RandomNormalLike = TypeVar(
2164
+ "T1_RandomNormalLike",
2165
+ BFLOAT16,
2166
+ BOOL,
2167
+ COMPLEX128,
2168
+ COMPLEX64,
2169
+ DOUBLE,
2170
+ FLOAT,
2171
+ FLOAT16,
2172
+ INT16,
2173
+ INT32,
2174
+ INT64,
2175
+ INT8,
2176
+ STRING,
2177
+ UINT16,
2178
+ UINT32,
2179
+ UINT64,
2180
+ UINT8,
2181
+ )
2182
+
2183
+ T2_RandomNormalLike: TypeAlias = Union[BFLOAT16, DOUBLE, FLOAT, FLOAT16]
2184
+
2185
+ def RandomNormalLike(
2186
+ self,
2187
+ input: T1_RandomNormalLike,
2188
+ *,
2189
+ dtype: Optional[int] = None,
2190
+ mean: float = 0.0,
2191
+ scale: float = 1.0,
2192
+ seed: Optional[float] = None,
2193
+ ) -> T2_RandomNormalLike:
2194
+ r"""[🌐 RandomNormalLike(22)](https://onnx.ai/onnx/operators/onnx__RandomNormalLike.html#randomnormallike-22 "Online Documentation")
2195
+
2196
+
2197
+ Generate a tensor with random values drawn from a normal distribution.
2198
+ The shape of the output tensor is copied from the shape of the input tensor,
2199
+ and the parameters of the normal distribution are specified by `mean` and `scale`.
2200
+
2201
+ The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided.
2202
+ The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the
2203
+ TensorProto message, and be valid as an output type.
2204
+
2205
+
2206
+ Args:
2207
+ input: Input tensor to copy shape and optionally type information from.
2208
+
2209
+ dtype: (Optional) The data type for the elements of the output tensor, if
2210
+ not specified, we will use the data type of the input tensor.
2211
+
2212
+ mean: The mean of the normal distribution.
2213
+
2214
+ scale: The standard deviation of the normal distribution.
2215
+
2216
+ seed: (Optional) Seed to the random generator, if not specified we will auto
2217
+ generate one.
2218
+ """
2219
+
2220
+ schema = get_schema("RandomNormalLike", 22, "")
2221
+ op = Op(self, "RandomNormalLike", schema)
2222
+ return op(
2223
+ *self._prepare_inputs(schema, input),
2224
+ dtype=dtype,
2225
+ mean=mean,
2226
+ scale=scale,
2227
+ seed=seed,
2228
+ )
2229
+
2230
+ T_RandomUniform: TypeAlias = Union[BFLOAT16, DOUBLE, FLOAT, FLOAT16]
2231
+
2232
+ def RandomUniform(
2233
+ self,
2234
+ *,
2235
+ dtype: int = 1,
2236
+ high: float = 1.0,
2237
+ low: float = 0.0,
2238
+ seed: Optional[float] = None,
2239
+ shape: Sequence[int],
2240
+ ) -> T_RandomUniform:
2241
+ r"""[🌐 RandomUniform(22)](https://onnx.ai/onnx/operators/onnx__RandomUniform.html#randomuniform-22 "Online Documentation")
2242
+
2243
+
2244
+ Generate a tensor with random values drawn from a uniform distribution. The shape
2245
+ of the tensor is specified by the `shape` argument and the range by `low` and `high`.
2246
+
2247
+ The data type is specified by the 'dtype' argument. The 'dtype' argument must
2248
+ be one of the data types specified in the 'DataType' enum field in the
2249
+ TensorProto message.
2250
+
2251
+
2252
+ Args:
2253
+ dtype: The data type for the elements of the output tensor. If not
2254
+ specified, default is TensorProto::FLOAT.
2255
+
2256
+ high: Upper boundary of the output values.
2257
+
2258
+ low: Lower boundary of the output values.
2259
+
2260
+ seed: (Optional) Seed to the random generator, if not specified we will auto
2261
+ generate one.
2262
+
2263
+ shape: The shape of the output tensor.
2264
+ """
2265
+
2266
+ schema = get_schema("RandomUniform", 22, "")
2267
+ op = Op(self, "RandomUniform", schema)
2268
+ return op(dtype=dtype, high=high, low=low, seed=seed, shape=shape)
2269
+
2270
+ T1_RandomUniformLike = TypeVar(
2271
+ "T1_RandomUniformLike",
2272
+ BFLOAT16,
2273
+ BOOL,
2274
+ COMPLEX128,
2275
+ COMPLEX64,
2276
+ DOUBLE,
2277
+ FLOAT,
2278
+ FLOAT16,
2279
+ INT16,
2280
+ INT32,
2281
+ INT64,
2282
+ INT8,
2283
+ STRING,
2284
+ UINT16,
2285
+ UINT32,
2286
+ UINT64,
2287
+ UINT8,
2288
+ )
2289
+
2290
+ T2_RandomUniformLike: TypeAlias = Union[BFLOAT16, DOUBLE, FLOAT, FLOAT16]
2291
+
2292
+ def RandomUniformLike(
2293
+ self,
2294
+ input: T1_RandomUniformLike,
2295
+ *,
2296
+ dtype: Optional[int] = None,
2297
+ high: float = 1.0,
2298
+ low: float = 0.0,
2299
+ seed: Optional[float] = None,
2300
+ ) -> T2_RandomUniformLike:
2301
+ r"""[🌐 RandomUniformLike(22)](https://onnx.ai/onnx/operators/onnx__RandomUniformLike.html#randomuniformlike-22 "Online Documentation")
2302
+
2303
+
2304
+ Generate a tensor with random values drawn from a uniform distribution.
2305
+ The shape of the output tensor is copied from the shape of the input tensor,
2306
+ and the parameters of the uniform distribution are specified by `low` and `high`.
2307
+
2308
+ The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided.
2309
+ The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the
2310
+ TensorProto message and be valid as an output type.
2311
+
2312
+
2313
+ Args:
2314
+ input: Input tensor to copy shape and optionally type information from.
2315
+
2316
+ dtype: (Optional) The data type for the elements of the output tensor, if
2317
+ not specified, we will use the data type of the input tensor.
2318
+
2319
+ high: Upper boundary of the output values.
2320
+
2321
+ low: Lower boundary of the output values.
2322
+
2323
+ seed: (Optional) Seed to the random generator, if not specified we will auto
2324
+ generate one.
2325
+ """
2326
+
2327
+ schema = get_schema("RandomUniformLike", 22, "")
2328
+ op = Op(self, "RandomUniformLike", schema)
2329
+ return op(
2330
+ *self._prepare_inputs(schema, input), dtype=dtype, high=high, low=low, seed=seed
2331
+ )
2332
+
2333
+ T1_RoiAlign = TypeVar("T1_RoiAlign", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2334
+
2335
+ T2_RoiAlign: TypeAlias = INT64
2336
+
2337
+ def RoiAlign(
2338
+ self,
2339
+ X: T1_RoiAlign,
2340
+ rois: T1_RoiAlign,
2341
+ batch_indices: T2_RoiAlign,
2342
+ *,
2343
+ coordinate_transformation_mode: str = "half_pixel",
2344
+ mode: str = "avg",
2345
+ output_height: int = 1,
2346
+ output_width: int = 1,
2347
+ sampling_ratio: int = 0,
2348
+ spatial_scale: float = 1.0,
2349
+ ) -> T1_RoiAlign:
2350
+ r"""[🌐 RoiAlign(22)](https://onnx.ai/onnx/operators/onnx__RoiAlign.html#roialign-22 "Online Documentation")
2351
+
2352
+
2353
+ Region of Interest (RoI) align operation described in the
2354
+ [Mask R-CNN paper](https://arxiv.org/abs/1703.06870).
2355
+ RoiAlign consumes an input tensor X and region of interests (rois)
2356
+ to apply pooling across each RoI; it produces a 4-D tensor of shape
2357
+ (num_rois, C, output_height, output_width).
2358
+
2359
+ RoiAlign is proposed to avoid the misalignment by removing
2360
+ quantizations while converting from original image into feature
2361
+ map and from feature map into RoI feature; in each ROI bin,
2362
+ the value of the sampled locations are computed directly
2363
+ through bilinear interpolation.
2364
+
2365
+
2366
+ Args:
2367
+ X: Input data tensor from the previous operator; 4-D feature map of shape
2368
+ (N, C, H, W), where N is the batch size, C is the number of channels,
2369
+ and H and W are the height and the width of the data.
2370
+
2371
+ rois: RoIs (Regions of Interest) to pool over; rois is 2-D input of shape
2372
+ (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates
2373
+ are in the coordinate system of the input image. Each coordinate set has
2374
+ a 1:1 correspondence with the 'batch_indices' input.
2375
+
2376
+ batch_indices: 1-D tensor of shape (num_rois,) with each element denoting
2377
+ the index of the corresponding image in the batch.
2378
+
2379
+ coordinate_transformation_mode: Allowed values are 'half_pixel' and
2380
+ 'output_half_pixel'. Use the value 'half_pixel' to pixel shift the input
2381
+ coordinates by -0.5 (the recommended behavior). Use the value
2382
+ 'output_half_pixel' to omit the pixel shift for the input (use this for
2383
+ a backward-compatible behavior).
2384
+
2385
+ mode: The pooling method. Two modes are supported: 'avg' and 'max'. Default
2386
+ is 'avg'.
2387
+
2388
+ output_height: default 1; Pooled output Y's height.
2389
+
2390
+ output_width: default 1; Pooled output Y's width.
2391
+
2392
+ sampling_ratio: Number of sampling points in the interpolation grid used to
2393
+ compute the output value of each pooled output bin. If > 0, then exactly
2394
+ sampling_ratio x sampling_ratio grid points are used. If == 0, then an
2395
+ adaptive number of grid points are used (computed as ceil(roi_width /
2396
+ output_width), and likewise for height). Default is 0.
2397
+
2398
+ spatial_scale: Multiplicative spatial scale factor to translate ROI
2399
+ coordinates from their input spatial scale to the scale used when
2400
+ pooling, i.e., spatial scale of the input feature map X relative to the
2401
+ input image. E.g.; default is 1.0f.
2402
+ """
2403
+
2404
+ schema = get_schema("RoiAlign", 22, "")
2405
+ op = Op(self, "RoiAlign", schema)
2406
+ return op(
2407
+ *self._prepare_inputs(schema, X, rois, batch_indices),
2408
+ coordinate_transformation_mode=coordinate_transformation_mode,
2409
+ mode=mode,
2410
+ output_height=output_height,
2411
+ output_width=output_width,
2412
+ sampling_ratio=sampling_ratio,
2413
+ spatial_scale=spatial_scale,
2414
+ )
2415
+
2416
+ T_Round = TypeVar("T_Round", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2417
+
2418
+ def Round(self, X: T_Round) -> T_Round:
2419
+ r"""[🌐 Round(22)](https://onnx.ai/onnx/operators/onnx__Round.html#round-22 "Online Documentation")
2420
+
2421
+
2422
+ Round takes one input Tensor and rounds the values, element-wise, meaning
2423
+ it finds the nearest integer for each value.
2424
+ In case of halves, the rule is to round them to the nearest even integer.
2425
+ If input x is integral, +0, -0, NaN, or infinite, x itself is returned.
2426
+ The output tensor has the same shape and type as the input.
2427
+
2428
+ Examples:
2429
+ ::
2430
+
2431
+ round([0.9]) = [1.0]
2432
+ round([2.5]) = [2.0]
2433
+ round([2.3]) = [2.0]
2434
+ round([1.5]) = [2.0]
2435
+ round([-4.5]) = [-4.0]
2436
+
2437
+
2438
+
2439
+
2440
+ Args:
2441
+ X: (non-differentiable) Input tensor
2442
+ """
2443
+
2444
+ schema = get_schema("Round", 22, "")
2445
+ op = Op(self, "Round", schema)
2446
+ return op(*self._prepare_inputs(schema, X))
2447
+
2448
+ T_Selu = TypeVar("T_Selu", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2449
+
2450
+ def Selu(
2451
+ self,
2452
+ X: T_Selu,
2453
+ *,
2454
+ alpha: float = 1.6732631921768188,
2455
+ gamma: float = 1.0507010221481323,
2456
+ ) -> T_Selu:
2457
+ r"""[🌐 Selu(22)](https://onnx.ai/onnx/operators/onnx__Selu.html#selu-22 "Online Documentation")
2458
+
2459
+
2460
+ Selu takes one input data (Tensor<T>) and produces one output data
2461
+ (Tensor<T>) where the scaled exponential linear unit function,
2462
+ `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`,
2463
+ is applied to the tensor elementwise.
2464
+
2465
+
2466
+ Args:
2467
+ X: (differentiable) Input tensor
2468
+
2469
+ alpha: Coefficient of SELU default to 1.67326319217681884765625 (i.e.,
2470
+ float32 approximation of 1.6732632423543772848170429916717).
2471
+
2472
+ gamma: Coefficient of SELU default to 1.05070102214813232421875 (i.e.,
2473
+ float32 approximation of 1.0507009873554804934193349852946).
2474
+ """
2475
+
2476
+ schema = get_schema("Selu", 22, "")
2477
+ op = Op(self, "Selu", schema)
2478
+ return op(*self._prepare_inputs(schema, X), alpha=alpha, gamma=gamma)
2479
+
2480
+ T_Sin = TypeVar("T_Sin", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2481
+
2482
+ def Sin(self, input: T_Sin) -> T_Sin:
2483
+ r"""[🌐 Sin(22)](https://onnx.ai/onnx/operators/onnx__Sin.html#sin-22 "Online Documentation")
2484
+
2485
+
2486
+ Calculates the sine of the given input tensor, element-wise.
2487
+
2488
+
2489
+ Args:
2490
+ input: (differentiable) Input tensor
2491
+ """
2492
+
2493
+ schema = get_schema("Sin", 22, "")
2494
+ op = Op(self, "Sin", schema)
2495
+ return op(*self._prepare_inputs(schema, input))
2496
+
2497
+ T_Sinh = TypeVar("T_Sinh", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2498
+
2499
+ def Sinh(self, input: T_Sinh) -> T_Sinh:
2500
+ r"""[🌐 Sinh(22)](https://onnx.ai/onnx/operators/onnx__Sinh.html#sinh-22 "Online Documentation")
2501
+
2502
+
2503
+ Calculates the hyperbolic sine of the given input tensor element-wise.
2504
+
2505
+
2506
+ Args:
2507
+ input: (differentiable) Input tensor
2508
+ """
2509
+
2510
+ schema = get_schema("Sinh", 22, "")
2511
+ op = Op(self, "Sinh", schema)
2512
+ return op(*self._prepare_inputs(schema, input))
2513
+
2514
+ T_Softplus = TypeVar("T_Softplus", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2515
+
2516
+ def Softplus(self, X: T_Softplus) -> T_Softplus:
2517
+ r"""[🌐 Softplus(22)](https://onnx.ai/onnx/operators/onnx__Softplus.html#softplus-22 "Online Documentation")
2518
+
2519
+
2520
+ Softplus takes one input data (Tensor<T>) and produces one output data
2521
+ (Tensor<T>) where the softplus function, y = ln(exp(x) + 1), is applied to
2522
+ the tensor elementwise.
2523
+
2524
+
2525
+ Args:
2526
+ X: (differentiable) 1D input tensor
2527
+ """
2528
+
2529
+ schema = get_schema("Softplus", 22, "")
2530
+ op = Op(self, "Softplus", schema)
2531
+ return op(*self._prepare_inputs(schema, X))
2532
+
2533
+ T_Softsign = TypeVar("T_Softsign", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2534
+
2535
+ def Softsign(self, input: T_Softsign) -> T_Softsign:
2536
+ r"""[🌐 Softsign(22)](https://onnx.ai/onnx/operators/onnx__Softsign.html#softsign-22 "Online Documentation")
2537
+
2538
+
2539
+ Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise.
2540
+
2541
+
2542
+ Args:
2543
+ input: (differentiable) Input tensor
2544
+ """
2545
+
2546
+ schema = get_schema("Softsign", 22, "")
2547
+ op = Op(self, "Softsign", schema)
2548
+ return op(*self._prepare_inputs(schema, input))
2549
+
2550
+ T_Tan = TypeVar("T_Tan", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2551
+
2552
+ def Tan(self, input: T_Tan) -> T_Tan:
2553
+ r"""[🌐 Tan(22)](https://onnx.ai/onnx/operators/onnx__Tan.html#tan-22 "Online Documentation")
2554
+
2555
+
2556
+ Calculates the tangent of the given input tensor, element-wise.
2557
+
2558
+
2559
+ Args:
2560
+ input: (differentiable) Input tensor
2561
+ """
2562
+
2563
+ schema = get_schema("Tan", 22, "")
2564
+ op = Op(self, "Tan", schema)
2565
+ return op(*self._prepare_inputs(schema, input))
2566
+
2567
+ T_ThresholdedRelu = TypeVar("T_ThresholdedRelu", BFLOAT16, DOUBLE, FLOAT, FLOAT16)
2568
+
2569
+ def ThresholdedRelu(
2570
+ self, X: T_ThresholdedRelu, *, alpha: float = 1.0
2571
+ ) -> T_ThresholdedRelu:
2572
+ r"""[🌐 ThresholdedRelu(22)](https://onnx.ai/onnx/operators/onnx__ThresholdedRelu.html#thresholdedrelu-22 "Online Documentation")
2573
+
2574
+
2575
+ ThresholdedRelu takes one input data (Tensor<T>) and produces one output data
2576
+ (Tensor<T>) where the rectified linear function, y = x for x > alpha, y = 0 otherwise,
2577
+ is applied to the tensor elementwise.
2578
+
2579
+
2580
+ Args:
2581
+ X: (differentiable) Input tensor
2582
+
2583
+ alpha: Threshold value
2584
+ """
2585
+
2586
+ schema = get_schema("ThresholdedRelu", 22, "")
2587
+ op = Op(self, "ThresholdedRelu", schema)
2588
+ return op(*self._prepare_inputs(schema, X), alpha=alpha)