Pass existing tensorboard SummaryWriter to Trainer PR (#4019)
Author: jaymody
Pull request: yes

Implements feature request for issue #4019.

You should be able to pass in you're own `SummaryWriter`s to `Trainer` via the `tb_writer` parameter to the `__init__` function:

```
tb_writer = SummaryWriter(log_dir="my_log_dir")
tb_writer.add_hparams(my_hparams_dict, my_metrics_dict)

trainer = Trainer(
    model = model,
    args = training_args,
    train_dataset = train_dataset,
    tb_writer = tb_writer
)

trainer.train()
```

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

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

```diff
@@           Coverage Diff           @@
##           master    #4020   +/-   ##
=======================================
  Coverage   78.44%   78.45%           
=======================================
  Files         111      111           
  Lines       18518    18520    +2     
=======================================
+ Hits        14527    14529    +2     
  Misses       3991     3991           
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/4020?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/trainer.py](https://codecov.io/gh/huggingface/transformers/pull/4020/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyLnB5) | `43.94% <66.66%> (+0.04%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/4020/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `92.76% <0.00%> (ø)` | |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/4020/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `91.06% <0.00%> (+0.12%)` | :arrow_up: |

------

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


Another consideration is that the user might want to add extra details to the log after the training has finished. Right now, the end of the training loop closes the `tb_writer`, preventing any further logging. Not sure what a reasonable workaround for this is, maybe add a param for the train function that if set to True, will close `tb_writer` and if False, will keep it open (default: True).

Looks good, thanks