code: def test_returns_correct_scores_deterministic(self):
      for batch_sz in [1, 13]:
          for temp in [1.0, 3.0]:
              n_words = 100
              _non_eos_idxs = [47, 51, 13, 88, 99]
              valid_score_dist_1 = torch.log_softmax(
                  torch.tensor([6.0, 5.0, 4.0, 3.0, 2.0, 1.0]), dim=0
              )
              valid_score_dist_2 = torch.log_softmax(
                  torch.tensor([6.0, 1.0]), dim=0
              )
              eos_idx = 2
              lengths = torch.randint(0, 30, (batch_sz,))
              samp = GreedySearch(
                  0,
                  1,
                  2,
                  3,
                  1,
                  1,
                  batch_sz,
                  GlobalScorerStub(),
                  0,
                  False,
                  set(),
                  False,
                  30,
                  temp,
                  1,
                  0,
                  1,
                  False,
              )
              samp.initialize(torch.zeros((1, 1)), lengths)
              # initial step
              i = 0
              word_probs = torch.full(
                  (batch_sz, n_words), -float("inf")
              )
              # batch 0 dies on step 0
              word_probs[0, eos_idx] = valid_score_dist_1[0]
              # include at least one prediction OTHER than EOS
              # that is greater than -1e20
              word_probs[0, _non_eos_idxs] = valid_score_dist_1[1:]
              word_probs[1:, _non_eos_idxs[0] + i] = 0
  
              attns = torch.randn(1, batch_sz, 53)
              samp.advance(word_probs, attns)
              self.assertTrue(all(samp.is_finished_list[0]))
              samp.update_finished()
              self.assertEqual(
                  [score for score, _, _ in samp.hypotheses[0]],
                  [valid_score_dist_1[0] / temp],
              )
              if batch_sz == 1:
                  self.assertTrue(samp.done)
                  continue
              else:
                  self.assertFalse(samp.done)
  
              # step 2
              i = 1
              word_probs = torch.full(
                  (batch_sz - 1, n_words), -float("inf")
              )
              # (old) batch 8 dies on step 1
              word_probs[7, eos_idx] = valid_score_dist_2[0]
              word_probs[0:7, _non_eos_idxs[:2]] = valid_score_dist_2
              word_probs[8:, _non_eos_idxs[:2]] = valid_score_dist_2
  
              attns = torch.randn(1, batch_sz, 53)
              samp.advance(word_probs, attns)
  
              self.assertTrue(all(samp.is_finished_list[7]))
              samp.update_finished()
              self.assertEqual(
                  [score for score, _, _ in samp.hypotheses[8]],
                  [valid_score_dist_2[0] / temp],
              )
  
              # step 3
              i = 2
              word_probs = torch.full(
                  (batch_sz - 2, n_words), -float("inf")
              )
              # everything dies
              word_probs[:, eos_idx] = 0
  
              attns = torch.randn(1, batch_sz, 53)
              samp.advance(word_probs, attns)
  
              self.assertTrue(
                  all(all(sublist) for sublist in samp.is_finished_list)
              )
              samp.update_finished()
              self.assertTrue(samp.done)
  
file_path: OpenNMT-py/onmt/tests/test_greedy_search.py
imports: import unittest
  from onmt.translate.greedy_search import GreedySearch
  import torch
label_desc: Use image node_id 2 for calling the TestGreedySearch obj's underlying member method code with example usage: obj.test_returns_correct_scores_deterministic() without return types