CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Potential padding problem when using cuDnnConvolutionEngine

Open e-thereal opened this issue 10 years ago • 4 comments

Disclaimer: I'm not entirely sure I interpret the lowerPad and upperPad parameters correctly. I'm assumging that those parameters are used to specify the amount of zero padding, where the two parameters allow you to specify different values for the padding of, e.g., the left and the right margins.

CNTK allows you to specify different padding values for the left and right margin through the use of lowerPad and upperPad. However, the cuDNN convolution implementation only accepts one padding parameter for each dimension and assumes that the padding is always symmetric. Consequently, the cuDnnConvolutionEngine only uses the lowerPad parameter and ignores the upperPad parameter, but both parameters are still used to calculate the image size after the convolution. If lowerPad is not equal upperPad, this causes several problems. If lowerPad is higher than upperPad, cuDNN complains about invalid parameters. If upperPad is higher than lowerPad, cuDNN does not complain but it seems as if the calculation is not performed correctly. Only the case where lowerPad == upperPad seems to work correctly. This has also more subtle consequences when using auto padding. For even kernel sizes, lowerPad and upperPad must be different in order to produce images of the same size as the inputs after convolution. However, cuDNN only supports symmetric padding, which leads to the aforementioned problems.

Can someone please confirm that this is a limitation of the cuDnnConvolutionEngine and maybe add a note to the description of the ConvolutionalLayer and Convolution function that auto padding using cuDNN only works for odd filters and that lowerPad and upperPad must be equal when using cuDNN?

Unfortunately, I don't have a minimal example that reproduces the issue. My conclusions are purely based on the cuDNN documentation, which shows that only one padding parameter can be specified, and my interpretation of the upperPad and lowerPad parameters.

e-thereal avatar Oct 11 '16 15:10 e-thereal

We have removed the lowerPad and upperPad parameters, please don't use them any more.

cha-zhang avatar Oct 26 '16 03:10 cha-zhang

@cha-zhang So how does auto padding work then? Previously, auto padding required different lower pad and upper pad parameters for even filter sizes in order to produce outputs of the same resolution. Will the outputs be of different resolution for even filter sizes when using auto padding?

e-thereal avatar Oct 26 '16 07:10 e-thereal

We have a pad flag that can be set to true or false. Padding is currently assumed always symmetric. That's what cuDNN supports anyway.

cha-zhang avatar Oct 27 '16 16:10 cha-zhang

Closing. Feel free to reopen.

n17s avatar Oct 29 '16 23:10 n17s