refactored beam search according to torch implementation
Author: patrickvonplaten
Pull request: yes

1:1 translation of PR #3135 from Pytorch to TF. 

Comments:
good to merge for me

# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3148?src=pr&el=h1) Report
> Merging [#3148](https://codecov.io/gh/huggingface/transformers/pull/3148?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/0001d056861bb1ec7bd6a825006f578629a101fc?src=pr&el=desc) will **decrease** coverage by `1.04%`.
> The diff coverage is `95.83%`.

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

```diff
@@            Coverage Diff             @@
##           master    #3148      +/-   ##
==========================================
- Coverage   78.03%   76.98%   -1.05%     
==========================================
  Files          98       98              
  Lines       16573    16583      +10     
==========================================
- Hits        12932    12766     -166     
- Misses       3641     3817     +176
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3148?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `91.47% <95.83%> (-1.95%)` | :arrow_down: |
| [src/transformers/modeling\_tf\_pytorch\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9weXRvcmNoX3V0aWxzLnB5) | `8.72% <0%> (-81.21%)` | :arrow_down: |
| [src/transformers/modeling\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19yb2JlcnRhLnB5) | `85.71% <0%> (-10%)` | :arrow_down: |
| [src/transformers/modeling\_xlnet.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ194bG5ldC5weQ==) | `73.48% <0%> (-2.3%)` | :arrow_down: |
| [src/transformers/modeling\_ctrl.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19jdHJsLnB5) | `96% <0%> (-2.23%)` | :arrow_down: |
| [src/transformers/modeling\_openai.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19vcGVuYWkucHk=) | `80.2% <0%> (-1.35%)` | :arrow_down: |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3148/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `94.56% <0%> (-0.16%)` | :arrow_down: |

------

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