受 PyTorch 支持的运算符 - 3.5 简体中文

Vitis AI 用户指南 (UG1414)

Document ID
UG1414
Release Date
2023-09-28
Version
3.5 简体中文
表 1. 受 PyTorch 支持的运算符
PyTorch XIR DPU 实现 
API 属性 OP 名称 属性
参数/张量/零 data const data 为输入数据分配存储器。
  shape
  data_type
Conv2d in_channels conv2d (groups = 1) / depthwise-conv2d (groups = input channel)   如果 groups == input channel,那么卷积将被编译到逐通道卷积引擎中。如果 groups == 1,那么卷积将映射到卷积引擎。否则,它将被映射到 CPU。
out_channels  
kernel_size kernel
stride stride
padding pad
padding_mode('zeros') pad_mode (FLOOR)
groups  
dilation dilation
ConvTranspose2d in_channels transposed-conv2d (groups = 1) / depthwise-transposed-conv2d (groups = input channel)   如果 groups == input channel,那么卷积将被编译到逐通道卷积引擎中。如果 groups == 1,那么卷积将映射到卷积引擎。否则,它将被映射到 CPU。对于 output_padding 特征,尚未支持 DPU,因此如果值并非全部为 0,则该运算符将分配给 CPU。
out_channels  
kernel_size kernel
stride stride
padding pad
output_padding output_padding
padding_mode('zeros') pad_mode (FLOOR)
groups  
dilation dilation
matmul    conv2d / matmul  transpose_a matmul 将被转换为 conv2d 并编译为卷积引擎。如果 matmul 转换失败,则将由 CPU 实现。 
  transpose_b
MaxPool2d / AdaptiveMaxPool2d kernel_size maxpool2d kernel 池化引擎
stride stride
padding pad
ceil_mode pad_mode
output_size (adaptive) global
AvgPool2d / AdaptiveAvgPool2d kernel_size avgpool2d kernel 池化引擎
stride stride
padding pad
ceil_mode pad_mode
count_include_pad count_include_pad
  count_include_invalid (true)
output_size (adaptive) global
ReLU   relu   激活将被融合到相邻运算(如 convolution)。
LeakyReLU negative_slope leakyrelu alpha
ReLU6   relu6  
Hardtanh  min_val = 0  
max_val = 6  
Hardsigmoid   hard-sigmoid  
Hardswish   hardswish  
ConstantPad2d / ZeroPad2d  padding pad  paddings 首个编译器将尝试把“CONSTANT”填充融合到相邻运算中,例如,卷积和池化。如不存在此类运算符,那么当填充维度等于 4 且满足硬件要求时,仍可将其映射到 DPU。
value = 0 constant_values
  mode ("CONSTANT")
add   add   如果 add 为逐元素加法,add 将映射到 DPU 逐元素加法引擎。如果 add 为逐通道加法,则伺机将 add 与相邻运算(例如,convolution)融合。如果这些运算与 shape 相关,那么在编译期间将被移除。如果属于低精度运算,则将与相邻运算融合。否则,这些运算将被编译到 CPU 实现中。只要 Mul 所含任一输入为常量,即可映射到 Depthwise-Convolution Engine(逐通道卷积引擎)。如果其两个输入为相同形状,则可将其作为逐元素乘法映射到 Misc Engine(其他引擎)。如果另有某些 mul 运算属于特殊运算符组合的一部分,则此 mul 可融合到这些组合内。否则,它将被映射到 CPU。
sub / rsub   sub  
mul   mul  
neg   neg  
sum dim reduction_sum axis
keepdim keep_dims
max  dim reduction_max  axis
keepdim keep_dims
mean  dim reduction_mean  axis
keepdim keep_dims
interpolate / upsample / upsample_bilinear / upsample_nearest size resize size 如果 resize 的模式为“BILINEAR”,那么 align_corner=false, half_pixel_centers = false, size = 2, 4, 8; align_corner=false, half_pixel_centers = true, size = 2, 4 可转换为 DPU 实现 (pad+depthwise-transposed conv2d)。如果 resize 模式为“NEAREST”,那么 size 为整数,且 resize 将被映射到 DPU 实现。
scale_factor  
mode mode
align_corners align_corners
  half_pixel_centers = !align_corners
transpose  dim0 transpose  order 在某些情况下,这些运算将被转换为 reshape 运算。此外,还会伺机将维度转换运算融合到相邻运算的特殊加载或保存指令中以减少开销。否则,将被映射到 CPU。
dim1  
permute dims    
view/reshape size reshape shape
flatten  start_dim reshape/flatten  start_axis
end_dim end_axis
squeeze dim reshape / squeeze axis
cat dim concat axis 通过特殊的读取或写入策略和谨慎分配片上存储器来减少源于 concat 的开销。
aten::slice* dim strided_slice   如果 strided_slice 与 shape 相关或者属于低精度运算,则将被移除。否则,strided_slice 将被编译到 CPU 实现中。
start begin
end end
step strides
BatchNorm2d eps depthwise-conv2d / scale epsilon 如果 batch_norm 已量化并且可等效转换为 depthwise-conv2d,那么它将被转换为 depthwise-conv2d 并且编译器会伺机执行编译以将 batch_norm 映射到 DPU 实现。否则,batch_norm 将由 CPU 执行。
  axis
  moving_mean
  moving_var
  gamma
  beta
softmax dim softmax axis 将仅被编译到 CPU 实现中。 
Tanh   tanh  
Sigmoid   sigmoid  
PixelShuffle upscale_factor pixel_shuffle scale 如果卷积为 input,则会将其变换为 tile。
      upscale=True
PixelUnshuffle downscale_factor pixel_shuffle scale
      upscale=False
  1. 如果 PyTorch 中的张量分片是以 Python 语法编写的,那么它将被转换为 aten::slice