Generate - add 1 to cur_len to make up the new beam length (#21993)

* add 1 to cur_len to make up the new beam length

cur_len is 1 token shorter comparing to the length of the sequence whose best_sum_logprobs is the numerator.

* cur_len+=1 before check if beam hyp is done

* format code

* reformat with black

---------

Co-authored-by: Chiming <chiming@biomap.com>
This commit is contained in:
jim 2023-03-08 19:47:55 +08:00 committed by GitHub
parent b338414e61
commit c1f85598eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -287,6 +287,7 @@ class BeamSearchScorer(BeamScorer):
)
# Check if we are done so that we can save a pad step if all(done)
cur_len += 1 # add up to the length which the next_scores is calculated on
self._done[batch_idx] = self._done[batch_idx] or beam_hyp.is_done(
next_scores[batch_idx].max().item(), cur_len
)
@ -616,6 +617,7 @@ class ConstrainedBeamSearchScorer(BeamScorer):
)
# Check if we are done so that we can save a pad step if all(done)
cur_len += 1 # add up to the length which the next_scores is calculated on
self._done[batch_idx] = self._done[batch_idx] or beam_hyp.is_done(
next_scores[batch_idx].max().item(), cur_len
)