[cleanup] factor out get_head_mask, invert_attn_mask, get_extended_attention_mask
Author: sshleifer
Pull request: yes

This is three changes applied all over:

1) `get_head_mask` from @LysandreJik is used instead of redundant snippet
2) `get_extended_attention_mask` is used instead of redundant snippet (that also makes causal mask)
3) `invert_attention_mask` is used instead of redundant snippet that doesn't make causal mask.

These changes make the forward passes more readable and allow us to update common logic in one place moving forward! I was reading code last night to try to get a sense of what all the models/tokenizers do and was frustrated with the amount of time spent scrolling through this stuff. Especially for new people, it makes getting to the meet of the `forward` pass much harder to have 100 lines repeated lines of input manipulation at the beginning.


Very open to suggestions.
Open to doing this for TF in a separate PR.
Also if `prune_heads` or other opportunities catch your eye, let me know.



Comments:
This looks nice

# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=h1) Report
> Merging [#3806](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/01c37dcdb529bff38aadd51001cb5812e5fe9b21&el=desc) will **increase** coverage by `0.15%`.
> The diff coverage is `90.14%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/3806/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #3806      +/-   ##
==========================================
+ Coverage   78.26%   78.42%   +0.15%     
==========================================
  Files         106      106              
  Lines       17964    17864     -100     
==========================================
- Hits        14060    14009      -51     
+ Misses       3904     3855      -49     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/modeling\_mmbt.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19tbWJ0LnB5) | `22.11% <40.00%> (+4.51%)` | :arrow_up: |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `90.94% <92.00%> (-0.03%)` | :arrow_down: |
| [src/transformers/modeling\_albert.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19hbGJlcnQucHk=) | `75.31% <100.00%> (+0.06%)` | :arrow_up: |
| [src/transformers/modeling\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19iZXJ0LnB5) | `88.40% <100.00%> (+0.24%)` | :arrow_up: |
| [src/transformers/modeling\_ctrl.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19jdHJsLnB5) | `97.81% <100.00%> (+0.78%)` | :arrow_up: |
| [src/transformers/modeling\_distilbert.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19kaXN0aWxiZXJ0LnB5) | `98.15% <100.00%> (+0.56%)` | :arrow_up: |
| [src/transformers/modeling\_electra.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19lbGVjdHJhLnB5) | `73.20% <100.00%> (+0.55%)` | :arrow_up: |
| [src/transformers/modeling\_flaubert.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19mbGF1YmVydC5weQ==) | `84.49% <100.00%> (+0.67%)` | :arrow_up: |
| [src/transformers/modeling\_gpt2.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19ncHQyLnB5) | `86.25% <100.00%> (+0.31%)` | :arrow_up: |
| [src/transformers/modeling\_openai.py](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19vcGVuYWkucHk=) | `81.78% <100.00%> (+0.24%)` | :arrow_up: |
| ... and [3 more](https://codecov.io/gh/huggingface/transformers/pull/3806/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=footer). Last update [01c37dc...2e7f6f4](https://codecov.io/gh/huggingface/transformers/pull/3806?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).