When decoding a sentence of length 5 and beamsize=10, and we entered the while loop. After the first while loop, we end up with a queue with length 10. Now we move to T=1. According to the code, we have to run 10 while loops to decode for T=1. So after decoding for T=1, we will end up with a queue of length 100 instead of 10 cause there is no topK selection in the queue. After decoding for T=2, we will have a queue with length 1000. This queue will explode quickly. Did I miss something here?