code: def test_repeating_excluded_index_does_not_die(self):
      # beam 0 and beam >= 2 will repeat (beam 2 repeats excluded idx)
      beam_sz = 5
      n_words = 100
      repeat_idx = 47  # will be repeated and should be blocked
      repeat_idx_ignored = (
          7  # will be repeated and should not be blocked
      )
      ngram_repeat = 3
      device_init = torch.zeros(1, 1)
      for batch_sz in [1, 3]:
          beam = BeamSearch(
              beam_sz,
              batch_sz,
              0,
              1,
              2,
              3,
              1,
              2,
              GlobalScorerStub(),
              0,
              30,
              False,
              ngram_repeat,
              {repeat_idx_ignored},
              False,
              0.0,
              False,
          )
          beam.initialize(
              device_init, torch.randint(0, 30, (batch_sz,))
          )
          for i in range(ngram_repeat + 4):
              # non-interesting beams are going to get dummy values
              word_probs = torch.full(
                  (batch_sz * beam_sz, n_words), -float("inf")
              )
              if i == 0:
                  word_probs[0::beam_sz, repeat_idx] = -0.1
                  word_probs[0::beam_sz, repeat_idx + i + 1] = -2.3
                  word_probs[0::beam_sz, repeat_idx_ignored] = -5.0
              else:
                  # predict the same thing in beam 0
                  word_probs[0::beam_sz, repeat_idx] = 0
                  # continue pushing around what beam 1 predicts
                  word_probs[1::beam_sz, repeat_idx + i + 1] = 0
                  # predict the allowed-repeat again in beam 2
                  word_probs[2::beam_sz, repeat_idx_ignored] = 0
              attns = torch.randn(batch_sz * beam_sz, 1, 53)
              beam.advance(word_probs, attns)
              if i < ngram_repeat:
                  self.assertFalse(
                      beam.topk_log_probs[:, 0]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
                  self.assertFalse(
                      beam.topk_log_probs[:, 1]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
                  self.assertFalse(
                      beam.topk_log_probs[:, 2]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
              else:
                  # now beam 0 dies, beam 1 -> beam 0, beam 2 -> beam 1
                  # and the rest die
                  self.assertFalse(
                      beam.topk_log_probs[:, 0]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
                  # since all preds after i=0 are 0, we can check
                  # that the beam is the correct idx by checking that
                  # the curr score is the initial score
                  self.assertTrue(
                      beam.topk_log_probs[:, 0].eq(-2.3).all()
                  )
                  self.assertFalse(
                      beam.topk_log_probs[:, 1]
                      .eq(self.BLOCKED_SCORE)
                      .all()
                  )
                  self.assertTrue(
                      beam.topk_log_probs[:, 1].eq(-5.0).all()
                  )
  
                  self.assertTrue(
                      beam.topk_log_probs[:, 2]
                      .eq(self.BLOCKED_SCORE)
                      .all()
                  )
  
imports: import unittest
  from onmt.translate.beam_search import BeamSearch, GNMTGlobalScorer
  from onmt.translate.beam_search import BeamSearchLM
  from copy import deepcopy
  import torch
label_desc: Use image node_id 3 for calling the TestBeamSearch obj's underlying member method code with example usage: obj.test_repeating_excluded_index_does_not_die() without return types