code: def check_constrained_beam_scorer_update(
      self,
      input_ids,
      next_tokens,
      next_indices,
      next_scores,
      scores_for_all_vocab,
  ):
      # check too many eos tokens
      constrained_beam_scorer = self.prepare_constrained_beam_scorer()
      stacked_token_ids = []
      for constraint in self.constraints:
          token_ids = constraint.token_ids
          token_ids = (
              token_ids[0]
              if isinstance(token_ids[0], list)
              else token_ids
          )
          stacked_token_ids = stacked_token_ids + token_ids
  
      fulfilling_sequence = torch.LongTensor(stacked_token_ids)
      fulfill_len = fulfilling_sequence.size(0)
      input_ids[:, :fulfill_len] = fulfilling_sequence
  
      tokens = next_tokens.clone()
      tokens[0, :] = self.eos_token_id
  
      with self.parent.assertRaises(ValueError):
          constrained_beam_scorer.process(
              input_ids,
              next_scores,
              tokens,
              next_indices,
              scores_for_all_vocab,
              eos_token_id=self.eos_token_id,
          )
  
      # check all batches are done
      constrained_beam_scorer = self.prepare_constrained_beam_scorer()
  
      tokens = next_tokens.clone()
      tokens[:, : self.num_beams] = self.eos_token_id
      constrained_beam_scorer.process(
          input_ids,
          next_scores,
          tokens,
          next_indices,
          scores_for_all_vocab,
          eos_token_id=self.eos_token_id,
      )
      # beam scorer should be done
      self.parent.assertTrue(constrained_beam_scorer.is_done)
  
      # check
      constrained_beam_scorer = self.prepare_constrained_beam_scorer()
  
      tokens = next_tokens.clone()
      tokens[:, 1] = self.eos_token_id
      beam_outputs = constrained_beam_scorer.process(
          input_ids,
          next_scores,
          tokens,
          next_indices,
          scores_for_all_vocab,
          eos_token_id=self.eos_token_id,
      )
      output_scores = beam_outputs["next_beam_scores"]
      output_tokens = beam_outputs["next_beam_tokens"]
      output_indices = beam_outputs["next_beam_indices"]
  
      def cut_expected_tensor(tensor):
          return torch.cat(
              [tensor[:, :1], tensor[:, 2 : self.num_beams + 1]], dim=1
          ).flatten()
  
      # check all outptus
      # cut out id of eos token and take best `num_beams` outputs
      expected_output_tokens = cut_expected_tensor(tokens)
      expected_output_scores = cut_expected_tensor(next_scores)
  
      # add num_beams * batch_idx
      expected_output_indices = (
          cut_expected_tensor(next_indices)
          + (
              torch.arange(
                  self.num_beams * self.batch_size, device=torch_device
              )
              // self.num_beams
          )
          * self.num_beams
      )
  
      self.parent.assertListEqual(
          expected_output_tokens.tolist(), output_tokens.tolist()
      )
      self.parent.assertListEqual(
          expected_output_indices.tolist(), output_indices.tolist()
      )
      self.parent.assertTrue(
          torch.allclose(
              expected_output_scores, output_scores, atol=1e-3
          )
      )
  
      # make sure ids of eos token are correctly saved in beam_hyps of beam scorer
      for batch_idx in range(self.batch_size):
          correct_idx = (
              batch_idx * self.num_beams + next_indices[batch_idx, 1]
          )
          self.parent.assertListEqual(
              input_ids[correct_idx].tolist(),
              constrained_beam_scorer._beam_hyps[batch_idx]
              .beams[0][1]
              .tolist(),
          )
  
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 5 for calling the ConstrainedBeamSearchTester obj's underlying member method code with example usage: obj.check_constrained_beam_scorer_update(input_ids, next_tokens, next_indices, next_scores, scores_for_all_vocab) and returns: torch