code: def test_sample_decoder(self):
      # greedy check eos_token_id
      for beam_search in [1, 3]:
          decode_paths = []
          # 因为是随机，所以需要测试100次，如果至少有一次是对的，应该就问题不大
          num_tests = 10
          for i in range(num_tests):
              decoder_output = torch.randn(2, 10, 5) * 10
              decoder_output[:, :7, 4].fill_(-100)
              decoder_output[0, 7, 4] = 10000  # 在第8个结束
              decoder_output[1, 5, 4] = 10000
              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=True,
                  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
                  ),
              )
              decode_paths.append([decode_path, path])
          sizes = []
          eqs = []
          eq2s = []
          for i in range(num_tests):
              decode_path, path = decode_paths[i]
              sizes.append(decode_path.size(1) == 8)
              eqs.append(decode_path[0].eq(path[0, :8]).sum() == 8)
              eq2s.append(decode_path[1, :6].eq(path[1, :6]).sum() == 6)
          assert any(sizes)
          assert any(eqs)
          assert any(eq2s)
  
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 3 for calling the TestSequenceGenerator obj's underlying member method code with example usage: obj.test_sample_decoder() without return types