[ONNX] RuntimeError: 0 INTERNAL ASSERT FAILED at "/pytorch/torch/csrc/jit/ir/ir.cpp":518
Labels: oncall: jit, module: onnx, onnx-needs-info

### 🐛 Describe the bug

I want to export an onnx model which contains a dynamic for loop determined by the input tensor.
However, I got the bug below.
# Full Error Information
```
Traceback (most recent call last):
  File "d:\End2End\test_onnx.py", line 22, in <module>
    export(model_script, inputs, 'script.onnx',opset_version=11, example_outputs=output)
  File "D:\anaconda\envs\mmlab\lib\site-packages\torch\onnx\__init__.py", line 271, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "D:\anaconda\envs\mmlab\lib\site-packages\torch\onnx\utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "D:\anaconda\envs\mmlab\lib\site-packages\torch\onnx\utils.py", line 694, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "D:\anaconda\envs\mmlab\lib\site-packages\torch\onnx\utils.py", line 463, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "D:\anaconda\envs\mmlab\lib\site-packages\torch\onnx\utils.py", line 174, in _optimize_graph
    torch._C._jit_pass_lint(graph)
RuntimeError: 0 INTERNAL ASSERT FAILED at "..\\torch\\csrc\\jit\\ir\\ir.cpp":518, please report a bug to PyTorch. 20 not in scope
```
# code to reproduce the bug.
```python
import torch
from torch import nn, jit
from typing import List
from torch.onnx import export


class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv3d(1, 1, 3, 1, 1)

    def forward(self, x):
        outputs = jit.annotate(List[torch.Tensor], [])
        for i in range(x.size(0)):
            outputs.append(self.conv(x[i].unsqueeze(0)))
        return torch.stack(outputs, 0).squeeze()


inputs = torch.rand((3, 1, 5, 5, 5))
model = Model()
with torch.no_grad():
    output = model(inputs)
model_script = jit.script(model)
export(model_script, inputs, 'script.onnx',
       opset_version=11, example_outputs=output)
```

### Versions

PyTorch version: 1.8.1+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 家庭中文版
GCC version: (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Clang version: Could not collect
CMake version: version 3.21.1
Libc version: N/A

Python version: 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19044-SP0
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060 Laptop GPU
Nvidia driver version: 466.81
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.22.4
[pip3] torch==1.8.1+cu111
[pip3] torchvision==0.9.1+cu111
[conda] numpy                     1.22.4                    <pip>
[conda] torch                     1.8.1+cu111               <pip>
[conda] torchvision               0.9.1+cu111               <pip>