Model bart cannot correctly process the length of attention_mask when the item of past_key_values is added.
### System Info

- `transformers` version: 4.18.0
- Platform: Linux-5.4.0-109-generic-x86_64-with-glibc2.31
- Python version: 3.9.12
- Huggingface_hub version: 0.2.1
- PyTorch version (GPU?): 1.11.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

@patil-sura

### Information

- [X] The official example scripts
- [ ] 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

execute the code:
`
outputs = self.bart(input_ids=input_ids,
                                attention_mask=attention_mask,
                                past_key_values=past_key_values,
                                labels=labels)
`
Model bart cannot correctly process the length of attention_mask when the item of past_key_values is added.

Additionally,

If someone uses past_key_values, it seems to raise the following exception:

`
RuntimeError: view size is not compatible with input tensor‘s size and stride ...
`
since bart executes torch.cat in BartAttention class:

`
key_states = torch.cat([past_key_value[0], key_states], dim=2)
`
`
value_states = torch.cat([past_key_value[1], value_states], dim=2)
`
Thus, we should make key_states and value_states contiguous.


@patrickvonplaten

---




### Expected behavior

It will run correctly.
cc @ArthurZucker 

@xyjigsaw could you please add a complete reproducible code snippet here though? 

We cannot run:

```python
outputs = self.bart(input_ids=input_ids, attention_mask=attention_mask, past_key_values=past_key_values, labels=labels)
```

because we don't know what `input_ids`, etc... is.<|||||>This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.