[WIP][Wav2Vec2] Fix Wav2Vec2 Pretraining
Author: patrickvonplaten
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

## 1. Fix Wav2Vec2 Pretraining with PyTorch & Deepspeed

Changes in the initialization and loss calculation seemed to have solved the unstable wav2vec2 pretraining loss problem for now. In a first run, the following loss curves were obtained:

```
{'loss': 4.7028, 'learning_rate': 1.1098409651313401e-05, 'epoch': 0.49}                                                                                                                     
{'loss': 4.6605, 'learning_rate': 1.443936386052536e-05, 'epoch': 0.99}                                                                                                                      
{'loss': 4.7504, 'learning_rate': 1.639369678954086e-05, 'epoch': 1.49}                                                                                                                      
{'loss': 4.5622, 'learning_rate': 1.778031806973732e-05, 'epoch': 1.99}                                                                                                                      
{'loss': 4.5645, 'learning_rate': 1.885586509341484e-05, 'epoch': 2.49}                                                                                                                      
{'loss': 4.513, 'learning_rate': 1.9734650998752817e-05, 'epoch': 2.99}                                                                                                                      
{'loss': 4.5666, 'learning_rate': 2.0477653894913667e-05, 'epoch': 3.49}                                                                                                                     
{'loss': 4.4167, 'learning_rate': 2.112127227894928e-05, 'epoch': 3.99}                                                                                                                      
{'loss': 4.5131, 'learning_rate': 2.1742243895858865e-05, 'epoch': 4.49}                                                                                                                     
{'loss': 4.4049, 'learning_rate': 2.2244779679123014e-05, 'epoch': 4.99}                                                                                                                     
{'loss': 4.5507, 'learning_rate': 2.269983228781891e-05, 'epoch': 5.49}                                                                                                                      
{'loss': 4.4056, 'learning_rate': 2.3115605255534444e-05, 'epoch': 5.99}                                                                                                                     
{'loss': 4.4998, 'learning_rate': 2.349834418215476e-05, 'epoch': 6.49}                                                                                                                      
{'loss': 4.4116, 'learning_rate': 2.385291414268169e-05, 'epoch': 6.99}                                                                                                                      
{'loss': 4.539, 'learning_rate': 2.418317878182792e-05, 'epoch': 7.49}                                                                                                                       
{'loss': 4.3734, 'learning_rate': 2.4492257601320028e-05, 'epoch': 7.99}                                                                                                                     
{'loss': 4.4986, 'learning_rate': 2.4810810490944393e-05, 'epoch': 8.49}                                                                                                                     
{'loss': 4.3982, 'learning_rate': 2.5083198105070827e-05, 'epoch': 8.99}                                                                                                                     
{'loss': 4.4946, 'learning_rate': 2.5341012393499218e-05, 'epoch': 9.49}                                                                                                                     
{'loss': 4.3938, 'learning_rate': 2.5585733888334973e-05, 'epoch': 9.99}                                                                                                                     
{'loss': 4.4944, 'learning_rate': 2.5818628371128123e-05, 'epoch': 10.49}                                                                                                                    
{'loss': 4.4035, 'learning_rate': 2.604078649703087e-05, 'epoch': 10.99}                                                                                                                     
  6%|████████▎                                                                                                                                          | 227/4000 [16:55<4:45:30,  4.54s/it]
```

The run can be reproduced by doing the following:

**1. Create training folder**

```bash
mkdir wav2vec2_reproduce
cd wav2vec2_reproduce
```

**2. Create data folder**

```
git lfs install
git clone https://huggingface.co/patrickvonplaten/LibriSpeechTest
```

**3. Create model & experiment folder**

```
git lfs install
git clone https://huggingface.co/patrickvonplaten/wav2vec2_libri
```

**4. Prepare training**

We need to create a simlink as follows:

```
ln $(realpath ./LibriSpeechTest) LibriSpeech
```

and the manual data dir as defined in: https://huggingface.co/patrickvonplaten/wav2vec2_libri/blob/main/run_main.sh#L20

 should be renamed to the local absolute path that leads to the just created simlink folder `wav2vec2_reproduce/LibriSpeech`.

We have to make sure that the `transformers` is checkout to the branch of this PR: `https://github.com/patrickvonplaten/transformers/tree/wav2vec2-pretraining`

Finally, we can start running the training:

```
cd wav2vec2_libri
./run_main.sh
```

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      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/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] 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.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
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/master/CONTRIBUTING.md) are likely to be ignored.