Repository: pytorch
Issue: Transformers model tracing not working
Labels: oncall: jit

### 🐛 Describe the bug

When using torch.neuron.trace to compile a transformer model, an error appears : torch.jit.trace failed with following error: 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/alias_analysis.cpp":607, please report a bug to PyTorch. We don't have an op for aten::constant_pad_nd but it isn't a special case.

- Code to reproduce

```
import torch  
from torch import nn
import torch_neuron
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained(
            pretrained_model_name_or_path='shtoshni/longformer_coreference_joint', use_fast=True
        )
model = AutoModel.from_pretrained(
            pretrained_model_name_or_path='shtoshni/longformer_coreference_joint',
            output_hidden_states=False,
            add_pooling_layer=False,
            return_dict = False,
        )
model.eval()

#model wrapper
class Mymodel(nn.Module):
    def __init__(self):
        super(Mymodel,self).__init__()
        self.pretrained = AutoModel.from_pretrained(
            pretrained_model_name_or_path='shtoshni/longformer_coreference_joint',
            output_hidden_states=False,
            add_pooling_layer=False,
            #return_dict = False,
        )
        #self.pretrained.eval()
    
    def forward(self,*x):
        self.pretrained.eval()
        x = list(x)
        y = self.pretrained(*x)
        return y[0]

sequence_0 = "The company HuggingFace is based in New York City"
sequence_1 = "HuggingFace's headquarters are situated in Manhattan"

max_length=128
paraphrase = tokenizer.encode_plus(sequence_0, sequence_1, max_length=max_length, padding='max_length', truncation=True, return_tensors="pt")

example_inputs_paraphrase = paraphrase['input_ids'], paraphrase['attention_mask']
mymodel = Mymodel()
mymodel.eval()
model_neuron = torch.neuron.trace(mymodel, example_inputs_paraphrase)
```

- Error message
```
RuntimeError                              Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/torch_neuron/decorators.py in torch_trace_error_handler()
   1526     try:
-> 1527         yield
   1528     except RuntimeError as e:

~/anaconda3/lib/python3.7/site-packages/torch_neuron/convert.py in to_graph(func_or_mod, example_inputs, return_trace, **kwargs)
    218     with track_script() as script_tracker, torch_trace_error_handler():
--> 219         jit_trace = torch.jit.trace(func_or_mod, example_inputs, **kwargs)
    220     original_name = getattr(jit_trace, 'original_name',

~/anaconda3/lib/python3.7/site-packages/torch/jit/_trace.py in trace(func, example_inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit)
    749             _force_outplace,
--> 750             _module_class,
    751         )

~/anaconda3/lib/python3.7/site-packages/torch/jit/_trace.py in trace_module(mod, inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit)
    964                 _force_outplace,
--> 965                 argument_names,
    966             )

RuntimeError: 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/alias_analysis.cpp":607, please report a bug to PyTorch. We don't have an op for aten::constant_pad_nd but it isn't a special case.  Argument types: Tensor, int[], bool, 

Candidates:
...

torch.jit.trace failed with following error: 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/alias_analysis.cpp":607, please report a bug to PyTorch. We don't have an op for aten::constant_pad_nd but it isn't a special case.  Argument types: Tensor, int[], bool, 

Candidates:
	aten::constant_pad_nd(Tensor self, int[] pad, Scalar value=0) -> (Tensor)
```



### Versions

PyTorch version: 1.11.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.21.3
Libc version: glibc-2.10

Python version: 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)  [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-1088-aws-x86_64-with-debian-buster-sid
Is CUDA available: True
CUDA runtime version: 10.0.130
CUDA_MODULE_LOADING set to: 
GPU models and configuration: GPU 0: Tesla T4
Nvidia driver version: 450.142.00
cuDNN version: Probably one of the following:
/usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudnn.so.7.6.5
/usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.7.6.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.19.2
[pip3] numpydoc==1.1.0
[pip3] torch==1.11.0
[pip3] torch-model-archiver==0.6.0
[pip3] torch-neuron==1.11.0.2.3.0.0
[pip3] torchserve==0.6.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py37he8ac12f_0  
[conda] mkl_fft                   1.2.1            py37h54f3939_0  
[conda] mkl_random                1.1.1            py37h0573a6f_0  
[conda] numpy                     1.19.2           py37h54aff64_0  
[conda] numpy-base                1.19.2           py37hfa32c7d_0  
[conda] numpydoc                  1.1.0              pyhd3eb1b0_1  
[conda] torch                     1.11.0                   pypi_0    pypi
[conda] torch-model-archiver      0.6.0                    pypi_0    pypi
[conda] torch-neuron              1.11.0.2.3.0.0           pypi_0    pypi
[conda] torchserve                0.6.0                    pypi_0    pypi

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel