WIP: Add support for bfloat16 in Trainer and T5
Author: manuelciosici
Pull request: yes

# What does this PR do?

This PR adds support for `bfloat16` with `deepspeed` and the `T5` models.

`bfloat16` is of great interest due to its larger dynamic range. `bfloat16` is especially of interest for large models that were originally trained on TPUs (which have native `bfloat16` support). Some newer GPUs (A6000, A100) have hardware support for `bfloat16`. Recently, `deepspeed` added support for `bfloat16` (see [this commit](https://github.com/microsoft/DeepSpeed/commit/648f7bfa5009484b822064d0c28d377da6dd71a0)).

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ x ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Members/contributors who may be interested in this PR: @stas00 and @JamesDeAntonis.

Adding @patrickvonplaten and @patil-suraj due to the T5 changes in this PR.

## Coordination

@stas00 @JamesDeAntonis
I know James has been working on a PR to add `bfloat16` through amp. This PR is only focused on `deepspeed`. Maybe there is a way we can unite our efforts?



## Next steps

For extra context: I am aware of `bfloat16` coming to ZeRO stage 3, [this PR](https://github.com/microsoft/DeepSpeed/pull/1453). I hope to test compatibility with stage 3 as soon as it's ready. I've only aimed for stage 2 so far.

## TODO

- [ ] make sure that we require the right minimal deepspeed version before merging this.
- [ ] update deepspeed integration docs to include bf16 examples
- [ ] add bf16 tests



Comments:
OK, since we have 2 half-baked PRs, 

https://github.com/huggingface/transformers/pull/13207
https://github.com/huggingface/transformers/pull/14448
I'm going to try to merge the 2 to keep the credits and start a new PR.

If you have something to push now is the time.

@stas00 Merging the two PRs is a good idea. I have nothing to push now. I was planning to work on this tomorrow. Tag me once you merge the two PRs and I will continue tomorrow in the combined PR.

Most of the work is already in the other PR so it makes sense to use that as a base so will need to ask @JamesDeAntonis for him to temporarily give you access to his fork, or alternatively you can push your changes here and I can replay it into that other PR, so all your work will be still credited.

But in any case let's complete this work in the next few days, since I need to enable Deepspeed bf16 integration and this foundation is required.


So I merged our work here into https://github.com/huggingface/transformers/pull/13207, keeping the log intact - will work on polishing it now, there may have been some overlapping code left to clean up.

Thus ideally let's continue over at https://github.com/huggingface/transformers/pull/13207

@stas00 Thank you. I will close this PR now. We can continue in #13207