[onnx] AdaptiveMaxPool2d can not convert to GlobalMaxPool
Labels: module: onnx, triaged

### 🐛 Describe the bug

I try to convert the cbam block to onnx. The nn.AdaptiveMaxPool2d([1, 1]) used in ChannelAttention is expected to be a GlobalMaxPool in onnx accodring to according to https://github.com/pytorch/pytorch/blob/ff4569ae2939c3e81092fdf43c9d5f2f08453c42/torch/onnx/symbolic_opset9.py#L981, but i got onnx::MaxPool.  Is there any way to solve this problem? 
python script: 
~~~python
import torch
import torch.nn as nn
    
def conv3x3(in_planes, out_planes, stride=1):
    "3x3 convolution with padding"
    return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
                     padding=1, bias=False)

class ChannelAttention(nn.Module):
    def __init__(self, in_planes, ratio=16):
        super(ChannelAttention, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d([1, 1])
        self.max_pool = nn.AdaptiveMaxPool2d([1, 1])
           
        self.fc = nn.Sequential(nn.Conv2d(in_planes, in_planes // 16, 1, bias=False),
                               nn.ReLU(),
                               nn.Conv2d(in_planes // 16, in_planes, 1, bias=False))
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        avg_out = self.fc(self.avg_pool(x))
        max_out = self.fc(self.max_pool(x))
        out = avg_out + max_out
        return self.sigmoid(out)

class SpatialAttention(nn.Module):
    def __init__(self, kernel_size=7):
        super(SpatialAttention, self).__init__()

        self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=kernel_size//2, bias=False)
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        avg_out = torch.mean(x, dim=1, keepdim=True)
        max_out, _ = torch.max(x, dim=1, keepdim=True)
        x = torch.cat([avg_out, max_out], dim=1)
        x = self.conv1(x)
        return self.sigmoid(x)

class CBAM(nn.Module):
    expansion = 1

    def __init__(self, inplanes, planes, stride=1, downsample=None):
        super(CBAM, self).__init__()
        self.conv1 = conv3x3(inplanes, planes, stride)
        self.bn1 = nn.BatchNorm2d(planes)
        self.relu = nn.ReLU(inplace=True)
        self.conv2 = conv3x3(planes, planes)
        self.bn2 = nn.BatchNorm2d(planes)

        self.ca = ChannelAttention(planes)
        self.sa = SpatialAttention()

        self.downsample = downsample
        self.stride = stride

    def forward(self, x):
        residual = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)

        out = self.ca(out) * out
        out = self.sa(out) * out

        if self.downsample is not None:
            residual = self.downsample(x)

        out += residual
        out = self.relu(out)

        return out

if __name__ == '__main__':
    model = CBAM(16, 16)
    device = 'cuda:0'
    model.to(device)
    model.eval()
    dummpy_input = torch.zeros([1, 16, 400, 640], device=device)
    torch.onnx.export(
        model, 
        dummpy_input, 
        'model.onnx', 
        verbose=True,
        input_names=["input"],
        output_names=["output"],
        opset_version=14,
    )
~~~
script output: 
~~~
Exported graph: graph(%input : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=0, device=cuda:0),
      %ca.fc.0.weight : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=1, device=cuda:0),
      %ca.fc.2.weight : Float(16, 1, 1, 1, strides=[1, 1, 1, 1], requires_grad=1, device=cuda:0),
      %sa.conv1.weight : Float(1, 2, 7, 7, strides=[98, 49, 7, 1], requires_grad=1, device=cuda:0),
      %onnx::Conv_41 : Float(16, 16, 3, 3, strides=[144, 9, 3, 1], requires_grad=0, device=cuda:0),
      %onnx::Conv_42 : Float(16, strides=[1], requires_grad=0, device=cuda:0),
      %onnx::Conv_44 : Float(16, 16, 3, 3, strides=[144, 9, 3, 1], requires_grad=0, device=cuda:0)):
  %onnx::Conv_45 : Float(16, strides=[1], requires_grad=0, device=cuda:0) = onnx::Identity(%onnx::Conv_42)
  %/conv1/Conv_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1], onnx_name="/conv1/Conv"](%input, %onnx::Conv_41, %onnx::Conv_42), scope: __main__.CBAM::/torch.nn.modules.conv.Conv2d::conv1 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/relu/Relu_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Relu[onnx_name="/relu/Relu"](%/conv1/Conv_output_0), scope: __main__.CBAM::/torch.nn.modules.activation.ReLU::relu # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1455:0
  %/conv2/Conv_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1], onnx_name="/conv2/Conv"](%/relu/Relu_output_0, %onnx::Conv_44, %onnx::Conv_45), scope: __main__.CBAM::/torch.nn.modules.conv.Conv2d::conv2 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/ca/avg_pool/GlobalAveragePool_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::GlobalAveragePool[onnx_name="/ca/avg_pool/GlobalAveragePool"](%/conv2/Conv_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.pooling.AdaptiveAvgPool2d::avg_pool # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1214:0
  %/ca/fc/fc.0/Conv_output_0 : Float(1, 1, 1, 1, strides=[1, 1, 1, 1], requires_grad=0, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1], onnx_name="/ca/fc/fc.0/Conv"](%/ca/avg_pool/GlobalAveragePool_output_0, %ca.fc.0.weight), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.conv.Conv2d::fc.0 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/ca/fc/fc.1/Relu_output_0 : Float(1, 1, 1, 1, strides=[1, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::Relu[onnx_name="/ca/fc/fc.1/Relu"](%/ca/fc/fc.0/Conv_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.activation.ReLU::fc.1 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1457:0
  %/ca/fc/fc.2/Conv_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=0, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1], onnx_name="/ca/fc/fc.2/Conv"](%/ca/fc/fc.1/Relu_output_0, %ca.fc.2.weight), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.conv.Conv2d::fc.2 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/ca/max_pool/MaxPool_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::MaxPool[kernel_shape=[400, 640], pads=[0, 0, 0, 0], strides=[400, 640], onnx_name="/ca/max_pool/MaxPool"](%/conv2/Conv_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.pooling.AdaptiveMaxPool2d::max_pool # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1121:0
  %/ca/fc/fc.0_1/Conv_output_0 : Float(1, 1, 1, 1, strides=[1, 1, 1, 1], requires_grad=0, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1], onnx_name="/ca/fc/fc.0_1/Conv"](%/ca/max_pool/MaxPool_output_0, %ca.fc.0.weight), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.conv.Conv2d::fc.0 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/ca/fc/fc.1_1/Relu_output_0 : Float(1, 1, 1, 1, strides=[1, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::Relu[onnx_name="/ca/fc/fc.1_1/Relu"](%/ca/fc/fc.0_1/Conv_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.activation.ReLU::fc.1 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1457:0
  %/ca/fc/fc.2_1/Conv_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=0, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[1, 1], pads=[0, 0, 0, 0], strides=[1, 1], onnx_name="/ca/fc/fc.2_1/Conv"](%/ca/fc/fc.1_1/Relu_output_0, %ca.fc.2.weight), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.container.Sequential::fc/torch.nn.modules.conv.Conv2d::fc.2 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/ca/Add_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::Add[onnx_name="/ca/Add"](%/ca/fc/fc.2/Conv_output_0, %/ca/fc/fc.2_1/Conv_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca # /home/oem/Downloads/test.py:23:0
  %/ca/sigmoid/Sigmoid_output_0 : Float(1, 16, 1, 1, strides=[16, 1, 1, 1], requires_grad=1, device=cuda:0) = onnx::Sigmoid[onnx_name="/ca/sigmoid/Sigmoid"](%/ca/Add_output_0), scope: __main__.CBAM::/__main__.ChannelAttention::ca/torch.nn.modules.activation.Sigmoid::sigmoid # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/activation.py:295:0
  %/Mul_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Mul[onnx_name="/Mul"](%/ca/sigmoid/Sigmoid_output_0, %/conv2/Conv_output_0), scope: __main__.CBAM:: # /home/oem/Downloads/test.py:67:0
  %/sa/ReduceMean_output_0 : Float(1, 1, 400, 640, strides=[256000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::ReduceMean[axes=[1], keepdims=1, onnx_name="/sa/ReduceMean"](%/Mul_output_0), scope: __main__.CBAM::/__main__.SpatialAttention::sa # /home/oem/Downloads/test.py:34:0
  %/sa/ReduceMax_output_0 : Float(1, 1, 400, 640, strides=[256000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::ReduceMax[axes=[1], keepdims=1, onnx_name="/sa/ReduceMax"](%/Mul_output_0), scope: __main__.CBAM::/__main__.SpatialAttention::sa # /home/oem/Downloads/test.py:35:0
  %/sa/Concat_output_0 : Float(1, 2, 400, 640, strides=[512000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Concat[axis=1, onnx_name="/sa/Concat"](%/sa/ReduceMean_output_0, %/sa/ReduceMax_output_0), scope: __main__.CBAM::/__main__.SpatialAttention::sa # /home/oem/Downloads/test.py:36:0
  %/sa/conv1/Conv_output_0 : Float(1, 1, 400, 640, strides=[256000, 256000, 640, 1], requires_grad=0, device=cuda:0) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[7, 7], pads=[3, 3, 3, 3], strides=[1, 1], onnx_name="/sa/conv1/Conv"](%/sa/Concat_output_0, %sa.conv1.weight), scope: __main__.CBAM::/__main__.SpatialAttention::sa/torch.nn.modules.conv.Conv2d::conv1 # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/conv.py:459:0
  %/sa/sigmoid/Sigmoid_output_0 : Float(1, 1, 400, 640, strides=[256000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Sigmoid[onnx_name="/sa/sigmoid/Sigmoid"](%/sa/conv1/Conv_output_0), scope: __main__.CBAM::/__main__.SpatialAttention::sa/torch.nn.modules.activation.Sigmoid::sigmoid # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/modules/activation.py:295:0
  %/Mul_1_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Mul[onnx_name="/Mul_1"](%/sa/sigmoid/Sigmoid_output_0, %/Mul_output_0), scope: __main__.CBAM:: # /home/oem/Downloads/test.py:68:0
  %/Add_output_0 : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Add[onnx_name="/Add"](%/Mul_1_output_0, %input), scope: __main__.CBAM:: # /home/oem/Downloads/test.py:73:0
  %output : Float(1, 16, 400, 640, strides=[4096000, 256000, 640, 1], requires_grad=1, device=cuda:0) = onnx::Relu[onnx_name="/relu_1/Relu"](%/Add_output_0), scope: __main__.CBAM::/torch.nn.modules.activation.ReLU::relu # /home/oem/anaconda3/envs/torch/lib/python3.10/site-packages/torch/nn/functional.py:1455:0
  return (%output)

================ Diagnostic Run torch.onnx.export version 2.0.0 ================
verbose: False, log level: Level.ERROR
======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================
~~~

### Versions

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] pytorch-lightning==2.0.0
[pip3] torch==2.0.0
[pip3] torchaudio==2.0.0
[pip3] torchmetrics==0.11.4
[pip3] torchvision==0.15.0
[pip3] triton==2.0.0
[conda] blas                      1.0                         mkl  
[conda] libblas                   3.9.0            12_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            12_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            12_linux64_mkl    conda-forge
[conda] liblapacke                3.9.0            12_linux64_mkl    conda-forge
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0           py310h7f8727e_0  
[conda] mkl_fft                   1.3.1           py310hd6ae3a3_0  
[conda] mkl_random                1.2.2           py310h00e6091_0  
[conda] numpy                     1.23.5          py310hd5efca6_0  
[conda] numpy-base                1.23.5          py310h8e6c178_0  
[conda] pytorch                   2.0.0           py3.10_cuda11.8_cudnn8.7.0_0    pytorch
[conda] pytorch-cuda              11.8                 h7e8668a_3    pytorch
[conda] pytorch-lightning         2.0.0              pyhd8ed1ab_1    conda-forge
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                2.0.0               py310_cu118    pytorch
[conda] torchmetrics              0.11.4             pyhd8ed1ab_0    conda-forge
[conda] torchtriton               2.0.0                     py310    pytorch
[conda] torchvision               0.15.0              py310_cu118    pytorch