import builtins


def _is_valid_padding(kernel_sdims, strides, padding):
  """Returns True if `padding` corresponds to "VALID" padding for a transposed convolution."""
  # This is simply the padding == 'VALID' part of lax._conv_transpose_padding.
  for (begin, end), k, s in zip(padding, kernel_sdims, strides):
    pad_len = k + s - 2 + builtins.max(k - s, 0)
    pad_a = k - 1
    pad_b = pad_len - pad_a
    if begin != pad_a or end != pad_b:
      return False

  return True