Repository: pytorch
Issue: MMDet 3.x cannot run successfully in inductor mode
Labels: triaged,bug

### 🐛 Describe the bug

Hi guys, I'm going to verify dynamo on mmdet 3.x branch, but I'm getting some errors

Environmental information
``` bash 
sys.platform: linux
Python: 3.8.15 (default, Nov  4 2022, 20:59:55) [GCC 11.2.0]
CUDA available: True
numpy_random_seed: 2147483648
NVCC: Cuda compilation tools, release 11.7, V11.7.99
GCC: gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
PyTorch: 1.14.0.dev20221123
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201402
  - Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.0 (Git Hash 650085b2f3643aad05c629425983491d63b5c289)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.7
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_37,code=compute_37
  - CuDNN 8.5
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=1.14.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

TorchVision: 0.15.0.dev20221123
OpenCV: 4.6.0
MMEngine: 0.3.1
MMDetection: 3.0.0rc3+3f6dc71
```

The installation command is as follows: 

```bash
git clone https://github.com/open-mmlab/mmdetection.git
git clone https://github.com/open-mmlab/mmcv.git
git clone https://github.com/C1rN09/mmengine.git

cd mmengine
git checkout dynamo_1
pip install -e .

cd ../mmcv
git checkout 2.x
MMCV_WITH_OPS=1 pip install -e .

cd ../mmdetection
git checkout dev-3.x
pip install -e .

python tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py
```

## 1 eager mode
I use eager mode to verify that it works successfully at first.

![image](https://user-images.githubusercontent.com/17425982/204205920-f8fb4efc-bc9f-42e2-99bb-bfcd06635b0b.png)

I modified the following code：` torch.Tensor -> torch.tensor.`  I got the following error after modifying the code

![image (1)](https://user-images.githubusercontent.com/17425982/204205893-45dfb173-6e7d-49ef-a04b-a00a9a0770c3.png)

I modified the following code： `range -> tuple(range)`.  I got the following error after modifying the code

![image (2)](https://user-images.githubusercontent.com/17425982/204205972-f3c62fdc-b816-4db6-9d95-09eeed7feda6.png)

Remove all `dtype` parameters and use `float()` instead
-  https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/models/task_modules/prior_generators/anchor_generator.py#L222，
- https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/models/dense_heads/base_dense_head.py#L262

At this point, it works successfully, but it is very slow and some warning 

![image (3)](https://user-images.githubusercontent.com/17425982/204206085-1f874bde-9a23-474e-bdd9-b2302b9de5ee.png)


## 2 aot_eager mode
It can run but very slowly.

## 3 inductor mode
I get the error as below

![image (4)](https://user-images.githubusercontent.com/17425982/204206153-e1492c9a-040d-4981-8d5d-82186ee54305.png)


By the way, I train with `MMYOLO`, which can run successfully in inductor mode with a simple modification. But it is very slow and will OOM. 




### Error logs

_No response_

### Minified repro

_No response_