Repository: pytorch
Issue: torch.jit.script report error when using index to subscript nn.ModuleList
Labels: triage review,oncall: jit

## 🐛 Bug
torch.jit.script report error when using index to subscript nn.ModuleList

## To Reproduce

Steps to reproduce the behavior:

1. test.py
<pre>import torch.nn as nn

class my_model(nn.Module):
    def __init__(self):
        super(my_model, self).__init__()
        self.m = nn.ModuleList([nn.Conv3d(3, 64, kernel_size=(5, 7, 7), stride=(1, 2, 2), padding=(2, 3, 3), bias=False),
                                nn.BatchNorm3d(64),
                                nn.ReLU(True),
                                nn.MaxPool3d(kernel_size=(1, 3, 3), stride=(1, 2, 2), padding=(0, 1, 1))])
    def forward(self, x):
        for i in range(0, 4):
            x = self.m[i](x)
        return x
</pre>
2. import test.py and use torch.jit.script:
<pre>
(pytorch) PS D:\test> python
Python 3.8.2 | packaged by conda-forge | (default, Feb 28 2020, 16:38:51) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from test import *
>>> import torch
>>> model=my_model()
>>> model.eval()
my_model(
  (m): ModuleList(
    (0): Conv3d(3, 64, kernel_size=(5, 7, 7), stride=(1, 2, 2), padding=(2, 3, 3), bias=False)
    (1): BatchNorm3d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    (3): MaxPool3d(kernel_size=(1, 3, 3), stride=(1, 2, 2), padding=(0, 1, 1), dilation=1, ceil_mode=False)
  )
)
>>> torch.jit.script(model)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\jit\__init__.py", line 1255, in script
    return torch.jit._recursive.recursive_script(obj)
  File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\jit\_recursive.py", line 534, in recursive_script
    return create_script_module(nn_module, infer_methods_to_compile(nn_module))
  File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\jit\_recursive.py", line 296, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, cpp_module, stubs)
  File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\jit\_recursive.py", line 340, in create_script_module_impl
    create_methods_from_stubs(concrete_type, stubs)
  File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\jit\_recursive.py", line 259, in create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
RuntimeError:
'module' object is not subscriptable:
  File "D:\test\test.py", line 12
    def forward(self, x):
        for i in range(0, 4):
            x = self.m[i](x)
                ~~~~~~~~ <--- HERE
        return x
</pre>

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment
<pre>

(pytorch) PS D:\test> python .\collect_env.py
Collecting environment information...
PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Microsoft Windows 10 专业版
GCC version: Could not collect
CMake version: Could not collect

Python version: 3.8
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] numpy==1.18.1
[pip] torch==1.4.0
[pip] torchvision==0.5.0
[conda] libblas                   3.8.0                    15_mkl    https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
[conda] libcblas                  3.8.0                    15_mkl    https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
[conda] liblapack                 3.8.0                    15_mkl    https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
[conda] liblapacke                3.8.0                    15_mkl    https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
[conda] mkl                       2020.0                      166    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
[conda] pytorch                   1.4.0           py3.8_cuda101_cudnn7_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] torchvision               0.5.0                py38_cu101    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
(pytorch) PS D:\test>
</pre>

## Additional context

<!-- Add any other context about the problem here. -->


cc @suo