Repository: pytorch
Issue: `AvgPool` and `MaxPool` will crash in JIT w/o profiling executor
Labels: oncall: jit

### 🐛 Describe the bug

`AvgPool` and `MaxPool` will crash in JIT w/o profiling executor when the output size contains `0`

For `AdaptiveMaxPool`, it will directly crash in the forward phase

```py
import torch
torch._C._jit_set_profiling_executor(False)

class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        output_size = [0, 1, 1]
        arg_class = torch.nn.AdaptiveMaxPool3d(output_size)
        self.arg_class = arg_class

    def forward(self, inp):
        arg_class = self.arg_class
        fn_res = arg_class(inp)
        return fn_res

fn = M().to('cuda')

inp = torch.randn([1, 1, 1, 9, 10], dtype=torch.float32, device='cuda')

jit_fn = torch.jit.script(fn)
jit_fn(inp)
```

```
floating point exception (core dumped)
```

For `AvgPool`, it will crash in the backward phase

```py
import torch
torch._C._jit_set_profiling_executor(False)

class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        output_size = [0, 1, 1]
        arg_class = torch.nn.AdaptiveAvgPool3d(output_size, )
        self.arg_class = arg_class

    def forward(self, inp):
        arg_class = self.arg_class
        fn_res = arg_class(inp)
        return fn_res

inp = torch.rand([1, 1, 1, 9, 10], dtype=torch.float32)
inp = inp.to('cuda')

fn = M().to('cuda')
jit_fn = torch.jit.trace(fn, inp)

jit_fn(inp.requires_grad_()).sum().backward()
```

```
floating point exception (core dumped)
```

### Versions

```
Collecting environment information...
PyTorch version: 1.14.0.dev20221020
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Clang version: 14.0.0-1ubuntu1
CMake version: version 3.24.1
Libc version: glibc-2.35

Python version: 3.9.13 (main, Aug 25 2022, 23:26:10)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.5-051905-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.6.124
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060
Nvidia driver version: 515.76
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] functorch==0.2.1
[pip3] numpy==1.23.3
[pip3] torch==1.14.0.dev20221020
[pip3] torchaudio==0.14.0.dev20221020
[pip3] torchvision==0.15.0.dev20221020
[conda] _tflow_select             2.3.0                       mkl  
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] functorch                 0.2.1                    pypi_0    pypi
[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] 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.23.3                   pypi_0    pypi
[conda] numpy-base                1.23.1           py39ha15fc14_0  
[conda] pytorch                   1.14.0.dev20221020 py3.9_cuda11.6_cudnn8.3.2_0    pytorch-nightly
[conda] pytorch-cuda              11.6                 h867d48c_0    pytorch-nightly
[conda] pytorch-mutex             1.0                        cuda    pytorch-nightly
[conda] tensorflow-base           2.9.1           mkl_py39h353358b_0  
[conda] torchaudio                0.13.0.dev20220923+cu116          pypi_0    pypi
[conda] torchvision               0.14.0.dev20220923+cu116          pypi_0    pypi
```