From e75b752b9579c012a8a5bd3e940abc6ab2ec36f8 Mon Sep 17 00:00:00 2001 From: Thiago Crepaldi Date: Thu, 11 Apr 2024 21:07:58 +0000 Subject: [PATCH] Add bfloat16 to all relevant ops Fixes #3842 Signed-off-by: Thiago Crepaldi --- docs/Changelog.md | 2096 +++++++++++++++++++++++++++- docs/Operators.md | 372 ++--- onnx/defs/generator/defs.cc | 116 +- onnx/defs/generator/old.cc | 389 ++++++ onnx/defs/math/defs.cc | 442 +++--- onnx/defs/math/old.cc | 972 +++++++++++++ onnx/defs/nn/defs.cc | 110 +- onnx/defs/nn/old.cc | 1454 +++++++++++++++++++ onnx/defs/object_detection/defs.cc | 11 +- onnx/defs/object_detection/old.cc | 117 ++ onnx/defs/operator_sets.h | 92 +- onnx/defs/operator_sets_preview.h | 15 +- onnx/defs/rnn/defs.cc | 11 +- onnx/defs/rnn/old.cc | 259 ++++ onnx/defs/schema.h | 2 +- onnx/defs/tensor/defs.cc | 34 +- onnx/defs/tensor/old.cc | 283 ++++ onnx/defs/traditionalml/defs.cc | 11 +- onnx/defs/traditionalml/old.cc | 203 +++ onnx/defs/traditionalml/utils.cc | 33 + onnx/defs/traditionalml/utils.h | 19 +- onnx/defs/training/defs.cc | 8 +- onnx/defs/training/old.cc | 196 +++ onnx/version_converter/convert.h | 150 ++ 24 files changed, 6758 insertions(+), 637 deletions(-) create mode 100644 onnx/defs/traditionalml/utils.cc create mode 100644 onnx/defs/training/old.cc diff --git a/docs/Changelog.md b/docs/Changelog.md index 8f253ed0edc..278c5f7d84d 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4629,7 +4629,7 @@ This version of the operator has been available since version 2 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -10750,7 +10750,7 @@ This version of the operator has been available since version 11 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(float16), tensor(float16), tensor(float), tensor(double)
Constrain input and output types to float tensors.
@@ -14497,7 +14497,7 @@ This version of the operator has been available since version 12 of the default ``` output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) ``` - 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. + if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`. `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: ``` @@ -19038,7 +19038,7 @@ This version of the operator has been available since version 14 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
T1 : tensor(int32)
Constrain seq_lens to integer tensor.
@@ -19217,7 +19217,7 @@ This version of the operator has been available since version 14 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
T1 : tensor(int32)
Constrain seq_lens to integer tensor.
@@ -22627,7 +22627,7 @@ This version of the operator has been available since version 18 of the default ``` output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) ``` - 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. + if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`. `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: ``` @@ -25878,6 +25878,2090 @@ This version of the operator has been available since version 21 of the default
Constrain input and output types to all tensor types up to IRv10.
+## Version 22 of the default ONNX operator set +### **Acos-22** + + Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arccosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Acosh-22** + + Calculates the hyperbolic arccosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arccosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Asin-22** + + Calculates the arcsine (inverse of sine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arcsine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Asinh-22** + + Calculates the hyperbolic arcsine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arcsine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Atan-22** + + Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arctangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Atanh-22** + + Calculates the hyperbolic arctangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arctangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **AveragePool-22** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape is calculated differently + depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized. + With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + 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. + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + ``` + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
count_include_pad : int (default is 0)
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Bernoulli-22** + + Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor + containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, + where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p). + + This operator is non-deterministic and may not produce the same values in different + implementations (even if a seed is specified). + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
The data type for the elements of the output tensor. if not specified, we will use the data type of the input tensor.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
All values in input have to be in the range:[0, 1].
+
+ +#### Outputs + +
+
output : T2
+
The returned output tensor only has values 0 or 1, same shape as input tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input types to float tensors.
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain output types to all numeric tensors and bool tensors.
+
+ +### **Conv-22** + + The convolution operator consumes an input tensor and a filter, and + computes the output. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. Assuming zero based indices for the shape array, X.shape[1] == (W.shape[1] * group) == C and W.shape[0] mod G == 0. Or in other words FILTER_IN_CHANNEL multiplied by the number of groups should be equal to DATA_CHANNEL and the number of feature maps M should be a multiple of the number of groups G.
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **ConvTranspose-22** + + The convolution transpose operator consumes an input tensor and a filter, + and computes the output. + + If the pads parameter is provided the shape of the output is calculated via the following equation: + + 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] + + output_shape can also be explicitly specified in which case pads values are auto generated using these equations: + + total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i] + If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2) + Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2). + + + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = input_shape[i] * strides[i]` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
output_padding : list of ints
+
Additional elements added to the side with higher coordinate indices in the output. Each padding value in "output_padding" must be less than the corresponding stride/dilation dimension. By default, this attribute is a zero vector. Note that this attribute doesn't directly affect the computed output values. It only controls the selection of the computed values, so changing this attribute only adds or removes output elements. If "output_shape" is explicitly provided, "output_padding" does not contribute additional size to "output_shape" but participates in the computation of the needed padding amount. This is also called adjs or adjustment in some frameworks.
+
output_shape : list of ints
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified pads values are ignored. See doc for details for equations to generate pads. Note that the output_shape attribute value should not include dimensions for batch size and channels, which are automatically inferred.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn)
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (C x M/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the weight shape will be (C x M/group x k1 x k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the kernel. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, pad lengths and group count. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Cos-22** + + Calculates the cosine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The cosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Cosh-22** + + Calculates the hyperbolic cosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic cosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **DeformConv-22** + + Performs deformable convolution as described in https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. + This operator specification supports the general N-D case. Note that most common use cases have 2D or 3D data. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dilations : list of ints
+
Dilation value along each spatial axis of the kernel. Default is 1 along each axis.
+
group : int (default is 1)
+
Number of groups the input and output channels, C and oC, are divided into. C and oC must both be divisible by group. Default is 1.
+
kernel_shape : list of ints
+
Shape of the convolution kernel. If not present, it is inferred from the shape of input W.
+
offset_group : int (default is 1)
+
Number of groups of offset. C must be divisible by offset_group. Default is 1.
+
pads : list of ints
+
Padding for the beginning and end along each spatial axis. The values represent the number of pixels added to the beginning and end of the corresponding axis and can take any nonnegative value. The format should be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where xi_begin is the number of pixels added at the beginning of axis `i` and xi_end is the number of pixels added at the end of axis `i`. Default is 0 along each axis.
+
strides : list of ints
+
Stride along each spatial axis. Default is 1 along each axis.
+
+ +#### Inputs (3 - 5) + +
+
X : T
+
Input data tensor. For 2D image data, it has shape (N, C, H, W) where N is the batch size, C is the number of input channels, and H and W are the height and width. In general, the shape is (N, C, D1, D2, ... , Dn) for n-dimensional data, where D1 to Dn are the spatial dimension sizes. Most common use cases have n = 2 or 3.
+
W : T
+
Weight tensor that will be used in the convolutions. It has shape (oC, C/group, kH, kW), where oC is the number of output channels and kH and kW are the kernel height and width. For more than 2 dimensions, it has shape (oC, C/group, k1, k2, ... , kn).
+
offset : T
+
Offset tensor denoting the offset for the sampling locations in the convolution kernel. It has shape (N, offset_group * kH * kW * 2, oH, oW) for 2D data or (N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Use linear interpolationfor fractional offset values. Sampling locations outside of the padded input tensor gives zero.
+
B (optional) : T
+
Optional 1D bias of length oC to be added to the convolution. Default is a tensor of zeros.
+
mask (optional) : T
+
The mask tensor to be applied to each position in the convolution kernel. It has shape (N, offset_group * kH * kW, oH, oW) for 2D data or (N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Default is a tensor of ones.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor that contains the result of convolution. It has shape (N, oC, oH, oW) for 2D data or (N, oC, o1, o2, ..., on) for nD data
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Det-22** + + Det calculates determinant of a square matrix or batches of square matrices. + Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions, + and the inner-most 2 dimensions form square matrices. + The output is a tensor of shape `[*]`, containing the determinants of all input submatrices. + e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`). + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to floating-point tensors.
+
+ +### **Dropout-22** + + 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, + output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; + Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, + the user can simply not pass `training_mode` input or set it to false. + ``` + output = scale * data * mask, + ``` + where + ``` + scale = 1. / (1. - ratio). + ``` + This operator has **optional** inputs/outputs. See [the doc](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. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
seed : int
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs (1 - 3) + +
+
data (differentiable) : T
+
The input data as Tensor.
+
ratio (optional, non-differentiable) : T1
+
The ratio of random dropout, with value in [0, 1). If this input was not set, or if it was set to 0, the output would be a simple copy of the input. If it's non-zero, output will be a random dropout of the scaled input, which is typically the case during training. It is an optional value, if not specified it will default to 0.5.
+
training_mode (optional, non-differentiable) : T2
+
If set to true then it indicates dropout is being used for training. It is an optional value hence unless specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where nothing will be dropped from the input data and if mask is requested as output it will contain all ones.
+
+ +#### Outputs (1 - 2) + +
+
output (differentiable) : T
+
The output.
+
mask (optional, non-differentiable) : T2
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input 'ratio' types to float tensors.
+
T2 : tensor(bool)
+
Constrain output 'mask' types to boolean tensors.
+
+ +### **Elu-22** + + Elu takes one input data (Tensor) and produces one output data + (Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < + 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. + + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Coefficient of ELU.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **EyeLike-22** + + Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D + tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the + same as the input tensor. The data type can be specified by the 'dtype' argument. If + 'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal + is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor. If not specified,the data type of the input tensor T1 is used. If input tensor T1 is also notspecified, then type defaults to 'float'.
+
k : int (default is 0)
+
(Optional) Index of the diagonal to be populated with ones. Default is 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a lower diagonal.
+
+ +#### Inputs + +
+
input : T1
+
2D input tensor to copy shape, and optionally, type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor, same shape as input tensor T1.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain input types. Strings and complex are not supported.
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain output types. Strings and complex are not supported.
+
+ +### **GlobalAveragePool-22** + + GlobalAveragePool consumes an input tensor X and applies average pooling across + the values in the same channel. This is equivalent to AveragePool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **GridSample-22** + + Given an input `X` and a flow-field `grid`, computes the output `Y` using `X` values and pixel locations from the `grid`. + For spatial input `X` with shape (N, C, H, W), the `grid` will have shape (N, H_out, W_out, 2), + the output `Y` will have shape (N, C, H_out, W_out). For volumetric input `X` with shape (N, C, D, H, W), + 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). + More generally, for an input `X` of rank r+2 with shape (N, C, d1, d2, ..., dr), + 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). + + The tensor `X` contains values at centers of square pixels (voxels, etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). + The (n, d1_out, d2_out, ..., dr_out, :) values from the tensor `grid` are the normalized positions for interpolating the values + at the (n, c, d1_out, d2_out, ..., dr_out) locations from the output tensor `Y` using a specified interpolation method (the mode) + and a padding mode (for `grid` positions falling outside the 2-dimensional image). + + 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`. + They are used to interpolate output values of `Y[n, c, h_out, w_out]`. + + The GridSample operator is often used in doing grid generator and sampler in the + [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025). + See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html). + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
align_corners : int (default is 0)
+
If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input's corner pixels (voxels, etc.). If align_corners=0, they are instead considered as referring to the corner points of the input's corner pixels (voxels, etc.), making the sampling more resolution agnostic.
+
mode : string (default is linear)
+
Three interpolation modes: linear (default), nearest and cubic. The "linear" mode includes linear and N-linear interpolation modes depending on the number of spatial dimensions of the input tensor (i.e. linear for 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The "cubic" mode also includes N-cubic interpolation modes following the same rules. The "nearest" mode rounds to the nearest even index when the sampling point falls halfway between two indices.
+
padding_mode : string (default is zeros)
+
Support padding modes for outside grid values: `zeros`(default), `border`, `reflection`. zeros: use 0 for out-of-bound grid locations, border: use border values for out-of-bound grid locations, reflection: use values at locations reflected by the border for out-of-bound grid locations. If index 0 represents the margin pixel, the reflected value at index -1 will be the same as the value at index 1. For location far away from the border, it will keep being reflected until becoming in bound. If pixel location x = -3.5 reflects by border -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = 0.5.
+
+ +#### Inputs + +
+
X (differentiable) : T1
+
Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N is the batch size, C is the number of channels, D1, D2, ..., Dr are the spatial dimensions.
+
grid (non-differentiable) : T2
+
Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, D2_out, ..., Dr_out are the spatial dimensions of the grid and output, and r is the number of spatial dimensions. Grid specifies the sampling locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1]. If the grid has values outside the range of [-1, 1], the corresponding outputs will be handled as defined by padding_mode. Following computer vision convention, the coordinates in the length-r location vector are listed from the innermost tensor dimension to the outermost, the opposite of regular tensor indexing.
+
+ +#### Outputs + +
+
Y (differentiable) : T1
+
Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., Dr_out) of the sampled values. For integer input types, intermediate values are computed as floating point and cast to integer at the end.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain input `X` and output `Y` types to all tensor types.
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain grid types to float tensors.
+
+ +### **HardSigmoid-22** + + HardSigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.2)
+
Value of alpha.
+
beta : float (default is 0.5)
+
Value of beta.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **HardSwish-22** + + HardSwish takes one input data (Tensor) and produces one output data (Tensor) where + the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x), + where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **InstanceNormalization-22** + + Carries out instance normalization as described in the paper + https://arxiv.org/abs/1607.08022. + + y = scale * (x - mean) / sqrt(variance + epsilon) + B, + where mean and variance are computed per instance per channel. + + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
scale (differentiable) : T
+
The input 1-dimensional scale tensor of size C.
+
B (differentiable) : T
+
The input 1-dimensional bias tensor of size C.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output tensor of the same shape as input.
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **LpNormalization-22** + + Given a matrix, apply Lp-normalization along the provided axis. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
The axis on which to apply normalization, -1 mean last axis.
+
p : int (default is 2)
+
The order of the normalization, only 1 or 2 are supported.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input matrix
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Matrix after normalization
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **LpPool-22** + + LpPool consumes an input tensor X and applies Lp pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled `pad_shape[i]` is the sum of pads along axis `i`. + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] + ``` + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes.
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **MaxPool-22** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape is calculated differently + depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized. + With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + 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. + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + ``` + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major. This attribute is used only to convert an n-tuple index value into a single integer value for producing the second output.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional, non-differentiable) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(uint8)
+
Constrain input and output types to float and 8 bit tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **MaxRoiPool-22** + + ROI max pool consumes an input tensor X and region of interests (RoIs) to + apply max pooling across each RoI, to produce output 4-D tensor of shape + (num_rois, channels, pooled_shape[0], pooled_shape[1]). + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
pooled_shape : list of ints (required)
+
ROI pool output shape (height, width).
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois (non-differentiable) : T
+
RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1]).
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **MaxUnpool-22** + + MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the output information from a MaxPool op. The first + input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) + from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corresponding + to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op. + The third (optional) input is a tensor that specifies the output size of the unpooling operation. + + MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal + values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling + the result of an unpooling operation should give back the original input to the unpooling op. + + MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous. + The third input argument, output_size, is meant to disambiguate the op and produce output tensor of + known/predictable size. + + In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads, + which define the exact unpooling op. The attributes typically have the same values as the corresponding + pooling op that the unpooling op is trying to invert. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T1
+
Input data tensor that has to be unpooled. This tensor is typically the first output of the MaxPool op.Dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non-image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
I (non-differentiable) : T2
+
Input data tensor containing the indices corresponding to elements in the first input tensor X.This tensor is typically the second output of the MaxPool op.Dimensions must be the same as input tensor X. The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, assuming row-major storage. Also, the linear indices should not consider padding. So the values in indices are in the range [0, N x C x D1 x ... x Dn).
+
output_shape (optional, non-differentiable) : T2
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, 'pads' values are ignored.
+
+ +#### Outputs + +
+
output (differentiable) : T1
+
Output data tensor that contains the result of the unpooling.
+
+ +#### Type Constraints + +
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
T2 : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Mish-22** + + Mish: A Self Regularized Non-Monotonic Neural Activation Function. + + Perform the linear unit element-wise on the input tensor X using formula: + + ``` + mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) + ``` + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input X and output types to float tensors.
+
+ +### **Multinomial-22** + + Generate a tensor of samples from a multinomial distribution according to the probabilities + of each of the possible outcomes. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 6)
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use int32.
+
sample_size : int (default is 1)
+
Number of times to sample.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor with shape [batch_size, class_size], where class_size is the number of all possible outcomes. Each value along the axis zero represents the unnormalized log-probability of each corresponding outcome in a batch.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with shape [batch_size, sample_size], where sample_size is the number of times to sample. Each value along the axis zero represents the outcome of the corresponding sample in a batch.
+
+ +#### Type Constraints + +
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input types to float tensors.
+
T2 : tensor(int32), tensor(int64)
+
Constrain output types to integral tensors.
+
+ +### **NegativeLogLikelihoodLoss-22** + + A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. + Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. + The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). + The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) + or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. + 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: + + ``` + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + ``` + + When an optional "weight" is provided, the sample loss is calculated as: + + ``` + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + ``` + + loss is zero for the case when target-value equals ignore_index. + + ``` + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + ``` + + If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). + If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + + ``` + mean(loss), if "weight" is not provided, + ``` + + or if weight is provided, + + ``` + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + ``` + + If "reduction" attribute is set to "sum", the output is a scalar: `sum(loss)`. + + See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + + Example 1: + + ``` + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + ``` + + Example 2: + + ``` + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + + loss = np.sum(loss) + // print(loss) + // -1.1 + ``` + + Example 3: + + ``` + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + ``` + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean (default). 'none': the output is the loss for each sample. 'sum': the output will be summed. 'mean': the sum of the output will be divided by the sum of applied weights.
+
+ +#### Inputs (2 - 3) + +
+
input (differentiable) : T
+
Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk).
+
target (non-differentiable) : Tind
+
Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the target values should either be in the range [0, C) or have the value ignore_index.
+
weight (optional, non-differentiable) : T
+
Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs + +
+
loss (differentiable) : T
+
The negative log likelihood loss
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input, weight, and output types to floating-point tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ +### **RandomNormal-22** + + Generate a tensor with random values drawn from a normal distribution. The shape + of the tensor is specified by the `shape` argument and the parameter of the normal distribution + specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. Default is TensorProto::FLOAT.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain output types to float tensors.
+
+ +### **RandomNormalLike-22** + + Generate a tensor with random values drawn from a normal distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the normal distribution are specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message, and be valid as an output type. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain output types to float tensors.
+
+ +### **RandomUniform-22** + + Generate a tensor with random values drawn from a uniform distribution. The shape + of the tensor is specified by the `shape` argument and the range by `low` and `high`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. If not specified, default is TensorProto::FLOAT.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain output types to float tensors.
+
+ +### **RandomUniformLike-22** + + Generate a tensor with random values drawn from a uniform distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the uniform distribution are specified by `low` and `high`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain output types to float tensors.
+
+ +### **Resize-22** + + Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. + Each dimension value of the output tensor is: + ``` + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) + ``` + if input \"sizes\" is not specified. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
antialias : int (default is 0)
+
If set to 1, "linear" and "cubic" interpolation modes will use an antialiasing filter when downscaling. Antialiasing is achieved by stretching the resampling filter by a factor max(1, 1 / scale), which means that when downsampling, more input pixels contribute to an output pixel.
+
axes : list of ints
+
If provided, it specifies a subset of axes that 'roi', 'scales' and 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). Non-specified dimensions are interpreted as non-resizable. Negative value means counting dimensions from the back. Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined if an axis is repeated.
+
coordinate_transformation_mode : string (default is half_pixel)
+
+This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor. + +The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. +Denote `x_resized` as the coordinate of axis x in the resized tensor, + `x_original` as the coordinate of axis x in the original tensor, + `length_original` as the length of the original tensor in axis x, + `length_resized` as the length of the resized tensor in axis x, + `scale = length_resized / length_original`, + `output_width` the target length on the axis x which can be a fractional number when it is calculated out of a scale factor, + and `output_width_int` the effective output width as an integer. + +if coordinate_transformation_mode is `"half_pixel"`, +``` +x_original = (x_resized + 0.5) / scale - 0.5 +``` + +if coordinate_transformation_mode is `"half_pixel_symmetric"`, +``` +adjustment = output_width_int / output_width +center = input_width / 2 +offset = center * (1 - adjustment) +x_ori = offset + (x + 0.5) / scale - 0.5 +``` + +if coordinate_transformation_mode is `"pytorch_half_pixel"`, +``` +x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 +``` + +if coordinate_transformation_mode is `"align_corners"`, +``` +x_original = x_resized * (length_original - 1) / (length_resized - 1) +``` + +if coordinate_transformation_mode is `"asymmetric"`, +``` +x_original = x_resized / scale +``` + +if coordinate_transformation_mode is `"tf_crop_and_resize"`, +``` +x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) +``` +.
+
cubic_coeff_a : float (default is -0.75)
+
The coefficient 'a' used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. This attribute is valid only if mode is "cubic".
+
exclude_outside : int (default is 0)
+
If set to 1, the weight of sampling locations outside the tensor will be set to 0 and the weight will be renormalized so that their sum is 1.0. The default value is 0.
+
extrapolation_value : float (default is 0.0)
+
When coordinate_transformation_mode is "tf_crop_and_resize" and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.
+
keep_aspect_ratio_policy : string (default is stretch)
+
+This attribute describes how to interpret the `sizes` input with regard to keeping the original aspect ratio of the input, and it is not applicable when +the `scales` input is used. + +Given a set of `sizes`, associated with a subset of `axes` (explicitly provided or default), and assuming `d = axes[i]`, with `i` being the index of the provided `sizes`. + +If `keep_aspect_ratio_policy` is `"stretch"`, the original aspect ratio is disregarded, and the input is resized to the specified size: +`out_size[d] = sizes[i]` + +If `keep_aspect_ratio_policy` is `"not_larger"`, the sizes are adjusted so that no extent of the output is larger than the specified size, while keeping the original aspect ratio: +``` +scale = Min(sizes[i] / in_size[d]) +out_size[d] = round_int(scale * in_size[i]) +``` + +If `keep_aspect_ratio_policy` is `"not_smaller"`, the sizes are adjusted so that no extent of the output is smaller than the specified size, while keeping the original aspect ratio: +``` +scale = Max(sizes[i] / in_size[d]) +out_size[d] = round_int(scale * in_size[i]) +``` + +For non-resizable axes (those not specified in `axes`), the output size will be equal to the input size. + +Note: `round_int` stands for computing the nearest integer value, rounding halfway cases up.
+
mode : string (default is nearest)
+
Three interpolation modes: "nearest" (default), "linear" and "cubic". The "linear" mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). The "cubic" mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).
+
nearest_mode : string (default is round_prefer_floor)
+
Four modes: "round_prefer_floor" (default, as known as round half down), "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only used by nearest interpolation. It indicates how to get "nearest" pixel in input tensor from x_original, so this attribute is valid only if "mode" is "nearest".
+
+ +#### Inputs (1 - 4) + +
+
X (differentiable) : T1
+
N-D tensor
+
roi (optional, non-differentiable) : T2
+
1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is the rank of X or the length of axes, if provided. The RoIs' coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is "tf_crop_and_resize"
+
scales (optional, non-differentiable) : tensor(float)
+
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.
+
sizes (optional, non-differentiable) : tensor(int64)
+
Target size of the output tensor. Its interpretation depends on the 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' should be the same as the rank of input 'X', or the length of 'axes', if provided. Only one of 'scales' and 'sizes' can be specified.
+
+ +#### Outputs + +
+
Y (differentiable) : T1
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain roi type to float or double.
+
+ +### **RoiAlign-22** + + Region of Interest (RoI) align operation described in the + [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). + RoiAlign consumes an input tensor X and region of interests (rois) + to apply pooling across each RoI; it produces a 4-D tensor of shape + (num_rois, C, output_height, output_width). + + RoiAlign is proposed to avoid the misalignment by removing + quantizations while converting from original image into feature + map and from feature map into RoI feature; in each ROI bin, + the value of the sampled locations are computed directly + through bilinear interpolation. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value 'half_pixel' to pixel shift the input coordinates by -0.5 (the recommended behavior). Use the value 'output_half_pixel' to omit the pixel shift for the input (use this for a backward-compatible behavior).
+
mode : string (default is avg)
+
The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'.
+
output_height : int (default is 1)
+
default 1; Pooled output Y's height.
+
output_width : int (default is 1)
+
default 1; Pooled output Y's width.
+
sampling_ratio : int (default is 0)
+
Number of sampling points in the interpolation grid used to compute the output value of each pooled output bin. If > 0, then exactly sampling_ratio x sampling_ratio grid points are used. If == 0, then an adaptive number of grid points are used (computed as ceil(roi_width / output_width), and likewise for height). Default is 0.
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input spatial scale to the scale used when pooling, i.e., spatial scale of the input feature map X relative to the input image. E.g.; default is 1.0f.
+
+ +#### Inputs + +
+
X : T1
+
Input data tensor from the previous operator; 4-D feature map of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois : T1
+
RoIs (Regions of Interest) to pool over; rois is 2-D input of shape (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates are in the coordinate system of the input image. Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.
+
batch_indices : T2
+
1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch.
+
+ +#### Outputs + +
+
Y : T1
+
RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, output_width). The r-th batch element Y[r-1] is a pooled feature map corresponding to the r-th RoI X[r-1].
+
+ +#### Type Constraints + +
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain types to float tensors.
+
T2 : tensor(int64)
+
Constrain types to int tensors.
+
+ +### **Round-22** + + Round takes one input Tensor and rounds the values, element-wise, meaning + it finds the nearest integer for each value. + In case of halves, the rule is to round them to the nearest even integer. + If input x is integral, +0, -0, NaN, or infinite, x itself is returned. + The output tensor has the same shape and type as the input. + + Examples: + ``` + round([0.9]) = [1.0] + round([2.5]) = [2.0] + round([2.3]) = [2.0] + round([1.5]) = [2.0] + round([-4.5]) = [-4.0] + ``` + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Selu-22** + + Selu takes one input data (Tensor) and produces one output data + (Tensor) where the scaled exponential linear unit function, + `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.67326)
+
Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 approximation of 1.6732632423543772848170429916717).
+
gamma : float (default is 1.0507)
+
Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 approximation of 1.0507009873554804934193349852946).
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Sin-22** + + Calculates the sine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The sine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Sinh-22** + + Calculates the hyperbolic sine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic sine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Softplus-22** + + Softplus takes one input data (Tensor) and produces one output data + (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D input tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Softsign-22** + + Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The softsign (x/(1+|x|)) values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **Tan-22** + + Calculates the tangent of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The tangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ +### **ThresholdedRelu-22** + + ThresholdedRelu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 22 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Threshold value
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
+
Constrain input and output types to float tensors.
+
+ # ai.onnx.preview.training ## Version 1 of the 'ai.onnx.preview.training' operator set ### **ai.onnx.preview.training.Adagrad-1** diff --git a/docs/Operators.md b/docs/Operators.md index 372e42a4ac7..101191c5716 100644 --- a/docs/Operators.md +++ b/docs/Operators.md @@ -12,17 +12,17 @@ For an operator input/output's differentiability, it can be differentiable, |**Operator**|**Since version**|| |-|-|-| |Abs|13, 6, 1| -|Acos|7| -|Acosh|9| +|Acos|22, 7| +|Acosh|22, 9| |Add|14, 13, 7, 6, 1| |And|7, 1| |ArgMax|13, 12, 11, 1| |ArgMin|13, 12, 11, 1| -|Asin|7| -|Asinh|9| -|Atan|7| -|Atanh|9| -|AveragePool|19, 11, 10, 7, 1| +|Asin|22, 7| +|Asinh|22, 9| +|Atan|22, 7| +|Atanh|22, 9| +|AveragePool|22, 19, 11, 10, 7, 1| |BatchNormalization|15, 14, 9, 7, 6, 1| |BitShift|11| |BitwiseAnd|18| @@ -37,25 +37,25 @@ For an operator input/output's differentiability, it can be differentiable, |ConcatFromSequence|11| |Constant|21, 19, 13, 12, 11, 9, 1| |ConstantOfShape|21, 20, 9| -|Conv|11, 1| +|Conv|22, 11, 1| |ConvInteger|10| -|ConvTranspose|11, 1| -|Cos|7| -|Cosh|9| +|ConvTranspose|22, 11, 1| +|Cos|22, 7| +|Cosh|22, 9| |CumSum|14, 11| |DFT|20, 17| -|DeformConv|19| +|DeformConv|22, 19| |DepthToSpace|13, 11, 1| |DequantizeLinear|21, 19, 13, 10| -|Det|11| +|Det|22, 11| |Div|14, 13, 7, 6, 1| -|Dropout|13, 12, 10, 7, 6, 1| +|Dropout|22, 13, 12, 10, 7, 6, 1| |Einsum|12| |Equal|19, 13, 11, 7, 1| |Erf|13, 9| |Exp|13, 6, 1| |Expand|13, 8| -|EyeLike|9| +|EyeLike|22, 9| |Flatten|21, 13, 11, 9, 1| |Floor|13, 6, 1| |GRU|14, 7, 3, 1| @@ -63,16 +63,16 @@ For an operator input/output's differentiability, it can be differentiable, |GatherElements|13, 11| |GatherND|13, 12, 11| |Gemm|13, 11, 9, 7, 6, 1| -|GlobalAveragePool|1| +|GlobalAveragePool|22, 1| |GlobalLpPool|2, 1| |GlobalMaxPool|1| |Greater|13, 9, 7, 1| -|GridSample|20, 16| +|GridSample|22, 20, 16| |Hardmax|13, 11, 1| |Identity|21, 19, 16, 14, 13, 1| |If|21, 19, 16, 13, 11, 1| |ImageDecoder|20| -|InstanceNormalization|6, 1| +|InstanceNormalization|22, 6, 1| |IsInf|20, 10| |IsNaN|20, 13, 9| |LRN|13, 1| @@ -80,20 +80,20 @@ For an operator input/output's differentiability, it can be differentiable, |Less|13, 9, 7, 1| |Log|13, 6, 1| |Loop|21, 19, 16, 13, 11, 1| -|LpNormalization|1| -|LpPool|18, 11, 2, 1| +|LpNormalization|22, 1| +|LpPool|22, 18, 11, 2, 1| |MatMul|13, 9, 1| |MatMulInteger|10| |Max|13, 12, 8, 6, 1| -|MaxPool|12, 11, 10, 8, 1| -|MaxRoiPool|1| -|MaxUnpool|11, 9| +|MaxPool|22, 12, 11, 10, 8, 1| +|MaxRoiPool|22, 1| +|MaxUnpool|22, 11, 9| |Mean|13, 8, 6, 1| |MelWeightMatrix|17| |Min|13, 12, 8, 6, 1| |Mod|13, 10| |Mul|14, 13, 7, 6, 1| -|Multinomial|7| +|Multinomial|22, 7| |Neg|13, 6, 1| |NonMaxSuppression|11, 10| |NonZero|13, 9| @@ -109,10 +109,10 @@ For an operator input/output's differentiability, it can be differentiable, |QLinearMatMul|21, 10| |QuantizeLinear|21, 19, 13, 10| |RNN|14, 7, 1| -|RandomNormal|1| -|RandomNormalLike|1| -|RandomUniform|1| -|RandomUniformLike|1| +|RandomNormal|22, 1| +|RandomNormalLike|22, 1| +|RandomUniform|22, 1| +|RandomUniformLike|22, 1| |Reciprocal|13, 6, 1| |ReduceMax|20, 18, 13, 12, 11, 1| |ReduceMean|18, 13, 11, 1| @@ -121,10 +121,10 @@ For an operator input/output's differentiability, it can be differentiable, |ReduceSum|13, 11, 1| |RegexFullMatch|20| |Reshape|21, 19, 14, 13, 5, 1| -|Resize|19, 18, 13, 11, 10| +|Resize|22, 19, 18, 13, 11, 10| |ReverseSequence|10| -|RoiAlign|16, 10| -|Round|11| +|RoiAlign|22, 16, 10| +|Round|22, 11| |STFT|17| |Scan|21, 19, 16, 11, 9, 8| |Scatter (deprecated)|11, 9| @@ -139,8 +139,8 @@ For an operator input/output's differentiability, it can be differentiable, |Shape|21, 19, 15, 13, 1| |Sigmoid|13, 6, 1| |Sign|13, 9| -|Sin|7| -|Sinh|9| +|Sin|22, 7| +|Sinh|22, 9| |Size|21, 19, 13, 1| |Slice|13, 11, 10, 1| |SpaceToDepth|13, 1| @@ -153,7 +153,7 @@ For an operator input/output's differentiability, it can be differentiable, |StringSplit|20| |Sub|14, 13, 7, 6, 1| |Sum|13, 8, 6, 1| -|Tan|7| +|Tan|22, 7| |Tanh|13, 6, 1| |TfIdfVectorizer|9| |Tile|13, 6, 1| @@ -167,28 +167,28 @@ For an operator input/output's differentiability, it can be differentiable, |Xor|7, 1| |**Function**|**Since version**|**Function version**| |AffineGrid|20|20| -|Bernoulli|15|15| +|Bernoulli|22, 15|22| |BlackmanWindow|17|17| |CastLike|21, 19, 15|21| |Celu|12|12| |CenterCropPad|18|18| |Clip|13, 12, 11, 6, 1|13| |DynamicQuantizeLinear|11|11| -|Elu|6, 1|18| +|Elu|22, 6, 1|18| |Gelu|20|20| |GreaterOrEqual|16, 12|16| |GroupNormalization|21, 18|21| |HammingWindow|17|17| |HannWindow|17|17| -|HardSigmoid|6, 1|18| -|HardSwish|14|14| +|HardSigmoid|22, 6, 1|18| +|HardSwish|22, 14|22| |LayerNormalization|17|17, 18| |LeakyRelu|16, 6, 1|16| |LessOrEqual|16, 12|16| |LogSoftmax|13, 11, 1|13, 18| |MeanVarianceNormalization|13, 9|13, 18| -|Mish|18|18| -|NegativeLogLikelihoodLoss|13, 12|13| +|Mish|22, 18|22| +|NegativeLogLikelihoodLoss|22, 13, 12|22| |PRelu|16, 9, 7, 6, 1|16| |Range|11|11| |ReduceL1|18, 13, 11, 1|18| @@ -197,14 +197,14 @@ For an operator input/output's differentiability, it can be differentiable, |ReduceLogSumExp|18, 13, 11, 1|18| |ReduceSumSquare|18, 13, 11, 1|18| |Relu|14, 13, 6, 1|18| -|Selu|6, 1|18| +|Selu|22, 6, 1|18| |SequenceMap|17|17| |Shrink|9|18| |Softmax|13, 11, 1|13, 18| |SoftmaxCrossEntropyLoss|13, 12|13| -|Softplus|1|18| -|Softsign|1|18| -|ThresholdedRelu|10|18| +|Softplus|22, 1|18| +|Softsign|22, 1|18| +|ThresholdedRelu|22, 10|18| ### ai.onnx.preview.training |**Operator**|**Since version**|| @@ -295,7 +295,9 @@ def abs(input: np.ndarray) -> np.ndarray: # noqa: A001 #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -314,7 +316,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -349,7 +351,9 @@ expect(node, inputs=[x], outputs=[y], name="test_acos") #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Inputs @@ -368,7 +372,7 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -1397,7 +1401,9 @@ expect( #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -1416,7 +1422,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -1451,7 +1457,9 @@ expect(node, inputs=[x], outputs=[y], name="test_asin") #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Inputs @@ -1470,7 +1478,7 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -1505,7 +1513,9 @@ expect(node, inputs=[x], outputs=[y], name="test_asinh") #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -1524,7 +1534,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -1559,7 +1569,9 @@ expect(node, inputs=[x], outputs=[y], name="test_atan") #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Inputs @@ -1578,7 +1590,7 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -1644,9 +1656,9 @@ expect(node, inputs=[x], outputs=[y], name="test_atanh") #### Version -This version of the operator has been available since version 19 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1, 7, 10, 11 +Other versions of this operator: 1, 7, 10, 11, 19 #### Attributes @@ -1684,7 +1696,7 @@ Other versions of this operator: 1, -
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double)
Constrain input and output types to float tensors.
@@ -2610,7 +2622,9 @@ expect( #### Version -This version of the operator has been available since version 15 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 15 #### Attributes @@ -2638,9 +2652,9 @@ This version of the operator has been available since version 15 of the default #### Type Constraints
-
T1 : tensor(float16), tensor(float), tensor(double)
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input types to float tensors.
-
T2 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bool)
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain output types to all numeric tensors and bool tensors.
@@ -5546,9 +5560,9 @@ expect(node, inputs=[x], outputs=[y], name="test_constantofshape_int_zeros") #### Version -This version of the operator has been available since version 11 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1 +Other versions of this operator: 1, 11 #### Attributes @@ -5588,7 +5602,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -6004,9 +6018,9 @@ expect( #### Version -This version of the operator has been available since version 11 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1 +Other versions of this operator: 1, 11 #### Attributes @@ -6050,7 +6064,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -6491,7 +6505,9 @@ expect(node, inputs=[x, W], outputs=[y], name="test_convtranspose_pads") #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -6510,7 +6526,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -6545,7 +6561,9 @@ expect(node, inputs=[x], outputs=[y], name="test_cos") #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Inputs @@ -6564,7 +6582,7 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -6941,7 +6959,9 @@ expect( #### Version -This version of the operator has been available since version 19 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 19 #### Attributes @@ -6985,7 +7005,7 @@ This version of the operator has been available since version 19 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -7757,7 +7777,9 @@ expect( #### Version -This version of the operator has been available since version 11 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 11 #### Inputs @@ -7776,7 +7798,7 @@ This version of the operator has been available since version 11 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to floating-point tensors.
@@ -7926,9 +7948,9 @@ expect(node, inputs=[x, y], outputs=[z], name="test_div_bcast") #### Version -This version of the operator has been available since version 13 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1, 6, 7, 10, 12 +Other versions of this operator: 1, 6, 7, 10, 12, 13 #### Attributes @@ -7960,9 +7982,9 @@ Other versions of this operator: 1, -
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
-
T1 : tensor(float16), tensor(float), tensor(double)
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input 'ratio' types to float tensors.
T2 : tensor(bool)
Constrain output 'mask' types to boolean tensors.
@@ -8512,9 +8534,9 @@ expect(node, inputs=[X], outputs=[Y], name="test_einsum_transpose") #### Version -This version of the operator has been available since version 6 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator:
1 +Other versions of this operator: 1, 6 #### Attributes @@ -8540,7 +8562,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -8928,7 +8950,9 @@ expect( #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Attributes @@ -8956,9 +8980,9 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain input types. Strings and complex are not supported.
-
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain output types. Strings and complex are not supported.
@@ -9309,7 +9333,7 @@ Other versions of this operator: 1, 1 #### Inputs @@ -10450,7 +10476,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -10537,7 +10563,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -10799,9 +10825,9 @@ Other versions of this operator: 12 #### Version -This version of the operator has been available since version 20 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 16 +Other versions of this operator: 16, 20 #### Attributes @@ -10833,9 +10859,9 @@ Other versions of this operator: 16 #### Type Constraints
-
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain input `X` and output `Y` types to all tensor types.
-
T2 : tensor(float16), tensor(float), tensor(double)
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain grid types to float tensors.
@@ -11756,9 +11782,9 @@ expect(node, inputs=[size], outputs=[y], name="test_hannwindow_symmetric") #### Version -This version of the operator has been available since version 6 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1 +Other versions of this operator: 1, 6 #### Attributes @@ -11786,7 +11812,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -11840,7 +11866,9 @@ expect(node, inputs=[x], outputs=[y], name="test_hardsigmoid_default") #### Version -This version of the operator has been available since version 14 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 14 #### Inputs @@ -11859,7 +11887,7 @@ This version of the operator has been available since version 14 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -12707,9 +12735,9 @@ expect( #### Version -This version of the operator has been available since version 6 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1 +Other versions of this operator: 1, 6 #### Attributes @@ -12739,7 +12767,7 @@ Other versions of this operator: #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -13220,7 +13248,7 @@ Other versions of this operator:
1, 1 #### Attributes @@ -14732,7 +14762,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -14765,9 +14795,9 @@ This version of the operator has been available since version 1 of the default O #### Version -This version of the operator has been available since version 18 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1, 2, 11 +Other versions of this operator: 1, 2, 11, 18 #### Attributes @@ -14805,7 +14835,7 @@ Other versions of this operator: 1, -
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -15424,9 +15454,9 @@ for op_dtype in all_numeric_dtypes: #### Version -This version of the operator has been available since version 12 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator:
1, 8, 10, 11 +Other versions of this operator: 1, 8, 10, 11, 12 #### Attributes @@ -15466,7 +15496,7 @@ Other versions of this operator: 1, -
T : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(uint8)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(uint8)
Constrain input and output types to float and 8 bit tensors.
I : tensor(int64)
Constrain index tensor to int64
@@ -16293,7 +16323,9 @@ expect( #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator:
1 #### Attributes @@ -16323,7 +16355,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -16351,9 +16383,9 @@ This version of the operator has been available since version 1 of the default O #### Version -This version of the operator has been available since version 11 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 9 +Other versions of this operator: 9, 11 #### Attributes @@ -16387,7 +16419,7 @@ Other versions of this operator: 9 #### Type Constraints
-
T1 : tensor(float16), tensor(float), tensor(double)
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
T2 : tensor(int64)
Constrain index tensor to int64
@@ -16880,7 +16912,9 @@ for op_dtype in all_numeric_dtypes: #### Version -This version of the operator has been available since version 18 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 18 #### Inputs @@ -16899,7 +16933,7 @@ This version of the operator has been available since version 18 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input X and output types to float tensors.
@@ -17316,7 +17350,9 @@ expect(node, inputs=[x, y], outputs=[z], name="test_mul_bcast") #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Attributes @@ -17346,7 +17382,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T1 : tensor(float16), tensor(float), tensor(double)
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input types to float tensors.
T2 : tensor(int32), tensor(int64)
Constrain output types to integral tensors.
@@ -17517,9 +17553,9 @@ expect(node, inputs=[x], outputs=[y], name="test_neg") #### Version -This version of the operator has been available since version 13 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 12 +Other versions of this operator: 12, 13 #### Attributes @@ -17551,7 +17587,7 @@ Other versions of this operator: 1 #### Attributes @@ -21051,7 +21089,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain output types to float tensors.
@@ -21068,7 +21106,9 @@ This version of the operator has been available since version 1 of the default O #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 1 #### Attributes @@ -21100,9 +21140,9 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
-
T2 : tensor(float16), tensor(float), tensor(double)
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain output types to float tensors.
@@ -21118,7 +21158,9 @@ This version of the operator has been available since version 1 of the default O #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 1 #### Attributes @@ -21148,7 +21190,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain output types to float tensors.
@@ -21165,7 +21207,9 @@ This version of the operator has been available since version 1 of the default O #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 1 #### Attributes @@ -21197,9 +21241,9 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
-
T2 : tensor(float16), tensor(float), tensor(double)
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain output types to float tensors.
@@ -24364,9 +24408,9 @@ for test_name, shape in test_cases.items(): #### Version -This version of the operator has been available since version 19 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 10, 11, 13, 18 +Other versions of this operator: 10, 11, 13, 18, 19 #### Attributes @@ -24481,9 +24525,9 @@ Note: `round_int` stands for computing the nearest integer value, rounding halfw #### Type Constraints
-
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(uint4), tensor(int4)
Constrain input 'X' and output 'Y' to all tensor types.
-
T2 : tensor(float16), tensor(float), tensor(double)
+
T2 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain roi type to float or double.
@@ -26591,9 +26635,9 @@ expect( #### Version -This version of the operator has been available since version 16 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 10 +Other versions of this operator: 10, 16 #### Attributes @@ -26633,7 +26677,7 @@ Other versions of this operator: 10 #### Type Constraints
-
T1 : tensor(float16), tensor(float), tensor(double)
+
T1 : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain types to float tensors.
T2 : tensor(int64)
Constrain types to int tensors.
@@ -26978,7 +27022,9 @@ expect( #### Version -This version of the operator has been available since version 11 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 11 #### Inputs @@ -26997,7 +27043,7 @@ This version of the operator has been available since version 11 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -28223,9 +28269,9 @@ expect( #### Version -This version of the operator has been available since version 6 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. -Other versions of this operator: 1 +Other versions of this operator: 1, 6 #### Attributes @@ -28253,7 +28299,7 @@ Other versions of this operator: 1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -29279,7 +29325,9 @@ expect(node, inputs=[x], outputs=[y], name="test_sign") #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -29298,7 +29346,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -29333,7 +29381,9 @@ expect(node, inputs=[x], outputs=[y], name="test_sin") #### Version -This version of the operator has been available since version 9 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 9 #### Inputs @@ -29352,7 +29402,7 @@ This version of the operator has been available since version 9 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -31262,7 +31312,9 @@ expect( #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 1 #### Inputs @@ -31281,7 +31333,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -31318,7 +31370,9 @@ expect(node, inputs=[x], outputs=[y], name="test_softplus") #### Version -This version of the operator has been available since version 1 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 1 #### Inputs @@ -31337,7 +31391,7 @@ This version of the operator has been available since version 1 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -32937,7 +32991,9 @@ expect( #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 7 #### Inputs @@ -32956,7 +33012,7 @@ This version of the operator has been available since version 7 of the default O #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
@@ -33376,7 +33432,9 @@ expect( #### Version -This version of the operator has been available since version 10 of the default ONNX operator set. +This version of the operator has been available since version 22 of the default ONNX operator set. + +Other versions of this operator: 10 #### Attributes @@ -33402,7 +33460,7 @@ This version of the operator has been available since version 10 of the default #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
+
T : tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz)
Constrain input and output types to float tensors.
diff --git a/onnx/defs/generator/defs.cc b/onnx/defs/generator/defs.cc index 7269f7717eb..73f735e83aa 100644 --- a/onnx/defs/generator/defs.cc +++ b/onnx/defs/generator/defs.cc @@ -126,7 +126,7 @@ ONNX_OPERATOR_SET_SCHEMA( } })); -static const char* EyeLike_ver9_doc = R"DOC( +static const char* EyeLike_ver22_doc = R"DOC( Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the same as the input tensor. The data type can be specified by the 'dtype' argument. If @@ -138,9 +138,9 @@ TensorProto message and be valid as an output type. ONNX_OPERATOR_SET_SCHEMA( EyeLike, - 9, + 22, OpSchema() - .SetDoc(EyeLike_ver9_doc) + .SetDoc(EyeLike_ver22_doc) .Attr( "k", "(Optional) Index of the diagonal to be populated with ones. Default is 0." @@ -159,33 +159,11 @@ ONNX_OPERATOR_SET_SCHEMA( .Output(0, "output", "Output tensor, same shape as input tensor T1.", "T2") .TypeConstraint( "T1", - {"tensor(float16)", - "tensor(float)", - "tensor(double)", - "tensor(int8)", - "tensor(int16)", - "tensor(int32)", - "tensor(int64)", - "tensor(uint8)", - "tensor(uint16)", - "tensor(uint32)", - "tensor(uint64)", - "tensor(bool)"}, + OpSchema::all_tensor_types_ir10(), "Constrain input types. Strings and complex are not supported.") .TypeConstraint( "T2", - {"tensor(float16)", - "tensor(float)", - "tensor(double)", - "tensor(int8)", - "tensor(int16)", - "tensor(int32)", - "tensor(int64)", - "tensor(uint8)", - "tensor(uint16)", - "tensor(uint32)", - "tensor(uint64)", - "tensor(bool)"}, + OpSchema::all_tensor_types_ir10(), "Constrain output types. Strings and complex are not supported.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { if (ctx.getAttribute("dtype") != nullptr) { @@ -202,7 +180,7 @@ ONNX_OPERATOR_SET_SCHEMA( propagateShapeFromInputToOutput(ctx, 0, 0); })); -static const char* RandomUniform_ver1_doc = R"DOC( +static const char* RandomUniform_ver22_doc = R"DOC( Generate a tensor with random values drawn from a uniform distribution. The shape of the tensor is specified by the `shape` argument and the range by `low` and `high`. @@ -213,9 +191,9 @@ TensorProto message. ONNX_OPERATOR_SET_SCHEMA( RandomUniform, - 1, + 22, OpSchema() - .SetDoc(RandomUniform_ver1_doc) + .SetDoc(RandomUniform_ver22_doc) .Attr("low", "Lower boundary of the output values.", AttributeProto::FLOAT, 0.0f) .Attr("high", "Upper boundary of the output values.", AttributeProto::FLOAT, 1.0f) .Attr( @@ -230,16 +208,13 @@ ONNX_OPERATOR_SET_SCHEMA( static_cast(TensorProto::FLOAT)) .Attr("shape", "The shape of the output tensor.", AttributeProto::INTS) .Output(0, "output", "Output tensor of random values drawn from uniform distribution", "T") - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain output types to float tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0, TensorProto::FLOAT); propagateShapeFromAttributeToOutput(ctx, "shape", 0); })); -static const char* RandomNormal_ver1_doc = R"DOC( +static const char* RandomNormal_ver22_doc = R"DOC( Generate a tensor with random values drawn from a normal distribution. The shape of the tensor is specified by the `shape` argument and the parameter of the normal distribution specified by `mean` and `scale`. @@ -251,9 +226,9 @@ TensorProto message. ONNX_OPERATOR_SET_SCHEMA( RandomNormal, - 1, + 22, OpSchema() - .SetDoc(RandomNormal_ver1_doc) + .SetDoc(RandomNormal_ver22_doc) .Attr("mean", "The mean of the normal distribution.", AttributeProto::FLOAT, 0.0f) .Attr("scale", "The standard deviation of the normal distribution.", AttributeProto::FLOAT, 1.0f) .Attr( @@ -268,16 +243,13 @@ ONNX_OPERATOR_SET_SCHEMA( static_cast(TensorProto::FLOAT)) .Attr("shape", "The shape of the output tensor.", AttributeProto::INTS) .Output(0, "output", "Output tensor of random values drawn from normal distribution", "T") - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain output types to float tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0, TensorProto::FLOAT); propagateShapeFromAttributeToOutput(ctx, "shape", 0); })); -static const char* RandomUniformLike_ver1_doc = R"DOC( +static const char* RandomUniformLike_ver22_doc = R"DOC( Generate a tensor with random values drawn from a uniform distribution. The shape of the output tensor is copied from the shape of the input tensor, and the parameters of the uniform distribution are specified by `low` and `high`. @@ -289,9 +261,9 @@ TensorProto message and be valid as an output type. ONNX_OPERATOR_SET_SCHEMA( RandomUniformLike, - 1, + 22, OpSchema() - .SetDoc(RandomUniformLike_ver1_doc) + .SetDoc(RandomUniformLike_ver22_doc) .Attr("low", "Lower boundary of the output values.", AttributeProto::FLOAT, 0.0f) .Attr("high", "Upper boundary of the output values.", AttributeProto::FLOAT, 1.0f) .Attr( @@ -309,12 +281,9 @@ ONNX_OPERATOR_SET_SCHEMA( .Output(0, "output", "Output tensor of random values drawn from uniform distribution", "T2") .TypeConstraint( "T1", - OpSchema::all_tensor_types(), + OpSchema::all_tensor_types_ir10(), "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.") - .TypeConstraint( - "T2", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain output types to float tensors.") + .TypeConstraint("T2", OpSchema::all_float_types_ir10(), "Constrain output types to float tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { if (ctx.getAttribute("dtype") != nullptr) propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); @@ -326,7 +295,7 @@ ONNX_OPERATOR_SET_SCHEMA( propagateShapeFromInputToOutput(ctx, 0, 0); })); -static const char* RandomNormalLike_ver1_doc = R"DOC( +static const char* RandomNormalLike_ver22_doc = R"DOC( Generate a tensor with random values drawn from a normal distribution. The shape of the output tensor is copied from the shape of the input tensor, and the parameters of the normal distribution are specified by `mean` and `scale`. @@ -338,9 +307,9 @@ TensorProto message, and be valid as an output type. ONNX_OPERATOR_SET_SCHEMA( RandomNormalLike, - 1, + 22, OpSchema() - .SetDoc(RandomNormalLike_ver1_doc) + .SetDoc(RandomNormalLike_ver22_doc) .Attr("mean", "The mean of the normal distribution.", AttributeProto::FLOAT, 0.0f) .Attr("scale", "The standard deviation of the normal distribution.", AttributeProto::FLOAT, 1.0f) .Attr( @@ -358,12 +327,9 @@ ONNX_OPERATOR_SET_SCHEMA( .Output(0, "output", "Output tensor of random values drawn from normal distribution", "T2") .TypeConstraint( "T1", - OpSchema::all_tensor_types(), + OpSchema::all_tensor_types_ir10(), "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.") - .TypeConstraint( - "T2", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain output types to float tensors.") + .TypeConstraint("T2", OpSchema::all_float_types_ir10(), "Constrain output types to float tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { if (ctx.getAttribute("dtype") != nullptr) propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); @@ -375,16 +341,16 @@ ONNX_OPERATOR_SET_SCHEMA( propagateShapeFromInputToOutput(ctx, 0, 0); })); -static const char* Multinomial_ver7_doc = R"DOC( +static const char* Multinomial_ver22_doc = R"DOC( Generate a tensor of samples from a multinomial distribution according to the probabilities of each of the possible outcomes. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Multinomial, - 7, + 22, OpSchema() - .SetDoc(Multinomial_ver7_doc) + .SetDoc(Multinomial_ver22_doc) .Attr("sample_size", "Number of times to sample.", AttributeProto::INT, static_cast(1)) .Attr( "seed", @@ -406,10 +372,7 @@ ONNX_OPERATOR_SET_SCHEMA( "output", "Output tensor with shape [batch_size, sample_size], where sample_size is the number of times to sample. Each value along the axis zero represents the outcome of the corresponding sample in a batch.", "T2") - .TypeConstraint( - "T1", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input types to float tensors.") + .TypeConstraint("T1", OpSchema::all_float_types_ir10(), "Constrain input types to float tensors.") .TypeConstraint("T2", {"tensor(int32)", "tensor(int64)"}, "Constrain output types to integral tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { auto dtype = ctx.getAttribute("dtype"); @@ -562,7 +525,7 @@ ONNX_OPERATOR_SET_SCHEMA( } })); -static const char* Bernoulli_ver15_doc = R"DOC( +static const char* Bernoulli_ver22_doc = R"DOC( Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p). @@ -573,9 +536,9 @@ implementations (even if a seed is specified). ONNX_OPERATOR_SET_SCHEMA( Bernoulli, - 15, + 22, OpSchema() - .SetDoc(Bernoulli_ver15_doc) + .SetDoc(Bernoulli_ver22_doc) .Attr( "seed", "(Optional) Seed to the random generator, if not specified we will auto generate one.", @@ -589,25 +552,10 @@ ONNX_OPERATOR_SET_SCHEMA( OPTIONAL_VALUE) .Input(0, "input", "All values in input have to be in the range:[0, 1].", "T1") .Output(0, "output", "The returned output tensor only has values 0 or 1, same shape as input tensor.", "T2") - .TypeConstraint( - "T1", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input types to float tensors.") + .TypeConstraint("T1", OpSchema::all_float_types_ir10(), "Constrain input types to float tensors.") .TypeConstraint( "T2", - {"tensor(float16)", - "tensor(float)", - "tensor(double)", - "tensor(bfloat16)", - "tensor(uint8)", - "tensor(uint16)", - "tensor(uint32)", - "tensor(uint64)", - "tensor(int8)", - "tensor(int16)", - "tensor(int32)", - "tensor(int64)", - "tensor(bool)"}, + OpSchema::all_tensor_types_ir10(), "Constrain output types to all numeric tensors and bool tensors.") .TypeAndShapeInferenceFunction([](ONNX_NAMESPACE::InferenceContext& ctx) { if (ctx.getAttribute("dtype") != nullptr) diff --git a/onnx/defs/generator/old.cc b/onnx/defs/generator/old.cc index a0cf5b0a22c..88b7c6fc388 100644 --- a/onnx/defs/generator/old.cc +++ b/onnx/defs/generator/old.cc @@ -5,11 +5,400 @@ #include #include +#include "onnx/defs/function.h" #include "onnx/defs/generator/utils.h" #include "onnx/defs/schema.h" namespace ONNX_NAMESPACE { +static const char* Bernoulli_ver15_doc = R"DOC( +Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor +containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, +where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p). + +This operator is non-deterministic and may not produce the same values in different +implementations (even if a seed is specified). +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Bernoulli, + 15, + OpSchema() + .SetDoc(Bernoulli_ver15_doc) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "The data type for the elements of the output tensor. if not specified, we will use " + "the data type of the input tensor.", + AttributeProto::INT, + OPTIONAL_VALUE) + .Input(0, "input", "All values in input have to be in the range:[0, 1].", "T1") + .Output(0, "output", "The returned output tensor only has values 0 or 1, same shape as input tensor.", "T2") + .TypeConstraint( + "T1", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input types to float tensors.") + .TypeConstraint( + "T2", + {"tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(bool)"}, + "Constrain output types to all numeric tensors and bool tensors.") + .TypeAndShapeInferenceFunction([](ONNX_NAMESPACE::InferenceContext& ctx) { + if (ctx.getAttribute("dtype") != nullptr) + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); + else + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (!hasNInputShapes(ctx, 1)) { + return; + } + propagateShapeFromInputToOutput(ctx, 0, 0); + }) + .SetContextDependentFunctionBodyBuilder( + [](const FunctionBodyBuildContext& ctx, const OpSchema& schema, FunctionProto& functionProto) -> bool { + if (ctx.getInputType(0) == nullptr) { + // we cannot create a correct function body without knowing the input type + return false; + } + auto input_type = ctx.getInputType(0)->tensor_type().elem_type(); + auto dtype = ctx.getAttribute("dtype") != nullptr + ? static_cast(ctx.getAttribute("dtype")->i()) + : input_type; + FunctionBuilder builder(functionProto); + builder + .Add( + "X_random = RandomUniformLike (input)", + "dtype", + int64_t(input_type)) + .Add("X_greater = Greater (X_random, input)") + .Add("output = Cast (X_greater)", "to", int64_t(dtype)); + schema.BuildFunction(functionProto); + return true; + })); + +static const char* Multinomial_ver7_doc = R"DOC( +Generate a tensor of samples from a multinomial distribution according to the probabilities +of each of the possible outcomes. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Multinomial, + 7, + OpSchema() + .SetDoc(Multinomial_ver7_doc) + .Attr("sample_size", "Number of times to sample.", AttributeProto::INT, static_cast(1)) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "(Optional) The data type for the elements of the output tensor, if not specified, we will use int32.", + AttributeProto::INT, + static_cast(TensorProto::INT32)) + .Input( + 0, + "input", + "Input tensor with shape [batch_size, class_size], where class_size is the number of all possible outcomes. Each value along the axis zero represents the unnormalized log-probability of each corresponding outcome in a batch.", + "T1") + .Output( + 0, + "output", + "Output tensor with shape [batch_size, sample_size], where sample_size is the number of times to sample. Each value along the axis zero represents the outcome of the corresponding sample in a batch.", + "T2") + .TypeConstraint( + "T1", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input types to float tensors.") + .TypeConstraint("T2", {"tensor(int32)", "tensor(int64)"}, "Constrain output types to integral tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + auto dtype = ctx.getAttribute("dtype"); + auto dataType = TensorProto_DataType::TensorProto_DataType_INT32; + if (dtype != nullptr) { + dataType = static_cast(dtype->i()); + if (dataType != TensorProto_DataType::TensorProto_DataType_INT32 && + dataType != TensorProto_DataType::TensorProto_DataType_INT64) { + fail_type_inference("Output type must be int32 or int64"); + } + } + updateOutputElemType(ctx, 0, dataType); + + TensorShapeProto::Dimension batch_size, sample_size; + if (hasInputShape(ctx, 0)) { + auto& input_shape = getInputShape(ctx, 0); + if (input_shape.dim_size() != 2) { + fail_shape_inference("Input tensor must have rank 2"); + } + batch_size = input_shape.dim(0); + } // else statically-unknown batch-size + sample_size.set_dim_value(getAttribute(ctx, "sample_size", 1)); + updateOutputShape(ctx, 0, {batch_size, sample_size}); + })); + +static const char* RandomNormalLike_ver1_doc = R"DOC( +Generate a tensor with random values drawn from a normal distribution. +The shape of the output tensor is copied from the shape of the input tensor, +and the parameters of the normal distribution are specified by `mean` and `scale`. + +The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. +The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the +TensorProto message, and be valid as an output type. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RandomNormalLike, + 1, + OpSchema() + .SetDoc(RandomNormalLike_ver1_doc) + .Attr("mean", "The mean of the normal distribution.", AttributeProto::FLOAT, 0.0f) + .Attr("scale", "The standard deviation of the normal distribution.", AttributeProto::FLOAT, 1.0f) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "(Optional) The data type for the elements of the output tensor, if not specified, we will use " + "the data type of the input tensor.", + AttributeProto::INT, + OPTIONAL_VALUE) + .Input(0, "input", "Input tensor to copy shape and optionally type information from.", "T1") + .Output(0, "output", "Output tensor of random values drawn from normal distribution", "T2") + .TypeConstraint( + "T1", + OpSchema::all_tensor_types(), + "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.") + .TypeConstraint( + "T2", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + if (ctx.getAttribute("dtype") != nullptr) + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); + else + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (!hasNInputShapes(ctx, 1)) { + return; + } + propagateShapeFromInputToOutput(ctx, 0, 0); + })); + +static const char* RandomUniformLike_ver1_doc = R"DOC( +Generate a tensor with random values drawn from a uniform distribution. +The shape of the output tensor is copied from the shape of the input tensor, +and the parameters of the uniform distribution are specified by `low` and `high`. + +The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. +The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the +TensorProto message and be valid as an output type. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RandomUniformLike, + 1, + OpSchema() + .SetDoc(RandomUniformLike_ver1_doc) + .Attr("low", "Lower boundary of the output values.", AttributeProto::FLOAT, 0.0f) + .Attr("high", "Upper boundary of the output values.", AttributeProto::FLOAT, 1.0f) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "(Optional) The data type for the elements of the output tensor, if not specified, we will use " + "the data type of the input tensor.", + AttributeProto::INT, + OPTIONAL_VALUE) + .Input(0, "input", "Input tensor to copy shape and optionally type information from.", "T1") + .Output(0, "output", "Output tensor of random values drawn from uniform distribution", "T2") + .TypeConstraint( + "T1", + OpSchema::all_tensor_types(), + "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.") + .TypeConstraint( + "T2", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + if (ctx.getAttribute("dtype") != nullptr) + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); + else + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (!hasNInputShapes(ctx, 1)) { + return; + } + propagateShapeFromInputToOutput(ctx, 0, 0); + })); + +static const char* RandomNormal_ver1_doc = R"DOC( +Generate a tensor with random values drawn from a normal distribution. The shape +of the tensor is specified by the `shape` argument and the parameter of the normal distribution +specified by `mean` and `scale`. + +The data type is specified by the 'dtype' argument. The 'dtype' argument must +be one of the data types specified in the 'DataType' enum field in the +TensorProto message. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RandomNormal, + 1, + OpSchema() + .SetDoc(RandomNormal_ver1_doc) + .Attr("mean", "The mean of the normal distribution.", AttributeProto::FLOAT, 0.0f) + .Attr("scale", "The standard deviation of the normal distribution.", AttributeProto::FLOAT, 1.0f) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "The data type for the elements of the output tensor. Default is TensorProto::FLOAT.", + AttributeProto::INT, + static_cast(TensorProto::FLOAT)) + .Attr("shape", "The shape of the output tensor.", AttributeProto::INTS) + .Output(0, "output", "Output tensor of random values drawn from normal distribution", "T") + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0, TensorProto::FLOAT); + propagateShapeFromAttributeToOutput(ctx, "shape", 0); + })); + +static const char* RandomUniform_ver1_doc = R"DOC( +Generate a tensor with random values drawn from a uniform distribution. The shape +of the tensor is specified by the `shape` argument and the range by `low` and `high`. + +The data type is specified by the 'dtype' argument. The 'dtype' argument must +be one of the data types specified in the 'DataType' enum field in the +TensorProto message. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RandomUniform, + 1, + OpSchema() + .SetDoc(RandomUniform_ver1_doc) + .Attr("low", "Lower boundary of the output values.", AttributeProto::FLOAT, 0.0f) + .Attr("high", "Upper boundary of the output values.", AttributeProto::FLOAT, 1.0f) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::FLOAT, + OPTIONAL_VALUE) + .Attr( + "dtype", + "The data type for the elements of the output tensor. If not specified, default is TensorProto::FLOAT.", + AttributeProto::INT, + static_cast(TensorProto::FLOAT)) + .Attr("shape", "The shape of the output tensor.", AttributeProto::INTS) + .Output(0, "output", "Output tensor of random values drawn from uniform distribution", "T") + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0, TensorProto::FLOAT); + propagateShapeFromAttributeToOutput(ctx, "shape", 0); + })); + +static const char* EyeLike_ver9_doc = R"DOC( +Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D +tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the +same as the input tensor. The data type can be specified by the 'dtype' argument. If +'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal +is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. +The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the +TensorProto message and be valid as an output type. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + EyeLike, + 9, + OpSchema() + .SetDoc(EyeLike_ver9_doc) + .Attr( + "k", + "(Optional) Index of the diagonal to be populated with ones. Default is 0." + " If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the main diagonal, " + "k > 0 populates an upper diagonal, and k < 0 populates a lower diagonal.", + AttributeProto::INT, + static_cast(0)) + .Attr( + "dtype", + "(Optional) The data type for the elements of the output tensor. If not specified," + "the data type of the input tensor T1 is used. If input tensor T1 is also not" + "specified, then type defaults to 'float'.", + AttributeProto::INT, + OPTIONAL_VALUE) + .Input(0, "input", "2D input tensor to copy shape, and optionally, type information from.", "T1") + .Output(0, "output", "Output tensor, same shape as input tensor T1.", "T2") + .TypeConstraint( + "T1", + {"tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)"}, + "Constrain input types. Strings and complex are not supported.") + .TypeConstraint( + "T2", + {"tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)"}, + "Constrain output types. Strings and complex are not supported.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + if (ctx.getAttribute("dtype") != nullptr) { + propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0); + } else { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + } + if (hasInputShape(ctx, 0)) { + auto& input_shape = getInputShape(ctx, 0); + if (input_shape.dim_size() != 2) { + fail_shape_inference("Input tensor must be 2-dimensional"); + } + } + propagateShapeFromInputToOutput(ctx, 0, 0); + })); + static const char* Constant_ver19_doc = R"DOC( This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value, or value_* must be specified. diff --git a/onnx/defs/math/defs.cc b/onnx/defs/math/defs.cc index b7dfe3c86ff..9a69603bedd 100644 --- a/onnx/defs/math/defs.cc +++ b/onnx/defs/math/defs.cc @@ -341,7 +341,7 @@ ONNX_OPERATOR_SET_SCHEMA( } )ONNX")); -static const char* ThresholdedRelu_ver10_doc = R"DOC( +static const char* ThresholdedRelu_ver22_doc = R"DOC( ThresholdedRelu takes one input data (Tensor) and produces one output data (Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, is applied to the tensor elementwise. @@ -349,16 +349,13 @@ is applied to the tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( ThresholdedRelu, - 10, + 22, OpSchema() - .SetDoc(ThresholdedRelu_ver10_doc) + .SetDoc(ThresholdedRelu_ver22_doc) .Attr("alpha", "Threshold value", AttributeProto::FLOAT, 1.0f) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -373,7 +370,7 @@ ONNX_OPERATOR_SET_SCHEMA( )ONNX", 18)); -static const char* Selu_ver6_doc = R"DOC( +static const char* Selu_ver22_doc = R"DOC( Selu takes one input data (Tensor) and produces one output data (Tensor) where the scaled exponential linear unit function, `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, @@ -382,7 +379,7 @@ is applied to the tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( Selu, - 6, + 22, OpSchema() .Attr( "alpha", @@ -396,13 +393,10 @@ ONNX_OPERATOR_SET_SCHEMA( "(i.e., float32 approximation of 1.0507009873554804934193349852946).", AttributeProto::FLOAT, 1.05070102214813232421875f) - .SetDoc(Selu_ver6_doc) + .SetDoc(Selu_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -424,7 +418,7 @@ ONNX_OPERATOR_SET_SCHEMA( )ONNX", 18)); -static const char* Elu_ver6_doc = R"DOC( +static const char* Elu_ver22_doc = R"DOC( Elu takes one input data (Tensor) and produces one output data (Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. @@ -433,16 +427,13 @@ Elu takes one input data (Tensor) and produces one output data ONNX_OPERATOR_SET_SCHEMA( Elu, - 6, + 22, OpSchema() .Attr("alpha", "Coefficient of ELU.", AttributeProto::FLOAT, 1.0f) - .SetDoc(Elu_ver6_doc) + .SetDoc(Elu_ver22_doc) .Input(0, "X", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "1D output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -462,7 +453,7 @@ ONNX_OPERATOR_SET_SCHEMA( )ONNX", 18)); -static const char* mish_ver18_doc = R"DOC( +static const char* mish_ver22_doc = R"DOC( Mish: A Self Regularized Non-Monotonic Neural Activation Function. Perform the linear unit element-wise on the input tensor X using formula: @@ -474,15 +465,12 @@ mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) ONNX_OPERATOR_SET_SCHEMA( Mish, - 18, + 22, OpSchema() - .SetDoc(mish_ver18_doc) + .SetDoc(mish_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input X and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input X and output types to float tensors.") .FunctionBody(R"ONNX( { Softplus_X = Softplus (X) @@ -842,7 +830,7 @@ ONNX_OPERATOR_SET_SCHEMA( "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* HardSigmoid_ver6_doc = R"DOC( +static const char* HardSigmoid_ver22_doc = R"DOC( HardSigmoid takes one input data (Tensor) and produces one output data (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), is applied to the tensor elementwise. @@ -850,17 +838,14 @@ is applied to the tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( HardSigmoid, - 6, + 22, OpSchema() .Attr("alpha", "Value of alpha.", AttributeProto::FLOAT, 0.2f) .Attr("beta", "Value of beta.", AttributeProto::FLOAT, 0.5f) - .SetDoc(HardSigmoid_ver6_doc) + .SetDoc(HardSigmoid_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -881,7 +866,7 @@ ONNX_OPERATOR_SET_SCHEMA( )ONNX", 18)); -static const char* HardSwish_ver14_doc = R"DOC( +static const char* HardSwish_ver22_doc = R"DOC( HardSwish takes one input data (Tensor) and produces one output data (Tensor) where the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x), where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. @@ -889,15 +874,12 @@ where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( HardSwish, - 14, + 22, OpSchema() - .SetDoc(HardSwish_ver14_doc) + .SetDoc(HardSwish_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody(R"ONNX( { @@ -1232,15 +1214,15 @@ ONNX_OPERATOR_SET_SCHEMA( "hardmax", "Hardmax(element in input, axis) = 1 if the element is the first maximum value along the specified axis, 0 otherwise"))); -static const char* Softsign_ver1_doc = R"DOC( +static const char* Softsign_ver22_doc = R"DOC( Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Softsign, - 1, + 22, OpSchema() - .SetDoc(Softsign_ver1_doc) + .SetDoc(Softsign_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1251,10 +1233,7 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -1268,7 +1247,7 @@ ONNX_OPERATOR_SET_SCHEMA( )ONNX", 18)); -static const char* Softplus_ver1_doc = R"DOC( +static const char* Softplus_ver22_doc = R"DOC( Softplus takes one input data (Tensor) and produces one output data (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to the tensor elementwise. @@ -1276,15 +1255,12 @@ the tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( Softplus, - 1, + 22, OpSchema() - .SetDoc(Softplus_ver1_doc) + .SetDoc(Softplus_ver22_doc) .Input(0, "X", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) .FunctionBody( R"ONNX( @@ -1549,15 +1525,15 @@ ONNX_OPERATOR_SET_SCHEMA( return; })); -static const char* Sin_ver7_doc = R"DOC( +static const char* Sin_ver22_doc = R"DOC( Calculates the sine of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Sin, - 7, + 22, OpSchema() - .SetDoc(Sin_ver7_doc) + .SetDoc(Sin_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1569,21 +1545,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Cos_ver7_doc = R"DOC( +static const char* Cos_ver22_doc = R"DOC( Calculates the cosine of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Cos, - 7, + 22, OpSchema() - .SetDoc(Cos_ver7_doc) + .SetDoc(Cos_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1595,21 +1568,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Tan_ver7_doc = R"DOC( +static const char* Tan_ver22_doc = R"DOC( Calculates the tangent of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Tan, - 7, + 22, OpSchema() - .SetDoc(Tan_ver7_doc) + .SetDoc(Tan_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1621,21 +1591,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Asin_ver7_doc = R"DOC( +static const char* Asin_ver22_doc = R"DOC( Calculates the arcsine (inverse of sine) of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Asin, - 7, + 22, OpSchema() - .SetDoc(Asin_ver7_doc) + .SetDoc(Asin_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1647,21 +1614,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Acos_ver7_doc = R"DOC( +static const char* Acos_ver22_doc = R"DOC( Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Acos, - 7, + 22, OpSchema() - .SetDoc(Acos_ver7_doc) + .SetDoc(Acos_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1673,21 +1637,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Atan_ver7_doc = R"DOC( +static const char* Atan_ver22_doc = R"DOC( Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Atan, - 7, + 22, OpSchema() - .SetDoc(Atan_ver7_doc) + .SetDoc(Atan_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1699,10 +1660,7 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); static const char* Expand_ver13_doc = R"DOC( @@ -1749,15 +1707,15 @@ ONNX_OPERATOR_SET_SCHEMA( } })); -static const char* Sinh_ver9_doc = R"DOC( +static const char* Sinh_ver22_doc = R"DOC( Calculates the hyperbolic sine of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Sinh, - 9, + 22, OpSchema() - .SetDoc(Sinh_ver9_doc) + .SetDoc(Sinh_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1769,21 +1727,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Cosh_ver9_doc = R"DOC( +static const char* Cosh_ver22_doc = R"DOC( Calculates the hyperbolic cosine of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Cosh, - 9, + 22, OpSchema() - .SetDoc(Cosh_ver9_doc) + .SetDoc(Cosh_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1795,21 +1750,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Asinh_ver9_doc = R"DOC( +static const char* Asinh_ver22_doc = R"DOC( Calculates the hyperbolic arcsine of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Asinh, - 9, + 22, OpSchema() - .SetDoc(Asinh_ver9_doc) + .SetDoc(Asinh_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1821,21 +1773,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Acosh_ver9_doc = R"DOC( +static const char* Acosh_ver22_doc = R"DOC( Calculates the hyperbolic arccosine of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Acosh, - 9, + 22, OpSchema() - .SetDoc(Acosh_ver9_doc) + .SetDoc(Acosh_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1847,21 +1796,18 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Atanh_ver9_doc = R"DOC( +static const char* Atanh_ver22_doc = R"DOC( Calculates the hyperbolic arctangent of the given input tensor element-wise. )DOC"; ONNX_OPERATOR_SET_SCHEMA( Atanh, - 9, + 22, OpSchema() - .SetDoc(Atanh_ver9_doc) + .SetDoc(Atanh_ver22_doc) .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output( 0, @@ -1873,10 +1819,7 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); static const char* Sign_ver13_doc = R"DOC( @@ -2154,7 +2097,7 @@ ONNX_OPERATOR_SET_SCHEMA( .TypeConstraint("T2", {"tensor(int32)", "tensor(int64)"}, "axis tensor can be int32 or int64 only") .TypeAndShapeInferenceFunction(ONNX_NAMESPACE::propagateShapeAndTypeFromFirstInput)); -static const char* Round_ver11_doc = R"DOC( +static const char* Round_ver22_doc = R"DOC( Round takes one input Tensor and rounds the values, element-wise, meaning it finds the nearest integer for each value. In case of halves, the rule is to round them to the nearest even integer. @@ -2173,18 +2116,15 @@ round([-4.5]) = [-4.0] ONNX_OPERATOR_SET_SCHEMA( Round, - 11, + 22, OpSchema() - .SetDoc(Round_ver11_doc) + .SetDoc(Round_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::NonDifferentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::NonDifferentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Det_ver11_doc = R"DOC( +static const char* Det_ver22_doc = R"DOC( Det calculates determinant of a square matrix or batches of square matrices. Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions, and the inner-most 2 dimensions form square matrices. @@ -2194,14 +2134,14 @@ e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`). ONNX_OPERATOR_SET_SCHEMA( Det, - 11, + 22, OpSchema() - .SetDoc(Det_ver11_doc) + .SetDoc(Det_ver22_doc) .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .TypeConstraint( "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, + OpSchema::all_float_types_ir10(), "Constrain input and output types to floating-point tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { // Type inference @@ -2235,110 +2175,6 @@ ONNX_OPERATOR_SET_SCHEMA( } })); -static const char* NegativeLogLikelihoodLoss_ver13_doc = R"DOC( -A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. -Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. -The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). -The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) -or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. -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: - -``` -loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. -``` - -When an optional "weight" is provided, the sample loss is calculated as: - -``` -loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. -``` - -loss is zero for the case when target-value equals ignore_index. - -``` -loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index -``` - -If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). -If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: - -``` -mean(loss), if "weight" is not provided, -``` - -or if weight is provided, - -``` -sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. -``` - -If "reduction" attribute is set to "sum", the output is a scalar: `sum(loss)`. - -See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. - -Example 1: - -``` -// negative log likelihood loss, "none" reduction -N, C, d1 = 2, 3, 2 -input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] -target = [[2, 1], [0, 2]] - -loss = np.zeros((N, d1)) -for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] - -// print(loss) -// [[-3. -2.] -// [-0. -2.]] -``` - -Example 2: - -``` -// weighted negative log likelihood loss, sum reduction -N, C, d1 = 2, 3, 2 -input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] -target = [[2, 1], [0, 2]] -weight = [0.2, 0.3, 0.1] -loss = np.zeros((N, d1)) -for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - -loss = np.sum(loss) -// print(loss) -// -1.1 -``` - -Example 3: - -``` -// weighted negative log likelihood loss, mean reduction -N, C, d1 = 2, 3, 2 -input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] -target = [[2, 1], [0, 2]] -weight = [0.2, 0.3, 0.1] -loss = np.zeros((N, d1)) -weight_total = 0 -for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - weight_total = weight_total + weight[c] - -loss = np.sum(loss) / weight_total -// print(loss) -// -1.57 -``` -)DOC"; - bool BuildContextDependentFunctionBody( const FunctionBodyBuildContext& ctx, const OpSchema& schema, @@ -2451,11 +2287,115 @@ bool BuildContextDependentFunctionBody( return true; } +static const char* NegativeLogLikelihoodLoss_ver22_doc = R"DOC( +A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. +Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. +The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). +The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) +or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. +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: + +``` +loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. +``` + +When an optional "weight" is provided, the sample loss is calculated as: + +``` +loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. +``` + +loss is zero for the case when target-value equals ignore_index. + +``` +loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index +``` + +If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). +If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + +``` +mean(loss), if "weight" is not provided, +``` + +or if weight is provided, + +``` +sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. +``` + +If "reduction" attribute is set to "sum", the output is a scalar: `sum(loss)`. + +See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + +Example 1: + +``` +// negative log likelihood loss, "none" reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] + +loss = np.zeros((N, d1)) +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + +// print(loss) +// [[-3. -2.] +// [-0. -2.]] +``` + +Example 2: + +``` +// weighted negative log likelihood loss, sum reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] +weight = [0.2, 0.3, 0.1] +loss = np.zeros((N, d1)) +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + +loss = np.sum(loss) +// print(loss) +// -1.1 +``` + +Example 3: + +``` +// weighted negative log likelihood loss, mean reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] +weight = [0.2, 0.3, 0.1] +loss = np.zeros((N, d1)) +weight_total = 0 +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + +loss = np.sum(loss) / weight_total +// print(loss) +// -1.57 +``` +)DOC"; + ONNX_OPERATOR_SET_SCHEMA( NegativeLogLikelihoodLoss, - 13, + 22, OpSchema() - .SetDoc(NegativeLogLikelihoodLoss_ver13_doc) + .SetDoc(NegativeLogLikelihoodLoss_ver22_doc) .Input( 0, "input", @@ -2502,7 +2442,7 @@ ONNX_OPERATOR_SET_SCHEMA( false) .TypeConstraint( "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, + OpSchema::all_float_types_ir10(), "Constrain input, weight, and output types to floating-point tensors.") .TypeConstraint("Tind", {"tensor(int32)", "tensor(int64)"}, "Constrain target to integer types") .SetContextDependentFunctionBodyBuilder(BuildContextDependentFunctionBody) diff --git a/onnx/defs/math/old.cc b/onnx/defs/math/old.cc index 00048188888..9489db92cbc 100644 --- a/onnx/defs/math/old.cc +++ b/onnx/defs/math/old.cc @@ -11,6 +11,978 @@ namespace ONNX_NAMESPACE { +bool BuildContextDependentFunctionBody_opset13( + const FunctionBodyBuildContext& ctx, + const OpSchema& schema, + FunctionProto& functionProto) { + if (ctx.getInputType(0) == nullptr) { + // we cannot create a correct function body without knowing the input type + return false; + } + auto input_type = ctx.getInputType(0)->tensor_type().elem_type(); + bool float_input = input_type == TensorProto_DataType_FLOAT; + auto reduction_attr_proto = ctx.getAttribute("reduction"); + std::string reduction_attr = + reduction_attr_proto != nullptr && reduction_attr_proto->has_s() ? reduction_attr_proto->s() : "mean"; + + FunctionBuilder builder(functionProto); + builder.Const1D("const_zero", int64_t(0)) + .Const1D("const_one", int64_t(1)) + .Const1D("axes", int64_t(1)) + .Add("expanded_target = Unsqueeze (target, axes)"); + + if (ctx.getAttribute("ignore_index") == nullptr) { + builder.Add(R"( + input_gather_element = GatherElements (input, expanded_target) + loss_NCdd = Neg (input_gather_element) + loss_N1dd = Slice (loss_NCdd, const_zero, const_one, const_one) + )"); + + if (!ctx.hasInput(2)) { + if (reduction_attr == "none") { + builder.Add("loss = Squeeze (loss_N1dd, axes)"); + } else { + builder.Add("loss_Ndd = Squeeze (loss_N1dd, axes)"); + if (reduction_attr == "mean") { + builder.Add("loss = ReduceMean (loss_Ndd)"); + } else { + builder.Add("loss = ReduceSum (loss_Ndd)"); + } + } + } else { + builder.Add("weight_gather = Gather (weight, target)"); + builder.Add("loss_unweighted = Squeeze (loss_N1dd, axes)"); + if (reduction_attr == "none") { + builder.Add("loss = Mul (loss_unweighted, weight_gather)"); + } else { + builder.Add("loss_Ndd = Mul (loss_unweighted, weight_gather)"); + if (reduction_attr == "mean") { + builder.Add(R"( + loss_sum = ReduceSum (loss_Ndd) + weight_gather_sum = ReduceSum (weight_gather) + loss = Div (loss_sum, weight_gather_sum) + )"); + } else { + builder.Add("loss = ReduceSum (loss_Ndd)"); + } + } + } + } else { + builder.Const1D("const_ignore_index", ctx.getAttribute("ignore_index")->i()); + builder.Add(R"( + const_zero_target_typed = Sub (expanded_target, expanded_target) + expanded_target_int64 = Cast (expanded_target) + mask = Equal (expanded_target_int64, const_ignore_index) + transform_targets = Where (mask, const_zero_target_typed, expanded_target) + )"); + builder.Add("input_gather_element = GatherElements (input, transform_targets)"); + builder.Const1D("const_zero_float", 0.0f); + if (!float_input) { + builder.Add("const_zero_casted = Cast (const_zero_float)", "to", static_cast(input_type)) + .Add("input_gather_element_transform = Where (mask, const_zero_casted, input_gather_element)"); + } else + builder.Add("input_gather_element_transform = Where (mask, const_zero_float, input_gather_element)"); + builder.Add("loss_NCdd = Neg (input_gather_element_transform)"); + builder.Add("loss_N1dd = Slice (loss_NCdd, const_zero, const_one, const_one)"); + + if (!ctx.hasInput(2)) { + builder.Add("squeeze_mask = Squeeze (mask, axes)"); + builder.Const1D("const_one_float", 1.0f); + if (!float_input) { + builder.Add("const_one_casted = Cast (const_one_float)", "to", static_cast(input_type)) + .Add("weight_gather = Where (squeeze_mask, const_zero_casted, const_one_casted)"); + } else + builder.Add("weight_gather = Where (squeeze_mask, const_zero_float, const_one_float)"); + + } else { + builder.Add("weight_gather_temp = Gather (weight, transform_targets)"); + builder.Add( + float_input ? "weight_gather_temp_1 = Where (mask, const_zero_float, weight_gather_temp)" + : "weight_gather_temp_1 = Where (mask, const_zero_casted, weight_gather_temp)"); + builder.Add("weight_gather = Squeeze (weight_gather_temp_1, axes)"); + } + + builder.Add("loss_unweighted = Squeeze (loss_N1dd, axes)"); + if (reduction_attr == "none") { + builder.Add("loss = Mul (loss_unweighted, weight_gather)"); + } else { + builder.Add("loss_Ndd = Mul (loss_unweighted, weight_gather)"); + if (reduction_attr == "mean") { + builder.Add(R"( + loss_sum = ReduceSum (loss_Ndd) + weight_gather_sum = ReduceSum (weight_gather) + loss = Div (loss_sum, weight_gather_sum) + )"); + } else { + builder.Add("loss = ReduceSum (loss_Ndd)"); + } + } + } + + schema.BuildFunction(functionProto); + return true; +} + +static const char* NegativeLogLikelihoodLoss_ver13_doc = R"DOC( +A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. +Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. +The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). +The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) +or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. +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: + +``` +loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. +``` + +When an optional "weight" is provided, the sample loss is calculated as: + +``` +loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. +``` + +loss is zero for the case when target-value equals ignore_index. + +``` +loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index +``` + +If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). +If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + +``` +mean(loss), if "weight" is not provided, +``` + +or if weight is provided, + +``` +sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. +``` + +If "reduction" attribute is set to "sum", the output is a scalar: `sum(loss)`. + +See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + +Example 1: + +``` +// negative log likelihood loss, "none" reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] + +loss = np.zeros((N, d1)) +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + +// print(loss) +// [[-3. -2.] +// [-0. -2.]] +``` + +Example 2: + +``` +// weighted negative log likelihood loss, sum reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] +weight = [0.2, 0.3, 0.1] +loss = np.zeros((N, d1)) +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + +loss = np.sum(loss) +// print(loss) +// -1.1 +``` + +Example 3: + +``` +// weighted negative log likelihood loss, mean reduction +N, C, d1 = 2, 3, 2 +input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] +target = [[2, 1], [0, 2]] +weight = [0.2, 0.3, 0.1] +loss = np.zeros((N, d1)) +weight_total = 0 +for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + +loss = np.sum(loss) / weight_total +// print(loss) +// -1.57 +``` +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + NegativeLogLikelihoodLoss, + 13, + OpSchema() + .SetDoc(NegativeLogLikelihoodLoss_ver13_doc) + .Input( + 0, + "input", + "Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk).", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 1, + "target", + "Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value shall be in range of [0, C). " + "If ignore_index is specified, it may have a value outside [0, C) and the target values should either be " + "in the range [0, C) or have the value ignore_index.", + "Tind", + OpSchema::Single, + true, + 1, + OpSchema::NonDifferentiable) + .Input( + 2, + "weight", + "Optional rescaling weight tensor. " + "If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Output(0, "loss", "The negative log likelihood loss", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Attr( + "reduction", + "Type of reduction to apply to loss: none, sum, mean (default). " + "'none': the output is the loss for each sample. " + "'sum': the output will be summed. " + "'mean': the sum of the output will be divided by the sum of applied weights.", + AttributeProto::STRING, + std::string("mean")) + .Attr( + "ignore_index", + "Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.", + AttributeProto::INT, + false) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input, weight, and output types to floating-point tensors.") + .TypeConstraint("Tind", {"tensor(int32)", "tensor(int64)"}, "Constrain target to integer types") + .SetContextDependentFunctionBodyBuilder(BuildContextDependentFunctionBody_opset13) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + // Type inference + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + // Shape inference + if (hasNInputShapes(ctx, 2)) { + const TensorShapeProto& input_shape = ctx.getInputType(0)->tensor_type().shape(); + const TensorShapeProto& target_shape = ctx.getInputType(1)->tensor_type().shape(); + + const int input_rank = static_cast(input_shape.dim_size()); + const int target_rank = static_cast(target_shape.dim_size()); + + if (input_rank < 2) { + fail_shape_inference("Input rank must be >= 2.") + } + if (target_rank != input_rank - 1) { + fail_shape_inference("Target rank must be 1 less than the input rank."); + } + + // match input dimensions (N, C, d1, ..., dk) with target + // dimensions of (C, d1, ..., dk) + for (int dim = 0; dim < target_rank; dim++) { + const auto input_dim = dim == 0 ? input_shape.dim(dim) : input_shape.dim(dim + 1); + const auto target_dim = target_shape.dim(dim); + if (input_dim.has_dim_value() && target_dim.has_dim_value() && + input_dim.dim_value() != target_dim.dim_value()) + fail_shape_inference("Input and target dimension value mismatch."); + } + + if (ctx.getNumInputs() == 3 && hasInputShape(ctx, 2)) { + const TensorShapeProto& weight_shape = ctx.getInputType(2)->tensor_type().shape(); + if (weight_shape.dim_size() != 1) { + fail_shape_inference("Weight rank must be 1."); + } + } + + TensorShapeProto* output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + + if (getAttribute(ctx, "reduction", "mean") == "none") { + // output tensor is of shape (N, d1, d2, ..., dk) if + // reduction attribute is "none". + for (int i = 0; i < input_rank - 1; i++) { + auto* dim = output_shape->add_dim(); + if (i == 0) + *dim = input_shape.dim(i); + else + *dim = input_shape.dim(i + 1); + } + } + // otherwise output is a scalar. + } + })); + +static const char* Det_ver11_doc = R"DOC( +Det calculates determinant of a square matrix or batches of square matrices. +Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions, +and the inner-most 2 dimensions form square matrices. +The output is a tensor of shape `[*]`, containing the determinants of all input submatrices. +e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`). +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Det, + 11, + OpSchema() + .SetDoc(Det_ver11_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to floating-point tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + // Type inference + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + // Shape inference + if (hasInputShape(ctx, 0)) { + const TensorShapeProto& input_shape = ctx.getInputType(0)->tensor_type().shape(); + TensorShapeProto* output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + const int rank = static_cast(input_shape.dim_size()); + + if (rank < 2) { + fail_shape_inference("Input rank must be >= 2."); + } + + const auto mat_w = input_shape.dim(rank - 1); + const auto mat_h = input_shape.dim(rank - 2); + if (mat_w.has_dim_value() && mat_h.has_dim_value() && (mat_w.dim_value() != mat_h.dim_value())) { + fail_shape_inference( + "The inner-most 2 dimensions must have the same size (mat_w:", + mat_w.dim_value(), + " != mat_h:", + mat_h.dim_value(), + ")."); + } + + for (int i = 0; i < rank - 2; ++i) { + auto* dim = output_shape->add_dim(); + *dim = input_shape.dim(i); + } + } + })); + +static const char* Round_ver11_doc = R"DOC( +Round takes one input Tensor and rounds the values, element-wise, meaning +it finds the nearest integer for each value. +In case of halves, the rule is to round them to the nearest even integer. +If input x is integral, +0, -0, NaN, or infinite, x itself is returned. +The output tensor has the same shape and type as the input. + +Examples: +``` +round([0.9]) = [1.0] +round([2.5]) = [2.0] +round([2.3]) = [2.0] +round([1.5]) = [2.0] +round([-4.5]) = [-4.0] +``` +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Round, + 11, + OpSchema() + .SetDoc(Round_ver11_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::NonDifferentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::NonDifferentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Atanh_ver9_doc = R"DOC( +Calculates the hyperbolic arctangent of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Atanh, + 9, + OpSchema() + .SetDoc(Atanh_ver9_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The hyperbolic arctangent values of the input tensor " + "computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Acosh_ver9_doc = R"DOC( +Calculates the hyperbolic arccosine of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Acosh, + 9, + OpSchema() + .SetDoc(Acosh_ver9_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The hyperbolic arccosine values of the input tensor " + "computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Asinh_ver9_doc = R"DOC( +Calculates the hyperbolic arcsine of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Asinh, + 9, + OpSchema() + .SetDoc(Asinh_ver9_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The hyperbolic arcsine values of the input tensor " + "computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Cosh_ver9_doc = R"DOC( +Calculates the hyperbolic cosine of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Cosh, + 9, + OpSchema() + .SetDoc(Cosh_ver9_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The hyperbolic cosine values of the input tensor " + "computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Sinh_ver9_doc = R"DOC( +Calculates the hyperbolic sine of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Sinh, + 9, + OpSchema() + .SetDoc(Sinh_ver9_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The hyperbolic sine values of the input tensor " + "computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Atan_ver7_doc = R"DOC( +Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Atan, + 7, + OpSchema() + .SetDoc(Atan_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The arctangent of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Acos_ver7_doc = R"DOC( +Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Acos, + 7, + OpSchema() + .SetDoc(Acos_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The arccosine of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Asin_ver7_doc = R"DOC( +Calculates the arcsine (inverse of sine) of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Asin, + 7, + OpSchema() + .SetDoc(Asin_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The arcsine of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Tan_ver7_doc = R"DOC( +Calculates the tangent of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Tan, + 7, + OpSchema() + .SetDoc(Tan_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The tangent of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Cos_ver7_doc = R"DOC( +Calculates the cosine of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Cos, + 7, + OpSchema() + .SetDoc(Cos_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The cosine of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Sin_ver7_doc = R"DOC( +Calculates the sine of the given input tensor, element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Sin, + 7, + OpSchema() + .SetDoc(Sin_ver7_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The sine of the input tensor computed " + "element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Softplus_ver1_doc = R"DOC( +Softplus takes one input data (Tensor) and produces one output data +(Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to +the tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Softplus, + 1, + OpSchema() + .SetDoc(Softplus_ver1_doc) + .Input(0, "X", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + exp_x = Exp (X) + one = Constant () + one_cast = CastLike (one, X) + exp_x_add_one = Add (exp_x, one_cast) + Y = Log (exp_x_add_one) + } + )ONNX", + 18)); + +static const char* Softsign_ver1_doc = R"DOC( +Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Softsign, + 1, + OpSchema() + .SetDoc(Softsign_ver1_doc) + .Input(0, "input", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output( + 0, + "output", + "The softsign (x/(1+|x|)) values of the input tensor computed element-wise", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + One = Constant () + OneCast = CastLike (One, input) + AbsInput = Abs(input) + OneAddAbsInput = Add (OneCast, AbsInput) + output = Div(input, OneAddAbsInput) + } + )ONNX", + 18)); + +static const char* HardSwish_ver14_doc = R"DOC( +HardSwish takes one input data (Tensor) and produces one output data (Tensor) where +the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x), +where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + HardSwish, + 14, + OpSchema() + .SetDoc(HardSwish_ver14_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody(R"ONNX( + { + HS_X = HardSigmoid(X) + Y = Mul (X, HS_X) + } + )ONNX")); + +static const char* HardSigmoid_ver6_doc = R"DOC( +HardSigmoid takes one input data (Tensor) and produces one output data +(Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), +is applied to the tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + HardSigmoid, + 6, + OpSchema() + .Attr("alpha", "Value of alpha.", AttributeProto::FLOAT, 0.2f) + .Attr("beta", "Value of beta.", AttributeProto::FLOAT, 0.5f) + .SetDoc(HardSigmoid_ver6_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + Alpha = Constant () + AlphaCast = CastLike (Alpha, X) + Beta = Constant () + BetaCast = CastLike (Beta, X) + Zero = Constant () + ZeroCast = CastLike (Zero, X) + One = Constant () + OneCast = CastLike (One, X) + AlphaMulX = Mul (X, AlphaCast) + AlphaMulXAddBeta = Add (AlphaMulX, BetaCast) + MinOneOrAlphaMulXAddBeta = Min (AlphaMulXAddBeta, OneCast) + Y = Max(MinOneOrAlphaMulXAddBeta, ZeroCast) + } + )ONNX", + 18)); + +static const char* mish_ver18_doc = R"DOC( +Mish: A Self Regularized Non-Monotonic Neural Activation Function. + +Perform the linear unit element-wise on the input tensor X using formula: + +``` +mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) +``` +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Mish, + 18, + OpSchema() + .SetDoc(mish_ver18_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input X and output types to float tensors.") + .FunctionBody(R"ONNX( + { + Softplus_X = Softplus (X) + TanHSoftplusX = Tanh (Softplus_X) + Y = Mul (X, TanHSoftplusX) + } + )ONNX") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); + +static const char* Elu_ver6_doc = R"DOC( +Elu takes one input data (Tensor) and produces one output data +(Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < +0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. + +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Elu, + 6, + OpSchema() + .Attr("alpha", "Coefficient of ELU.", AttributeProto::FLOAT, 1.0f) + .SetDoc(Elu_ver6_doc) + .Input(0, "X", "1D input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "1D output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + Alpha = Constant () + AlphaCast = CastLike (Alpha, X) + Zero = Constant () + ZeroCast = CastLike (Zero, X) + One = Constant () + OneCast = CastLike (One, X) + XLessThanZero = Less (X, ZeroCast) + ExpX = Exp (X) + ExpXSubOne = Sub (ExpX, OneCast) + AlphaMulExpXSubOne = Mul (AlphaCast, ExpXSubOne) + Y = Where(XLessThanZero, AlphaMulExpXSubOne, X) + } + )ONNX", + 18)); + +static const char* Selu_ver6_doc = R"DOC( +Selu takes one input data (Tensor) and produces one output data +(Tensor) where the scaled exponential linear unit function, +`y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, +is applied to the tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Selu, + 6, + OpSchema() + .Attr( + "alpha", + "Coefficient of SELU default to 1.67326319217681884765625 " + "(i.e., float32 approximation of 1.6732632423543772848170429916717).", + AttributeProto::FLOAT, + 1.67326319217681884765625f) + .Attr( + "gamma", + "Coefficient of SELU default to 1.05070102214813232421875 " + "(i.e., float32 approximation of 1.0507009873554804934193349852946).", + AttributeProto::FLOAT, + 1.05070102214813232421875f) + .SetDoc(Selu_ver6_doc) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + Alpha = Constant () + AlphaCast = CastLike (Alpha, X) + Gamma = Constant () + GammaCast = CastLike (Gamma, X) + Zero = Constant () + ZeroCast = CastLike (Zero, X) + ExpX = Exp (X) + AlphaMulExpX = Mul(AlphaCast, ExpX) + AlphaMulExpXSubAlpha = Sub (AlphaMulExpX, AlphaCast) + Neg = Mul (GammaCast, AlphaMulExpXSubAlpha) + Pos = Mul (GammaCast, X) + XLessThanZero = Less (X, ZeroCast) + Y = Where(XLessThanZero, Neg, Pos) + } + )ONNX", + 18)); + +static const char* ThresholdedRelu_ver10_doc = R"DOC( +ThresholdedRelu takes one input data (Tensor) and produces one output data +(Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, +is applied to the tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + ThresholdedRelu, + 10, + OpSchema() + .SetDoc(ThresholdedRelu_ver10_doc) + .Attr("alpha", "Threshold value", AttributeProto::FLOAT, 1.0f) + .Input(0, "X", "Input tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "Y", "Output tensor", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput) + .FunctionBody( + R"ONNX( + { + Alpha = Constant () + AlphaCast = CastLike (Alpha, X) + Zero = Constant () + ZeroCast = CastLike (Zero, X) + AlphaLessThanX = Less(AlphaCast, X) + Y = Where(AlphaLessThanX, X, ZeroCast) + } + )ONNX", + 18)); + std::function MathDocGenerator_opset13(const char* name) { return [=](OpSchema& schema) { std::string doc; diff --git a/onnx/defs/nn/defs.cc b/onnx/defs/nn/defs.cc index 9757edb3a69..980c5545eed 100644 --- a/onnx/defs/nn/defs.cc +++ b/onnx/defs/nn/defs.cc @@ -192,9 +192,9 @@ void convPoolShapeInference( std::vector GetSupportedDataTypesForPoolingOps(bool supports8bit) { if (supports8bit) { - return {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(int8)", "tensor(uint8)"}; + return {"tensor(bfloat16)", "tensor(float16)", "tensor(float)", "tensor(double)", "tensor(int8)", "tensor(uint8)"}; } - return {"tensor(float16)", "tensor(float)", "tensor(double)"}; + return {"tensor(bfloat16)", "tensor(float16)", "tensor(float)", "tensor(double)"}; } std::function PoolOpSchemaGenerator( @@ -313,7 +313,7 @@ std::function PoolOpSchemaGenerator( ONNX_OPERATOR_SET_SCHEMA( AveragePool, - 19, + 22, OpSchema() .FillUsing(PoolOpSchemaGenerator( "AveragePool", @@ -334,7 +334,7 @@ ONNX_OPERATOR_SET_SCHEMA( ONNX_OPERATOR_SET_SCHEMA( MaxPool, - 12, + 22, OpSchema() .FillUsing(PoolOpSchemaGenerator( "MaxPool", @@ -454,7 +454,7 @@ void maxUnpoolShapeInference(InferenceContext& ctx) { } } -static const char* MaxUnpool_ver11_doc = R"DOC( +static const char* MaxUnpool_ver22_doc = R"DOC( MaxUnpool essentially computes the partial inverse of the MaxPool op. The input information to this op is typically the output information from a MaxPool op. The first input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) @@ -477,9 +477,9 @@ In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape ONNX_OPERATOR_SET_SCHEMA( MaxUnpool, - 11, + 22, OpSchema() - .SetDoc(MaxUnpool_ver11_doc) + .SetDoc(MaxUnpool_ver22_doc) .Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS) .Attr( "strides", @@ -541,10 +541,7 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T1", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T1", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeConstraint("T2", {"tensor(int64)"}, "Constrain index tensor to int64") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { maxUnpoolShapeInference(ctx); })); @@ -624,10 +621,7 @@ std::function LpPoolOpSchemaGenerator(const char* name) { true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromInputToOutput(ctx, 0, 0); convPoolShapeInference(ctx, true, true, 0, 1); @@ -635,7 +629,7 @@ std::function LpPoolOpSchemaGenerator(const char* name) { }; } -ONNX_OPERATOR_SET_SCHEMA(LpPool, 18, OpSchema().FillUsing(LpPoolOpSchemaGenerator("LpPool"))); +ONNX_OPERATOR_SET_SCHEMA(LpPool, 22, OpSchema().FillUsing(LpPoolOpSchemaGenerator("LpPool"))); // For ROI pool operations. void roiPoolTypeShapeInference(InferenceContext& ctx) { @@ -725,15 +719,12 @@ std::function RoiPoolOpSchemaGenerator(const char* name) { true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { roiPoolTypeShapeInference(ctx); }); }; } -ONNX_OPERATOR_SET_SCHEMA(MaxRoiPool, 1, OpSchema().FillUsing(RoiPoolOpSchemaGenerator("max"))); +ONNX_OPERATOR_SET_SCHEMA(MaxRoiPool, 22, OpSchema().FillUsing(RoiPoolOpSchemaGenerator("max"))); std::function ConvOpSchemaGenerator(const char* filter_desc) { return [=](OpSchema& schema) { @@ -806,10 +797,7 @@ computes the output.)DOC"; true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.Attr( "kernel_shape", "The shape of the convolution kernel. If not present, should be inferred from input W.", @@ -839,7 +827,7 @@ computes the output.)DOC"; }; } -ONNX_OPERATOR_SET_SCHEMA(Conv, 11, OpSchema().FillUsing(ConvOpSchemaGenerator("a filter"))); +ONNX_OPERATOR_SET_SCHEMA(Conv, 22, OpSchema().FillUsing(ConvOpSchemaGenerator("a filter"))); static const char* QLinearConv_ver10_doc = R"DOC( The convolution operator consumes a quantized input tensor, its scale and zero point, @@ -1322,10 +1310,7 @@ output_shape can also be explicitly specified in which case pads values are auto true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.Attr( "kernel_shape", "The shape of the convolution kernel. If not present, should be inferred from input W.", @@ -1373,18 +1358,18 @@ output_shape can also be explicitly specified in which case pads values are auto }; } -ONNX_OPERATOR_SET_SCHEMA(ConvTranspose, 11, OpSchema().FillUsing(ConvTransposeOpSchemaGenerator("a filter"))); +ONNX_OPERATOR_SET_SCHEMA(ConvTranspose, 22, OpSchema().FillUsing(ConvTransposeOpSchemaGenerator("a filter"))); -static const char* DeformConv_ver19_doc = R"DOC( +static const char* DeformConv_ver22_doc = R"DOC( Performs deformable convolution as described in https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. This operator specification supports the general N-D case. Note that most common use cases have 2D or 3D data. )DOC"; ONNX_OPERATOR_SET_SCHEMA( DeformConv, - 19, + 22, OpSchema() - .SetDoc(DeformConv_ver19_doc) + .SetDoc(DeformConv_ver22_doc) .Input( 0, "X", @@ -1429,10 +1414,7 @@ ONNX_OPERATOR_SET_SCHEMA( "Output data tensor that contains the result of convolution. It has shape (N, oC, oH, oW) " "for 2D data or (N, oC, o1, o2, ..., on) for nD data", "T") - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .Attr( "dilations", "Dilation value along each spatial axis of the kernel. Default is 1 along each axis.", @@ -1537,18 +1519,15 @@ std::function GlobalPoolingOpSchemaGenerator(const char* op_typ true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { globalPoolTypeShapeInference(ctx); }); }; } ONNX_OPERATOR_SET_SCHEMA( GlobalAveragePool, - 1, + 22, OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator("AveragePool", "average"))); -ONNX_OPERATOR_SET_SCHEMA(GlobalMaxPool, 1, OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator("MaxPool", "max"))); +ONNX_OPERATOR_SET_SCHEMA(GlobalMaxPool, 22, OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator("MaxPool", "max"))); std::function GlobalLpPoolingOpSchemaGenerator(const char* op_type, const char* op) { return [=](OpSchema& schema) { @@ -1589,10 +1568,7 @@ std::function GlobalLpPoolingOpSchemaGenerator(const char* op_t true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { globalPoolTypeShapeInference(ctx); }); }; } @@ -1779,7 +1755,7 @@ ONNX_OPERATOR_SET_SCHEMA( } })); -static const char* InstanceNormalization_ver6_doc = R"DOC( +static const char* InstanceNormalization_ver22_doc = R"DOC( Carries out instance normalization as described in the paper https://arxiv.org/abs/1607.08022. @@ -1790,9 +1766,9 @@ where mean and variance are computed per instance per channel. ONNX_OPERATOR_SET_SCHEMA( InstanceNormalization, - 6, + 22, OpSchema() - .SetDoc(InstanceNormalization_ver6_doc) + .SetDoc(InstanceNormalization_ver22_doc) .Attr("epsilon", "The epsilon value to use to avoid division by zero.", AttributeProto::FLOAT, 1e-5f) .Input( 0, @@ -1837,27 +1813,21 @@ ONNX_OPERATOR_SET_SCHEMA( true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); })); -static const char* LpNormalization_ver1_doc = R"DOC( +static const char* LpNormalization_ver22_doc = R"DOC( Given a matrix, apply Lp-normalization along the provided axis. )DOC"; ONNX_OPERATOR_SET_SCHEMA( LpNormalization, - 1, + 22, OpSchema() .Input(0, "input", "Input matrix", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(0, "output", "Matrix after normalization", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") - .SetDoc(LpNormalization_ver1_doc) + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") + .SetDoc(LpNormalization_ver22_doc) .Attr( "axis", "The axis on which to apply normalization, -1 mean last axis.", @@ -1870,7 +1840,7 @@ ONNX_OPERATOR_SET_SCHEMA( static_cast(2)) .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); })); -static const char* Dropout_ver13_doc = R"DOC( +static const char* Dropout_ver22_doc = R"DOC( 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, output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, @@ -1886,9 +1856,9 @@ scale = 1. / (1. - ratio). ONNX_OPERATOR_SET_SCHEMA( Dropout, - 13, + 22, OpSchema() - .SetDoc(GET_OP_DOC_STR(std::string(Dropout_ver13_doc) + GenerateOptionalArgumentsDoc())) + .SetDoc(GET_OP_DOC_STR(std::string(Dropout_ver22_doc) + GenerateOptionalArgumentsDoc())) .Attr( "seed", "(Optional) Seed to the random generator, if not specified we will auto generate one.", @@ -1920,14 +1890,8 @@ ONNX_OPERATOR_SET_SCHEMA( OpSchema::NonDifferentiable) .Output(0, "output", "The output.", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) .Output(1, "mask", "The output mask.", "T2", OpSchema::Optional, true, 1, OpSchema::NonDifferentiable) - .TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(bfloat16)"}, - "Constrain input and output types to float tensors.") - .TypeConstraint( - "T1", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input 'ratio' types to float tensors.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors.") + .TypeConstraint("T1", OpSchema::all_float_types_ir10(), "Constrain input 'ratio' types to float tensors.") .TypeConstraint("T2", {"tensor(bool)"}, "Constrain output 'mask' types to boolean tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromInputToOutput(ctx, 0, 0); diff --git a/onnx/defs/nn/old.cc b/onnx/defs/nn/old.cc index 4c12dc94b23..3cb9a8f9d1d 100644 --- a/onnx/defs/nn/old.cc +++ b/onnx/defs/nn/old.cc @@ -8,6 +8,1460 @@ #include "onnx/defs/schema.h" namespace ONNX_NAMESPACE { +const char* pads_doc_opset11 = + "Padding for the beginning and ending along each spatial axis, it can take any value greater " + "than or equal to 0. The value represent the number of pixels added to the beginning " + "and end part of the corresponding axis. `pads` format should be as follow " + "[x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels " + "added at the beginning of axis `i` and xi_end, the number of pixels added at " + "the end of axis `i`. This attribute cannot be used simultaneously with " + "auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis."; +const char* conv_auto_pad_doc_opset19 = + "auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where " + "default value is NOTSET, which means explicit padding is used. " + "SAME_UPPER or SAME_LOWER mean pad the input so that " + "`output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. " + "The padding is split between the two sides equally or almost equally (depending " + "on whether it is even or odd). In case the padding is an odd number, the extra " + "padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER."; +const char* conv_transpose_auto_pad_doc_opset19 = + "auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where " + "default value is NOTSET, which means explicit padding is used. " + "SAME_UPPER or SAME_LOWER mean pad the input so that " + "`output_shape[i] = input_shape[i] * strides[i]` for each axis `i`. " + "The padding is split between the two sides equally or almost equally (depending " + "on whether it is even or odd). In case the padding is an odd number, the extra " + "padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER."; + +void convPoolShapeInference_opset19( + InferenceContext& ctx, + bool use_dilation, + bool require_kernel_shape, + int input1Idx, + int input2Idx) { + // we need the first input shape for this inference. + if (!hasInputShape(ctx, input1Idx)) { + return; + } + + // if kernel shape is an input (and not attribute) + // we need the shape of the second input. + if (!require_kernel_shape && !hasInputShape(ctx, input2Idx)) { + return; + } + + auto input_shape = ctx.getInputType(input1Idx)->tensor_type().shape(); + if (input_shape.dim_size() < 2) { + fail_shape_inference("Input tensor must have at least 2 dimensions"); + } + + // first dim is the batch axis and the next is the number of channels. + size_t n_input_dims = static_cast(input_shape.dim_size() - 2); + + // Only MaxPool and Conv support dilation. For + // simplicity of the code, we just treat the rest of them as having all-1s + // dilation. + std::vector dilations; + if (use_dilation && getRepeatedAttribute(ctx, "dilations", dilations)) { + if (dilations.size() != n_input_dims) { + fail_shape_inference("Attribute dilations has incorrect size"); + } + } else { + dilations.assign(n_input_dims, 1); + } + + std::vector strides; + if (getRepeatedAttribute(ctx, "strides", strides)) { + if (strides.size() != n_input_dims) { + fail_shape_inference("Attribute strides has incorrect size"); + } + } else { + strides.assign(n_input_dims, 1); + } + + std::vector kernel_shape; + if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) { + if (kernel_shape.size() != n_input_dims) { + fail_shape_inference("Attribute kernel_shape has incorrect size"); + } + } else if (require_kernel_shape) { + fail_shape_inference("Attribute kernel_shape must be specified"); + } else { + auto second_input_shape = ctx.getInputType(input2Idx)->tensor_type().shape(); + for (int i = 2; i < second_input_shape.dim_size(); ++i) { + if (!second_input_shape.dim(i).has_dim_value()) { + return; + } + kernel_shape.push_back(second_input_shape.dim(i).dim_value()); + } + } + + std::vector effective_kernel_shape = kernel_shape; + for (int i = 0; i < static_cast(kernel_shape.size()); i++) { + // accounting for dilation, how big is the kernel in this dimension + effective_kernel_shape[i] = (effective_kernel_shape[i] - 1) * dilations[i] + 1; + } + + std::vector pads; + if (getRepeatedAttribute(ctx, "pads", pads)) { + if (pads.size() != n_input_dims * 2) { + fail_shape_inference("Attribute pads has incorrect size"); + } + } else { + pads.assign(n_input_dims * 2, 0); + const auto* auto_pad_attr = ctx.getAttribute("auto_pad"); + if ((nullptr != auto_pad_attr) && (auto_pad_attr->s() != "VALID")) { + int input_dims_size = static_cast(n_input_dims); + for (int i = 0; i < input_dims_size; ++i) { + int64_t residual = 0; + int64_t stride = strides[i]; + if (stride > 1) { + if (!input_shape.dim(2 + i).has_dim_value()) { + continue; + } + residual = input_shape.dim(2 + i).dim_value(); + while (residual >= stride) { + residual -= stride; + } + } + int64_t total_pad = residual == 0 ? effective_kernel_shape[i] - stride : effective_kernel_shape[i] - residual; + if (total_pad < 0) + total_pad = 0; + int64_t half_pad_small = total_pad >> 1; + int64_t half_pad_big = total_pad - half_pad_small; + if (auto_pad_attr->s() == "SAME_UPPER") { + pads[i] = half_pad_small; + pads[i + input_dims_size] = half_pad_big; + } else if (auto_pad_attr->s() == "SAME_LOWER") { + pads[i] = half_pad_big; + pads[i + input_dims_size] = half_pad_small; + } + } + } + } + + auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + + if (require_kernel_shape) { + // add the first two dimensions from the input. + *output_shape->add_dim() = input_shape.dim(0); + *output_shape->add_dim() = input_shape.dim(1); + } else { + *output_shape->add_dim() = input_shape.dim(0); + auto& second_input_shape = getInputShape(ctx, input2Idx); + if (second_input_shape.dim_size() < 1) { + fail_shape_inference("Second input tensor has wrong dimension"); + } + *output_shape->add_dim() = second_input_shape.dim(0); + } + + int kernel_shape_size = static_cast(kernel_shape.size()); + for (int i = 0; i < kernel_shape_size; ++i) { + auto newdim = output_shape->add_dim(); + if (!input_shape.dim(2 + i).has_dim_value()) { + continue; + } + // how big is the input, including padding + int64_t effective_input_size = input_shape.dim(2 + i).dim_value(); + effective_input_size += pads[i]; + effective_input_size += pads[i + kernel_shape_size]; + + // default is floor mode .i.e. ceil_mode is set to 0 + auto ceil_mode = getAttribute(ctx, "ceil_mode", 0); + + // how many times we can move the kernel from it's initial position, based + // on the stride + int64_t strided_kernel_positions; + + if (ceil_mode == 1) + strided_kernel_positions = + (int64_t)(std::ceil((effective_input_size - effective_kernel_shape[i]) / float(strides[i]))); + else + strided_kernel_positions = (effective_input_size - effective_kernel_shape[i]) / strides[i]; + + // add in the initial position + newdim->set_dim_value(1 + strided_kernel_positions); + } + + if (ctx.getNumOutputs() > 1) { + // MaxPool with two outputs case. + auto second_output_shape = ctx.getOutputType(1)->mutable_tensor_type()->mutable_shape(); + second_output_shape->CopyFrom(*output_shape); + } +} + +static const char* Dropout_ver13_doc = R"DOC( +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, +output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; +Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, +the user can simply not pass `training_mode` input or set it to false. +``` +output = scale * data * mask, +``` +where +``` +scale = 1. / (1. - ratio). +``` +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Dropout, + 13, + OpSchema() + .SetDoc(GET_OP_DOC_STR(std::string(Dropout_ver13_doc) + GenerateOptionalArgumentsDoc())) + .Attr( + "seed", + "(Optional) Seed to the random generator, if not specified we will auto generate one.", + AttributeProto::INT, + OPTIONAL_VALUE) + .Input(0, "data", "The input data as Tensor.", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Input( + 1, + "ratio", + "The ratio of random dropout, with value in [0, 1). If this input was not set, " + "or if it was set to 0, the output would be a simple copy of the input. " + "If it's non-zero, output will be a random dropout of the scaled input, which is typically " + "the case during training. It is an optional value, if not specified it will default to 0.5.", + "T1", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Input( + 2, + "training_mode", + "If set to true then it indicates dropout is being used for training. It is an optional value hence unless " + "specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where " + "nothing will be dropped from the input data and if mask is requested as output it will contain all ones.", + "T2", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Output(0, "output", "The output.", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(1, "mask", "The output mask.", "T2", OpSchema::Optional, true, 1, OpSchema::NonDifferentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(bfloat16)"}, + "Constrain input and output types to float tensors.") + .TypeConstraint( + "T1", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input 'ratio' types to float tensors.") + .TypeConstraint("T2", {"tensor(bool)"}, "Constrain output 'mask' types to boolean tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (hasInputShape(ctx, 0)) { + propagateShapeFromInputToOutput(ctx, 0, 0); + } + + if (ctx.getNumInputs() > 1 && hasInputShape(ctx, 1)) { + auto& ratio_input_shape = getInputShape(ctx, 1); + if (static_cast(ratio_input_shape.dim_size()) != 0) { + fail_shape_inference("Ratio of Dropout must be a scalar."); + } + } + + if (ctx.getNumInputs() > 2 && hasInputShape(ctx, 2)) { + auto& training_mode_input_shape = getInputShape(ctx, 2); + if (static_cast(training_mode_input_shape.dim_size()) != 0) { + fail_shape_inference("training_mode of Dropout must be a scalar."); + } + } + + if (ctx.getNumOutputs() == 2) { + updateOutputElemType(ctx, 1, TensorProto::BOOL); + if (hasNInputShapes(ctx, 1)) { + propagateShapeFromInputToOutput(ctx, 0, 1); + } + } + })); + +static const char* LpNormalization_ver1_doc = R"DOC( +Given a matrix, apply Lp-normalization along the provided axis. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + LpNormalization, + 1, + OpSchema() + .Input(0, "input", "Input matrix", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Output(0, "output", "Matrix after normalization", "T", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .SetDoc(LpNormalization_ver1_doc) + .Attr( + "axis", + "The axis on which to apply normalization, -1 mean last axis.", + AttributeProto::INT, + static_cast(-1)) + .Attr( + "p", + "The order of the normalization, only 1 or 2 are supported.", + AttributeProto::INT, + static_cast(2)) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); })); + +static const char* InstanceNormalization_ver6_doc = R"DOC( +Carries out instance normalization as described in the paper +https://arxiv.org/abs/1607.08022. + +y = scale * (x - mean) / sqrt(variance + epsilon) + B, +where mean and variance are computed per instance per channel. + +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + InstanceNormalization, + 6, + OpSchema() + .SetDoc(InstanceNormalization_ver6_doc) + .Attr("epsilon", "The epsilon value to use to avoid division by zero.", AttributeProto::FLOAT, 1e-5f) + .Input( + 0, + "input", + "Input data tensor from the previous operator; " + "dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the " + "width of the data. For non image case, the " + "dimensions are in the form of " + "(N x C x D1 x D2 ... Dn), where N is the batch " + "size.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 1, + "scale", + "The input 1-dimensional scale tensor of size C.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 2, + "B", + "The input 1-dimensional bias tensor of size C.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Output( + 0, + "output", + "The output tensor of the same shape as input.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); })); + +void maxUnpoolShapeInference_opset11(InferenceContext& ctx) { + // we need at least two inputs to have a shape for this inference. + if (ctx.getNumInputs() != 2 && ctx.getNumInputs() != 3) { + fail_type_inference("MaxUnpool op must have either two or three inputs."); + } + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (!hasInputShape(ctx, 0)) { + return; // If first input does not have shape, we cannot infer much. + } + auto input_shape = ctx.getInputType(0)->tensor_type().shape(); + if (input_shape.dim_size() < 2) { + fail_shape_inference("Input tensor X must have at least 2 dimensions."); + } + + // first dim is the batch axis and the next is the number of channels. + size_t n_input_dims = static_cast(input_shape.dim_size() - 2); + + std::vector pads; + if (getRepeatedAttribute(ctx, "pads", pads)) { + if (pads.size() != n_input_dims * 2) { + fail_shape_inference("Attribute pads has incorrect size."); + } + } else { + pads.assign(n_input_dims * 2, 0); + } + + std::vector strides; + if (getRepeatedAttribute(ctx, "strides", strides)) { + if (strides.size() != n_input_dims) { + fail_shape_inference("Attribute strides has incorrect size."); + } + } else { + strides.assign(n_input_dims, 1); + } + + std::vector kernel_shape; + if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) { + if (kernel_shape.size() != n_input_dims) { + fail_shape_inference("Attribute kernel_shape has incorrect size."); + } + } else { + fail_shape_inference("Attribute kernel_shape must be specified."); + } + + if (ctx.getNumInputs() == 3) { + // If the third input, output_size, is specified, then use that instead + // of inferring shape from inputs. + if (hasInputShape(ctx, 2)) { + auto& output_shape = getInputShape(ctx, 2); + if (output_shape.dim_size() != 1) { + fail_type_inference("'output_shape' must be rank 1 tensor."); + } + if (output_shape.dim((int)0).has_dim_value() && + static_cast(output_shape.dim((int)0).dim_value()) != input_shape.dim_size()) { + fail_shape_inference("'output_shape' must have same number of elements as the shape of input tensor X."); + } + } + return; // 'output_shape' is specified as input. Actual shape will be + // determined at runtime. + } + + auto final_output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + + *final_output_shape->add_dim() = input_shape.dim(0); + *final_output_shape->add_dim() = + ctx.getInputType(1)->tensor_type().shape().dim(1); // channels should be the second dim of second input. + + int kernel_shape_size = static_cast(kernel_shape.size()); + for (int i = 0; i < kernel_shape_size; ++i) { + auto newdim = final_output_shape->add_dim(); + if (!input_shape.dim(2 + i).has_dim_value()) { + continue; + } + + int64_t newdim_value = strides[i] * (input_shape.dim(2 + i).dim_value() - 1); + newdim_value += kernel_shape[i]; + newdim_value -= pads[i]; + newdim_value -= pads[i + kernel_shape_size]; + + // add in the initial position + newdim->set_dim_value(newdim_value); + } +} + +// For GlobalPool operations. +void globalPoolTypeShapeInference_opset1(InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + // needs at least one input with shape. + if (!hasNInputShapes(ctx, 1)) { + return; + } + + auto input_shape = ctx.getInputType(0)->tensor_type().shape(); + if (input_shape.dim_size() < 2) { + return; + } + + // first dim is the batch axis and the next is the number of channels. + size_t n_input_dims = static_cast(input_shape.dim_size() - 2); + + // (N, C, 1, 1, ..., 1) + auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + *output_shape->add_dim() = input_shape.dim(0); + *output_shape->add_dim() = input_shape.dim(1); + + for (size_t i = 0; i < n_input_dims; ++i) { + output_shape->add_dim()->set_dim_value(1); + } +} + +std::function GlobalPoolingOpSchemaGenerator_opset1(const char* op_type, const char* op) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR(doc = R"DOC( + Global{op_type} consumes an input tensor X and applies {op} pooling across + the values in the same channel. This is equivalent to {op_type} with kernel size + equal to the spatial dimension of input tensor.)DOC"; + ReplaceAll(doc, "{op_type}", op_type); + ReplaceAll(doc, "{op}", op);); + schema.SetDoc(doc); + schema.Input( + 0, + "X", + "Input data tensor from the previous operator; " + "dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the width " + "of the data. For non image case, the dimensions are " + "in the form of (N x C x D1 x D2 ... Dn), " + "where N is the batch size.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 0, + "Y", + "Output data tensor from pooling across the input " + "tensor. The output tensor has the same rank as the input. " + "The first two dimensions of output shape are the same as " + "the input (N x C), while the other dimensions are all 1.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { globalPoolTypeShapeInference_opset1(ctx); }); + }; +} +ONNX_OPERATOR_SET_SCHEMA( + GlobalAveragePool, + 1, + OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator_opset1("AveragePool", "average"))); +ONNX_OPERATOR_SET_SCHEMA( + GlobalMaxPool, + 1, + OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator_opset1("MaxPool", "max"))); + +void convTransposeShapeInference_opset11(InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + // we need at least two inputs to have a shape for this inference. + if (!hasNInputShapes(ctx, 2)) { + return; + } + + int64_t group = getAttribute(ctx, "group", 1); + + auto input_shape = ctx.getInputType(0)->tensor_type().shape(); + if (input_shape.dim_size() < 2) { + return; // Input tensor should have at least two dimensions. + } + + // first dim is the batch axis and the next is the number of channels. + size_t n_input_dims = static_cast(input_shape.dim_size() - 2); + + std::vector dilations; + if (getRepeatedAttribute(ctx, "dilations", dilations)) { + if (dilations.size() != n_input_dims) { + return; + } + } else { + dilations.assign(n_input_dims, 1); + } + + std::vector strides; + if (getRepeatedAttribute(ctx, "strides", strides)) { + if (strides.size() != n_input_dims) { + return; + } + } else { + strides.assign(n_input_dims, 1); + } + + std::vector kernel_shape; + if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) { + if (kernel_shape.size() != n_input_dims) { + return; + } + } else { + auto second_input_shape = ctx.getInputType(1)->tensor_type().shape(); + for (int i = 2; i < second_input_shape.dim_size(); ++i) { + if (!second_input_shape.dim(i).has_dim_value()) { + return; + } + kernel_shape.push_back(second_input_shape.dim(i).dim_value()); + } + } + + std::vector effective_kernel_shape = kernel_shape; + for (int i = 0; i < static_cast(kernel_shape.size()); i++) { + // accounting for dilation, how big is the kernel in this dimension + effective_kernel_shape[i] = (effective_kernel_shape[i] - 1) * dilations[i] + 1; + } + + std::vector pads; + if (getRepeatedAttribute(ctx, "pads", pads)) { + if (pads.size() != n_input_dims * 2) { + fail_shape_inference("Attribute pads has incorrect size"); + } + const auto* auto_pad_attr = ctx.getAttribute("auto_pad"); + if (nullptr != auto_pad_attr && auto_pad_attr->s() != "NOTSET") { + fail_shape_inference("The pads attribute cannot be used simultaneously with auto_pad attribute"); + } + } else { + pads.assign(n_input_dims * 2, 0); + const auto* auto_pad_attr = ctx.getAttribute("auto_pad"); + if ((nullptr != auto_pad_attr) && (auto_pad_attr->s() != "VALID")) { + int input_dims_size = static_cast(n_input_dims); + for (int i = 0; i < input_dims_size; ++i) { + int64_t total_pad = effective_kernel_shape[i] - strides[i]; + if (total_pad < 0) + total_pad = 0; + int64_t half_pad_small = total_pad >> 1; + int64_t half_pad_big = total_pad - half_pad_small; + if (auto_pad_attr->s() == "SAME_UPPER") { + pads[i] = half_pad_small; + pads[i + input_dims_size] = half_pad_big; + } else if (auto_pad_attr->s() == "SAME_LOWER") { + pads[i] = half_pad_big; + pads[i + input_dims_size] = half_pad_small; + } + } + } + } + + std::vector output_shape; + bool output_shape_presented = true; + if (getRepeatedAttribute(ctx, "output_shape", output_shape)) { + if (output_shape.size() != n_input_dims) { + return; + } + } else { + output_shape_presented = false; + } + + std::vector output_padding; + if (getRepeatedAttribute(ctx, "output_padding", output_padding)) { + if (output_padding.size() != n_input_dims) { // Added only to one side. + return; + } + } else { + output_padding.assign(n_input_dims, 0); + } + + auto final_output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + + *final_output_shape->add_dim() = input_shape.dim(0); + *final_output_shape->add_dim() = + ctx.getInputType(1)->tensor_type().shape().dim(1) * group; // channels should be the second dim of second input + // multiply group. + + int size_of_output; + if (output_shape_presented) { + size_of_output = static_cast(output_shape.size()); + for (int i = 0; i < size_of_output; ++i) { + if (input_shape.dim(i + 2).has_dim_value()) { + if (output_shape[i] < input_shape.dim(i + 2).dim_value()) { + // TODO: throw exception? + return; // output shape value cannot be smaller than the input shape + // value + } + } + final_output_shape->add_dim()->set_dim_value(output_shape[i]); + } + return; + } else { + size_of_output = input_shape.dim_size() - 2; + for (int i = 0; i < size_of_output; ++i) { + if (input_shape.dim(i + 2).has_dim_value()) { + int64_t output_shape_dim = strides[i] * (input_shape.dim(i + 2).dim_value() - 1) + output_padding[i] + + effective_kernel_shape[i] - pads[i] - pads[i + n_input_dims]; + final_output_shape->add_dim()->set_dim_value(output_shape_dim); + } else { + final_output_shape->add_dim(); + } + } + return; + } +} + +static const char* DeformConv_ver19_doc = R"DOC( +Performs deformable convolution as described in https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. +This operator specification supports the general N-D case. Note that most common use cases have 2D or 3D data. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + DeformConv, + 19, + OpSchema() + .SetDoc(DeformConv_ver19_doc) + .Input( + 0, + "X", + "Input data tensor. For 2D image data, it has shape (N, C, H, W) where N is the batch size, " + "C is the number of input channels, and H and W are the height and width. " + "In general, the shape is (N, C, D1, D2, ... , Dn) for n-dimensional data, where " + "D1 to Dn are the spatial dimension sizes. Most common use cases have n = 2 or 3.", + "T") + .Input( + 1, + "W", + "Weight tensor that will be used in the convolutions. It has shape (oC, C/group, kH, kW), " + "where oC is the number of output channels and kH and kW are the kernel height and width. " + "For more than 2 dimensions, it has shape (oC, C/group, k1, k2, ... , kn).", + "T") + .Input( + 2, + "offset", + "Offset tensor denoting the offset for the sampling locations in the convolution kernel. " + "It has shape (N, offset_group * kH * kW * 2, oH, oW) for 2D data or " + "(N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Use linear interpolation" + "for fractional offset values. Sampling locations outside of the padded input tensor gives zero.", + "T") + .Input( + 3, + "B", + "Optional 1D bias of length oC to be added to the convolution. Default is a tensor of zeros.", + "T", + OpSchema::Optional) + .Input( + 4, + "mask", + "The mask tensor to be applied to each position in the convolution kernel. " + "It has shape (N, offset_group * kH * kW, oH, oW) for 2D data or " + "(N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Default is a " + "tensor of ones.", + "T", + OpSchema::Optional) + .Output( + 0, + "Y", + "Output data tensor that contains the result of convolution. It has shape (N, oC, oH, oW) " + "for 2D data or (N, oC, o1, o2, ..., on) for nD data", + "T") + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .Attr( + "dilations", + "Dilation value along each spatial axis of the kernel. Default is 1 along each axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr( + "group", + "Number of groups the input and output channels, C and oC, are divided into. C and oC must both " + "be divisible by group. Default is 1.", + AttributeProto::INT, + static_cast(1)) + .Attr( + "kernel_shape", + "Shape of the convolution kernel. If not present, it is inferred from the shape of input W.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr( + "offset_group", + "Number of groups of offset. C must be divisible by offset_group. Default is 1.", + AttributeProto::INT, + static_cast(1)) + .Attr( + "pads", + "Padding for the beginning and end along each spatial axis. The values represent the number of pixels " + "added to the beginning and end of the corresponding axis and can take any nonnegative value. " + "The format should be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where xi_begin " + "is the number of pixels added at the beginning of axis `i` and xi_end is the number of pixels " + "added at the end of axis `i`. Default is 0 along each axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr( + "strides", + "Stride along each spatial axis. Default is 1 along each axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + convPoolShapeInference_opset19(ctx, true, false, 0, 1); + })); + +std::function ConvTransposeOpSchemaGenerator_opset11(const char* filter_desc) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR(doc = R"DOC( +The convolution transpose operator consumes an input tensor and {filter_desc}, +and computes the output. + +If the pads parameter is provided the shape of the output is calculated via the following equation: + + 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] + +output_shape can also be explicitly specified in which case pads values are auto generated using these equations: + + total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i] + If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2) + Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2). + + )DOC"; + ReplaceAll(doc, "{filter_desc}", filter_desc);); + schema.SetDoc(doc); + schema.Input( + 0, + "X", + "Input data tensor from previous layer; has size (N x C x H x W)" + ", where N is the batch size, C is the number of channels, and" + " H and W are the height and width. Note that this is for the 2D image. " + "Otherwise the size is (N x C x D1 x D2 ... x Dn)", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 1, + "W", + "The weight tensor that will be used in the " + "convolutions; has size (C x M/group x kH x kW), where C " + "is the number of channels, and kH and kW are the " + "height and width of the kernel, and M is the number " + "of feature maps. For more than 2 dimensions, the " + "weight shape will be (C x M/group x k1 x k2 x ... x kn), " + "where (k1 x k2 x ... x kn) is the dimension of the kernel. " + "The number of channels in the output should be equal to W.shape[1] * group " + "(assuming zero based indices of the shape array)", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 2, + "B", + "Optional 1D bias to be added to the convolution, has size of M.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 0, + "Y", + "Output data tensor that contains the result of the convolution. The " + "output dimensions are functions of the kernel size, stride size, " + "pad lengths and group count. " + "The number of channels in the output should be equal to W.shape[1] * group " + "(assuming zero based indices of the shape array)", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.Attr( + "kernel_shape", + "The shape of the convolution kernel. If not present, should be inferred from input W.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "output_shape", + "The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified " + "pads values are ignored. See doc for details for equations to generate pads. Note that the output_shape attribute value " + "should not include dimensions for batch size and channels, which are automatically inferred.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "output_padding", + "Additional elements added to the side with higher coordinate indices in the output. " + "Each padding value in \"output_padding\" must be less than the corresponding stride/dilation dimension. " + "By default, this attribute is a zero vector. " + "Note that this attribute doesn't directly affect the computed output values. " + "It only controls the selection of the computed values, " + "so changing this attribute only adds or removes output elements. " + "If \"output_shape\" is explicitly provided, " + "\"output_padding\" does not contribute additional size to \"output_shape\" but " + "participates in the computation of the needed padding amount. " + "This is also called adjs or adjustment in some frameworks.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "dilations", + "dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "strides", + "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr("auto_pad", conv_transpose_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET")); + schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE); + schema.Attr( + "group", + "number of groups input channels and output channels are divided into.", + AttributeProto::INT, + static_cast(1)); + schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { convTransposeShapeInference_opset11(ctx); }); + }; +} + +ONNX_OPERATOR_SET_SCHEMA(ConvTranspose, 11, OpSchema().FillUsing(ConvTransposeOpSchemaGenerator_opset11("a filter"))); + +std::function ConvOpSchemaGenerator_opset11(const char* filter_desc) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR(doc = R"DOC( +The convolution operator consumes an input tensor and {filter_desc}, and +computes the output.)DOC"; + ReplaceAll(doc, "{filter_desc}", filter_desc);); + schema.SetDoc(doc); + schema.Input( + 0, + "X", + "Input data tensor from previous layer; " + "has size (N x C x H x W), where N is the batch size, " + "C is the number of channels, and H and W are the " + "height and width. Note that this is for the 2D image. " + "Otherwise the size is (N x C x D1 x D2 ... x Dn). " + "Optionally, if dimension denotation is " + "in effect, the operation expects input data tensor " + "to arrive with the dimension denotation of [DATA_BATCH, " + "DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 1, + "W", + "The weight tensor that will be used in the " + "convolutions; has size (M x C/group x kH x kW), where C " + "is the number of channels, and kH and kW are the " + "height and width of the kernel, and M is the number " + "of feature maps. For more than 2 dimensions, the " + "kernel shape will be (M x C/group x k1 x k2 x ... x kn), " + "where (k1 x k2 x ... kn) is the dimension of the kernel. " + "Optionally, if dimension denotation is in effect, " + "the operation expects the weight tensor to arrive " + "with the dimension denotation of [FILTER_OUT_CHANNEL, " + "FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. " + "Assuming zero based indices for the shape array, " + "X.shape[1] == (W.shape[1] * group) == C and " + "W.shape[0] mod G == 0. Or in other words " + "FILTER_IN_CHANNEL multiplied by the number of groups " + "should be equal to DATA_CHANNEL and the number of " + "feature maps M should be a multiple of the number of " + "groups G.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 2, + "B", + "Optional 1D bias to be added to the convolution, has size of M.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 0, + "Y", + "Output data tensor that contains the result of the " + "convolution. The output dimensions are functions " + "of the kernel size, stride size, and pad lengths.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.Attr( + "kernel_shape", + "The shape of the convolution kernel. If not present, should be inferred from input W.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "dilations", + "dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "strides", + "Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET")); + schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE); + schema.Attr( + "group", + "number of groups input channels and output channels are divided into.", + AttributeProto::INT, + static_cast(1)); + schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + convPoolShapeInference_opset19(ctx, true, false, 0, 1); + }); + }; +} + +ONNX_OPERATOR_SET_SCHEMA(Conv, 11, OpSchema().FillUsing(ConvOpSchemaGenerator_opset11("a filter"))); + +void roiPoolTypeShapeInference_opset1(InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + // rois is the second input. + if (!hasNInputShapes(ctx, 2)) { + return; + } + + auto input_shape = ctx.getInputType(0)->tensor_type().shape(); + auto rios_shape = ctx.getInputType(1)->tensor_type().shape(); + + if (input_shape.dim_size() < 2) { + fail_shape_inference("Input tensor must have at least 2 dimensions"); + } + if (rios_shape.dim_size() != 2) { + fail_shape_inference("RoIs tensor must have 2 dimensions"); + } + + // first dim is the batch axis and the next is the number of channels. + size_t n_input_dims = static_cast(input_shape.dim_size() - 2); + + std::vector pooled_shape; + if (getRepeatedAttribute(ctx, "pooled_shape", pooled_shape)) { + if (pooled_shape.size() != n_input_dims) { + fail_shape_inference("Attribute pooled_shape has incorrect length"); + } + } else { + fail_shape_inference("Attribute pooled_shape must be specified"); + } + + // (num_rois, channels, pooled_shape[0], pooled_shape[1]) + auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape(); + + *output_shape->add_dim() = rios_shape.dim(0); + *output_shape->add_dim() = input_shape.dim(1); + output_shape->add_dim()->set_dim_value(pooled_shape[0]); + output_shape->add_dim()->set_dim_value(pooled_shape[1]); +} + +std::function RoiPoolOpSchemaGenerator_opset1(const char* name) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR(doc = R"DOC( + ROI {name} pool consumes an input tensor X and region of interests (RoIs) to + apply {name} pooling across each RoI, to produce output 4-D tensor of shape + (num_rois, channels, pooled_shape[0], pooled_shape[1]).)DOC"; + ReplaceAll(doc, "{name}", name);); + schema.SetDoc(doc); + schema.Attr("pooled_shape", "ROI pool output shape (height, width).", AttributeProto::INTS); + schema.Attr( + "spatial_scale", + "Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling.", + AttributeProto::FLOAT, + 1.f); + schema.Input( + 0, + "X", + "Input data tensor from the previous operator; " + "dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the " + "width of the data.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 1, + "rois", + "RoIs (Regions of Interest) to pool over. Should " + "be a 2-D tensor of shape (num_rois, 5) given as " + "[[batch_id, x1, y1, x2, y2], ...].", + "T", + OpSchema::Single, + true, + 1, + OpSchema::NonDifferentiable); + schema.Output( + 0, + "Y", + "RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1]).", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { roiPoolTypeShapeInference_opset1(ctx); }); + }; +} + +ONNX_OPERATOR_SET_SCHEMA(MaxRoiPool, 1, OpSchema().FillUsing(RoiPoolOpSchemaGenerator_opset1("max"))); + +std::function LpPoolOpSchemaGenerator_opset18(const char* name) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR(doc = R"DOC( + {name} consumes an input tensor X and applies Lp pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled `pad_shape[i]` is the sum of pads along axis `i`. + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] + ```)DOC"; + ReplaceAll(doc, "{name}", name);); + schema.SetDoc(doc); + schema.Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS); + schema.Attr( + "strides", + "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr( + "dilations", + "dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET")); + schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE); + schema.Attr( + "p", "p value of the Lp norm used to pool over the input data.", AttributeProto::INT, static_cast(2)); + schema.Attr( + "ceil_mode", + "Whether to use ceil or floor (default) to compute the output shape.", + AttributeProto::INT, + static_cast(0)); + schema.Input( + 0, + "X", + "Input data tensor from the previous operator; " + "dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the " + "width of the data. For non image case, the " + "dimensions are in the form of " + "(N x C x D1 x D2 ... Dn), where N is the " + "batch size.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 0, + "Y", + "Output data tensor from Lp pooling across the input " + "tensor. Dimensions will vary based on various kernel, stride, and pad " + "sizes.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + convPoolShapeInference_opset19(ctx, true, true, 0, 1); + }); + }; +} + +ONNX_OPERATOR_SET_SCHEMA(LpPool, 18, OpSchema().FillUsing(LpPoolOpSchemaGenerator_opset18("LpPool"))); + +static const char* MaxUnpool_ver11_doc = R"DOC( +MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the output information from a MaxPool op. The first + input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) + from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corresponding + to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op. + The third (optional) input is a tensor that specifies the output size of the unpooling operation. + +MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal + values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling + the result of an unpooling operation should give back the original input to the unpooling op. + +MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous. + The third input argument, output_size, is meant to disambiguate the op and produce output tensor of + known/predictable size. + +In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads, + which define the exact unpooling op. The attributes typically have the same values as the corresponding + pooling op that the unpooling op is trying to invert. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + MaxUnpool, + 11, + OpSchema() + .SetDoc(MaxUnpool_ver11_doc) + .Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS) + .Attr( + "strides", + "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE) + .Input( + 0, + "X", + "Input data tensor that has to be unpooled. " + "This tensor is typically the first output of the MaxPool op." + "Dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the " + "width of the data. For non-image case, the " + "dimensions are in the form of " + "(N x C x D1 x D2 ... Dn), where N is the batch " + "size. Optionally, if dimension denotation is " + "in effect, the operation expects the input " + "data tensor to arrive with the dimension denotation " + "of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].", + "T1", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 1, + "I", + "Input data tensor containing the indices corresponding to " + "elements in the first input tensor X." + "This tensor is typically the second output of the MaxPool op." + "Dimensions must be the same as input tensor X. " + "The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, " + "assuming row-major storage. Also, the linear indices should not consider padding. " + "So the values in indices are in the range [0, N x C x D1 x ... x Dn).", + "T2", + OpSchema::Single, + true, + 1, + OpSchema::NonDifferentiable) + .Input( + 2, + "output_shape", + "The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, " + "'pads' values are ignored.", + "T2", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Output( + 0, + "output", + "Output data tensor that contains the result of the unpooling.", + "T1", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T1", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeConstraint("T2", {"tensor(int64)"}, "Constrain index tensor to int64") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { maxUnpoolShapeInference_opset11(ctx); })); + +std::vector GetSupportedDataTypesForPoolingOps_opset19(bool supports8bit) { + if (supports8bit) { + return {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(int8)", "tensor(uint8)"}; + } + return {"tensor(float16)", "tensor(float)", "tensor(double)"}; +} + +std::function PoolOpSchemaGenerator_opset19( + const char* name, + const char* opName, + const char* additionalDescription, + bool use_dilation, + bool supports8bit = false) { + return [=](OpSchema& schema) { + std::string doc; + POPULATE_OP_DOC_STR( + doc = R"DOC( + {name} consumes an input tensor X and applies {opName} pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + {opName} pooling consisting of computing the {opName} on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape is calculated differently + depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized. + With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`. + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + ``` + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] + ``` + {additionalDescription} + )DOC"; + ReplaceAll(doc, "{name}", name); + ReplaceAll(doc, "{opName}", opName); + ReplaceAll(doc, "{additionalDescription}", additionalDescription); + ReplaceAll( + doc, + "{kernelSpatialShape}", + use_dilation ? "((kernel_spatial_shape[i] - 1) * dilations[i] + 1)" : "kernel_spatial_shape[i]");); + schema.SetDoc(doc); + schema.Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS); + schema.Attr( + "strides", + "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE); + schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET")); + schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE); + schema.Attr( + "ceil_mode", + "Whether to use ceil or floor (default) to compute the output shape.", + AttributeProto::INT, + static_cast(0)); + schema.Input( + 0, + "X", + "Input data tensor from the previous operator; " + "dimensions for image case are (N x C x H x W), " + "where N is the batch size, C is the number of " + "channels, and H and W are the height and the " + "width of the data. For non image case, the " + "dimensions are in the form of " + "(N x C x D1 x D2 ... Dn), where N is the batch " + "size. Optionally, if dimension denotation is " + "in effect, the operation expects the input " + "data tensor to arrive with the dimension denotation " + "of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 0, + "Y", + "Output data tensor from average or max pooling across " + "the input tensor. Dimensions will vary based " + "on various kernel, stride, and pad sizes. Floor value of " + "the dimension is used", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + GetSupportedDataTypesForPoolingOps_opset19(supports8bit), + supports8bit ? "Constrain input and output types to float and 8 bit tensors." + : "Constrain input and output types to float tensors."); + schema.TypeAndShapeInferenceFunction([use_dilation](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (ctx.getNumOutputs() > 1) { + // MaxPool with two outputs case. + auto output_type = ctx.getOutputType(1); + if (output_type->value_case() == TypeProto::kTensorType || + output_type->value_case() == TypeProto::VALUE_NOT_SET) { + output_type->mutable_tensor_type()->set_elem_type(TensorProto::INT64); + } + } + convPoolShapeInference_opset19(ctx, use_dilation, true, 0, 1); + }); + }; +} + +ONNX_OPERATOR_SET_SCHEMA( + AveragePool, + 19, + OpSchema() + .FillUsing(PoolOpSchemaGenerator_opset19( + "AveragePool", + "average", + "The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).", + true, /* use_dilation: dilations attribute has been added in opset 19. */ + false /* supports8bit: does not support 8bit. */)) + .Attr( + "dilations", + "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr( + "count_include_pad", + "Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.", + AttributeProto::INT, + static_cast(0))); + +ONNX_OPERATOR_SET_SCHEMA( + MaxPool, + 12, + OpSchema() + .FillUsing(PoolOpSchemaGenerator_opset19( + "MaxPool", + "max", + "The output of each pooling window is maximum number of elements exclude pad. ", + true, + true)) + .Attr( + "storage_order", + "The storage order of the tensor. 0 is row major, and 1 is column major. " + "This attribute is used only to convert an n-tuple index value into " + "a single integer value for producing the second output. ", + AttributeProto::INT, + static_cast(0)) + .Attr( + "dilations", + "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Output( + 1, + "Indices", + "Indices tensor from max pooling across the input tensor. " + "The dimensions of indices are the same as output tensor. " + "The values in indices of are the indices of the selected values during pooling. " + "The indices are computed as flatten 1-D tensor, " + "and the indices do not consider padding. " + "So the values in indices are in [0, N x C x D1 x ... x Dn).", + "I", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .TypeConstraint("I", {"tensor(int64)"}, "Constrain index tensor to int64")); static const char* Dropout_ver12_doc = R"DOC( 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, diff --git a/onnx/defs/object_detection/defs.cc b/onnx/defs/object_detection/defs.cc index 82bdf15440b..11be1369175 100644 --- a/onnx/defs/object_detection/defs.cc +++ b/onnx/defs/object_detection/defs.cc @@ -7,7 +7,7 @@ using namespace ONNX_NAMESPACE; namespace ONNX_NAMESPACE { -static const char* RoiAlign_ver16_doc = R"DOC( +static const char* RoiAlign_ver22_doc = R"DOC( Region of Interest (RoI) align operation described in the [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). RoiAlign consumes an input tensor X and region of interests (rois) @@ -23,9 +23,9 @@ through bilinear interpolation. ONNX_OPERATOR_SET_SCHEMA( RoiAlign, - 16, + 22, OpSchema() - .SetDoc(RoiAlign_ver16_doc) + .SetDoc(RoiAlign_ver22_doc) .Attr( "spatial_scale", "Multiplicative spatial scale factor to translate ROI coordinates " @@ -89,10 +89,7 @@ ONNX_OPERATOR_SET_SCHEMA( "(num_rois, C, output_height, output_width). The r-th batch element Y[r-1] " "is a pooled feature map corresponding to the r-th RoI X[r-1].", "T1") - .TypeConstraint( - "T1", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain types to float tensors.") + .TypeConstraint("T1", OpSchema::all_float_types_ir10(), "Constrain types to float tensors.") .TypeConstraint("T2", {"tensor(int64)"}, "Constrain types to int tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromInputToOutput(ctx, 0, 0); diff --git a/onnx/defs/object_detection/old.cc b/onnx/defs/object_detection/old.cc index 28ae0c5009f..65659bb35db 100644 --- a/onnx/defs/object_detection/old.cc +++ b/onnx/defs/object_detection/old.cc @@ -7,6 +7,123 @@ using namespace ONNX_NAMESPACE; namespace ONNX_NAMESPACE { +static const char* RoiAlign_ver16_doc = R"DOC( +Region of Interest (RoI) align operation described in the +[Mask R-CNN paper](https://arxiv.org/abs/1703.06870). +RoiAlign consumes an input tensor X and region of interests (rois) +to apply pooling across each RoI; it produces a 4-D tensor of shape +(num_rois, C, output_height, output_width). + +RoiAlign is proposed to avoid the misalignment by removing +quantizations while converting from original image into feature +map and from feature map into RoI feature; in each ROI bin, +the value of the sampled locations are computed directly +through bilinear interpolation. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RoiAlign, + 16, + OpSchema() + .SetDoc(RoiAlign_ver16_doc) + .Attr( + "spatial_scale", + "Multiplicative spatial scale factor to translate ROI coordinates " + "from their input spatial scale to the scale used when pooling, " + "i.e., spatial scale of the input feature map X relative to the " + "input image. E.g.; default is 1.0f. ", + AttributeProto::FLOAT, + 1.f) + .Attr("output_height", "default 1; Pooled output Y's height.", AttributeProto::INT, static_cast(1)) + .Attr("output_width", "default 1; Pooled output Y's width.", AttributeProto::INT, static_cast(1)) + .Attr( + "sampling_ratio", + "Number of sampling points in the interpolation grid used to compute " + "the output value of each pooled output bin. If > 0, then exactly " + "sampling_ratio x sampling_ratio grid points are used. If == 0, then " + "an adaptive number of grid points are used (computed as " + "ceil(roi_width / output_width), and likewise for height). Default is 0.", + AttributeProto::INT, + static_cast(0)) + .Attr( + "mode", + "The pooling method. Two modes are supported: 'avg' and 'max'. " + "Default is 'avg'.", + AttributeProto::STRING, + std::string("avg")) + .Attr( + "coordinate_transformation_mode", + "Allowed values are 'half_pixel' and 'output_half_pixel'. " + "Use the value 'half_pixel' to pixel shift the input coordinates by -0.5 (the recommended behavior). " + "Use the value 'output_half_pixel' to omit the pixel shift for the input (use this for a " + "backward-compatible behavior).", + AttributeProto::STRING, + std::string("half_pixel")) + .Input( + 0, + "X", + "Input data tensor from the previous operator; " + "4-D feature map of shape (N, C, H, W), " + "where N is the batch size, C is the number of channels, " + "and H and W are the height and the width of the data.", + "T1") + .Input( + 1, + "rois", + "RoIs (Regions of Interest) to pool over; rois is " + "2-D input of shape (num_rois, 4) given as " + "[[x1, y1, x2, y2], ...]. " + "The RoIs' coordinates are in the coordinate system of the input image. " + "Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.", + "T1") + .Input( + 2, + "batch_indices", + "1-D tensor of shape (num_rois,) with each element denoting " + "the index of the corresponding image in the batch.", + "T2") + .Output( + 0, + "Y", + "RoI pooled output, 4-D tensor of shape " + "(num_rois, C, output_height, output_width). The r-th batch element Y[r-1] " + "is a pooled feature map corresponding to the r-th RoI X[r-1].", + "T1") + .TypeConstraint( + "T1", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain types to float tensors.") + .TypeConstraint("T2", {"tensor(int64)"}, "Constrain types to int tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + size_t input_param = 0, rois_param = 1, batch_index_param = 2; + + checkInputRank(ctx, input_param, 4); + checkInputRank(ctx, rois_param, 2); + checkInputRank(ctx, batch_index_param, 1); + + // Output dimensions, initialized to an unknown-dimension-value + Dim num_rois, C, ht, width; + + // Get value of C from dim 1 of input_param, if available + unifyInputDim(ctx, input_param, 1, C); + + // Get value of num_rois from dim 0 of rois_param, if available + unifyInputDim(ctx, rois_param, 0, num_rois); + // ... or from dim 0 of batch_index_param, if available + unifyInputDim(ctx, batch_index_param, 0, num_rois); + + // Get height from attribute, using default-value of 1 + unifyDim(ht, getAttribute(ctx, "output_height", 1)); + + // Get width from attribute, using default-value of 1 + unifyDim(width, getAttribute(ctx, "output_width", 1)); + + // set output shape: + updateOutputShape(ctx, 0, {num_rois, C, ht, width}); + })); + static const char* RoiAlign_ver10_doc = R"DOC( Region of Interest (RoI) align operation described in the [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). diff --git a/onnx/defs/operator_sets.h b/onnx/defs/operator_sets.h index 552ddce622d..71e96634086 100644 --- a/onnx/defs/operator_sets.h +++ b/onnx/defs/operator_sets.h @@ -1186,13 +1186,99 @@ class OpSet_Onnx_ver21 { }; // Forward declarations for ai.onnx version 22 +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, EyeLike); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, RandomUniform); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, RandomNormal); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, RandomUniformLike); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, RandomNormalLike); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Multinomial); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Bernoulli); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, ThresholdedRelu); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Selu); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Elu); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Mish); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, HardSigmoid); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, HardSwish); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Softsign); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Softplus); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Sin); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Cos); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Tan); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Asin); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Acos); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Atan); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Sinh); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Cosh); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Asinh); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Acosh); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Atanh); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Round); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Det); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, NegativeLogLikelihoodLoss); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, AveragePool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, MaxPool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, MaxUnpool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, LpPool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, MaxRoiPool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Conv); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, ConvTranspose); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, DeformConv); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, GlobalAveragePool); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, InstanceNormalization); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, LpNormalization); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Dropout); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, RoiAlign); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, Resize); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 22, GridSample); // Iterate over schema from ai.onnx version 22 class OpSet_Onnx_ver22 { public: static void ForEachSchema(std::function fn) { - // TODO: Remove after introducing the first schema to opset 22 - (void)fn; + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); + fn(GetOpSchema()); } }; @@ -1227,7 +1313,7 @@ inline void RegisterOnnxOperatorSetSchema(int target_version, bool fail_duplicat // Update here if opset_version bumps // These calls for schema registration here are required to be in descending order for this to work correctly // - // Version-sepcific registration sees duplicate schema version request as error if fail_duplicate_schema + // Version-specific registration sees duplicate schema version request as error if fail_duplicate_schema RegisterOpSetSchema(target_version, fail_duplicate_schema); RegisterOpSetSchema(target_version, fail_duplicate_schema); RegisterOpSetSchema(target_version, fail_duplicate_schema); diff --git a/onnx/defs/operator_sets_preview.h b/onnx/defs/operator_sets_preview.h index 55ca07bdfb9..7060db8e004 100644 --- a/onnx/defs/operator_sets_preview.h +++ b/onnx/defs/operator_sets_preview.h @@ -8,7 +8,7 @@ namespace ONNX_NAMESPACE { -// Declare training operators. +// Declare training operators version 1 class ONNX_PREVIEW_OPERATOR_SET_SCHEMA_CLASS_NAME(1, Gradient); class ONNX_PREVIEW_OPERATOR_SET_SCHEMA_CLASS_NAME(1, Momentum); @@ -26,12 +26,25 @@ class OpSet_OnnxPreview_ver1 { } }; +// Declare training operators version 2 + +class ONNX_PREVIEW_OPERATOR_SET_SCHEMA_CLASS_NAME(2, Gradient); + +// Iterate over schema from ai.onnx.training version 2 +class OpSet_OnnxPreview_ver2 { + public: + static void ForEachSchema(std::function fn) { + fn(GetOpSchema()); + } +}; + // Register preview operators. inline void RegisterOnnxPreviewOperatorSetSchema() { // Preview operators should have only one version. // If changes are needed for a specific preview operator, // its spec should be modified without increasing its version. RegisterOpSetSchema(); + RegisterOpSetSchema(); } } // namespace ONNX_NAMESPACE diff --git a/onnx/defs/rnn/defs.cc b/onnx/defs/rnn/defs.cc index b5844444ca8..4bae7060547 100644 --- a/onnx/defs/rnn/defs.cc +++ b/onnx/defs/rnn/defs.cc @@ -167,16 +167,13 @@ std::function RNNDocGenerator(const char* /*name*/) { true, 1, OpSchema::Differentiable); - schema.TypeConstraint( - "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors."); + schema.TypeConstraint("T", OpSchema::all_float_types_ir10(), "Constrain input and output types to float tensors."); schema.TypeConstraint("T1", {"tensor(int32)"}, "Constrain seq_lens to integer tensor."); schema.TypeAndShapeInferenceFunction(RNNShapeInference); }; } -static const char* RNN_ver14_doc = R"DOC( +static const char* RNN_ver22_doc = R"DOC( Computes an one-layer simple RNN. This operator is usually supported via some custom implementation such as CuDNN. @@ -220,9 +217,9 @@ Equations (Default: f=Tanh): ONNX_OPERATOR_SET_SCHEMA( RNN, - 14, + 22, OpSchema() - .SetDoc(GET_OP_DOC_STR(std::string(RNN_ver14_doc) + GenerateOptionalArgumentsDoc())) + .SetDoc(GET_OP_DOC_STR(std::string(RNN_ver22_doc) + GenerateOptionalArgumentsDoc())) .Attr( "activations", "One (or two if bidirectional) activation function for " diff --git a/onnx/defs/rnn/old.cc b/onnx/defs/rnn/old.cc index 51fe5960f8b..8153f2e7684 100644 --- a/onnx/defs/rnn/old.cc +++ b/onnx/defs/rnn/old.cc @@ -5,6 +5,265 @@ #include "onnx/defs/schema.h" namespace ONNX_NAMESPACE { +void RNNShapeInference_opset14(InferenceContext& ctx) { + TensorShapeProto::Dimension num_directions, seq_length, batch_size, hidden_size; + + auto direction = getAttribute(ctx, "direction", "forward"); + if ((direction == "forward") || (direction == "reverse")) + num_directions.set_dim_value(1); + else if (direction == "bidirectional") + num_directions.set_dim_value(2); + // else leave num_directions unknown in case of incorrect attribute value + + auto hidden_size_value = getAttribute(ctx, "hidden_size", -1); + if (hidden_size_value > 0) + hidden_size.set_dim_value(hidden_size_value); + + auto layout_value = getAttribute(ctx, "layout", 0); + + if (hasInputShape(ctx, 0)) { + auto& first_input_shape = getInputShape(ctx, 0); + if (first_input_shape.dim_size() != 3) { + fail_shape_inference("First input tensor must have rank 3"); + } + seq_length = first_input_shape.dim((layout_value == 0) ? 0 : 1); + batch_size = first_input_shape.dim((layout_value == 0) ? 1 : 0); + } + + auto num_outputs = ctx.getNumOutputs(); + + if (num_outputs > 0) { + // Y + propagateElemTypeFromInputToOutput(ctx, 0, 0); + + if (layout_value == 0) { + auto dims = {seq_length, num_directions, batch_size, hidden_size}; + updateOutputShape(ctx, 0, dims); + } else { + auto dims = {batch_size, seq_length, num_directions, hidden_size}; + updateOutputShape(ctx, 0, dims); + } + } + + if (num_outputs > 1) { + // Y_h + propagateElemTypeFromInputToOutput(ctx, 0, 1); + + if (layout_value == 0) { + auto dims = {num_directions, batch_size, hidden_size}; + updateOutputShape(ctx, 1, dims); + } else { + auto dims = {batch_size, num_directions, hidden_size}; + updateOutputShape(ctx, 1, dims); + } + } + + if (num_outputs > 2) { + // Y_c : only in the case of LSTM + propagateElemTypeFromInputToOutput(ctx, 0, 2); + + if (layout_value == 0) { + auto dims = {num_directions, batch_size, hidden_size}; + updateOutputShape(ctx, 2, dims); + } else { + auto dims = {batch_size, num_directions, hidden_size}; + updateOutputShape(ctx, 2, dims); + } + } +} +std::function RNNDocGenerator_opset14(const char* /*name*/) { + return [=](OpSchema& schema) { + schema.Attr( + "direction", + "Specify if the RNN is forward, reverse, or bidirectional. " + "Must be one of forward (default), reverse, or bidirectional.", + AttributeProto::STRING, + std::string("forward")); + schema.Attr( + "layout", + "The shape format of inputs X, initial_h and outputs Y, Y_h. " + "If 0, the following shapes are expected: " + "X.shape = [seq_length, batch_size, input_size], " + "Y.shape = [seq_length, num_directions, batch_size, hidden_size], " + "initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. " + "If 1, the following shapes are expected: " + "X.shape = [batch_size, seq_length, input_size], " + "Y.shape = [batch_size, seq_length, num_directions, hidden_size], " + "initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].", + AttributeProto::INT, + static_cast(0)); + schema.Attr("hidden_size", "Number of neurons in the hidden layer", AttributeProto::INT, OPTIONAL_VALUE); + schema.Attr( + "activation_alpha", + "Optional scaling values used by some activation functions. The values " + "are consumed in the order of activation functions, for example (f, g, h) " + "in LSTM. Default values are the same as of corresponding ONNX operators." + "For example with LeakyRelu, the default alpha is 0.01.", + AttributeProto::FLOATS, + OPTIONAL_VALUE); + schema.Attr( + "activation_beta", + "Optional scaling values used by some activation functions. The values " + "are consumed in the order of activation functions, for example (f, g, h) " + "in LSTM. Default values are the same as of corresponding ONNX operators.", + AttributeProto::FLOATS, + OPTIONAL_VALUE); + schema.Attr( + "clip", + "Cell clip threshold. Clipping bounds the elements of a tensor " + "in the range of [-threshold, +threshold] and is applied to the input " + "of activations. No clip if not specified.", + AttributeProto::FLOAT, + OPTIONAL_VALUE); + schema.Input( + 0, + "X", + "The input sequences packed (and potentially padded) into one 3-D " + "tensor with the shape of `[seq_length, batch_size, input_size]`.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable); + schema.Input( + 4, + "sequence_lens", + "Optional tensor specifying lengths of the sequences in a batch. " + "If not specified - assumed all sequences in the batch to have " + "length `seq_length`. It has shape `[batch_size]`.", + "T1", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable); + schema.Input( + 5, + "initial_h", + "Optional initial value of the hidden. If not specified - assumed " + "to be 0. It has shape `[num_directions, batch_size, hidden_size]`.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable); + schema.Output( + 0, + "Y", + "A tensor that concats all the intermediate output values of the hidden. " + "It has shape `[seq_length, num_directions, batch_size, hidden_size]`. ", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::Differentiable); + schema.Output( + 1, + "Y_h", + "The last output value of the hidden. It has shape " + "`[num_directions, batch_size, hidden_size]`.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::Differentiable); + schema.TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors."); + schema.TypeConstraint("T1", {"tensor(int32)"}, "Constrain seq_lens to integer tensor."); + schema.TypeAndShapeInferenceFunction(RNNShapeInference_opset14); + }; +} +static const char* RNN_ver14_doc = R"DOC( +Computes an one-layer simple RNN. This operator is usually supported +via some custom implementation such as CuDNN. + +Notations: + +* `X` - input tensor +* `i` - input gate +* `t` - time step (t-1 means previous time step) +* `Wi` - W parameter weight matrix for input gate +* `Ri` - R recurrence weight matrix for input gate +* `Wbi` - W parameter bias vector for input gate +* `Rbi` - R parameter bias vector for input gate +* `WBi` - W parameter weight matrix for backward input gate +* `RBi` - R recurrence weight matrix for backward input gate +* `WBbi` - WR bias vectors for backward input gate +* `RBbi` - RR bias vectors for backward input gate +* `H` - Hidden state +* `num_directions` - 2 if direction == bidirectional else 1 + +Activation functions: + +* Relu(x) - max(0, x) +* Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) +* Sigmoid(x) - 1/(1 + e^{-x}) + +NOTE: Below are optional + +* Affine(x) - alpha*x + beta +* LeakyRelu(x) - x if x >= 0 else alpha * x +* ThresholdedRelu(x) - x if x >= alpha else 0 +* ScaledTanh(x) - alpha*Tanh(beta*x) +* HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) +* Elu(x) - x if x >= 0 else alpha*(e^x - 1) +* Softsign(x) - x/(1 + |x|) +* Softplus(x) - log(1 + e^x) + +Equations (Default: f=Tanh): + +* Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + RNN, + 14, + OpSchema() + .SetDoc(GET_OP_DOC_STR(std::string(RNN_ver14_doc) + GenerateOptionalArgumentsDoc())) + .Attr( + "activations", + "One (or two if bidirectional) activation function for " + "input gate. The activation function must be one of the activation " + "functions specified above. Optional: Default `Tanh` if not specified.", + AttributeProto::STRINGS, + std::vector{"Tanh", "Tanh"}) + .Input( + 1, + "W", + "The weight tensor for input gate. Concatenation of `Wi` and `WBi` " + "(if bidirectional). The tensor has shape " + "`[num_directions, hidden_size, input_size]`.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 2, + "R", + "The recurrence weight tensor. Concatenation of `Ri` and `RBi` " + "(if bidirectional). The tensor has shape " + "`[num_directions, hidden_size, hidden_size]`.", + "T", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 3, + "B", + "The bias tensor for input gate. Concatenation of `[Wbi, Rbi]` " + "and `[WBbi, RBbi]` (if bidirectional). The tensor has shape " + "`[num_directions, 2*hidden_size]`. Optional: If not specified - assumed " + "to be 0.", + "T", + OpSchema::Optional, + true, + 1, + OpSchema::Differentiable) + .FillUsing(RNNDocGenerator_opset14("RNN"))); + std::function RNNDocGeneratorOld(const char* /*name*/) { return [=](OpSchema& schema) { schema.Attr( diff --git a/onnx/defs/schema.h b/onnx/defs/schema.h index e786a96b299..d78eea8bb69 100644 --- a/onnx/defs/schema.h +++ b/onnx/defs/schema.h @@ -1185,7 +1185,7 @@ class OpSchemaRegistry final : public ISchemaRegistry { // Version corresponding last release of ONNX. Update this to match with // the max version above in a *release* version of ONNX. But in other // versions, the max version may be ahead of the last-release-version. - last_release_version_map_[ONNX_DOMAIN] = 21; + last_release_version_map_[ONNX_DOMAIN] = 22; last_release_version_map_[AI_ONNX_ML_DOMAIN] = 5; last_release_version_map_[AI_ONNX_TRAINING_DOMAIN] = 1; last_release_version_map_[AI_ONNX_PREVIEW_TRAINING_DOMAIN] = 1; diff --git a/onnx/defs/tensor/defs.cc b/onnx/defs/tensor/defs.cc index 5cad024803d..928aa9a3908 100644 --- a/onnx/defs/tensor/defs.cc +++ b/onnx/defs/tensor/defs.cc @@ -2139,7 +2139,7 @@ ONNX_OPERATOR_SET_SCHEMA( .SetDoc(Upsample_ver10_doc) .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { resizeShapeInference_opset7_to_10(ctx); })); -static const char* Resize_ver19_doc = R"DOC( +static const char* Resize_ver22_doc = R"DOC( Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. Each dimension value of the output tensor is: ``` @@ -2148,7 +2148,7 @@ output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \"sizes\" is not specified. )DOC"; -static const char* Resize_ver19_attr_coordinate_transformation_mode_doc = R"DOC( +static const char* Resize_ver22_attr_coordinate_transformation_mode_doc = R"DOC( This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor. The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. @@ -2194,7 +2194,7 @@ x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * ``` .)DOC"; -static const char* Resize_ver19_attr_keep_aspect_ratio_policy_doc = R"DOC( +static const char* Resize_ver22_attr_keep_aspect_ratio_policy_doc = R"DOC( This attribute describes how to interpret the `sizes` input with regard to keeping the original aspect ratio of the input, and it is not applicable when the `scales` input is used. @@ -2221,7 +2221,7 @@ Note: `round_int` stands for computing the nearest integer value, rounding halfw ONNX_OPERATOR_SET_SCHEMA( Resize, - 19, + 22, OpSchema() .Attr( "mode", @@ -2245,7 +2245,7 @@ ONNX_OPERATOR_SET_SCHEMA( static_cast(0)) .Attr( "coordinate_transformation_mode", - Resize_ver19_attr_coordinate_transformation_mode_doc, + Resize_ver22_attr_coordinate_transformation_mode_doc, AttributeProto::STRING, std::string("half_pixel")) .Attr( @@ -2275,7 +2275,7 @@ ONNX_OPERATOR_SET_SCHEMA( false) .Attr( "keep_aspect_ratio_policy", - Resize_ver19_attr_keep_aspect_ratio_policy_doc, + Resize_ver22_attr_keep_aspect_ratio_policy_doc, AttributeProto::STRING, std::string("stretch")) .Input(0, "X", "N-D tensor", "T1", OpSchema::Single, true, 1, OpSchema::Differentiable) @@ -2315,16 +2315,13 @@ ONNX_OPERATOR_SET_SCHEMA( .Output(0, "Y", "N-D tensor after resizing", "T1", OpSchema::Single, true, 1, OpSchema::Differentiable) .TypeConstraint( "T1", - OpSchema::all_tensor_types_ir4(), + OpSchema::all_tensor_types_ir10(), "Constrain input 'X' and output 'Y' to all tensor types.") - .TypeConstraint( - "T2", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain roi type to float or double.") - .SetDoc(Resize_ver19_doc) + .TypeConstraint("T2", OpSchema::all_float_types_ir10(), "Constrain roi type to float or double.") + .SetDoc(Resize_ver22_doc) .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { resizeShapeInference_opset18_to_19(ctx); })); -static const char* GridSample_ver20_doc = R"DOC( +static const char* GridSample_ver22_doc = R"DOC( Given an input `X` and a flow-field `grid`, computes the output `Y` using `X` values and pixel locations from the `grid`. For spatial input `X` with shape (N, C, H, W), the `grid` will have shape (N, H_out, W_out, 2), the output `Y` will have shape (N, C, H_out, W_out). For volumetric input `X` with shape (N, C, D, H, W), @@ -2347,7 +2344,7 @@ See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/stable/ge ONNX_OPERATOR_SET_SCHEMA( GridSample, - 20, + 22, OpSchema() .Attr( "mode", @@ -2413,13 +2410,10 @@ ONNX_OPERATOR_SET_SCHEMA( OpSchema::Differentiable) .TypeConstraint( "T1", - OpSchema::all_tensor_types(), + OpSchema::all_tensor_types_ir10(), "Constrain input `X` and output `Y` types to all tensor types.") - .TypeConstraint( - "T2", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain grid types to float tensors.") - .SetDoc(GridSample_ver20_doc) + .TypeConstraint("T2", OpSchema::all_float_types_ir10(), "Constrain grid types to float tensors.") + .SetDoc(GridSample_ver22_doc) .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { gridSampleShapeInference(ctx); })); static const char* AffineGrid_ver20_doc = R"DOC( diff --git a/onnx/defs/tensor/old.cc b/onnx/defs/tensor/old.cc index b7188b84b46..97043d691d4 100644 --- a/onnx/defs/tensor/old.cc +++ b/onnx/defs/tensor/old.cc @@ -13,6 +13,289 @@ namespace ONNX_NAMESPACE { +static const char* GridSample_ver20_doc = R"DOC( +Given an input `X` and a flow-field `grid`, computes the output `Y` using `X` values and pixel locations from the `grid`. +For spatial input `X` with shape (N, C, H, W), the `grid` will have shape (N, H_out, W_out, 2), +the output `Y` will have shape (N, C, H_out, W_out). For volumetric input `X` with shape (N, C, D, H, W), +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). +More generally, for an input `X` of rank r+2 with shape (N, C, d1, d2, ..., dr), +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). + +The tensor `X` contains values at centers of square pixels (voxels, etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). +The (n, d1_out, d2_out, ..., dr_out, :) values from the tensor `grid` are the normalized positions for interpolating the values +at the (n, c, d1_out, d2_out, ..., dr_out) locations from the output tensor `Y` using a specified interpolation method (the mode) +and a padding mode (for `grid` positions falling outside the 2-dimensional image). + +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`. +They are used to interpolate output values of `Y[n, c, h_out, w_out]`. + +The GridSample operator is often used in doing grid generator and sampler in the +[Spatial Transformer Networks](https://arxiv.org/abs/1506.02025). +See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html). +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + GridSample, + 20, + OpSchema() + .Attr( + "mode", + "Three interpolation modes: linear (default), nearest and cubic. " + "The \"linear\" mode includes linear and N-linear interpolation modes depending on the number of spatial dimensions " + "of the input tensor (i.e. linear for 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). " + "The \"cubic\" mode also includes N-cubic interpolation modes following the same rules. The \"nearest\" mode rounds " + "to the nearest even index when the sampling point falls halfway between two indices.", + AttributeProto::STRING, + std::string("linear")) + .Attr( + "padding_mode", + "Support padding modes for outside grid values: `zeros`(default), `border`, `reflection`. " + "zeros: use 0 for out-of-bound grid locations, " + "border: use border values for out-of-bound grid locations, " + "reflection: use values at locations reflected by the border for out-of-bound grid locations. " + "If index 0 represents the margin pixel, the reflected value at index -1 will be the same as the value at index 1. " + "For location far away from the border, it will keep being reflected until becoming in bound. " + "If pixel location x = -3.5 reflects by border -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = 0.5.", + AttributeProto::STRING, + std::string("zeros")) + .Attr( + "align_corners", + "If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input's corner pixels (voxels, etc.). " + "If align_corners=0, they are instead considered as referring to the corner points of the input's corner pixels (voxels, etc.), " + "making the sampling more resolution agnostic.", + AttributeProto::INT, + static_cast(0)) + .Input( + 0, + "X", + "Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N is the batch size, " + "C is the number of channels, D1, D2, ..., Dr are the spatial dimensions.", + "T1", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .Input( + 1, + "grid", + "Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, D2_out, ..., " + "Dr_out are the spatial dimensions of the grid and output, and r is the number of spatial dimensions. " + "Grid specifies the sampling locations normalized by the input spatial dimensions. " + "Therefore, it should have most values in the range of [-1, 1]. If the grid has values outside the range of [-1, 1], " + "the corresponding outputs will be handled as defined by padding_mode. Following computer vision convention, " + "the coordinates in the length-r location vector are listed from the innermost tensor dimension to the outermost, " + "the opposite of regular tensor indexing.", + "T2", + OpSchema::Single, + true, + 1, + OpSchema::NonDifferentiable) + .Output( + 0, + "Y", + "Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., Dr_out) of the sampled values. " + "For integer input types, intermediate values are computed as floating point and cast to integer at the end.", + "T1", + OpSchema::Single, + true, + 1, + OpSchema::Differentiable) + .TypeConstraint( + "T1", + OpSchema::all_tensor_types(), + "Constrain input `X` and output `Y` types to all tensor types.") + .TypeConstraint( + "T2", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain grid types to float tensors.") + .SetDoc(GridSample_ver20_doc) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { gridSampleShapeInference(ctx); })); + +static const char* Resize_ver19_attr_keep_aspect_ratio_policy_doc = R"DOC( +This attribute describes how to interpret the `sizes` input with regard to keeping the original aspect ratio of the input, and it is not applicable when +the `scales` input is used. + +Given a set of `sizes`, associated with a subset of `axes` (explicitly provided or default), and assuming `d = axes[i]`, with `i` being the index of the provided `sizes`. + +If `keep_aspect_ratio_policy` is `"stretch"`, the original aspect ratio is disregarded, and the input is resized to the specified size: +`out_size[d] = sizes[i]` + +If `keep_aspect_ratio_policy` is `"not_larger"`, the sizes are adjusted so that no extent of the output is larger than the specified size, while keeping the original aspect ratio: +``` +scale = Min(sizes[i] / in_size[d]) +out_size[d] = round_int(scale * in_size[i]) +``` + +If `keep_aspect_ratio_policy` is `"not_smaller"`, the sizes are adjusted so that no extent of the output is smaller than the specified size, while keeping the original aspect ratio: +``` +scale = Max(sizes[i] / in_size[d]) +out_size[d] = round_int(scale * in_size[i]) +``` + +For non-resizable axes (those not specified in `axes`), the output size will be equal to the input size. + +Note: `round_int` stands for computing the nearest integer value, rounding halfway cases up.)DOC"; + +static const char* Resize_ver19_attr_coordinate_transformation_mode_doc = R"DOC( +This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor. + +The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. +Denote `x_resized` as the coordinate of axis x in the resized tensor, + `x_original` as the coordinate of axis x in the original tensor, + `length_original` as the length of the original tensor in axis x, + `length_resized` as the length of the resized tensor in axis x, + `scale = length_resized / length_original`, + `output_width` the target length on the axis x which can be a fractional number when it is calculated out of a scale factor, + and `output_width_int` the effective output width as an integer. + +if coordinate_transformation_mode is `"half_pixel"`, +``` +x_original = (x_resized + 0.5) / scale - 0.5 +``` + +if coordinate_transformation_mode is `"half_pixel_symmetric"`, +``` +adjustment = output_width_int / output_width +center = input_width / 2 +offset = center * (1 - adjustment) +x_ori = offset + (x + 0.5) / scale - 0.5 +``` + +if coordinate_transformation_mode is `"pytorch_half_pixel"`, +``` +x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 +``` + +if coordinate_transformation_mode is `"align_corners"`, +``` +x_original = x_resized * (length_original - 1) / (length_resized - 1) +``` + +if coordinate_transformation_mode is `"asymmetric"`, +``` +x_original = x_resized / scale +``` + +if coordinate_transformation_mode is `"tf_crop_and_resize"`, +``` +x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) +``` +.)DOC"; + +static const char* Resize_ver19_doc = R"DOC( +Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. +Each dimension value of the output tensor is: +``` +output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) +``` +if input \"sizes\" is not specified. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Resize, + 19, + OpSchema() + .Attr( + "mode", + "Three interpolation modes: \"nearest\" (default), \"linear\" and \"cubic\". " + "The \"linear\" mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). " + "The \"cubic\" mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).", + AttributeProto::STRING, + std::string("nearest")) + .Attr( + "cubic_coeff_a", + "The coefficient 'a' used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75" + " (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. " + "This attribute is valid only if mode is \"cubic\".", + AttributeProto::FLOAT, + static_cast(-0.75)) + .Attr( + "exclude_outside", + "If set to 1, the weight of sampling locations outside the tensor will be set to 0" + " and the weight will be renormalized so that their sum is 1.0. The default value is 0.", + AttributeProto::INT, + static_cast(0)) + .Attr( + "coordinate_transformation_mode", + Resize_ver19_attr_coordinate_transformation_mode_doc, + AttributeProto::STRING, + std::string("half_pixel")) + .Attr( + "nearest_mode", + "Four modes: \"round_prefer_floor\" (default, as known as round half down), \"round_prefer_ceil\" (as known as round half up), \"floor\", \"ceil\". Only used by nearest interpolation. It indicates how to get \"nearest\" pixel in input tensor from x_original, so this attribute is valid only if \"mode\" is \"nearest\".", + AttributeProto::STRING, + std::string("round_prefer_floor")) + .Attr( + "extrapolation_value", + "When coordinate_transformation_mode is \"tf_crop_and_resize\" and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.", + AttributeProto::FLOAT, + static_cast(0)) + .Attr( + "antialias", + "If set to 1, \"linear\" and \"cubic\" interpolation modes will use an antialiasing filter when downscaling. " + "Antialiasing is achieved by stretching the resampling filter by a factor max(1, 1 / scale), which means that when downsampling, more input pixels contribute to an output pixel.", + AttributeProto::INT, + static_cast(0)) + .Attr( + "axes", + "If provided, it specifies a subset of axes that 'roi', 'scales' and 'sizes' refer to. " + "If not provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). " + "Non-specified dimensions are interpreted as non-resizable. " + "Negative value means counting dimensions from the back. Accepted range is [-r, r-1], where r = rank(data). " + "Behavior is undefined if an axis is repeated.", + AttributeProto::INTS, + false) + .Attr( + "keep_aspect_ratio_policy", + Resize_ver19_attr_keep_aspect_ratio_policy_doc, + AttributeProto::STRING, + std::string("stretch")) + .Input(0, "X", "N-D tensor", "T1", OpSchema::Single, true, 1, OpSchema::Differentiable) + .Input( + 1, + "roi", + "1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is the rank of X or the length of axes, if provided. " + "The RoIs' coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is \"tf_crop_and_resize\"", + "T2", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Input( + 2, + "scales", + "The scale array along each dimension. It takes value greater than 0. If it's less than 1," + " it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should" + " be the same as the rank of input 'X' or the length of 'axes', if provided. " + "One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.", + "tensor(float)", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Input( + 3, + "sizes", + "Target size of the output tensor. Its interpretation depends on the 'keep_aspect_ratio_policy' value." + "The number of elements of 'sizes' should be the same as the" + " rank of input 'X', or the length of 'axes', if provided. Only one of 'scales' and 'sizes' can be specified. ", + "tensor(int64)", + OpSchema::Optional, + true, + 1, + OpSchema::NonDifferentiable) + .Output(0, "Y", "N-D tensor after resizing", "T1", OpSchema::Single, true, 1, OpSchema::Differentiable) + .TypeConstraint( + "T1", + OpSchema::all_tensor_types_ir4(), + "Constrain input 'X' and output 'Y' to all tensor types.") + .TypeConstraint( + "T2", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain roi type to float or double.") + .SetDoc(Resize_ver19_doc) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { resizeShapeInference_opset18_to_19(ctx); })); + static const char* Cast_ver19_doc = R"DOC( The operator casts the elements of a given input tensor to a data type specified by the 'to' argument and returns an output tensor of the same size in diff --git a/onnx/defs/traditionalml/defs.cc b/onnx/defs/traditionalml/defs.cc index 146b290db83..231da5c2955 100644 --- a/onnx/defs/traditionalml/defs.cc +++ b/onnx/defs/traditionalml/defs.cc @@ -998,7 +998,7 @@ ONNX_ML_OPERATOR_SET_SCHEMA( AttributeProto::TENSOR, OPTIONAL_VALUE)); -static const char* TreeEnsemble_ver5_doc = R"DOC( +static const char* TreeEnsemble_ver22_doc = R"DOC( Tree Ensemble operator. Returns the regressed values for each input in a batch. Inputs have dimensions `[N, F]` where `N` is the input batch size and `F` is the number of input features. Outputs have dimensions `[N, num_targets]` where `N` is the batch size and `num_targets` is the number of targets, which is a configurable attribute. @@ -1016,15 +1016,12 @@ static const char* TreeEnsemble_ver5_doc = R"DOC( ONNX_ML_OPERATOR_SET_SCHEMA( TreeEnsemble, - 5, + 22, OpSchema() - .SetDoc(TreeEnsemble_ver5_doc) + .SetDoc(TreeEnsemble_ver22_doc) .Input(0, "X", "Input of shape [Batch Size, Number of Features]", "T") .Output(0, "Y", "Output of shape [Batch Size, Number of targets]", "T") - .TypeConstraint( - "T", - {"tensor(float)", "tensor(double)", "tensor(float16)"}, - "The input type must be a tensor of a numeric type.") + .TypeConstraint("T", OpSchema::all_float_types_ir10(), "The input type must be a tensor of a numeric type.") .Attr("nodes_featureids", "Feature id for each node.", AttributeProto::INTS, true) .Attr( "nodes_splits", diff --git a/onnx/defs/traditionalml/old.cc b/onnx/defs/traditionalml/old.cc index 0bf9819ec4a..37b67618403 100644 --- a/onnx/defs/traditionalml/old.cc +++ b/onnx/defs/traditionalml/old.cc @@ -3,9 +3,212 @@ */ #include "onnx/defs/schema.h" +#include "onnx/defs/traditionalml/utils.h" #ifdef ONNX_ML namespace ONNX_NAMESPACE { + +static const char* TreeEnsemble_ver5_doc = R"DOC( + Tree Ensemble operator. Returns the regressed values for each input in a batch. + Inputs have dimensions `[N, F]` where `N` is the input batch size and `F` is the number of input features. + Outputs have dimensions `[N, num_targets]` where `N` is the batch size and `num_targets` is the number of targets, which is a configurable attribute. + + The encoding of this attribute is split along interior nodes and the leaves of the trees. Notably, attributes with the prefix `nodes_*` are associated with interior nodes, and attributes with the prefix `leaf_*` are associated with leaves. + The attributes `nodes_*` must all have the same length and encode a sequence of tuples, as defined by taking all the `nodes_*` fields at a given position. + + All fields prefixed with `leaf_*` represent tree leaves, and similarly define tuples of leaves and must have identical length. + + This operator can be used to implement both the previous `TreeEnsembleRegressor` and `TreeEnsembleClassifier` nodes. + The `TreeEnsembleRegressor` node maps directly to this node and requires changing how the nodes are represented. + The `TreeEnsembleClassifier` node can be implemented by adding a `ArgMax` node after this node to determine the top class. + To encode class labels, a `LabelEncoder` or `GatherND` operator may be used. +)DOC"; + +ONNX_ML_OPERATOR_SET_SCHEMA( + TreeEnsemble, + 5, + OpSchema() + .SetDoc(TreeEnsemble_ver5_doc) + .Input(0, "X", "Input of shape [Batch Size, Number of Features]", "T") + .Output(0, "Y", "Output of shape [Batch Size, Number of targets]", "T") + .TypeConstraint( + "T", + {"tensor(float)", "tensor(double)", "tensor(float16)"}, + "The input type must be a tensor of a numeric type.") + .Attr("nodes_featureids", "Feature id for each node.", AttributeProto::INTS, true) + .Attr( + "nodes_splits", + "Thresholds to do the splitting on for each node with mode that is not 'BRANCH_MEMBER'.", + AttributeProto::TENSOR, + true) + .Attr( + "nodes_hitrates", + "Popularity of each node, used for performance and may be omitted.", + AttributeProto::TENSOR, + OPTIONAL_VALUE) + .Attr( + "nodes_modes", + "The comparison operation performed by the node. This is encoded as an enumeration of 0 ('BRANCH_LEQ'), 1 " + "('BRANCH_LT'), 2 ('BRANCH_GTE'), 3 ('BRANCH_GT'), 4 ('BRANCH_EQ'), 5 ('BRANCH_NEQ'), and 6 " + "('BRANCH_MEMBER'). Note this is a tensor of type uint8.", + AttributeProto::TENSOR, + true) + .Attr( + "nodes_truenodeids", + "If `nodes_trueleafs` is false at an entry, this represents the position of the true branch node. This " + "position can be used to index into a `nodes_*` entry. If `nodes_trueleafs` is false, it is an index into " + "the leaf_* attributes.", + AttributeProto::INTS, + true) + .Attr( + "nodes_falsenodeids", + "If `nodes_falseleafs` is false at an entry, this represents the position of the false branch node. This " + "position can be used to index into a `nodes_*` entry. If `nodes_falseleafs` is false, it is an index into " + "the leaf_* attributes.", + AttributeProto::INTS, + true) + .Attr( + "nodes_trueleafs", + "1 if true branch is leaf for each node and 0 an interior node. To represent a tree that is a leaf (only " + "has one node), one can do so by having a single `nodes_*` entry with true and false branches referencing " + "the same `leaf_*` entry", + AttributeProto::INTS, + true) + .Attr( + "nodes_falseleafs", + "1 if false branch is leaf for each node and 0 if an interior node. To represent a tree that is a leaf " + "(only has one node), one can do so by having a single `nodes_*` entry with true and false branches " + "referencing the same `leaf_*` entry", + AttributeProto::INTS, + true) + .Attr( + "nodes_missing_value_tracks_true", + "For each node, define whether to follow the true branch (if attribute value is 1) or false branch (if " + "attribute value is 0) in the presence of a NaN input feature. This attribute may be left undefined and " + "the default value is false (0) for all nodes.", + AttributeProto::INTS, + OPTIONAL_VALUE) + .Attr( + "tree_roots", + "Index into `nodes_*` for the root of each tree. The tree structure is derived from the branching of each " + "node.", + AttributeProto::INTS, + true) + .Attr( + "membership_values", + "Members to test membership of for each set membership node. List all of the members to test again in the " + "order that the 'BRANCH_MEMBER' mode appears in `node_modes`, delimited by `NaN`s. Will have the same " + "number " + "of sets of values as nodes with mode 'BRANCH_MEMBER'. This may be omitted if the node doesn't contain any " + "'BRANCH_MEMBER' nodes.", + AttributeProto::TENSOR, + OPTIONAL_VALUE) + .Attr( + "leaf_targetids", + "The index of the target that this leaf contributes to (this must be in range `[0, n_targets)`).", + AttributeProto::INTS, + true) + .Attr("leaf_weights", "The weight for each leaf.", AttributeProto::TENSOR, true) + .Attr("n_targets", "The total number of targets.", AttributeProto::INT, OPTIONAL_VALUE) + .Attr( + "post_transform", + "Indicates the transform to apply to the score.
One of 'NONE' (0), 'SOFTMAX' (1), 'LOGISTIC' (2), " + "'SOFTMAX_ZERO' (3) or 'PROBIT' (4), defaults to 'NONE' (0)", + AttributeProto::INT, + static_cast(0)) + .Attr( + "aggregate_function", + "Defines how to aggregate leaf values within a target.
One of 'AVERAGE' (0) 'SUM' (1) 'MIN' (2) 'MAX " + "(3) defaults to 'SUM' (1)", + AttributeProto::INT, + static_cast(1)) + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + checkInputRank(ctx, 0, 2); + auto* nodes_splits = ctx.getAttribute("nodes_splits"); + if (nullptr == nodes_splits) { + fail_shape_inference("Attribute 'nodes_splits' is required."); + } + if (nodes_splits->t().dims_size() != 1) { + fail_shape_inference("Attribute 'nodes_splits' must be 1D."); + } + auto input_type = ctx.getInputType(0)->tensor_type().elem_type(); + // Check that input type is same as split type + if (input_type != nodes_splits->t().data_type()) { + fail_shape_inference( + "Attribute 'nodes_splits' must have same type as input. Input type is ", + input_type, + " and attribute type is ", + nodes_splits->t().data_type()); + } + + // Expected nodes_* length + auto expected_length = nodes_splits->t().dims(0); + // Validate all nodes_* attributes that are set have the same length and are 1D. + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_featureids"), expected_length, TensorProto_DataType_INT64, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_hitrates"), expected_length, TensorProto_DataType_FLOAT, false); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_modes"), expected_length, TensorProto_DataType_UINT8, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_truenodeids"), expected_length, TensorProto_DataType_INT64, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_falsenodeids"), expected_length, TensorProto_DataType_INT64, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_trueleafs"), expected_length, TensorProto_DataType_INT64, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_falseleafs"), expected_length, TensorProto_DataType_INT64, true); + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_missing_value_tracks_true"), expected_length, TensorProto_DataType_INT64, false); + + // The set membership values and the splits must have the same type as the input. + auto* membership_values = ctx.getAttribute("membership_values"); + if (nullptr != membership_values && membership_values->t().data_type() != input_type) { + fail_shape_inference( + "Attribute 'membership_values' must have same type as input. Input type is ", + input_type, + " and attribute type is ", + membership_values->t().data_type()); + } + AssertAttributeProtoTypeAndLength( + ctx.getAttribute("nodes_splits"), expected_length, static_cast(input_type), true); + + // Validate all leaf_* attributes that are set have the same length and are 1D. + auto* leaf_targetids = ctx.getAttribute("leaf_targetids"); + auto* leaf_weights = ctx.getAttribute("leaf_weights"); + if (nullptr != leaf_targetids && nullptr != leaf_weights) { + if (leaf_targetids->ints_size() != leaf_weights->t().dims(0)) { + fail_shape_inference( + "Attribute 'leaf_targetids' must have same length as attribute 'leaf_weights'. 'leaf_targetids' " + "length is ", + leaf_targetids->ints_size(), + " and 'leaf_weights' length is ", + leaf_weights->t().dims(0)); + } + } else { + fail_shape_inference("Attributes 'leaf_targetids' and 'leaf_weights' must both be set."); + } + + // Validate weights have same type as input. + if (leaf_weights->t().data_type() != input_type) { + fail_shape_inference( + "Attribute 'leaf_weights' must have same type as input. Input type is ", + input_type, + " and attribute type is ", + leaf_weights->t().data_type()); + } + + checkInputRank(ctx, 0, 2); + + Dim N, E; + unifyInputDim(ctx, 0, 0, N); + if (nullptr != ctx.getAttribute("n_targets")) { + unifyDim(E, ctx.getAttribute("n_targets")->i()); + } + updateOutputElemType(ctx, 0, input_type); + updateOutputShape(ctx, 0, {N, E}); + })); + static const char* LabelEncoder_ver1_doc = R"DOC( Converts strings to integers and vice versa.
If the string default value is set, it will convert integers to strings. diff --git a/onnx/defs/traditionalml/utils.cc b/onnx/defs/traditionalml/utils.cc new file mode 100644 index 00000000000..0fadd7c093e --- /dev/null +++ b/onnx/defs/traditionalml/utils.cc @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "onnx/defs/traditionalml/utils.h" + +#include "onnx/defs/schema.h" +#include "onnx/defs/shape_inference.h" + +namespace ONNX_NAMESPACE { + +void AssertAttributeProtoTypeAndLength( + const AttributeProto* attr_proto, + int expected_length, + TensorProto_DataType expected_type, + bool required) { + if (nullptr == attr_proto) { + if (required) { + fail_shape_inference("Unspecified required attribute."); + } + return; + } + const auto& [type, length] = getAttributeProtoElemTypeAndLength(attr_proto); + if (type != expected_type) { + fail_shape_inference( + "Attribute '", attr_proto->name(), "' must have type ", TensorProto_DataType_Name(expected_type), "."); + } + if (length != expected_length) { + fail_shape_inference("Attribute '", attr_proto->name(), "' must have ", expected_length, " elements."); + } +} + +} // namespace ONNX_NAMESPACE diff --git a/onnx/defs/traditionalml/utils.h b/onnx/defs/traditionalml/utils.h index c0aeeab2b1d..c73bdb15d9f 100644 --- a/onnx/defs/traditionalml/utils.h +++ b/onnx/defs/traditionalml/utils.h @@ -1,3 +1,5 @@ +#pragma once + #include "onnx/defs/schema.h" #include "onnx/defs/shape_inference.h" @@ -7,21 +9,6 @@ void AssertAttributeProtoTypeAndLength( const AttributeProto* attr_proto, int expected_length, TensorProto_DataType expected_type, - bool required) { - if (nullptr == attr_proto) { - if (required) { - fail_shape_inference("Unspecified required attribute."); - } - return; - } - const auto& [type, length] = getAttributeProtoElemTypeAndLength(attr_proto); - if (type != expected_type) { - fail_shape_inference( - "Attribute '", attr_proto->name(), "' must have type ", TensorProto_DataType_Name(expected_type), "."); - } - if (length != expected_length) { - fail_shape_inference("Attribute '", attr_proto->name(), "' must have ", expected_length, " elements."); - } -} + bool required); } // namespace ONNX_NAMESPACE diff --git a/onnx/defs/training/defs.cc b/onnx/defs/training/defs.cc index 0c3ed7a6311..0967e9242ee 100644 --- a/onnx/defs/training/defs.cc +++ b/onnx/defs/training/defs.cc @@ -10,7 +10,7 @@ namespace ONNX_NAMESPACE { -static const char* Gradient_ver1_doc = R"DOC( +static const char* Gradient_ver2_doc = R"DOC( Gradient operator computes the partial derivatives of a specific tensor w.r.t. some other tensors. This operator is widely used in gradient-based training algorithms. To illustrate its use, let's consider a computation graph, @@ -138,9 +138,9 @@ auto-differentiation. ONNX_PREVIEW_TRAINING_OPERATOR_SET_SCHEMA( Gradient, - 1, + 2, OpSchema() - .SetDoc(Gradient_ver1_doc) + .SetDoc(Gradient_ver2_doc) .Input( 0, "Inputs", @@ -190,7 +190,7 @@ ONNX_PREVIEW_TRAINING_OPERATOR_SET_SCHEMA( .TypeConstraint("T1", OpSchema::all_tensor_types(), "Allow outputs to be any kind of tensor.") .TypeConstraint( "T2", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, + OpSchema::all_float_types_ir10(), "Allow inputs to be any kind of floating-point tensor.")); static const char* Adagrad_ver1_doc = R"DOC( diff --git a/onnx/defs/training/old.cc b/onnx/defs/training/old.cc new file mode 100644 index 00000000000..c9cf97c25e3 --- /dev/null +++ b/onnx/defs/training/old.cc @@ -0,0 +1,196 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include "onnx/defs/function.h" +#include "onnx/defs/schema.h" + +namespace ONNX_NAMESPACE { + +static const char* Gradient_ver1_doc = R"DOC( +Gradient operator computes the partial derivatives of a specific tensor w.r.t. +some other tensors. This operator is widely used in gradient-based training +algorithms. To illustrate its use, let's consider a computation graph, + +``` +X -----. + | + v +W --> Conv --> H --> Gemm --> Y + ^ + | + Z +``` + +, where W and Z are trainable tensors. Note that operators' attributes are +omitted for the sake of simplicity. Let dY/dW (dY/dZ) be the gradient of +Y with respect to W (Z). The user can compute gradient by inserting Gradient +operator to form another graph shown below. + +``` +W --> Conv --> H --> Gemm --> Y +| ^ ^ +| | | +| X Z +| | | +| | .----------' +| | | (W/Z/X is the 1st/2nd/3rd input of Gradient as shown in +| | | "xs" followed by "zs") +| v v +'---> Gradient(xs=["W", "Z"], zs=["X"], y="Y") + | | + | '-----------------------------------> dY/dW (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) +``` + +By definition, the tensor "y" is a function of independent variables in "xs" +and "zs". Since we only compute the gradient of "y" w.r.t. the differentiable +variables in "xs", this Gradient only outputs dY/dW and dY/dZ. Note that "H" +cannot appear in "xs" and "zs". The reason is that "H" can be determined by +tensors "W" and "X" and therefore "H" is not an independent variable. + +All outputs are optional. If needed, for example, user can assign an empty +string to the 1st output name of that Gradient to skip the generation of dY/dW. +Note that the concept of optional outputs can also be found in ONNX's RNN, GRU, +and LSTM. + +Gradient operator can compute derivative against intermediate tensors. For +example, the gradient of Y with respect to H can be done via + +``` +W --> Conv --> H --> Gemm --> Y + ^ | ^ + | | | + X | Z + .-------' | + | .----------' + | | (H/Z is the 1st/2nd input of Gradient as shown in "xs") + v v + Gradient(xs=["H", "Z"], y="Y") + | | + | '-----------------------------------> dY/dH (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) +``` + +It is possible to represent high-order differentiation using Gradient operators. +For example, given the following linear model: + +``` +W --> Gemm --> Y --> Loss --> O + ^ ^ + | | + X L +``` + +To compute the 2nd order derivative of O with respect to W (denoted by +d^2O/dW^2), one can do + +``` +W --> Gemm --> Y --> Loss --> O +| ^ ^ +| | | +| X .------------L +| | | | +| | | v ++------+-+> Gradient(xs=["X", "W"], zs=["L"], y="O") ---> dO/dX (1st output of Gradient) +| | | | +| | | '---> dO/dW (2nd output of Gradient) +| v v +'---> Gradient(xs=["X", "W"], zs=["L"], y="dO/dW") ---> d(dO/dW)dX (1st output of + | Gradient) + | + | + '---> d^2O/dW^2 (2nd output of Gradient) +``` + +The tensors named in attributes "xs", "zs", and "y" define the differentiated +computation graph, and the inputs to Gradient node define the values at +which the gradient is computed. We can feed different tensors to the identified +graph. For example, one can compute the gradient of Y with respect to H at +a specific value of H, H_1, by providing that value as an input to the Gradient +node. + +``` +W --> Conv --> H --> Gemm --> Y + ^ ^ + | | + X Z + + Z_1 (2nd input of Gradient) + | + v +H_1 --> Gradient(xs=["H", "Z"], y="Y") ---> dY/dH when H = H_1 and Y = Y_1. + | + '------------------------------> dY/dZ (2nd output of Gradient) +``` + +When the inputs of Gradient are the tensors named in "xs" and "zs", the +computation can be optimized. More specifically, intermediate variables in +forward pass can be reused if the gradient is computed via reverse-mode +auto-differentiation. + +)DOC"; + +ONNX_PREVIEW_TRAINING_OPERATOR_SET_SCHEMA( + Gradient, + 1, + OpSchema() + .SetDoc(Gradient_ver1_doc) + .Input( + 0, + "Inputs", + "The values fed into graph identified by the attributes. " + "The i-th input is the value of the i-th tensor specified in the " + "concatenated list of the attribute \"xs\" and the attribute " + " \"zs\". For example, if xs=[\"A\", \"B\"] and zs=[\"C\"], the " + "first input is used as the value of symbol \"A\" and the 3rd " + "input is substituted for all the occurrences of \"C\".", + "T1", + OpSchema::Variadic, + false) + .Output( + 0, + "Outputs", + "The gradient of the tensor specified by the attribute \"y\" " + "with respect to each of tensors specified in the " + "attribute \"xs\". The i-th output is the gradient of \"y\" with " + "respect to the i-th tensor specified in the attribute \"xs\".", + "T2", + OpSchema::Variadic, + false) + .Attr( + "xs", + "Input tensor names of the differentiated sub-graph. It " + "contains only the necessary differentiated " + "inputs of a (sub-)graph. Variables (usually called " + "intermediate variables) that can be generated from inputs " + "cannot be included in this attribute.", + AttributeProto::STRINGS) + .Attr( + "zs", + "Input tensor names of the differentiated sub-graph. It " + "contains only the necessary non-differentiated " + "inputs of a (sub-)graph. Variables (usually called " + "intermediate variables) that can be generated from inputs " + "cannot be included in this attribute.", + AttributeProto::STRINGS, + OPTIONAL_VALUE) + .Attr( + "y", + "The targeted tensor. It can be viewed as the output of the " + "differentiated function. The attribute \"xs\" and attribute " + "\"zs\" are the minimal independent variable set that determines " + "the value of \"y\".", + AttributeProto::STRING) + .TypeConstraint("T1", OpSchema::all_tensor_types(), "Allow outputs to be any kind of tensor.") + .TypeConstraint( + "T2", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Allow inputs to be any kind of floating-point tensor.")); + +} // namespace ONNX_NAMESPACE diff --git a/onnx/version_converter/convert.h b/onnx/version_converter/convert.h index 189f63d64ac..2b66ff7ce9b 100644 --- a/onnx/version_converter/convert.h +++ b/onnx/version_converter/convert.h @@ -671,6 +671,156 @@ class DefaultVersionConverter : public BaseVersionConverter { registerAdapter(std::make_unique("Squeeze", OpSetID(21), OpSetID(20), ir10_types_not_in_ir4)); registerAdapter(std::make_unique("Transpose", OpSetID(21), OpSetID(20), ir10_types_not_in_ir9)); registerAdapter(std::make_unique("Unsqueeze", OpSetID(21), OpSetID(20), ir10_types_not_in_ir4)); + + /******** 21 -> 22 ********/ + registerAdapter(std::make_unique("EyeLike", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("RandomUniform", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("RandomNormal", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("RandomUniformLike", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("RandomNormalLike", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Multinomial", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Bernoulli", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("ThresholdedRelu", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Selu", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Elu", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Mish", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("HardSigmoid", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("HardSwish", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Softsign", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Softplus", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Sin", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Cos", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Tan", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Asin", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Acos", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Atan", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Sinh", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Cosh", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Asinh", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Acosh", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Atanh", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Round", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Det", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("NegativeLogLikelihoodLoss", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("AveragePool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("MaxPool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("MaxUnpool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("LpPool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("MaxRoiPool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Conv", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("ConvTranspose", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("DeformConv", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("GlobalAveragePool", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("InstanceNormalization", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("LpNormalization", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Dropout", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("RoiAlign", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("Resize", OpSetID(21), OpSetID(22))); + registerAdapter(std::make_unique("GridSample", OpSetID(21), OpSetID(22))); + + /******** 22 -> 21 ********/ + const std::vector bfloat16_not_allowed = {TensorProto_DataType_BFLOAT16}; + registerAdapter(std::make_unique("EyeLike", OpSetID(22), OpSetID(21), bfloat16_not_allowed)); + registerAdapter(std::make_unique("AveragePool", OpSetID(22), OpSetID(21), bfloat16_not_allowed)); + registerAdapter(std::make_unique("MaxPool", OpSetID(22), OpSetID(21), bfloat16_not_allowed)); + + const std::vector bfloat16_and_float8_not_allowed = { + TensorProto_DataType_BFLOAT16, + TensorProto_DataType_FLOAT8E4M3FN, + TensorProto_DataType_FLOAT8E4M3FNUZ, + TensorProto_DataType_FLOAT8E5M2, + TensorProto_DataType_FLOAT8E5M2FNUZ}; + registerAdapter( + std::make_unique("RandomUniform", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("RandomNormal", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Multinomial", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Bernoulli", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter(std::make_unique( + "ThresholdedRelu", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Selu", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Elu", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Mish", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("HardSigmoid", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("HardSwish", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Softsign", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Softplus", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Sin", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Cos", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Tan", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Asin", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Acos", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Atan", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Sinh", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Cosh", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Asinh", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Acosh", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Atanh", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Round", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Det", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter(std::make_unique( + "NegativeLogLikelihoodLoss", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("MaxUnpool", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("LpPool", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("MaxRoiPool", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Conv", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("ConvTranspose", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("DeformConv", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter(std::make_unique( + "GlobalAveragePool", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter(std::make_unique( + "InstanceNormalization", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter(std::make_unique( + "LpNormalization", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Dropout", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("RoiAlign", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("Resize", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + registerAdapter( + std::make_unique("GridSample", OpSetID(22), OpSetID(21), bfloat16_and_float8_not_allowed)); + + const std::vector ir10_tensor_types_not_in_before_ir4 = { + TensorProto_DataType_INT4, + TensorProto_DataType_UINT4, + TensorProto_DataType_BFLOAT16, + TensorProto_DataType_FLOAT8E4M3FN, + TensorProto_DataType_FLOAT8E4M3FNUZ, + TensorProto_DataType_FLOAT8E5M2, + TensorProto_DataType_FLOAT8E5M2FNUZ}; + registerAdapter(std::make_unique( + "RandomNormalLike", OpSetID(22), OpSetID(21), ir10_tensor_types_not_in_before_ir4)); + registerAdapter(std::make_unique( + "RandomUniformLike", OpSetID(22), OpSetID(21), ir10_tensor_types_not_in_before_ir4)); } ModelProto convert_version(const ModelProto& mp_in, const OpSetID& initial_version, const OpSetID& target_version)