| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 3 months ago | ||
| 30 days ago | ||
| 26 days ago | ||
| 30 days ago | ||
| 19 days ago | ||
| 30 days ago | ||
| 26 days ago | ||
| 18 days ago |
MaxPool3DGrad
English | 简体中文
Applicable Products
| Product | Support |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | × |
| Atlas A2 products | × |
| Atlas 200I/500 A2 inference products | × |
| Atlas inference products | × |
| Atlas training products | × |
Function
Operator function: Performs backpropagation after the forward max pooling, backfills the gradient at the coordinates of the maximum value of each window, and accumulates the gradients at the same coordinates.
Formula for deriving the forward output shape
The output shape of the forward MaxPool3D (that is, the shape of orig_y and grads) is jointly determined by the input shape, ksize, strides, pads, and the padding mode. Taking the NCDHW format as an example, the shape of the input orig_x is (N,C,Din,Hin,Win)(N, C, D_{in}, H_{in}, W_{in}), and the forward output shape is (N,C,Dout,Hout,Wout)(N, C, D_{out}, H_{out}, W_{out}). The formulas for computing the dimensions are as follows (ceil_mode defaults to False, rounding down):
CALCULATED mode:
Dout=⌊Din+2×pads[0]−(kd−1)−1sd⌋+1D_{out} = \left\lfloor \frac{D_{in} + 2 \times pads[0] - (k_d - 1) - 1}{s_d} \right\rfloor + 1
Hout=⌊Hin+2×pads[2]−(kh−1)−1sh⌋+1H_{out} = \left\lfloor \frac{H_{in} + 2 \times pads[2] - (k_h - 1) - 1}{s_h} \right\rfloor + 1
Wout=⌊Win+2×pads[4]−(kw−1)−1sw⌋+1W_{out} = \left\lfloor \frac{W_{in} + 2 \times pads[4] - (k_w - 1) - 1}{s_w} \right\rfloor + 1
VALID mode:
It is equivalent to the CALCULATED mode with all pads being 0, that is:
Dout=⌊Din−(kd−1)−1sd⌋+1D_{out} = \lfloor{\frac{D_{in} - {(k_d - 1) - 1}}{s_d}}\rfloor + 1
Hout=⌊Hin−(kh−1)−1sh⌋+1H_{out} = \lfloor{\frac{H_{in} - {(k_h - 1) - 1}}{s_h}}\rfloor + 1
Wout=⌊Win−(kw−1)−1sw⌋+1W_{out} = \lfloor{\frac{W_{in} - {(k_w - 1) - 1}}{s_w}}\rfloor + 1
SAME mode:
Dout=⌊Din+sd−1sd⌋D_{out} = \lfloor{\frac{D_{in} + {s_d} - 1}{s_d}}\rfloor
Hout=⌊Hin+sh−1sh⌋H_{out} = \lfloor{\frac{H_{in} + {s_h} - 1}{s_h}}\rfloor
Wout=⌊Win+sw−1sw⌋W_{out} = \lfloor{\frac{W_{in} + {s_w} - 1}{s_w}}\rfloor
Output shape:
The output y of the backpropagation has exactly the same shape as the input orig_x:
y.shape=orig_x.shape=(N,C,Din,Hin,Win)y.shape = orig\_x.shape = (N, C, D_{in}, H_{in}, W_{in})
Parameter description:
- kd,kh,kwk_d, k_h, k_w: window sizes of ksize in the D, H, and W dimensions
- sd,sh,sws_d, s_h, s_w: strides in the D, H, and W dimensions
Parameters
| Parameter name | Input/Output/Attribute | Description | Data type | Data format |
|---|---|---|---|---|
| orig_x | Input | Input parameter for the MaxPool3DGrad computation, representing the forward input tensor. | FLOAT, FLOAT16, BFLOAT16 | NCDHW, NDHWC |
| orig_y | Input | Index positions of the maximum elements in the forward input. The data format must be the same as that of `orig_x`, and the shape must be the same as that of `grads`. | FLOAT, FLOAT16, BFLOAT16 | NCDHW, NDHWC |
| grads | Input | Input parameter for the MaxPool3DGrad computation, representing the gradient of the current node. | FLOAT, FLOAT16, BFLOAT16 | NCDHW, NDHWC |
| ksize | Attribute | Window size of the max pooling. | INT64 | - |
| strides | Attribute | Stride of the pooling operation. | INT64 | - |
| padding | Optional attribute | Pad mode. SAME, VALID, and CALCULATED are supported. The padded data is -inf, and the default value is SAME. | - | - |
| pads | Attribute | Takes effect when the pad mode is CALCULATED. It specifies the padding amounts at the front and back in the D/H/W dimensions, in the format of [d_front, d_back, h_front, h_back, w_front, w_back]. | INT64 | - |
| data_format | Optional attribute | Supported data formats. | - | NCDHW and NDHWC are supported |
| y | Output | Output parameter of the MaxPool3DGrad computation. The shape and data format must be the same as those of `orig_x`. | FLOAT, FLOAT16, BFLOAT16 | NCDHW, NDHWC |
Constraints
- ksize: The array length must be 5, and the values corresponding to the N and C dimensions must be 1, that is,
(1, 1, k_d, k_h, k_w). - strides: The array length must be 5, and the values corresponding to the N and C dimensions must be 1, that is,
(1, 1, s_d, s_h, s_w). - pads: It takes effect only when
padding="CALCULATED". The array length must be 6, in the format of[d_front, d_back, h_front, h_back, w_front, w_back], and each value must be >= 0. The front pads (pads[0], pads[2], and pads[4]) must satisfy <= the corresponding dimension kernel_size / 2. - The shapes of orig_y and grads must be the same and must match the output shape of the forward MaxPool3D.
- The shape of y must be the same as the shape of
orig_x.
Invocation Description
| Invocation method | Sample code | Description |
|---|---|---|
| Graph-mode API | test_geir_max_pool3d_grad | Invoke the MaxPool3DGrad operator by building a graph through the IR MaxPool3DGrad. |