code: def test_adaptive_padding():
      for padding in ("same", "corner"):
          kernel_size = 16
          stride = 16
          dilation = 1
          input = torch.rand(1, 1, 15, 17)
          pool = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          out = pool(input)
          # padding to divisible by 16
          assert (out.shape[2], out.shape[3]) == (16, 32)
          input = torch.rand(1, 1, 16, 17)
          out = pool(input)
          # padding to divisible by 16
          assert (out.shape[2], out.shape[3]) == (16, 32)
  
          kernel_size = (2, 2)
          stride = (2, 2)
          dilation = (1, 1)
  
          adap_pad = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          input = torch.rand(1, 1, 11, 13)
          out = adap_pad(input)
          # padding to divisible by 2
          assert (out.shape[2], out.shape[3]) == (12, 14)
  
          kernel_size = (2, 2)
          stride = (10, 10)
          dilation = (1, 1)
  
          adap_pad = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          input = torch.rand(1, 1, 10, 13)
          out = adap_pad(input)
          #  no padding
          assert (out.shape[2], out.shape[3]) == (10, 13)
  
          kernel_size = (11, 11)
          adap_pad = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          input = torch.rand(1, 1, 11, 13)
          out = adap_pad(input)
          #  all padding
          assert (out.shape[2], out.shape[3]) == (21, 21)
  
          # test padding as kernel is (7,9)
          input = torch.rand(1, 1, 11, 13)
          stride = (3, 4)
          kernel_size = (4, 5)
          dilation = (2, 2)
          # actually (7, 9)
          adap_pad = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          dilation_out = adap_pad(input)
          assert (dilation_out.shape[2], dilation_out.shape[3]) == (
              16,
              21,
          )
          kernel_size = (7, 9)
          dilation = (1, 1)
          adap_pad = AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=padding,
          )
          kernel79_out = adap_pad(input)
          assert (kernel79_out.shape[2], kernel79_out.shape[3]) == (
              16,
              21,
          )
          assert kernel79_out.shape == dilation_out.shape
  
      # assert only support "same" "corner"
      with pytest.raises(AssertionError):
          AdaptivePadding(
              kernel_size=kernel_size,
              stride=stride,
              dilation=dilation,
              padding=1,
          )
  
file_path: mmdetection/tests/test_models/test_layers/test_transformer.py
imports: import pytest
  import torch
  from mmengine.config import ConfigDict
  from mmdet.models.layers.transformer import AdaptivePadding, DDQTransformerDecoder, DetrTransformerDecoder, DetrTransformerEncoder, PatchEmbed, PatchMerging
label_desc: Use image node_id 1 for calling a global function with example usage: test_adaptive_padding() without return types