code: def test_advance_with_some_repeats_gets_blocked(self):
      # beam 0 and beam >=2 will repeat (beam >= 2 repeat dummy scores)
      beam_sz = 5
      n_words = 100
      repeat_idx = 47
      ngram_repeat = 3
      no_repeat_score = -2.3
      repeat_score = -0.1
      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,
              set(),
              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:
                  # on initial round, only predicted scores for beam 0
                  # matter. Make two predictions. Top one will be repeated
                  # in beam zero, second one will live on in beam 1.
                  word_probs[0::beam_sz, repeat_idx] = repeat_score
                  word_probs[
                      0::beam_sz, repeat_idx + i + 1
                  ] = no_repeat_score
              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
              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::beam_sz]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
                  self.assertFalse(
                      beam.topk_log_probs[1::beam_sz]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
              elif i == ngram_repeat:
                  # now beam 0 dies (along with the others), beam 1 -> beam 0
                  self.assertFalse(
                      beam.topk_log_probs[:, 0]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
  
                  expected = torch.full(
                      [batch_sz, beam_sz], float("-inf")
                  )
                  expected[:, 0] = no_repeat_score
                  expected[:, 1] = self.BLOCKED_SCORE
                  self.assertTrue(
                      beam.topk_log_probs[:, :].equal(expected)
                  )
              else:
                  # now beam 0 dies (along with the others), beam 1 -> beam 0
                  self.assertFalse(
                      beam.topk_log_probs[:, 0]
                      .eq(self.BLOCKED_SCORE)
                      .any()
                  )
  
                  expected = torch.full(
                      [batch_sz, beam_sz], float("-inf")
                  )
                  expected[:, 0] = no_repeat_score
                  expected[:, 1:3] = self.BLOCKED_SCORE
                  expected[:, 3:] = float("-inf")
                  self.assertTrue(beam.topk_log_probs.equal(expected))
  
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 2 for calling the TestBeamSearch obj's underlying member method code with example usage: obj.test_advance_with_some_repeats_gets_blocked() without return types