Training & fine-tuning quickstart
Author: joeddav
Pull request: yes

This PR adds a short guide to the docs demonstrating how to train & fine-tune models in native PyTorch, native TF2, and using Trainer.

My aim was not to show how to train on every type of task, but simply to communicate the key points along with a couple of very simple and easy-to-follow examples. More involved examples spanning many tasks are linked at the bottom.

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5034?src=pr&el=h1) Report
> Merging [#5034](https://codecov.io/gh/huggingface/transformers/pull/5034?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/24f46ea3f3e5006ca38735306753a846a0823174&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master    #5034      +/-   ##
==========================================
+ Coverage   79.08%   79.10%   +0.02%     
==========================================
  Files         138      138              
  Lines       24078    24078              
==========================================
+ Hits        19041    19046       +5     
+ Misses       5037     5032       -5     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5034?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5034/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `87.77% <0.00%> (+0.14%)` | :arrow_up: |
| [src/transformers/modeling\_openai.py](https://codecov.io/gh/huggingface/transformers/pull/5034/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19vcGVuYWkucHk=) | `80.90% <0.00%> (+1.38%)` | :arrow_up: |

------

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


@patrickvonplaten This is a little bit less verbose than what I think you were envisioning but curious what you think. I just showed sequence classification to communicate the general principles rather than covering multiple different tasks, which would make things pretty long.

I think it's great! At the moment we can't really show causal lm training because it's not implemented yet in TF :D So sequence classification sounds good to me! 

In the longer term, think we should have one section for each model type for both TF and PT:

- Causal LM

- Masked LM

- Seq2Seq

- Seq classifaction

....

But for now I like it! 



I don't think, the section would become too long if we show training for every model type (CLM, MLM, Seq2Seq, ...). If we would start with CLM and in the following sections only add a couple of sentences explaining what should be done differently for MLM *e.g.* and so on I don't think the page becomes too long.

Nevertheless, I'm still wondering if we should have a training section on each model page since training can differ quite a lot between models: XLNet has a very special training scheme, T5 pretraining is different from Bart, Longformer has a special global attention that has to be set, ... => what do you think about this @sgugger @joeddav ? 

I personally think this is okay if each task is shown in a different notebook/tutorial (there is a big table of tasks after all). When we are at a point where all tasks can be easily loaded in a few lines of code we can maybe show more, but I fear that the specificity of each task/dataset requiring its own preprocessing function will lose the reader when the essential point of this (beginner's) tutorial is on training and Trainer/TFTrainer.

Having an example on each model page may also be problematic since models can be used for several tasks. So it might turn up in having way too many things in the docs as well. For now I think making more independent notebooks that show how to train/fine-tune a model on a given task and link to those in all the right places might be the best solution. That way the reader opts in to see this model trained on that task.

I think it's a legitimate question how much guidance we should give for more obscure cases that you mentioned, @patrickvonplaten. My feeling is that those are fairly specialized and it's fair to expect users to be able to figure out more advanced cases like that out between docs/source code/table of tasks. I wouldn't be opposed to incorporating some of the more common tasks here (e.g. MLM training), but I generally agree with @sgugger to err on the side of brevity and clarity for the purpose of a quickstart guide like this one. Then we can lean on a combination of model docs and the big table of tasks for the more obscure/specialized cases.

Also, it would help to have docs for Trainer.