Tosa Conv2D idiv_check constraints

Hello,
There has been a recent change on the MLIR Tosa dialect that adds some extra verifications on the arguments shapes for Conv2D. After the update we noticed failures on some pretty standard networks.
The conditions as written in specification are:

ERROR_IF(OH != idiv_check(IH - 1 + pad_top + pad_bottom - (KH - 1) * dilation_y, stride_y) + 1);
ERROR_IF(OW != idiv_check(IW - 1 + pad_left + pad_right - (KW - 1) * dilation_x, stride_x) + 1);

The problem seems to be the idiv_check which by definition fails if a % b != 0
Example from a resnet50 model:

  • input 1x224x224x3
  • kernel_shape: 64x7x7x3
  • padding [3,3,3,3]
  • dilation [1, 1]
  • stride [2, 2]
  • output 1x112x112x64

Calculating the condition we get idiv_check(223, 2) which fails.

loc(""): error: 'tosa.conv2d' op expected input_height - 1 + pad_top + pad_bottom - (kernel_height - 1) * dilation_y to be wholly divisible by stride_y, got (224 - 1 + 3 + 3 - (7 - 1) * 1) / 2
loc(""): error: 'tosa.conv2d' op expected input_height - 1 + pad_top + pad_bottom - (kernel_height - 1) * dilation_y to be wholly divisible by stride_y, got (224 - 1 + 3 + 3 - (7 - 1) * 1) / 2

We were wondering that maybe idiv_check was mistakingly used instead of a simple floor(idiv).

Thank you

Hi. In this case we do mean idiv_check. We want the networks to be precise in the amount of padding so that the size calculation is always correct. In most cases, the padding needs to be adjusted so that the sizes are properly reflected. In your case, changing the right/bottom padding to 1 should work.

We’ve been working on some legalizations to ensure that they meet this requirement. The harder requirement is when some of the input data is not used by the given set of parameters. That requires a SLICE to cut off the extra data to make the sizes correct.