`compute_transition_scores` becomes erroneous when setting the minimal length of generation
Author: Aktsvigun
Pull request: no

### System Info

transformers==4.27.0.dev0 (latest from master)

### Who can help?

@gante @pat

### 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

Code to reproduce:
```
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import numpy as np

checkpoint = 'facebook/bart-large-cnn'
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

text = "Liverpool football club was established in 1892. It is one of the largest and the most famous football clubs in the world with six Champions League titles, 19 premier league titles and others. In 2015 Jurgen Klopp became a Liverpool manager and since that time led the team to another Champions league and Premier League trophies."
inputs = tokenizer([text], return_tensors="pt")

# Example 1: Print the scores for each token generated with Greedy Search
outputs = model.generate(
    **inputs,
    min_new_tokens=10,
    max_new_tokens=256,
    return_dict_in_generate=True,
    output_scores=True
)
transition_scores = model.compute_transition_scores(
    outputs.sequences, outputs.scores, outputs.beam_indices, normalize_logits=True
)
generated_tokens = outputs.sequences[:, 1:]
for tok, score in zip(generated_tokens[0], transition_scores[0]):
    print(f"| {tok:5d} | {tokenizer.decode(tok):8s} | {score.numpy():.3f} | {np.exp(score.numpy()):.2%}")
print(outputs.sequences_scores[0].item(), transition_scores.mean().item())
```

### Expected behavior

Hi. A recently added `compute_transition_scores` method for text generation behaves erroneously when the minimal length of generated text is set. The last row in my code prints the average sequence log score obtained throughout generation and it clearly differs from that obtained via the function (0.02 vs 0.19) - I observe the same behavior for other sequences/models when `min_length` parameter is not default in the `model.generate` method.

P.s. Unsure what the argument `normalize_logits` in the function does, however, setting it to False does not solve the problem.

Comments:
Hey @Aktsvigun 👋 Thank you for raising this issue, it is great to iron out usage difficulties 🤗 

There is no bug, you forgot to account for `length_penalty` -- see the other example in `compute_transition_scores`'s docstring. I'm pasting the corrected snippet below.

Two further notes:
- `normalize_logits` normalizes the logits, such that `sum(exp(logits)) = 1` at each generated token. Our models do not perform this normalization by default, and it is very helpful to evaluate the generate output.
- To get `outputs.sequences_scores` back, we need to make sure we operate on the scores in the same conditions as in `.generate()` -- with `normalize_logits=False` and applying `length_penalty` as in the example below.

___________________________

```py
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import numpy as np

checkpoint = 'facebook/bart-large-cnn'
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

text = "Liverpool football club was established in 1892. It is one of the largest and the most famous football clubs in the world with six Champions League titles, 19 premier league titles and others. In 2015 Jurgen Klopp became a Liverpool manager and since that time led the team to another Champions league and Premier League trophies."
inputs = tokenizer([text], return_tensors="pt")

# Example 1: Print the scores for each token generated with Greedy Search
outputs = model.generate(
    **inputs,
    min_new_tokens=10,
    max_new_tokens=256,
    return_dict_in_generate=True,
    output_scores=True
)
transition_scores = model.compute_transition_scores(
    outputs.sequences, outputs.scores, outputs.beam_indices, normalize_logits=False
)
generated_tokens = outputs.sequences[:, 1:]
for tok, score in zip(generated_tokens[0], transition_scores[0]):
    print(f"| {tok:5d} | {tokenizer.decode(tok):8s} | {score.numpy():.3f} | {np.exp(score.numpy()):.2%}")

# output_length -> 1 from forced BOS token, np.sum(transition_scores.numpy() < 0, axis=1) from the other tokens
output_length = 1 + np.sum(transition_scores.numpy() < 0, axis=1)
length_penalty = model.generation_config.length_penalty
reconstructed_scores = transition_scores.sum(axis=1) / (output_length**length_penalty)
print(np.allclose(outputs.sequences_scores, reconstructed_scores))
```

I'm closing this issue as it seems to be solved, but feel free to reopen it if you have other related issues :)

Hi @gante! 
Thanks a lot for the quick response!

Sure, my bad omitting the length penalty parameter. 

Thanks again for the amazing function!