max_pooling3d_grad_grad

Description

Computes the second-order gradient of max pooling operation for 3D data.

The compute formula is as follows:

input_d = 4, input_h =4, input_w = 4

stride_d = 2, stride_h = 2, stride_w =2

kernel_d = 2, kernel_h = 2, kernel_w = 2

The detailed computation is as follows.

  • input_d: depth of orig_in
  • input_h: height of orig_in
  • input_w: width of orig_in
  • kernel_d: depth of ksize
  • kernel_w: width of ksize
  • kernel_h: height of ksize
  • stride_d: depth of strides
  • stride_h: height of strides
  • stride_w: width of strides
  • pad_top: top padding along the D dimension of orig_in, which is 0 in this example.
  • pad_bottom: bottom padding along the D dimension of orig_in, which is 0 in this example.
  • pad_front: front padding along the H dimension of orig_in, which is 0 in this example.
  • pad_back: back padding along the H dimension of orig_in, which is 0 in this example.
  • pad_left: left padding along the W dimension of orig_in, which is 0 in this example.
  • pad_right: right padding along the W dimension of orig_in, which is 0 in this example.

Prototype

max_pooling3d_grad_grad(orig_input, orig_output, grad_grad, assist_tensor, ksize, strides, pads=(0, 0, 0, 0, 0, 0), data_format="NDHWC", padding="SAME")

Parameters

  • orig_input: a tvm.tensor for the input feature map. Has a 6D format of NDC1HWC0.
  • orig_output: a tvm.tensor for the result tensor. Has a 6D format of NDC1HWC0.
  • grad_grad: a tvm.tensor for the second-order gradient value. Has a 6D format of NDC1HWC0.
  • assist_tensor: auxiliary matrix automatically constructed based on the fusion pattern, which is used to eliminate the repeated maximum tensors. The value depends on the value of ksize. For example, if ksize = 2x2x2, then ksize = [8,7,6...2,1]
  • ksize: a list or tuple for the sizes of the input slider. ksize[0] indicates the depth of the input window. ksize[1] indicates the width of the input window. ksize[2] indicates the height of the input window.
  • strides: a list or tuple for the strides of the input slider. stride[0] indicates the depth stride of the window for the feature map. stride[1] indicates the width stride of the window for the feature map. stride[2] indicates the height stride of the window for the feature map.
  • pads: (optional) a list or tuple for the padding sizes, which is for the compatibility with Caffe pooling. pads[0], pads[1], pads[2], pads[3], pads[4], and pads[5] indicate the padding size in the top, bottom, front, back, left, and right side respectively. Defaults to (0,0,0,0,0,0). If pads has a non-0 value, the padding rule in SAME mode is used. If pads values are all 0s, the padding rule in VALID mode is used.
  • data_format: format.
  • padding: padding mode, either VALID (padding disabled) or SAME (padding enabled).

Returns

res_tensor: a tvm.tensor for the result tensor. Has a 6D of NDC1HWC0

The shape of tensor_in is [N, D, C1, H, W, C0=16]; the shape of window is [F, F]; and the shape of stride is [S, S].

In VALID mode and SAME mode of MAX pooling and AVG pooling, the shape of the output tensor is computed as follows:

  • In VALID mode:
    • The N and C dimensions remain unchanged.
    • The dimensions of Dout, Hout, and Wout are as follows:

      new_depth=new_height=new_width = CEIL(W-F+1/S)

  • In SAME mode:
    • The N and C dimensions remain unchanged.
    • The dimensions of Dout, Hout, and Wout are as follows:

      new_depth=new_height=new_width = CEIL(W/S)

      W is the input size; F is the filter size; S is the stride; and [] is the round-up sign.

Restrictions

This API cannot be used in conjunction with other TBE DSL APIs.

This API does not support output quantization function.

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Example

from tbe import tvm
from tbe import dsl
shape_in = (1, 416, 2, 416, 416, 16) 
shape_out = (1, 208, 2, 208, 208, 16) 
shape_ksize = (3, 3, 3)
input_dtype = "float16"
orig_in = tvm.placeholder(shape_in, name="orig_in", dtype=input_dtype) 
orig_out = tvm.placeholder(shape_out, name="orig_out", dtype=input_dtype)
grad_grad = tvm.placeholder(shape_in, name="grad_grad", dtype=input_dtype)  
assist_tensor = tvm.placeholder(shape_in, name="assist_tensor", dtype=input_dtype)
res = dsl.max_pooling3d_grad_grad(orig_in, orig_out, grad_grad, assist_tensor, (3, 3, 3), (2, 2, 2), (0, 0, 0, 0, 0, 0), "NDHWC")
# res.shape = (1, 208, 2, 208, 208, 16)