Add Data2Vec
Author: edugp
Pull request: yes

# What does this PR do?

Add Data2Vec to transformers.

I started by cloning the RoBERTa model and fixing the conversion script for Data2Vec. We then added the audio model using some components from Wav2Vec2.

Conversion logs show identical forward passes for both text and audio:
```
max_absolute_diff = 0.0
Do both models output the same tensors? 🔥
```
Example usage for text:
```python
from transformers import RobertaTokenizer, Data2VecTextForSequenceClassification, Data2VecTextConfig
import torch

tokenizer = RobertaTokenizer.from_pretrained("roberta-large")
config = Data2VecTextConfig.from_pretrained("facebook/data2vec-text-base")
model = Data2VecTextForSequenceClassification.from_pretrained("facebook/data2vec-text-base", config=config)
# Fine-tune this model

inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)

prediction_logits = outputs.logits
```
`data2vec-text-base` converted weights are [here](https://huggingface.co/facebook/data2vec-text-base), from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/nlp_base.pt)
`data2vec-audio-base` converted weights are [here](facebook/data2vec-audio-base) from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/audio_base_ls.pt) with no finetuning
`data2vec-audio-base-960h` converted weights are [here](https://huggingface.co/facebook/data2vec-audio-base-960h) from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/audio_base_ls_960h.pt) fine-tuned on 960 hours of Librispeech
NOTE: Data2Vec image model weights have not been released yet.
NOTE: The current implementation does not support pre-training yet, only fine-tuning on text and audio tasks.


Fixes # (issue)

## Who can review?

@patil-suraj @patrickvonplaten @mrm8488 @anton-l 


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_15507). All of your documentation changes will be reflected on that endpoint.

Ah the new test design just got merged [here](https://github.com/huggingface/transformers/pull/15725) :sweat_smile:  

@edugp - I'm afraid you'll have to merge current master into your branch here (or do `git rebase`) and resolve the conflicts before we can merge this one. Would be amazing if you could give it a stab - should be pretty easy I think, just create a test dir called for data2vec and move the files there :-)

Here some step-by-step explanation from @sgugger :-) 

To fix your open PR if it touched some test files, three simple steps:
Get the latest master
```
git checkout origin/master
git pull
```
2. Rebase
```
git checkout your_branch
git rebase origin/master
```
This will automatically port your changes to the test modeling files where they now are. If you have new tests files (e.g. a model PR) make sure to adapt the structure to match the new one (with a subfolder for your new model for instance)
3. Force-push your changes (force to avoid GitHub showing a diff of 666 files)
```
git push -u your_branch remote_branch -f
```

Thanks @patrickvonplaten, I synced the latest master with this branch and moved the tests to the new directory structure (and verified that they still pass). I also added all `Copied from` statements and  addressed the rest of comments. Thanks for the thorough review! 

Fixed the red CI @edugp - should be good for merge now.

@sgugger - I'm not 100% whether it's ok what I've done here: https://github.com/huggingface/transformers/pull/15507/files#r813404423 . Given that we have one `data2vec` folder and one `data2vec` paper I think it's also better to have one doc page no? If you're ok with this change in the `utils/...` I think we can merge.

> # What does this PR do?
> Add Data2Vec to transformers.
> 
> I started by cloning the RoBERTa model and fixing the conversion script for Data2Vec. We then added the audio model using some components from Wav2Vec2.
> 
> Conversion logs show identical forward passes for both text and audio:
> 
> ```
> max_absolute_diff = 0.0
> Do both models output the same tensors? 🔥
> ```
> 
> Example usage for text:
> 
> ```python
> from transformers import RobertaTokenizer, Data2VecTextForSequenceClassification, Data2VecTextConfig
> import torch
> 
> tokenizer = RobertaTokenizer.from_pretrained("roberta-large")
> config = Data2VecTextConfig.from_pretrained("facebook/data2vec-text-base")
> model = Data2VecTextForSequenceClassification.from_pretrained("facebook/data2vec-text-base", config=config)
> # Fine-tune this model
> 
> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
> outputs = model(**inputs)
> 
> prediction_logits = outputs.logits
> ```
> 
> `data2vec-text-base` converted weights are [here](https://huggingface.co/facebook/data2vec-text-base), from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/nlp_base.pt) `data2vec-audio-base` converted weights are [here](facebook/data2vec-audio-base) from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/audio_base_ls.pt) with no finetuning `data2vec-audio-base-960h` converted weights are [here](https://huggingface.co/facebook/data2vec-audio-base-960h) from [fairseq original weights](https://dl.fbaipublicfiles.com/fairseq/data2vec/audio_base_ls_960h.pt) fine-tuned on 960 hours of Librispeech NOTE: Data2Vec image model weights have not been released yet.
> 
> Fixes # (issue)
> 
> ## Who can review?
> @patil-suraj @patrickvonplaten @mrm8488 @anton-l

~~Is this supposed to work? I'm getting `ImportError: cannot import name 'Data2VecTextConfig' from 'transformers' (/data/home/justincho/Data2Vec_lightning/transformers/src/transformers/__init__.py)` after cloning this branch and using it to install the transformers library : `https://github.com/edugp/transformers/tree/add-data2vec-from-roberta`~~

Never mind, I didn't checkout to the branch `add-data2vec-from-roberta` before doing `pip install -e .`

Does this update include changes necessary for training using the data2vec objective? I'm curious because I don't see an EMA implementation anywhere. 

> Does this update include changes necessary for training using the data2vec objective? I'm curious because I don't see an EMA implementation anywhere.

@wise-east it does not support pre-training yet, unfortunately! Only fine-tuning on text and audio tasks. I will update the PR description to reflect that.

@sgugger @osanseviero @julien-c - merging this now. Sorry, I'm not 100% sure yet how to handle the HF Hub <=> Transformers doc page linking for this model, but I think we can solve this in a follow-up PR.

Great job @edugp :partying_face: 

Enorme, @edugp !!!