

TITLE
Add missing type hints

COMMENTS
69

REACTIONS
+1: 0
-1: 0
laugh: 0
hooray: 2
heart: 0
rocket: 4
eyes: 0

BODY
### This issue is part of our **Great Code Cleanup 2022**. If you're interested in helping out, take a look at [this thread](https://twitter.com/carrigmat/status/1502319813510766599), or come [join us on Discord](https://t.co/kS42XBvpWH) and talk with other contributors!

# 🚀 Add missing type hints

Type hints are used inconsistently in the `transformers` repo across both TF and PT models, and it'd be nice to make them a complete, consistent thing for the core models, especially because we want to develop features that depend on them!

### Guide to contributing:

1. Ensure you've read our contributing [guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) 📜 
2. Claim your architecture(s) in this thread (ensure no one is working on it). It's 100% okay to only take the TensorFlow or PyTorch version of a model, if you're not familiar with both frameworks! It's also okay to claim multiple models and group those changes into a single PR! 🎯 
3. Implement the changes as in https://github.com/huggingface/transformers/pull/16057 or https://github.com/huggingface/transformers/pull/16074 (see the diff on the model architectures for a few examples) 💪 
4. Open the PR and tag me in it. You should run `make fixup` at the end to do a code quality check before your final commit!

### Tips for making your PR

1. The files you need to edit will be in `src/transformers/models/[model_name]/`
2. For TensorFlow, you want the `modeling_tf_[model_name].py` file. For PyTorch, you want the `modeling_[model_name].py` file.
3.  Remember, you **do not** have to cover every class in that file!. The main thing we want to cover is the `call` (for TF) or `forward` (for PT) method for user-facing classes like `TFRobertaForMaskedLM` or `RobertaForSequenceClassification`. It's not necessary to add type hints to base classes like `RobertaModel` or `TFRobertaPreTrainedModel` - these are trickier to write, and generally people do not use those classes as standalone models.
4. If you're unfamiliar with how type hints work, you can read the [Python library documentation on them](https://docs.python.org/3/library/typing.html), but it's probably even easier to just look at another PR that added them. Take a look at the list of changes in the pull requests linked above!
5. The types will usually be obvious - most inputs are `Optional[Union[np.ndarray, tf.Tensor]]` for TF models and `Optional[torch.Tensor]` for PyTorch models, and boolean inputs are `Optional[bool]`. Pay attention to the first input of TF models, though, which is usually `TFModelInputType` - this is because Keras handles that first input in a special way! Other inputs to pay attention to are `past_key_values`, which can vary between models, and also the model output type. For the base model classes like `RobertaModel`, you may have to look at the corresponding `MainLayer` to figure out the right output type! Also, note that the output type may be a tuple if `return_dict` is False, in which case you should specify `Union[Tuple, ...]`.
6. Note that some code is copied across our codebase. If you see a line like `# Copied from transformers.models.bert...`, this means that the code is copied from that source, and our scripts will automatically keep that in sync. If you see that, you should not edit the copied method! Instead, edit the original method it's copied from, and run `make fixup` to synchronize that across all the copies. Be sure you installed the development dependencies with `pip install -e ".[dev"]`, as described in the contributor guidelines above, to ensure that the code quality tools in `make fixup` can run.


### Models updated:

#### TensorFlow:

- [x] BART
- [x] Blenderbot
- [ ] CTRL
- [x] Camembert
- [ ] ConvBert
- [ ] DPR
- [x] Distilbert
- [x] Electra
- [ ] Flaubert
- [ ] Funnel
- [x] GPT2
- [x] Longformer
- [ ] Lxmert
- [ ] MBart
- [ ] MPNet
- [ ] MT5
- [ ] MobileBert
- [ ] OpenAIGPT
- [ ] Rag
- [X] Roberta
- [x] T5
- [ ] TransfoXL
- [x] XLM
- [ ] XLMRoberta
- [ ] XLNet

#### PyTorch:

- [x] Albert
- [x] BART
- [x] BeiT
- [x] BERT
- [x] BigBird
- [ ] BigBirdPegasus
- [x] Blenderbot
- [x] BlenderbotSmall
- [x] CLIP
- [ ] CTRL
- [x] CamemBERT
- [ ] Canine
- [x] ConvBert
- [ ] Data2Vec
- [x] Deberta
- [x] DeiT
- [x] Distilbert
- [x] Electra
- [x] FNet
- [ ] FSMT
- [x] Flaubert
- [x] Funnel
- [x] GPT2
- [x] GPTJ
- [x] GPTNeo
- [x] Hubert
- [x] IBert
- [x] ImageGPT
- [ ] LED
- [x] LayoutLM
- [x] LayoutLMv2
- [x] Longformer
- [x] Luke
- [ ] Lxmert
- [ ] M2M
- [x] MBart
- [ ] MPNet
- [ ] MT5
- [x] Marian
- [ ] MegatronBert
- [x] MobileBert
- [ ] Nystromformer
- [ ] OpenAIGPT
- [x] PLBart
- [x] Pegasus
- [x] Perceiver
- [x] PoolFormer
- [ ] ProphetNet
- [ ] rag
- [ ] Reformer
- [x] RemBert
- [ ] RoFormer
- [x] RoBERTa
- [ ] SEWD
- [x] Segformer
- [x] Splinter
- [x] SqueezeBERT
- [x] Swin
- [x] T5
- [ ] TransfoXL
- [ ] UniSpeech
- [ ] UniSpeechSat
- [x] ViT
- [ ] Vilt
- [ ] VisualBERT
- [x] Wav2Vec2
- [ ] WavLM
- [ ] XGLM
- [ ] XLM
- [ ] XLMProphetNet
- [ ] XLMRoBERTa
- [x] XLMRobertaXL
- [ ] XLNet
- [ ] Yoso