feat: config what's trainable in Bert layers
Author: gthb
Pull request: yes
Labels: name: wontfix

Make it possible to configure trainability for specific subparts of a `TFBertMainLayer`.

This is minimal and Bert-only. Really should be added in more model types, not just Bert, but it probably necessarily differs quite a bit between model types, so probably can't be done in a very “DRY” way.

See https://github.com/tensorflow/tensorflow/issues/37541 which makes this necessary: if we set `l.trainable = False` on a layer _after_ initializing it, then training and serialization proceeds without apparent problems but then deserialization will fail, because:

* the `trainable` attribute doesn't get persisted
* parameter values are deserialized and batch-assigned to model parameters _in order_ — with the implicit assumption that the ordering of parameters is the same as in the model before serialization
* that assumption doesn't hold if some layers were not trainable before serialization, because the ordering of parameters depends on the `trainable` attribute, which is `True` by default because it wasn't persisted

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3440?src=pr&el=h1) Report
> Merging [#3440](https://codecov.io/gh/huggingface/transformers/pull/3440?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/010e0460b22ddd7f74e31163f69ab3da2e9741ba&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master    #3440      +/-   ##
==========================================
+ Coverage   77.61%   77.62%   +0.01%     
==========================================
  Files         100      100              
  Lines       16972    16985      +13     
==========================================
+ Hits        13172    13185      +13     
  Misses       3800     3800              
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3440?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/configuration\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/3440/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX2JlcnQucHk=) | `100.00% <100.00%> (ø)` | |
| [src/transformers/modeling\_tf\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/3440/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9iZXJ0LnB5) | `96.16% <100.00%> (+0.08%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/3440?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/3440?src=pr&el=footer). Last update [010e046...2597d20](https://codecov.io/gh/huggingface/transformers/pull/3440?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.