Repository: pytorch
Issue: When using `ceil_mode=True`, `torch.nn.AvgPool1d` could get negative shape.
Labels: module: bc-breaking,triaged,module: shape checking,topic: bc breaking

### 🐛 Describe the bug

It is similar to [#88464](https://github.com/pytorch/pytorch/issues/88464), `torch.nn.AvgPool1d` can also get negative shape with specific input shape when `ceil_mode=True` in Pytorch 1.9.0\1.10.0\1.11.0\1.12.0\1.13.0.

The reason for this behavior seems to be that the calculation with `ceil_mode` parameter by both `torch.nn.AvgPool` and `torch.nn.MaxPool` are similar.


### To Reproduce
```python
import torch

def test():
    tmp_result= torch.nn.AvgPool1d(kernel_size=4, stride=1, padding=0, ceil_mode=True)
    return tmp_result
m = test()
input = torch.randn(20, 16, 1)
output = m(input)
```

The error result is
```
Traceback (most recent call last):  File "vanilla.py", line 9, in <module>
    output = m(input)
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/pooling.py", line 544, in forward
    self.count_include_pad)
RuntimeError: Given input size: (16x1x1). Calculated output size: (16x1x-2). Output size is too small
```

### Expected behavior
It is hoped that after solving the problem of `MaxPool1d`, this similar bug of `AvgPool1d` can be fixed together.

### Versions

<details>
  <summary>pytorch 1.9.0</summary>
  <pre><code>
  [pip3] numpy==1.20.2
  [pip3] torch==1.9.0
  [pip3] torchelastic==0.2.0
  [pip3] torchtext==0.10.0
  [pip3] torchvision==0.10.0
  [conda] blas                      1.0                         mkl  
  [conda] cudatoolkit               11.1.74              h6bb024c_0    nvidia
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.2.0           h06a4308_296  
  [conda] mkl-service               2.3.0            py37h27cfd23_1  
  [conda] mkl_fft                   1.3.0            py37h42c9631_2  
  [conda] mkl_random                1.2.1            py37ha9443f7_2  
  [conda] numpy                     1.20.2           py37h2d18471_0  
  [conda] numpy-base                1.20.2           py37hfae3a4d_0  
  [conda] pytorch                   1.9.0           py3.7_cuda11.1_cudnn8.0.5_0    pytorch
  [conda] torchelastic              0.2.0                    pypi_0    pypi
  [conda] torchtext                 0.10.0                     py37    pytorch
  [conda] torchvision               0.10.0               py37_cu111    pytorch</code></pre>
</details>


<details>
  <summary>pytorch 1.10.0</summary>
  <pre><code>
  [pip3] numpy==1.21.2
  [pip3] torch==1.10.0
  [pip3] torch-tb-profiler==0.4.0
  [pip3] torchelastic==0.2.0
  [pip3] torchtext==0.11.0
  [pip3] torchvision==0.11.0
  [conda] blas                      1.0                         mkl  
  [conda] cudatoolkit               11.3.1               ha36c431_9    nvidia
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.3.0           h06a4308_520  
  [conda] mkl-service               2.4.0            py37h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py37hd3c417c_0  
  [conda] mkl_random                1.2.2            py37h51133e4_0  
  [conda] numpy                     1.21.2           py37h20f2e39_0  
  [conda] numpy-base                1.21.2           py37h79a1101_0  
  [conda] pytorch                   1.10.0          py3.7_cuda11.3_cudnn8.2.0_0    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torch-tb-profiler         0.4.0                    pypi_0    pypi
  [conda] torchelastic              0.2.0                    pypi_0    pypi
  [conda] torchtext                 0.11.0                     py37    pytorch
  [conda] torchvision               0.11.0               py37_cu113    pytorch</code></pre>
</details>


<details>
  <summary>pytorch 1.11.0</summary>
  <pre><code>
  [pip3] numpy==1.21.6
  [pip3] pytorch-lightning==1.6.3
  [pip3] torch==1.11.0
  [pip3] torch-tb-profiler==0.4.0
  [pip3] torchaudio==0.11.0
  [pip3] torchmetrics==0.9.0
  [pip3] torchvision==0.12.0
  [conda] blas                      1.0                         mkl  
  [conda] cudatoolkit               11.3.1               h2bc3f7f_2  
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0            py38h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py38hd3c417c_0  
  [conda] mkl_random                1.2.2            py38h51133e4_0  
  [conda] numpy                     1.19.5                   pypi_0    pypi
  [conda] numpy-base                1.21.5           py38hf524024_1  
  [conda] pytorch                   1.11.0          py3.8_cuda11.3_cudnn8.2.0_0    pytorch
  [conda] pytorch-lightning         1.6.3                    pypi_0    pypi
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torch                     1.10.0                   pypi_0    pypi
  [conda] torch-tb-profiler         0.4.0                    pypi_0    pypi
  [conda] torchaudio                0.11.0               py38_cu113    pytorch
  [conda] torchmetrics              0.9.0                    pypi_0    pypi
  [conda] torchvision               0.12.0               py38_cu113    pytorch</code></pre>
</details>

<details>
  <summary>pytorch 1.12.0</summary>
  <pre><code>
  [pip3] numpy==1.21.5
  [pip3] torch==1.12.0
  [pip3] torchelastic==0.2.0
  [pip3] torchtext==0.13.0
  [pip3] torchvision==0.13.0
  [conda] blas                      1.0                         mkl  
  [conda] cudatoolkit               11.3.1               ha36c431_9    nvidia
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0            py37h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py37hd3c417c_0  
  [conda] mkl_random                1.2.2            py37h51133e4_0  
  [conda] numpy                     1.21.5           py37he7a7128_2  
  [conda] numpy-base                1.21.5           py37hf524024_2  
  [conda] pytorch                   1.12.0          py3.7_cuda11.3_cudnn8.3.2_0    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torchelastic              0.2.0                    pypi_0    pypi
  [conda] torchtext                 0.13.0                     py37    pytorch
  [conda] torchvision               0.13.0               py37_cu113    pytorch</code></pre>
</details>

<details>
  <summary>pytorch 1.13.0</summary>
  <pre><code>
  [pip3] numpy==1.22.3
  [pip3] torch==1.13.0
  [pip3] torchtext==0.14.0
  [pip3] torchvision==0.14.0
  [conda] blas                      1.0                         mkl  
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0            py39h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py39hd3c417c_0  
  [conda] mkl_random                1.2.2            py39h51133e4_0  
  [conda] numpy                     1.22.3           py39he7a7128_0  
  [conda] numpy-base                1.22.3           py39hf524024_0  
  [conda] pytorch                   1.13.0          py3.9_cuda11.6_cudnn8.3.2_0    pytorch
  [conda] pytorch-cuda              11.6                 h867d48c_0    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torchtext                 0.14.0                     py39    pytorch
  [conda] torchvision               0.14.0               py39_cu116    pytorch</code></pre>
</details>

cc @ezyang @gchanan @zou3519