code: def check_beam_hypotheses(self, input_ids, *args):
      # check that correct number of beam hypotheses is set in beam scorer
      constrained_beam_scorer = self.prepare_constrained_beam_scorer(
          do_early_stopping=True
      )
      beam_hyp = constrained_beam_scorer._beam_hyps[0]
  
      self.parent.assertEqual(
          len(constrained_beam_scorer._beam_hyps), self.batch_size
      )
  
      # check correct type
      self.parent.assertTrue(isinstance(beam_hyp, BeamHypotheses))
  
      # check that num_beams is correctly set
      self.parent.assertEqual(beam_hyp.num_beams, self.num_beams)
  
      # check for early stopping deactivated
      for beam_idx in range(self.num_beams):
          beam_hyp.add(input_ids[beam_idx], -10.0)
  
      # if early stopping True -> score does not matter
      self.parent.assertTrue(beam_hyp.is_done(-10.0, 5))
  
      # re-init
      constrained_beam_scorer = self.prepare_constrained_beam_scorer(
          do_early_stopping=False
      )
      beam_hyp = constrained_beam_scorer._beam_hyps[0]
  
      # add `num_beams + 1` beams to change `worst_score`
      for beam_idx in range(self.num_beams + 1):
          beam_hyp.add(input_ids[beam_idx], -10.0 + float(beam_idx))
  
      # -10.0 is removed => -9.0 is worst score
      self.parent.assertAlmostEqual(
          beam_hyp.worst_score,
          -9.0 / (self.sequence_length**beam_hyp.length_penalty),
      )
  
      # -5.0 is better than worst score => should not be finished
      self.parent.assertFalse(
          beam_hyp.is_done(-5.0, self.sequence_length)
      )
  
      # -20.0 is worse than worst score => should be finished
      self.parent.assertTrue(
          beam_hyp.is_done(-20.0, self.sequence_length)
      )
  
imports: import unittest
  from transformers import is_torch_available
  from transformers.testing_utils import require_torch, torch_device
  from ..test_modeling_common import floats_tensor, ids_tensor
label_desc: Use image node_id 4 for calling the ConstrainedBeamSearchTester obj's underlying member method code with example usage: obj.check_beam_hypotheses(input_ids) without return types