Adds option to keep tb_writer open after training finishes
Author: jaymody
Pull request: yes
Labels: name: wontfix

Set the `close_tb_writer` parameter to `False` in `Trainer.train()` to keep the tensorboard writer open.

```
tb_writer = SummaryWriter(log_dir="some_dir")

# do some stuff with tb_writer before training

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    eval_dataset=test_dataset,
    compute_metrics=compute_metrics,
    tb_writer=tb_writer,
)
trainer.train(close_tb_writer=False)

# you can now use tb_writer even after training!
```

Closes #5329 

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

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

```diff
@@            Coverage Diff             @@
##           master    #5328      +/-   ##
==========================================
+ Coverage   77.54%   77.91%   +0.37%     
==========================================
  Files         138      138              
  Lines       24284    24284              
==========================================
+ Hits        18831    18922      +91     
+ Misses       5453     5362      -91     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5328?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/trainer.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyLnB5) | `39.38% <50.00%> (ø)` | |
| [src/transformers/modeling\_tf\_distilbert.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9kaXN0aWxiZXJ0LnB5) | `66.25% <0.00%> (-32.52%)` | :arrow_down: |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `91.26% <0.00%> (+0.12%)` | :arrow_up: |
| [src/transformers/configuration\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX3V0aWxzLnB5) | `96.37% <0.00%> (+0.72%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `87.62% <0.00%> (+1.47%)` | :arrow_up: |
| [src/transformers/tokenization\_auto.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fYXV0by5weQ==) | `97.77% <0.00%> (+2.22%)` | :arrow_up: |
| [src/transformers/tokenization\_xlm\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25feGxtX3JvYmVydGEucHk=) | `95.23% <0.00%> (+38.09%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_electra.py](https://codecov.io/gh/huggingface/transformers/pull/5328/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9lbGVjdHJhLnB5) | `95.38% <0.00%> (+68.46%)` | :arrow_up: |

------

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


@JetRunner I'm not exactly sure why the circleci build failed. I had the same result from this pull request https://github.com/huggingface/transformers/pull/5331, but I can't figure out how if at all it's related to my added code.

It’s not, don’t worry.
Let’s see if we can get that fixed. Otherwise, we’ll still be able to merge this PR since the CI failure has nothing to do with your added code.

@sgugger do you want to take a look at this?

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.