conv2d_backprop_input
功能说明
在给定5HD格式的out_backprop和FracZ格式的Weight的情况下计算float16的2-D反卷积。
out_backprop Tensor 的shape是 5HD,即(N, C1, H, W, C0);Weight Tensor的shape是FracZ,即(C1*KH*KW,Cout//C0_out,C0_out,C0)。
函数原型
conv2d_backprop_input(filters, out_backprop, filter_sizes, input_sizes, para_dict)
参数说明
- filters:2d卷积的Weight,tensor,FracZ格式,目前支持float16类型
- out_backprop:2d卷积的输出反向,目前支持float16类型
- filter_size:2d卷积的权重矩阵大小
- input_sizes:2d卷积的输入矩阵大小
- para_dict:字典格式,包含各种参数,后续参数扩展一般都在para_dict
其中目前在para_dict里要传递的参数:
- strides:list类型,2d卷积在FeatureMap HW方向的移动步长。
- padding:list类型,2d卷积在FeatureMap HW方向的补边。
- dilations:list类型,2d卷积在Filter HW方向的膨胀系数。
- res_dtype:输出的数据类型,默认是float16类型。
- offset_x:量化过程中针对输入矩阵的补偿。
- offset_w:量化过程针对权重的补偿,暂不支持,目前需设置为None。
- kernel_name:算子名称。
- group_dict:字典格式,包含支持conv2d_backprop_input group卷积相关的参数,通过下列计算过程获得。
参数1:w_shape_nchw,weight shape,排布方式为NCHW。
参数2:groups,group卷积参数。
参数3:c0_size,为tbe_platform.C0_SIZE,默认值为16。
参数4:c0_size_k,为tbe_platform.CUBE_MKN[filter_dtype]['mac'][1],filter_dtype为float16时值为16
具体计算公式:
_lcm(param1, param2):计算最小公倍数。
ceil(param1, param2):计算param1 / param2并向上取整。
dx_c_ori = w_shape_nchw[1]
dy_c_ori = w_shape_nchw[0] // groups
filter_batch_ori = w_shape_nchw[0] // groups
filter_c_ori = w_shape_nchw[1]
dx_c_extend = _lcm(dx_c_ori, c0_size) // dx_c_ori
dy_c_extend = _lcm(dy_c_ori, c0_size_k) // dy_c_ori
multiple_extend = min(_lcm(dx_c_extend, dy_c_extend), groups)
dx_c1_extend = ceil(multiple_extend * dx_c_ori, c0_size)
dy_c1_extend = ceil(multiple_extend * dy_c_ori, c0_size_k)
group_dict = {
"g_extend": g_extend,
"multiple_extend": multiple_extend,
"groups": groups,
"dx_c1_extend": dx_c1_extend,
"dy_c1_extend": dy_c1_extend,
"dx_c_ori": dx_c_ori,
"dy_c_ori": dy_c_ori,
"filter_batch_ori": filter_batch_ori,
"filter_c_ori": filter_c_ori,
"filter_ori_format": "NCHW"
}
返回值
res_tensor:表示卷积计算的tensor,即卷积计算的结果输出。
约束说明
此接口暂不支持与其他TBE DSL计算接口混合使用。
支持的型号
Atlas 200/300/500 推理产品
Atlas 训练系列产品
Atlas 推理系列产品
Atlas 200/500 A2推理产品
Atlas A2训练系列产品/Atlas 800I A2推理产品
调用示例
from tbe import tvm from tbe import dsl from tbe.dsl.compute import cube_util out_backprop_shape = (1, 1, 7, 7, 16) out_backprop_dtype = "float16" filter_frac = (1, 1, 16, 16) filter_dtype = "float16" filter_sizes = (16, 16, 1, 1) input_sizes = (1, 16, 7, 7) out_backprop = tvm.placeholder(out_backprop_shape, name="out_backprop", dtype=out_backprop_dtype) filters = tvm.placeholder(filter_frac, name="filters", dtype=filter_dtype) strides = [1, 1] padding = [0, 0, 0, 0] dilations = [1, 1, 1, 1] res_dtype = "float32" offset_x = 0 offset_w = None kernel_name = "conv2d_backprop_input_dx_1_1_7_7_16_dy_1_1_7_7_16_dw_16_16_1_1_s_1_1_p_SAME" group_dict = { "groups": 1, "g_extend": 1, "multiple_extend": 1, "dx_c1_extend": (input_sizes[1] + 16 - 1)// 16, "dy_c1_extend": out_backprop_shape [1], "dx_c_ori": input_sizes[1], "dy_c_ori": filter_sizes[0], "filter_batch_ori": filter_sizes[0], "filter_c_ori": filter_sizes[1], "filter_ori_format": "NCHW" } para_dict = { "strides": strides, "padding": padding, "dilations": dilations, "res_dtype": res_dtype, "offset_x": offset_x, "offset_w": offset_w, "kernel_name": kernel_name, "group_dict": group_dict } input_backprop = dsl.conv2d_backprop_input( filters=filters, out_backprop=out_backprop, filter_sizes=filter_sizes, input_sizes=input_sizes, para_dict=para_dict )