Question about the why num_beams is multiplied by 2 in Beamsearch
Hi, I have a simple question, in the code for beam_search, here:

https://github.com/huggingface/transformers/blob/ef9c3ca348cb11c4ba951f8bdab068ecd8b847ce/src/transformers/generation_utils.py#L2137

Why the num_beams is multiplied by 2 ? Thanks!
Ping @patrickvonplaten <|||||>Good question @cloudygoose!

The reason is simply due to the fact that a beam might finish in an EOS in which case the beam search would not be able to continue anymore. 

E.g. think about the following scenario where we have num_beams=3 


1. step

1. ["hello"]
2. ["hey"]
3. ["hi"]

The best three beams from this are;

1. ["hello", "my"]
2. ["hello", "are"]
3. ["hi", "there"]

Now in the next step the following three beams are the best three beams

1. ["hello", "my", "dear"]
2. ["hello", "are", "there"]
3. ["hi", "there", "EOS"]

No we have a problem because we can't continue with EOS (end of sentence). So what we do now is to put `["hi", "there", "EOS"]` in the finished beams and take the 4th best beam and continue from there:

1. ["hello", "my", "dear"]
2. ["hello", "are", "there"]
4. ["hello", "are", "any"] -> becomes the 3rd best beam

So in the worst case we have all three best beams ending in EOS. In this case we might have to take the 4th, 5th, 6th beams to continue beam search which is why we do `2 * num_beams`
<|||||>thanks for the reply, could you explain more about where the beam with EOS is saved? I did not find the place where "finished beams" is saved in the code...