Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions onnxscript/onnx_opset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@
from onnxscript.onnx_opset._impl.opset22 import Opset22
from onnxscript.onnx_opset._impl.opset23 import Opset23
from onnxscript.onnx_opset._impl.opset24 import Opset24
from onnxscript.onnx_opset._impl.opset25 import Opset25
from onnxscript.onnx_opset._impl.opset26 import Opset26
from onnxscript.onnx_opset._impl.opset27 import Opset27
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml1 import Opset_ai_onnx_ml1
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml2 import Opset_ai_onnx_ml2
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml3 import Opset_ai_onnx_ml3
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml4 import Opset_ai_onnx_ml4
from onnxscript.onnx_opset._impl.opset_ai_onnx_ml5 import Opset_ai_onnx_ml5
from onnxscript.onnx_opset._impl.opset_ai_onnx_preview1 import Opset_ai_onnx_preview1
from onnxscript.values import Opset

__all__ = [
Expand Down Expand Up @@ -72,11 +76,15 @@
"opset22",
"opset23",
"opset24",
"opset25",
"opset26",
"opset27",
"opset_ai_onnx_ml1",
"opset_ai_onnx_ml2",
"opset_ai_onnx_ml3",
"opset_ai_onnx_ml4",
"opset_ai_onnx_ml5",
"opset_ai_onnx_preview1",
]


