code: def test_mix(self):
      datasets = {"d1": d1, "d2": d2, "d3": d3}
      dl = MixDataLoader(
          datasets=datasets,
          mode="mix",
          collate_fn="auto",
          drop_last=True,
      )
      for idx, batch in enumerate(dl):
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 22:
              raise ValueError(f"out of range")
  
      # collate_fn = Callable
      def collate_batch(batch):
          new_batch = {"x": [], "y": []}
          for ins in batch:
              new_batch["x"].append(ins["x"])
              new_batch["y"].append(ins["y"])
          return new_batch
  
      dl1 = MixDataLoader(
          datasets=datasets,
          mode="mix",
          collate_fn=collate_batch,
          drop_last=True,
      )
      for idx, batch in enumerate(dl1):
          assert isinstance(batch["x"], list)
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 22:
              raise ValueError(f"out of range")
  
      collate_fns = {
          "d1": Collator(backend="auto").set_pad("x", -1),
          "d2": Collator(backend="auto").set_pad("x", -2),
          "d3": Collator(backend="auto").set_pad("x", -3),
      }
      with pytest.raises(ValueError):
          MixDataLoader(
              datasets=datasets, mode="mix", collate_fn=collate_fns
          )
  
      # sampler 为 str
      dl3 = MixDataLoader(
          datasets=datasets, mode="mix", sampler="seq", drop_last=True
      )
      for idx, batch in enumerate(dl3):
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 22:
              raise ValueError(f"out of range")
      dl4 = MixDataLoader(
          datasets=datasets, mode="mix", sampler="rand", drop_last=True
      )
      for idx, batch in enumerate(dl4):
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 22:
              raise ValueError(f"out of range")
      # sampler 为 Dict
      samplers = {
          "d1": SequentialSampler(d1),
          "d2": SequentialSampler(d2),
          "d3": RandomSampler(d3),
      }
      dl5 = MixDataLoader(
          datasets=datasets,
          mode="mix",
          sampler=samplers,
          drop_last=True,
      )
      for idx, batch in enumerate(dl5):
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 22:
              raise ValueError(f"out of range")
      # ds_ratio 为 'truncate_to_least'
      dl6 = MixDataLoader(
          datasets=datasets, mode="mix", ds_ratio="truncate_to_least"
      )
      d1_len, d2_len, d3_len = 0, 0, 0
      for idx, batch in enumerate(dl6):
          for item in batch["y"].tolist():
              if item in [1, 0, 1]:
                  d1_len += 1
              elif item in [20, 10, 10]:
                  d2_len += 1
              elif item in [100, 100, 200]:
                  d3_len += 1
          if idx >= 6:
              raise ValueError(f"ds_ratio 为 'truncate_to_least'出错了")
      assert d1_len == d2_len == d3_len == 30
  
      # ds_ratio 为 'pad_to_most'
      dl7 = MixDataLoader(
          datasets=datasets, mode="mix", ds_ratio="pad_to_most"
      )
      d1_len, d2_len, d3_len = 0, 0, 0
      for idx, batch in enumerate(dl7):
          for item in batch["y"].tolist():
              if item in [1, 0, 1]:
                  d1_len += 1
              elif item in [20, 10, 10]:
                  d2_len += 1
              elif item in [100, 100, 200]:
                  d3_len += 1
  
          if idx >= 57:
              raise ValueError(f"ds_ratio 为 'pad_to_most'出错了")
      assert d1_len == d2_len == d3_len == 300
  
      # ds_ratio 为 Dict[str, float]
      ds_ratio = {"d1": 1.0, "d2": 2.0, "d3": 2.0}
      dl8 = MixDataLoader(
          datasets=datasets, mode="mix", ds_ratio=ds_ratio
      )
      d1_len, d2_len, d3_len = 0, 0, 0
      for idx, batch in enumerate(dl8):
          for item in batch["y"].tolist():
              if item in [1, 0, 1]:
                  d1_len += 1
              elif item in [20, 10, 10]:
                  d2_len += 1
              elif item in [100, 100, 200]:
                  d3_len += 1
          if idx >= 44:
              raise ValueError(f"ds_ratio 为 'Dict'出错了")
      assert d1_len == 30
      assert d2_len == 60
      assert d3_len == 600
  
      ds_ratio = {"d1": 0.1, "d2": 0.6, "d3": 1.0}
      dl9 = MixDataLoader(
          datasets=datasets, mode="mix", ds_ratio=ds_ratio
      )
      d1_len, d2_len, d3_len = 0, 0, 0
      for idx, batch in enumerate(dl9):
          for item in batch["y"].tolist():
              if item in [1, 0, 1]:
                  d1_len += 1
              elif item in [20, 10, 10]:
                  d2_len += 1
              elif item in [100, 100, 200]:
                  d3_len += 1
          if idx >= 21:
              raise ValueError(f"ds_ratio 为 'Dict'出错了")
  
file_path: fastNLP/tests/core/dataloaders/torch_dataloader/test_mixdataloader.py
imports: import pytest
  from typing import Mapping
  from fastNLP.core.dataloaders import MixDataLoader
  from fastNLP import DataSet
  from fastNLP.core.collators import Collator
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
label_desc: Use image node_id 2 for calling the TestMixDataLoader obj's underlying member method code with example usage: obj.test_mix() and returns: new_batch