Beam search indices calculation issue
### System Info

In the generator, the final [beam_indices](https://github.com/huggingface/transformers/blob/bd469c40659ce76c81f69c7726759d249b4aef49/src/transformers/generation_utils.py#L2376) calculated here may not be the `beam_indices` with the best score.

For example, assume a generated text ended at time step T, the output length = T, and it has best score in the `beam_hypo` in the end.  The beam indices length is T.

When in `T+1` step, the `beam_indices` still keeps adding next beam index from TopK, for example, the TopK returns a text with `T+1` length, the beam_indices will add this Top 1 beam idx in `T+1` even though it is not the best score. `beam_indices` length becomes `T+1`.  So in the end, the `beam_indices` represents a longer sequence T+1, but the `generated_outputs.sequence` is a short sequence T with best score, and its beam indices are not stored in `beam_hypo`

### Who can help?

@patrickvonplaten

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

The logic is shown in the code.

### Expected behavior

`beam_indices` should be consistent with and representing the best sequence.
cc @gante <|||||>Look like it was fixed in the latest version. The bug exists in Version 4.18<|||||>Hi @woshizouguo 👋 Glad to hear it is fixed in the most recent versions! Feel free to reopen this issue if you believe you have further queries (related to the latest version, as we can't change the past :) )