GPT2 jit trace ERROR 
### System Info

version
transformers: 4.29.1
pytorch: 2.0.0+cu117
python: 3.8.8

code:
```
from transformers import GPT2Tokenizer, GPT2Model
import torch
import transformers
print(transformers.__version__)
print(torch.__version__)


model_name = 'gpt2'

input_text = ["nice to meet you " * 63 + "hello gpt."]
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
inputs = tokenizer(input_text, return_tensors="pt")
input_tuple = (inputs['input_ids'], inputs['attention_mask'])

model = GPT2Model.from_pretrained(model_name, torchscript=True).eval()

traced_model = torch.jit.trace(model, input_tuple)
print(traced_model.graph) 
```

ERROR:
```
Traceback (most recent call last):
  File "test_gpt.py", line 17, in <module>
    traced_model = torch.jit.trace(model, input_tuple)
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 794, in trace
    return trace_module(
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 1056, in trace_module
    module._c._create_method_from_trace(
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/hjl/.local/lib/python3.8/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 800, in forward
    past_length = past_key_values[0][0].size(-2)
IndexError: Dimension specified as -2 but tensor has no dimensions
```

### Who can help?

@ArthurZucker @youn

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

code:
```python
from transformers import GPT2Tokenizer, GPT2Model
import torch
import transformers
print(transformers.__version__)
print(torch.__version__)


model_name = 'gpt2'

input_text = ["nice to meet you " * 63 + "hello gpt."]
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
inputs = tokenizer(input_text, return_tensors="pt")
input_tuple = (inputs['input_ids'], inputs['attention_mask'])

model = GPT2Model.from_pretrained(model_name, torchscript=True).eval()

traced_model = torch.jit.trace(model, input_tuple)
print(traced_model.graph) 
```

ERROR:
```python
Traceback (most recent call last):
  File "test_gpt.py", line 17, in <module>
    traced_model = torch.jit.trace(model, input_tuple)
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 794, in trace
    return trace_module(
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 1056, in trace_module
    module._c._create_method_from_trace(
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/hjl/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/hjl/.local/lib/python3.8/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 800, in forward
    past_length = past_key_values[0][0].size(-2)
IndexError: Dimension specified as -2 but tensor has no dimensions
```

### Expected behavior

torch.jit.trace(gpt2model)
input_tuple = (inputs['input_ids'], inputs['attention_mask'])

updata

input_tuple = inputs['input_ids']