docstr: If there are enough hypotheses and that none of the hypotheses being generated can become better than the worst
  one in the heap, then we are done with this sentence.
docstr_tok: ["If","there","are","enough","hypotheses","and","that","none","of","the","hypotheses","being","generated","can","become","better","than","the","worst","one","in","the","heap",",","then","we","are","done","with","this","sentence","."]
code: def is_done(
      self,
      best_sum_logprobs: float,
      cur_len: int,
      decoder_prompt_len: Optional[int] = 0,
  ) -> bool:
      """
      If there are enough hypotheses and that none of the hypotheses being generated can become better than the worst
      one in the heap, then we are done with this sentence.
      """
  
      if len(self) < self.num_beams:
          return False
  
      # `True`: stop as soon as at least `num_beams` hypotheses are finished
      if self.early_stopping is True:
          return True
      # `False`: heuristic -- compute best possible score from `cur_len`, even though it is not entirely accurate
      #  when `length_penalty` is positive. See the discussion below for more details.
      # https://github.com/huggingface/transformers/pull/20901#issuecomment-1369845565
      elif self.early_stopping is False:
          highest_attainable_score = (
              best_sum_logprobs
              / (cur_len - decoder_prompt_len) ** self.length_penalty
          )
          ret = self.worst_score >= highest_attainable_score
          return ret
      # `"never"`: compute the best possible score, depending on the signal of `length_penalty`
      else:
          # `length_penalty` > 0.0 -> max denominator is obtaned from `max_length`, not from `cur_len` -> min
          # abs(`highest_attainable_score`) is obtained -> `highest_attainable_score` is negative, hence we obtain
          # its max this way
          if self.length_penalty > 0.0:
              if self.max_length <= decoder_prompt_len:
                  raise ValueError(
                      "max_length is not larger than decoder prompt length"
                  )
              highest_attainable_score = (
                  best_sum_logprobs
                  / (self.max_length - decoder_prompt_len)
                  ** self.length_penalty
              )
          # the opposite logic applies here (max `highest_attainable_score` from `cur_len`)
          else:
              highest_attainable_score = (
                  best_sum_logprobs
                  / (cur_len - decoder_prompt_len)
                  ** self.length_penalty
              )
          ret = self.worst_score >= highest_attainable_score
          return ret
  
imports: from abc import ABC, abstractmethod
  from collections import UserDict
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from ..utils import add_start_docstrings
  from .beam_constraints import Constraint, ConstraintListState
label_desc: Use image node_id 4 for calling the BeamHypotheses obj's underlying member method code with example usage: obj.is_done(best_sum_logprobs, cur_len, decoder_prompt_len) and returns: False, True, ret, ret