4.2.4.3. Supported Operators¶
4.2.4.3.1. Supported Torch Operator¶
The operators in the table below have the following restrictions unless otherwise specified: input/output data type int8, input_shape: [N, C, H, W], input_size <1 G bytes, 1<=N<=4096, 1<=H, W, C<=65536, Feature dimension: 4. If additional restriction information is added to the table, the table shall prevail.
Torch ops |
To prepare the floating point model, replace it with |
Bernoulli2 Support |
Bayes/Bayes-e Support |
|---|---|---|---|
torch.add |
torch.nn.quantized.FloatFunctional or horizon.nn.quantized.FloatFunctional |
Supported. QAT has training parameters and cannot be used alone in prediction. |
Support. QAT has training parameters and cannot be used alone in prediction. |
torch.sub |
horizon.nn.quantized.FloatFunctional |
Supported. QAT has training parameters and cannot be used alone in prediction. |
Support. QAT has training parameters and cannot be used alone in prediction. |
torch.mul |
torch.nn.quantized.FloatFunctional or horizon.nn.quantized.FloatFunctional |
Supported. QAT has training parameters and cannot be used alone in prediction. |
Support. QAT has training parameters and cannot be used alone in prediction. |
torch.sum |
horizon.nn.quantized.FloatFunctional |
only supports sum in batch and channel directions. QAT has |
Support. QAT has training parameters and cannot be used alone in prediction. |
torch.matmul |
horizon.nn.quantized.FloatFunctional |
Supported. For matmul(a, b), |
support. Input int8, output int8/int16/int32. |
torch.cat |
torch.nn.quantized.FloatFunctional or horizon.nn.quantized.FloatFunctional |
For cat(a, b), the difference between a and b should not be too large, otherwise |
For cat(a, b), the difference between a and b should not be too large, otherwise |
torch.maximum |
horizon.nn.quantized.FloatFunctional |
Not supported |
Support input and output int8/int16 |
torch.minimum |
horizon.nn.quantized.FloatFunctional |
Not supported |
Support input and output int8/int16 |
torch.mean |
horizon.nn.quantized.FloatFunctional |
Only the mean in the channel direction is supported. The training parameters are provided in the QAT and cannot be used alone in prediction. |
Find mean on the CHW.The training parameters are provided in the QAT and cannot be used alone in prediction. The input/output supports int8/int16. |
torch.sqrt |
horizon.nn.Sqrt |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.atan |
horizon.nn.Atan |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.sin |
horizon.nn.Sin |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.cos |
horizon.nn.Cos |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.clamp/clip, tensor.clamp/clip |
Not supported |
Supported inputs for min and max are Tensor/constant Tensor/scalar/None. When it is a constant Tensor, the input data range of min and max should be consistent with the input, otherwise there is a risk of precision |
|
torch.pow |
horizon.nn.Pow |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.max |
support. Only available as model output. The output format is different from torch: the output supported by the compiler |
supported. Input supports int8/int16. One output is int8/16 value and the other is int32 index. The index can only be available as model output. Input_shape: [N, C, H, W], 1<=N<=4096, 1<=H, W, C<=65535 |
|
torch.min |
Not supported |
Refer to torch.max |
|
tensor.max |
Refer to torch.max |
Refer to torch.max |
|
tensor.min |
Not supported |
Refer to torch.min |
|
torch.split |
Supported |
Input/output int8/int16 |
|
torch.eq |
Not supported |
Input/output int8/int16 |
|
torch.ge |
Not supported |
Input/output int8/int16 |
|
torch.greater |
Not supported |
Input/output int8/int16 |
|
torch.greater_equal |
Not supported |
Input/output int8/int16 |
|
torch.gt |
Not supported |
Input/output int8/int16 |
|
torch.le |
Not supported |
Input/output int8/int16 |
|
torch.less |
Not supported |
Input/output int8/int16 |
|
torch.less_equal |
Not supported |
Input/output int8/int16 |
|
torch.lt |
Not supported |
Input/output int8/int16 |
|
tensor.eq |
Not supported |
Input/output int8/int16 |
|
tensor.ge |
Not supported |
Input/output int8/int16 |
|
tensor.greater |
Not supported |
Input/output int8/int16 |
|
tensor.greater_equal |
Not supported |
Input/output int8/int16 |
|
tensor.gt |
Not supported |
Input/output int8/int16 |
|
tensor.le |
Not supported |
Input/output int8/int16 |
|
tensor.less |
Not supported |
Input/output int8/int16 |
|
tensor.less_equal |
Not supported |
Input/output int8/int16 |
|
tensor.expand |
Not supported |
Input/output int8/int16 |
|
tensor.repeat |
Not supported |
Input/output int8/int16 |
|
torch.nn.GLU |
Not supported |
Support input and output int8/int16 |
|
tensor.tile |
Not supported |
Input/output int8/int16 |
|
torch.nn.GELU |
Not supported |
Input/output int8/int16 |
|
torch.nn.LSTMCell |
Not supported |
Input/output int8/int16.input is 2 dimension |
|
torch.nn.LeakyReLU |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
|
torch.nn.PReLU |
Not supported |
Input/output int8/int16 |
|
torch.argmax |
Refer to torch.max |
Refer to torch.max |
|
torch.argmin |
Refer to torch.min |
Refer to torch.min |
|
tensor.argmax |
Refer to torch.max |
Refer to torch.max |
|
tensor.argmin |
Refer to torch.min |
Refer to torch.min |
|
tensor.reshape |
Only the reshape in H and W direction can be supported. |
dim <= 10, 1 <= each_dim_size <= 65536 |
|
torch.nn.Tanh |
Supported. Underlying implementation of lookup tables with some accuracy risk. |
Supports input and output int8/int16 |
|
torch.nn.ReLU |
Conv2d+BN+ReLU This mode will automatically fuse into |
Conv2d+BN+ReLU This mode will automatically fuse into BpuConv2d, otherwise it’s not friendly for QAT to to run ReLU alone. |
|
torch.nn.SiLU |
Supported. Underlying implementation of lookup tables. |
Supported |
|
torch.nn.Conv2d |
Supported. kernel<=7.channel(one group) <= 2048. |
Supported. out_channel<=8192, when output as a model, out_channel <= 16384. |
|
torch.nn.Linear |
Not supported |
Supported. in_features <= 8192, out_features <= 8192. |
|
torch.nn.Conv3d |
Not supported |
input: [N, C, D, H, W] int8, N<=128; H, W, D, C<=65536; |
|
tensor.transpose |
Not supported |
Input/output int8, int16, int32.Transpose for N dimensions is not supported. |
|
torch.nn.Sigmoid |
Supported. Underlying implementation of lookup tables. |
Supports input and output int8/int16 |
|
torch.nn.Dropout |
Training op, not reflected in the prediction model. |
Training op, not reflected in the prediction model. |
|
torch.nn.Softmax |
Not supported |
Input/output int8/int16. Underlying implementation of lookup tables. |
|
torch.nn.Identity |
Training op, not reflected in the prediction model. |
Training op, not reflected in the prediction model. |
|
torch.nn.AvgPool2d |
1<=kernel<=7, 1<=stride<=185 |
Supported. 1<=kernel, stride, padding<=256; |
|
torch.nn.MaxPool2d |
1<=kernel<=64, 1<=stride<=256, padding>=0 |
input_shape: [N, C, H, W], 1<=H, W, C<=8192;1<=kernel, stride<=256; |
|
torch.nn.ZeroPad2d |
Supported. |
Input/output int8/int16. |
|
torch.nn.Dropout2d |
Training op, not reflected in the prediction model. |
Training op, not reflected in the prediction model. |
|
torch.nn.Layernorm |
Not supported |
Input/output int8/int16, Underlying implementation of lookup tables. |
|
torch.nn.BatchNorm2d |
BatchNorm2d. Absorbed at the QAT stage and not reflected in the |
BatchNorm2d. Absorbed at the QAT stage and |
|
torch.nn.BatchNorm3d |
BatchNorm3d. Absorbed at the QAT stage and not reflected in the |
BatchNorm3d. Absorbed at the QAT stage and |
|
Tensor.__getitem__ |
Supported |
Supported |
|
torch.nn.ConstantPad2d |
Supported |
Supported. Limitations refer to ZeroPad2d. |
|
torch.nn.SyncBatchNorm |
Training op, not reflected in the prediction model. |
Training op, not reflected in the prediction model. |
|
torch.nn.ChannelShuffle |
Supported |
Input/output int8/int16. The values in shuffle_index cannot be duplicated. |
|
torch.nn.PixelShuffle |
Supported. Input/output int8/int16. |
Supported. Input/output int8/int16. |
|
torch.nn.PixelUnshuffle |
Supported. Input/output int8/int16. |
Supported. Input/output int8/int16. |
|
torch.nn.ConvTranspose2d |
Supported. 2<=kernel<= 14.channel<=2048. |
Supported. Input shape: [N, C, H, W], 1<=N<=128, 1<=channel<=2048; |
|
torch.nn.Upsample |
Supported. Refer to torch.nn.functional.interpolate |
Refer to torch.nn.functional.interpolate |
|
torch.nn.UpsamplingNearest2d |
Supported. The limitations refer to torch.nn.functional.interpolate |
Supported. The limitations refer to torch.nn.functional.interpolate |
|
torch.nn.UpsamplingBilinear2d |
Supported. The limitations refer to torch.nn.functional.interpolate |
Supported. The limitations refer to torch.nn.functional.interpolate |
|
torch.nn.functional.pad |
Support pad mode except |
Support pad mode except |
|
torch.nn.functional.relu |
torch.nn.ReLU |
Conv2d+BN+ReLU This mode will automatically fuse into |
Conv2d+BN+ReLU This mode will automatically fuse into |
torch.nn.functional.relu6(fused) |
torch.nn.ReLU6 |
Conv2d+BN+ReLU6 This mode will automatically fuse into BpuConv2d, |
Conv2d+BN+ReLU6 This mode will automatically fuse into BpuConv2d, |
torch.nn.ReplicationPad2d |
Supported |
Supported. The limitations refer to ZeroPad2d. |
|
torch.quantization.QuantStub |
horizon.quantization.QuantStub |
Supported. Typical usage scenario: Network model input. |
Supported.Typical usage scenario: Network model input. |
torch.quantization.DeQuantStub |
Typical usage scenario: In the scenario of network model segmentation, it is necessary to transfer data |
Typical usage scenario: In the scenario of network model segmentation, it is necessary to transfer data |
|
torch.nn.functional.interpolate |
horizon.nn.Interpolate |
Only nearest and billinear interpolation modes are supported. 1/256 |
Only nearest and billinear interpolation modes are supported. Input_shape: [N, C, H, W], 1<=C, H, W<=8192 |
torch.nn.functional.grid_sample |
Not supported |
Supported. Input shape: [N, C, H, W], 1<=H, W<=1024 and HW<=5121024; |
|
No Correlation operator in torch |
horizon.nn.Correlation |
Not supported |
Supported. Input shape: [N, C, H, W], 1<=C<=1024, kernel must be odd number, |
torch.log |
horizon.nn.HardLog |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.masked_fill |
Not supported |
Supports input and output int8/int16 |
|
No PointPillarsScatter operator in torch |
horizon.nn.PointPillarsScatter |
Not supported |
Supports input and output int8/int16. Requires three inputs, the shapes of the three inputs are: [M, C], [M, 4] and [4], and the third input represents the shape of the output feature of the operator: (N, C, H, W) |
torch.div |
horizon.nn.Div |
Not supported |
Supports input and output int16 |
No bgr2centered_yuv operator in torch |
horizon.bgr2centered_yuv |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of 0~255 to centered YUV |
No rgb2bgr operator in torch |
horizon.rgb2bgr |
Not supported |
Supported. Used for data preprocessing. Convert RGB images of shape [N, 3, H, W] to BGR |
No bgr2rgb operator in torch |
horizon.bgr2rgb |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of shape [N, 3, H, W] to RGB |
No bgr2yuv operator in torch |
horizon.bgr2yuv |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of 0~255 to YUV |
No rgb2yuv operator in torch |
horizon.rgb2yuv |
Not supported |
Supported. Used for data preprocessing. Convert RGB images of 0~255 to YUV |
No bgr2centered_yuv operator in torch |
horizon.bgr2centered_yuv |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of 0~255 to centered YUV |
No rgb2centered_yuv operator in torch |
horizon.rgb2centered_yuv |
Not supported |
Supported. Used for data preprocessing. Convert RGB images of 0~255 to centered YUV |
No bgr2gray operator in torch |
horizon.bgr2gray |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of 0~255 to gray |
No rgb2gray operator in torch |
horizon.rgb2gray |
Not supported |
Supported. Used for data preprocessing. Convert RGB images of 0~255 to gray |
No bgr2centered_gray operator in torch |
horizon.bgr2centered_gray |
Not supported |
Supported. Used for data preprocessing. Convert BGR images of 0~255 to centered gray |
No rgb2centered_gray operator in torch |
horizon.rgb2centered_gray |
Not supported |
Supported. Used for data preprocessing. Convert RGB images of 0~255 to centered gray |
No centered_yuv2bgr operator in torch |
horizon.centered_yuv2bgr |
Not supported |
Supports input and output int8. Used when users have trained QAT model with BGR images. Inserts this operator in the quantized model to convert centered YUV inputs to BGR |
No centered_yuv2rgb operator in torch |
horizon.centered_yuv2rgb |
Not supported |
Supports input and output int8. Used when users have trained QAT model with RGB images. Inserts this operator in the quantized model to convert centered YUV inputs to RGB |
torch.nn.MultiheadAttention |
Not supported |
Do not support add_bias_kv, add_zero_attn and qkv with different embed_dim. Supports input and output int8/int16. with low_level look-up table implementation and mask quantization, there is a risk of accuracy. |
|
torch.reciprocal |
horizon.nn.Reciprocal |
Not supported |
Supports input and output int8/int16 |
No rcnn_post_process operator in torch |
horizon.nn.RcnnPostProcess |
Not supported |
This operator can only be deployed on CPU when inference. Supports input and output float. Includes a post-process pipeline such as NMS for the output of RCNN. |
torch.topk |
Not supported |
Supports input and output int8/int16/int32. |
|
torch.gather |
Not supported |
Supports input and output int8/int16/int32. |
|
torch.abs |
Not supported |
Supports input and output int8/int16. |
|
torch.nn.Softplus |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy. |
|
torch.nn.ELU |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy. |
|
torch.ceil |
horizon.nn.Ceil |
Not supported |
Supports input and output int8/int16. int8 supports input magnitude not greater than 1e6, while int16 supports input magnitude not greater than 1e8. |
torch.floor |
horizon.nn.Floor |
Not supported |
Supports input and output int8/int16. int8 supports input magnitude not greater than 1e6, while int16 supports input magnitude not greater than 1e8. |
no MultiScaleDeformableAttention operator in torch |
horizon.nn.MultiScaleDeformableAttention |
Not supported |
Supports input and output int8. |
torch.nn.HardSigmoid |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy. |
|
torch.acos |
horizon.nn.Acos |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.acosh |
horizon.nn.Acosh |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.asin |
horizon.nn.Asin |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.asinh |
horizon.nn.Asinh |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.atanh |
horizon.nn.Atanh |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.cosh |
horizon.nn.Cosh |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.erf |
horizon.nn.Erf |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.selu |
horizon.nn.Selu |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.sinh |
horizon.nn.Sinh |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
torch.tan |
horizon.nn.Tan |
Not supported |
Supports input and output int8/int16. Low-level look-up table implementation, there is a risk of accuracy |
4.2.4.3.2. Supported Torchvision Operator¶
torchvision Operator |
To prepare the floating point model, replace it with |
Bernoulli2 Support |
Bayes/Bayes-e Support |
|---|---|---|---|
torchvision.ops.RoIAlign |
Supported |
Supported. 1<=feature number<=5;bbox need to be |
|
torchvision.ops.MultiScaleRoIAlign |
horizon.nn.MultiScaleRoIAlign |
Supported |
Supported. The limitations refer to RoIAlign. |
torchvision.models.detection.rpn.AnchorGenerator |
horizon.nn.AnchorGenerator |
Only the case where Tensor.shape can be determined offline is supported. |
Input: int8/int16/int32/float32, output: float32 |