code: def check_beam_scorer_update(
      self, input_ids, next_tokens, next_indices, next_scores
  ):
      # check too many eos tokens
      beam_scorer = self.prepare_beam_scorer()
  
      tokens = next_tokens.clone()
      tokens[0, :] = self.eos_token_id
  
      with self.parent.assertRaises(ValueError):
          beam_scorer.process(
              input_ids,
              next_scores,
              tokens,
              next_indices,
              eos_token_id=self.eos_token_id,
          )
  
      # check all batches are done
      beam_scorer = self.prepare_beam_scorer()
  
      tokens = next_tokens.clone()
      tokens[:, : self.num_beams] = self.eos_token_id
      beam_indices = torch.zeros_like(input_ids) + torch.arange(
          input_ids.shape[-1], device=input_ids.device
      )
      beam_indices = tuple(tuple(b) for b in beam_indices)
      beam_scorer.process(
          input_ids,
          next_scores,
          tokens,
          next_indices,
          eos_token_id=self.eos_token_id,
          beam_indices=beam_indices,
      )
      # beam scorer should be done
      self.parent.assertTrue(beam_scorer.is_done)
  
      # check
      beam_scorer = self.prepare_beam_scorer()
  
      tokens = next_tokens.clone()
      tokens[:, 1] = self.eos_token_id
      beam_outputs = beam_scorer.process(
          input_ids,
          next_scores,
          tokens,
          next_indices,
          eos_token_id=self.eos_token_id,
          beam_indices=beam_indices,
      )
      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
      offset = torch.div(
          torch.arange(
              self.num_beams * self.batch_size, device=torch_device
          ),
          self.num_beams,
          rounding_mode="floor",
      )
      expected_output_indices = (
          cut_expected_tensor(next_indices) + offset * 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
      expected_beam_indices = list(range(10))
      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(),
              beam_scorer._beam_hyps[batch_idx].beams[0][1].tolist(),
          )
          self.parent.assertListEqual(
              expected_beam_indices + [correct_idx],
              torch.tensor(
                  beam_scorer._beam_hyps[batch_idx].beams[0][2]
              ).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 BeamSearchTester obj's underlying member method code with example usage: obj.check_beam_scorer_update(input_ids, next_tokens, next_indices, next_scores) and returns: torch