mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
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:
parent
b338414e61
commit
c1f85598eb
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user