Expand Down Expand Up @@ -110,11 +118,15 @@
opset22 = Opset22()
opset23 = Opset23()
opset24 = Opset24()
opset25 = Opset25()
opset26 = Opset26()
opset27 = Opset27()
opset_ai_onnx_ml1 = Opset_ai_onnx_ml1()
opset_ai_onnx_ml2 = Opset_ai_onnx_ml2()
opset_ai_onnx_ml3 = Opset_ai_onnx_ml3()
opset_ai_onnx_ml4 = Opset_ai_onnx_ml4()
opset_ai_onnx_ml5 = Opset_ai_onnx_ml5()
opset_ai_onnx_preview1 = Opset_ai_onnx_preview1()
all_opsets: Mapping[Tuple[str, int], Opset] = {
(
"",
Expand Down Expand Up @@ -212,6 +224,18 @@
"",
24,
): opset24,
(
"",
25,
): opset25,
(
"",
26,
): opset26,
(
"",
27,
): opset27,
(
"ai.onnx.ml",
1,
Expand All @@ -232,4 +256,8 @@
"ai.onnx.ml",
5,
): opset_ai_onnx_ml5,
(
"ai.onnx.preview",
1,
): opset_ai_onnx_preview1,
}
16 changes: 13 additions & 3 deletions onnxscript/onnx_opset/_impl/opset1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,9 @@ def LpNormalization(


Given a matrix, apply Lp-normalization along the provided axis.
The output is computed as: `output = input / Lp_norm(input, axis)`.
When the Lp norm is zero (i.e., all elements along the axis are zero),
the output is defined to be zero to avoid division by zero.


Args:
Expand Down Expand Up @@ -4036,9 +4039,16 @@ def Transpose(
r"""[🌐 Transpose(1)](https://onnx.ai/onnx/operators/onnx__Transpose.html#transpose-1 "Online Documentation")


Transpose the input tensor similar to numpy.transpose. For example, when
perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape
will be (2, 1, 3).
Returns a transpose of the input tensor. (Similar to `numpy.transpose`).
The optional attribute `perm` must be a permutation of the dimensions of
the input tensor. Axis `i` of the output tensor corresponds to the axis
`perm[i]` of the input tensor.
For example, when perm=(1, 0, 2), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 1, 3).
When perm=(1, 2, 0), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 3, 1).
If the attribute `perm` is omitted, its default value is `(n-1, ..., 0)`,
where `n` is the rank of the input tensor.


Args:
Expand Down
1 change: 1 addition & 0 deletions onnxscript/onnx_opset/_impl/opset10.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def NonMaxSuppression(

Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.
Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.
Boxes are suppressed if their IOU with a previously selected box is strictly greater than iou_threshold (i.e., boxes with IOU exactly equal to the threshold are kept).
Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to
orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system
result in the same boxes being selected by the algorithm.
Expand Down
21 changes: 8 additions & 13 deletions onnxscript/onnx_opset/_impl/opset11.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def DynamicQuantizeLinear(
::

intermediate_zero_point = qmin - min(x)/y_scale
y_zero_point = cast(round(saturate(itermediate_zero_point)))
y_zero_point = cast(round(saturate(intermediate_zero_point)))



Expand Down Expand Up @@ -1586,7 +1586,7 @@ def Loop(
1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can
be referenced in the inputs of the loop.
2) Any values computed in the loop body that needs to be used in a subsequent
iteration or after the loop are modelled using a pair of variables in the loop-body,
iteration or after the loop are modeled using a pair of variables in the loop-body,
consisting of an input variable (eg., b_in) and an output variable (eg., b_out).
These are referred to as loop-carried dependences. The loop operation node
supplies the input value of the input variable for the first iteration, and
Expand Down Expand Up @@ -1901,6 +1901,7 @@ def NonMaxSuppression(

Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.
Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.
Boxes are suppressed if their IOU with a previously selected box is strictly greater than iou_threshold (i.e., boxes with IOU exactly equal to the threshold are kept).
Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to
orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system
result in the same boxes being selected by the algorithm.
Expand All @@ -1920,7 +1921,8 @@ def NonMaxSuppression(
Default to 0, which means no output.

iou_threshold: (optional) Float representing the threshold for deciding
whether boxes overlap too much with respect to IOU. It is scalar. Value
whether boxes overlap too much with respect to IOU. Boxes with IoU
strictly greater than this threshold are suppressed. It is scalar. Value
range [0, 1]. Default to 0.

score_threshold: (optional) Float representing the threshold for deciding
Expand Down Expand Up @@ -2190,34 +2192,27 @@ def Range(self, start: T_Range, limit: T_Range, delta: T_Range) -> T_Range:
up to `limit` (exclusive).

The number of elements in the output of range is computed as below:

::

number_of_elements = max( ceil( (limit - start) / delta ) , 0 )



The pseudocode determining the contents of the output is shown below:

::

for(int i=0; i<number_of_elements; ++i) {
output[i] = start + (i * delta);
}



Example 1

Example 1:
::

Inputs: start = 3, limit = 9, delta = 3
Output: [3, 6]



Example 2

Example 2:
::

Inputs: start = 10, limit = 4, delta = -2
Expand Down Expand Up @@ -3130,7 +3125,7 @@ def ScatterND(
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
output[tuple(indices[idx])] = updates[idx]

The order of iteration in the above loop is not specified.
In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].
Expand Down
52 changes: 26 additions & 26 deletions onnxscript/onnx_opset/_impl/opset13.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ def Div(self, A: T_Div, B: T_Div) -> T_Div:

This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check `Broadcasting in ONNX <https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md>`_.

For integer inputs, the result is computed using truncating division (rounding toward zero).


Args:
A: (differentiable) First operand.
Expand Down Expand Up @@ -700,21 +702,7 @@ def Equal(self, A: T_Equal, B: T_Equal) -> T1_Equal:
op = Op(self, "Equal", schema)
return op(*self._prepare_inputs(schema, A, B))

T_Erf = TypeVar(
"T_Erf",
BFLOAT16,
DOUBLE,
FLOAT,
FLOAT16,
INT16,
INT32,
INT64,
INT8,
UINT16,
UINT32,
UINT64,
UINT8,
)
T_Erf = TypeVar("T_Erf", BFLOAT16, DOUBLE, FLOAT, FLOAT16)

def Erf(self, input: T_Erf) -> T_Erf:
r"""[🌐 Erf(13)](https://onnx.ai/onnx/operators/onnx__Erf.html#erf-13 "Online Documentation")
Expand Down Expand Up @@ -1741,7 +1729,7 @@ def Loop(
1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can
be referenced in the inputs of the loop.
2) Any values computed in the loop body that needs to be used in a subsequent
iteration or after the loop are modelled using a pair of variables in the loop-body,
iteration or after the loop are modeled using a pair of variables in the loop-body,
consisting of an input variable (eg., b_in) and an output variable (eg., b_out).
These are referred to as loop-carried dependences. The loop operation node
supplies the input value of the input variable for the first iteration, and
Expand Down Expand Up @@ -2810,17 +2798,22 @@ def ReduceSum(
which to reduce. The default is to reduce over empty axes. When axes is
empty (either not provided or explicitly empty), behavior depends on
'noop_with_empty_axes': reduction over all axes if
'noop_with_empty_axes' is false, or no reduction is applied if
'noop_with_empty_axes' is true (but other operations will be performed).
Accepted range is [-r, r-1] where r = rank(data).
'noop_with_empty_axes' is false, and reduction over the empty set of
axes when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1]
where r = rank(data).

keepdims: Keep the reduced dimension or not, default 1 means keep reduced
dimension.

noop_with_empty_axes: Defines behavior when axes is not provided or is
empty. If false (default), reduction happens over all axes. If true, no
reduction is applied, but other operations will be performed. For
example, ReduceSumSquare acts as a vanilla Square.
empty. If false (default), reduction happens over all axes (similar to
the case when `axis=None` in numpy). If true, reduction happens over an
empty set of axes (similar to the case when `axis=()` in numpy). Note
that reduction over an empty set of axes means that the reduction step
behaves like a no-op (identity function), but composite-reduction
operators will still perform the non-reduction steps as needed. Thus,
ReduceLogSum returns the Log of input tensor, and ReduceSumSquare
returns the Square of the input tensor, in this case.
"""

schema = get_schema("ReduceSum", 13, "")
Expand Down Expand Up @@ -3246,7 +3239,7 @@ def ScatterND(
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
output[tuple(indices[idx])] = updates[idx]

The order of iteration in the above loop is not specified.
In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].
Expand Down Expand Up @@ -3943,9 +3936,16 @@ def Transpose(
r"""[🌐 Transpose(13)](https://onnx.ai/onnx/operators/onnx__Transpose.html#transpose-13 "Online Documentation")


Transpose the input tensor similar to numpy.transpose. For example, when
perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape
will be (2, 1, 3).
Returns a transpose of the input tensor. (Similar to `numpy.transpose`).
The optional attribute `perm` must be a permutation of the dimensions of
the input tensor. Axis `i` of the output tensor corresponds to the axis
`perm[i]` of the input tensor.
For example, when perm=(1, 0, 2), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 1, 3).
When perm=(1, 2, 0), given an input tensor of shape (1, 2, 3),
the output shape will be (2, 3, 1).
If the attribute `perm` is omitted, its default value is `(n-1, ..., 0)`,
where `n` is the rank of the input tensor.


Args:
Expand Down
1 change: 1 addition & 0 deletions onnxscript/onnx_opset/_impl/opset14.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def Div(self, A: T_Div, B: T_Div) -> T_Div:

This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check `Broadcasting in ONNX <https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md>`_.

For integer inputs, the result is computed using truncating division (rounding toward zero).
(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.


Expand Down
8 changes: 4 additions & 4 deletions onnxscript/onnx_opset/_impl/opset16.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def Loop(
1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can
be referenced in the inputs of the loop.
2) Any values computed in the loop body that needs to be used in a subsequent
iteration or after the loop are modelled using a pair of variables in the loop-body,
iteration or after the loop are modeled using a pair of variables in the loop-body,
consisting of an input variable (eg., b_in) and an output variable (eg., b_out).
These are referred to as loop-carried dependences. The loop operation node
supplies the input value of the input variable for the first iteration, and
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def ScatterND(
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
output[tuple(indices[idx])] = updates[idx]
The order of iteration in the above loop is not specified.
In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].
This ensures that the output value does not depend on the iteration order.
Expand All @@ -1130,12 +1130,12 @@ def ScatterND(
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] += updates[idx]
output[tuple(indices[idx])] += updates[idx]
When `reduction` is set to "mul", `output` is calculated as follows:
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] *= updates[idx]
output[tuple(indices[idx])] *= updates[idx]
This operator is the inverse of GatherND.
Example 1:
::
Expand Down
20 changes: 11 additions & 9 deletions onnxscript/onnx_opset/_impl/opset17.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def DFT(
dft_length: (optional, non-differentiable) The length of the signal as a
scalar. If greater than the axis dimension, the signal will be
zero-padded up to dft_length. If less than the axis dimension, only the
first dft_length values will be used as the signal. It's an optional
value.
first dft_length values will be used as the signal. If not provided, the
default dft_length = signal_dim_axis, except for the IRFFT case
(onesided=1, inverse=1), in which case the default dft_length is 2 *
(signal_dim_axis - 1). It's an optional value.

axis: The axis on which to perform the DFT. By default this value is set to
1, which corresponds to the first dimension after the batch index.
Expand All @@ -134,13 +136,13 @@ def DFT(
default this value is set to 0, which corresponds to false.

onesided: If onesided is 1, only values for w in [0, 1, 2, ...,
floor(n_fft/2) + 1] are returned because the real-to-complex Fourier
transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m,
n_fft-w]*. Note if the input or window tensors are complex, then
onesided output is not possible. Enabling onesided with real inputs
performs a Real-valued fast Fourier transform (RFFT). When invoked with
real or complex valued input, the default value is 0. Values can be 0 or
1.
floor(n_fft/2) + 1] are used or returned because the real-to-complex
Fourier transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m,
n_fft-w]*. When onesided=1 and inverse=0 (forward DFT), only real input
is supported and a one-sided complex spectrum is returned (RFFT). When
onesided=1 and inverse=1 (inverse DFT), only complex input is supported
and a full real signal is returned (IRFFT). When invoked with real or
complex valued input, the default value is 0. Values can be 0 or 1.
"""

schema = get_schema("DFT", 17, "")
Expand Down
Loading
Loading