Output `None` as attention when layer is skipped
Author: jonghwanhyeon
Pull request: yes

# What does this PR do?

Fixes an out of index error caused by skipped layers when `output_attentions` is `True` in training mode on WavLM model.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [X] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@sanchit-gandhi @patrickvonplaten 


Comments:
Hi @jonghwanhyeon, thanks for adding this! Could you add a test which passes with this fix and fails on main? 

cc @kamilakesbi for first review 

> Hi @jonghwanhyeon, thanks for adding this! Could you add a test which passes with this fix and fails on main?
> 
> cc @kamilakesbi for first review

Added a test case

Hi @jonghwanhyeon, 

Thank you very much for working on this!

Could you provide your working environnement (by running `transformers-cli env`) as well as a minimal reproducer of the bug? 

I've run the test you suggested both with`layer_outputs = (None,None,None)` and `layer_outputs = (None,None)`, and the test seems to pass in both cases ( I'm using `transformers` version 4.41.0.dev0).

Thanks! 

cc @sanchit-gandhi 

Oh, that is because the value of `model.config.layerdrop` is so low. Please check the following code and updated commits:

```python
import torch

from transformers import WavLMConfig, WavLMModel

model = WavLMModel(WavLMConfig())
model.config.layerdrop = 1.0
model.train()
outputs = model(torch.randn(1, 8_000), output_attentions=True)
```

For your information, my environment is as below (with the modifications of `(None, None, None)`):
- `transformers` version: 4.41.0.dev0
- Platform: Linux-5.4.0-174-generic-x86_64-with-glibc2.35
- Python version: 3.11.9
- Huggingface_hub version: 0.22.2
- Safetensors version: 0.4.3
- Accelerate version: 0.29.2
- Accelerate config:    not found
- PyTorch version (GPU?): 2.2.2+cu118 (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>

Ok, thanks a lot @jonghwanhyeon! 

LGTM - I can reproduce the bug and your code seems to fix it. I've tried your test and it passes know.

CC @amyeroberts for a final check!