Unverified Commit c1f85598 authored by jim's avatar jim Committed by GitHub
Browse files

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: default avatarChiming <chiming@biomap.com>
parent b338414e
......@@ -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
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment