code: def test_torch_padder():
      if not _NEED_IMPORT_TORCH:
          pytest.skip("No torch.")
      import torch
  
      backend = "torch"
      target_type = torch.Tensor
      batch_field = [1, 2, 3]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend=backend,
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, target_type)
      assert (pad_batch == torch.LongTensor(batch_field)).sum() == len(
          batch_field
      )
  
      batch_field = [[1], [2, 2], [3, 3, 3]]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend=backend,
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, target_type)
      assert pad_batch.shape == (3, 3)
      assert (pad_batch == torch.zeros(pad_batch.shape)).sum() == 3
  
      batch_field = [
          torch.ones((3, 3)),
          torch.ones((2, 3)),
          torch.ones((1, 3)),
      ]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend=backend,
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, target_type)
      assert pad_batch.shape == (3, 3, 3)
      assert (pad_batch == torch.zeros(pad_batch.shape)).sum() == 9
  
      batch_field = [
          torch.ones((3, 3)),
          torch.ones((2, 3)),
          torch.ones((1, 0)),
      ]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend=backend,
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, target_type)
      assert pad_batch.shape == (3, 3, 3)
      assert (pad_batch == torch.zeros(pad_batch.shape)).sum() == 12
  
      batch_field = [
          torch.ones((3, 3)),
          torch.ones((2, 3)),
          torch.ones((1,)),
      ]
      with pytest.raises(InconsistencyError):
          padder = get_padder(
              batch_field,
              pad_val=0,
              backend=backend,
              dtype=int,
              field_name="test",
          )
  
      # 可以是 numpy.ndarray
      batch_field = [np.ones((3, 3)), np.ones((2, 3)), np.ones((1, 0))]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend=backend,
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, target_type)
      assert pad_batch.shape == (3, 3, 3)
      assert (pad_batch == torch.zeros(pad_batch.shape)).sum() == 12
  
      # 测试 to numpy
      batch_field = [
          torch.ones((3, 3)),
          torch.ones((2, 3)),
          torch.ones((1, 0)),
      ]
      padder = get_padder(
          batch_field,
          pad_val=0,
          backend="numpy",
          dtype=int,
          field_name="test",
      )
      pad_batch = padder(batch_field)
      assert isinstance(pad_batch, np.ndarray)
      assert np.shape(pad_batch) == (3, 3, 3)
      assert (pad_batch == np.zeros(np.shape(pad_batch))).sum() == 12
  
file_path: fastNLP/tests/core/collators/padders/test_get_padder.py
imports: import pytest
  import numpy
  from fastNLP.core.collators.padders.get_padder import get_padder, InconsistencyError, DtypeError, _get_element_shape_dtype
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH, _NEED_IMPORT_PADDLE, _NEED_IMPORT_JITTOR, _NEED_IMPORT_ONEFLOW
label_desc: Use image node_id 5 for calling a global function with example usage: test_torch_padder() without return types