code: def test_advance_with_all_repeats_gets_blocked(self):
      # all beams repeat (beam >= 1 repeat dummy scores)
      beam_sz = 5
      n_words = 100
      repeat_idx = 47
      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,
              set(),
              False,
              0.0,
              False,
          )
          beam.initialize(
              device_init, torch.randint(0, 30, (batch_sz,))
          )
          for i in range(ngram_repeat + 4):
              # predict repeat_idx over and over again
              word_probs = torch.full(
                  (batch_sz * beam_sz, n_words), -float("inf")
              )
              word_probs[0::beam_sz, repeat_idx] = 0
  
              attns = torch.randn(batch_sz * beam_sz, 1, 53)
              beam.advance(word_probs, attns)
  
              if i < ngram_repeat:
                  # before repeat, scores are either 0 or -inf
                  expected_scores = torch.tensor(
                      [0] + [-float("inf")] * (beam_sz - 1)
                  ).repeat(batch_sz, 1)
                  self.assertTrue(
                      beam.topk_log_probs.equal(expected_scores)
                  )
              elif i % ngram_repeat == 0:
                  # on repeat, `repeat_idx` score is BLOCKED_SCORE
                  # (but it's still the best score, thus we have
                  # [BLOCKED_SCORE, -inf, -inf, -inf, -inf]
                  expected_scores = torch.tensor(
                      [self.BLOCKED_SCORE]
                      + [-float("inf")] * (beam_sz - 1)
                  ).repeat(batch_sz, 1)
                  self.assertTrue(
                      beam.topk_log_probs.equal(expected_scores)
                  )
              else:
                  # repetitions keeps maximizing score
                  # index 0 has been blocked, so repeating=>+0.0 score
                  # other indexes are -inf so repeating=>BLOCKED_SCORE
                  # which is higher
                  expected_scores = torch.tensor(
                      [self.BLOCKED_SCORE]
                      + [-float("inf")] * (beam_sz - 1)
                  ).repeat(batch_sz, 1)
                  self.assertTrue(
                      beam.topk_log_probs.equal(expected_scores)
                  )
  
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 1 for calling the TestBeamSearch obj's underlying member method code with example usage: obj.test_advance_with_all_repeats_gets_blocked() without return types