code: def test_prepare_torch_dataloader(self):
      # 测试 fastNLP 的 dataset
      ds = DataSet(
          {
              "x": [[1, 2], [2, 3, 4], [4, 5, 6, 7]] * 10,
              "y": [1, 0, 1] * 10,
          }
      )
      dl = prepare_torch_dataloader(
          ds, batch_size=8, shuffle=True, num_workers=2
      )
      assert isinstance(dl, TorchDataLoader)
  
      ds1 = DataSet(
          {
              "x": [[1, 2], [2, 3, 4], [4, 5, 6, 7]] * 10,
              "y": [1, 0, 1] * 10,
          }
      )
      dbl = DataBundle(datasets={"train": ds, "val": ds1})
      dl_bundle = prepare_torch_dataloader(dbl)
      assert isinstance(dl_bundle["train"], TorchDataLoader)
      assert isinstance(dl_bundle["val"], TorchDataLoader)
  
      ds_dict = {"train_1": ds, "val": ds1}
      dl_dict = prepare_torch_dataloader(ds_dict)
      assert isinstance(dl_dict["train_1"], TorchDataLoader)
      assert isinstance(dl_dict["val"], TorchDataLoader)
  
      # 测试其他 dataset
      class _DataSet:
          def __init__(self):
              pass
  
          def __getitem__(self, item):
              return np.random.randn(5), [[1, 2], [2, 3, 4]]
  
          def __len__(self):
              return 10
  
          def __getattribute__(self, item):
              return object.__getattribute__(self, item)
  
      ds2 = _DataSet()
      dl1 = prepare_torch_dataloader(
          ds2, batch_size=8, shuffle=True, num_workers=2
      )
      assert isinstance(dl1, TorchDataLoader)
  
      ds3 = _DataSet()
      dbl1 = DataBundle(datasets={"train": ds2, "val": ds3})
      dl_bundle1 = prepare_torch_dataloader(dbl1)
      assert isinstance(dl_bundle1["train"], TorchDataLoader)
      assert isinstance(dl_bundle1["val"], TorchDataLoader)
  
      ds_dict1 = {"train_1": ds2, "val": ds3}
      dl_dict1 = prepare_torch_dataloader(ds_dict1)
      assert isinstance(dl_dict1["train_1"], TorchDataLoader)
      assert isinstance(dl_dict1["val"], TorchDataLoader)
  
      ds = [[1, [1]], [2, [2, 2]]]
      dl = prepare_torch_dataloader(ds, batch_size=2)
      for batch in dl:
          assert (batch[0] == torch.LongTensor([1, 2])).sum() == 2
          assert (
              batch[1] == torch.LongTensor([[1, 0], [2, 2]])
          ).sum() == 4
  
file_path: fastNLP/tests/core/dataloaders/torch_dataloader/test_fdl.py
imports: import pytest
  from fastNLP.core.dataloaders.torch_dataloader import TorchDataLoader, prepare_torch_dataloader
  from fastNLP.core.dataset import DataSet
  from fastNLP.io.data_bundle import DataBundle
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from pkg_resources import parse_version
  from tests.helpers.utils import Capturing, recover_logger
  from fastNLP import logger
  import numpy
label_desc: Use image node_id 7 for calling the TestFdl obj's underlying member method code with example usage: obj.test_prepare_torch_dataloader() and returns: np,  list, int, object