code: def test_beam_is_done_when_X_beams_eos_using_min_length(self):
      # this is also a test that when block_ngram_repeat=0,
      # repeating is acceptable
      beam_sz = 5
      batch_sz = 3
      n_words = 100
      _non_eos_idxs = [47, 51, 13, 88, 99]
      valid_score_dist = torch.log_softmax(
          torch.tensor([6.0, 5.0, 4.0, 3.0, 2.0, 1.0]), dim=0
      )
      min_length = 5
      eos_idx = 2
      beam = BeamSearch(
          beam_sz,
          batch_sz,
          0,
          1,
          2,
          3,
          1,
          2,
          GlobalScorerStub(),
          min_length,
          30,
          False,
          0,
          set(),
          False,
          0.0,
          False,
      )
      device_init = torch.zeros(1, 1)
      beam.initialize(device_init, torch.randint(0, 30, (batch_sz,)))
      for i in range(min_length + 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:
              # "best" prediction is eos - that should be blocked
              word_probs[0::beam_sz, eos_idx] = valid_score_dist[0]
              # include at least beam_sz predictions OTHER than EOS
              # that are greater than -1e20
              for j, score in zip(_non_eos_idxs, valid_score_dist[1:]):
                  word_probs[0::beam_sz, j] = score
          elif i <= min_length:
              # predict eos in beam 1
              word_probs[1::beam_sz, eos_idx] = valid_score_dist[0]
              # provide beam_sz other good predictions in other beams
              for k, (j, score) in enumerate(
                  zip(_non_eos_idxs, valid_score_dist[1:])
              ):
                  beam_idx = min(beam_sz - 1, k)
                  word_probs[beam_idx::beam_sz, j] = score
          else:
              for j in range(beam_sz):
                  word_probs[j::beam_sz, eos_idx] = valid_score_dist[0]
  
          attns = torch.randn(batch_sz * beam_sz, 1, 53)
          beam.advance(word_probs, attns)
          if i < min_length:
              self.assertFalse(beam.done)
          elif i == min_length:
              # beam 1 dies on min_length
              self.assertTrue(
                  all([subbeam[1] for subbeam in beam.is_finished_list])
              )
              beam.update_finished()
              self.assertFalse(beam.done)
          else:  # i > min_length
              # beam 0 dies on the step after beam 1 dies
              self.assertTrue(
                  all([subbeam[0] for subbeam in beam.is_finished_list])
              )
              beam.update_finished()
              self.assertTrue(beam.done)
  
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 5 for calling the TestBeamSearch obj's underlying member method code with example usage: obj.test_beam_is_done_when_X_beams_eos_using_min_length() without return types