code: def test_greedy_decode(self):
      # 测试能否正确的generate
      # greedy
      for beam_search in [1, 3]:
          decoder_output = torch.randn(2, 10, 5)
          path = decoder_output.argmax(dim=-1)  # 2 x 10
          decoder = GreedyDummyDecoder(decoder_output)
          generator = SequenceGenerator(
              decoder=decoder,
              max_length=decoder_output.size(1),
              num_beams=beam_search,
              do_sample=False,
              temperature=1,
              top_k=50,
              top_p=1,
              bos_token_id=1,
              eos_token_id=None,
              repetition_penalty=1,
              length_penalty=1,
              pad_token_id=0,
          )
          decode_path = generator.generate(
              DummyState(decoder),
              tokens=decoder_output[:, 0].argmax(dim=-1, keepdim=True),
          )
  
          assert decode_path.eq(path).sum() == path.numel()
  
      # greedy check eos_token_id
      for beam_search in [1, 3]:
          decoder_output = torch.randn(2, 10, 5)
          decoder_output[:, :7, 4].fill_(-100)
          decoder_output[0, 7, 4] = 1000  # 在第8个结束
          decoder_output[1, 5, 4] = 1000
          path = decoder_output.argmax(dim=-1)  # 2 x 4
          decoder = GreedyDummyDecoder(decoder_output)
          generator = SequenceGenerator(
              decoder=decoder,
              max_length=decoder_output.size(1),
              num_beams=beam_search,
              do_sample=False,
              temperature=1,
              top_k=50,
              top_p=0.5,
              bos_token_id=1,
              eos_token_id=4,
              repetition_penalty=1,
              length_penalty=1,
              pad_token_id=0,
          )
          decode_path = generator.generate(
              DummyState(decoder),
              tokens=decoder_output[:, 0].argmax(dim=-1, keepdim=True),
          )
          assert decode_path.size(1) == 8  # 长度为8
          assert decode_path[0].eq(path[0, :8]).sum() == 8
          assert decode_path[1, :6].eq(path[1, :6]).sum() == 6
  
file_path: fastNLP/tests/modules/torch/generator/test_seq2seq_generator.py
imports: import pytest
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
label_desc: Use image node_id 2 for calling the TestSequenceGenerator obj's underlying member method code with example usage: obj.test_greedy_decode() without return types