code: def test_sequential_init(self):
      datasets = {"d1": d1, "d2": d2, "d3": d3}
      # drop_last = True, collate_fn = 'auto
      dl = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          collate_fn="auto",
          drop_last=True,
      )
      for idx, batch in enumerate(dl):
          if idx == 0:
              # d1
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              # d2
              assert batch["x"].shape == torch.Size([16, 3])
          if idx > 1:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
  
      # 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="sequential",
          collate_fn=collate_batch,
          drop_last=True,
      )
      for idx, batch in enumerate(dl1):
          if idx == 0:
              # d1
              assert [1, 2] in batch["x"]
          if idx == 1:
              # d2
              assert [101, 201] in batch["x"]
          if idx > 1:
              # d3
              assert [1000, 2000] in batch["x"]
          assert "x" in batch and "y" in batch
  
      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),
      }
      dl2 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          collate_fn=collate_fns,
          drop_last=True,
      )
      for idx, batch in enumerate(dl2):
          if idx == 0:
              assert _test_pad_val(batch["x"], val=-1)
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              assert _test_pad_val(batch["x"], val=-2)
              assert batch["x"].shape == torch.Size([16, 3])
          if idx > 1:
              assert _test_pad_val(batch["x"], val=-3)
              assert batch["x"].shape == torch.Size([16, 4])
  
      # sampler 为 str
      dl3 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          sampler="seq",
          drop_last=True,
      )
      dl4 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          sampler="rand",
          drop_last=True,
      )
      for idx, batch in enumerate(dl3):
          if idx == 0:
              # d1
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape == torch.Size([16, 3])
          if idx == 2:
              # d3
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
          if idx > 1:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
  
      for idx, batch in enumerate(dl4):
          if idx == 0:
              # d1
              assert batch["x"][:3].tolist() != [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              # d2
              assert batch["x"][:3].tolist() != [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape == torch.Size([16, 3])
          if idx == 2:
              # d3
              assert batch["x"][:3].tolist() != [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
          if idx > 1:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
  
      # sampler 为 Dict
      samplers = {
          "d1": SequentialSampler(d1),
          "d2": SequentialSampler(d2),
          "d3": RandomSampler(d3),
      }
      dl5 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          sampler=samplers,
          drop_last=True,
      )
      for idx, batch in enumerate(dl5):
          if idx == 0:
              # d1
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape == torch.Size([16, 3])
          if idx > 1:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
  
      # ds_ratio 为 'truncate_to_least'
      dl6 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          ds_ratio="truncate_to_least",
          drop_last=True,
      )
      for idx, batch in enumerate(dl6):
          if idx == 0:
              # d1
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape == torch.Size([16, 4])
          if idx == 1:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape == torch.Size([16, 3])
          if idx == 2:
              # d3
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
          if idx > 2:
              raise ValueError(f"ds_ratio: 'truncate_to_least' error")
  
      # ds_ratio 为 'pad_to_most'
      dl7 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          ds_ratio="pad_to_most",
          drop_last=True,
      )
      for idx, batch in enumerate(dl7):
          if idx < 18:
              # d1
              assert batch["x"].shape == torch.Size([16, 4])
          if 18 <= idx < 36:
              # d2
              assert batch["x"].shape == torch.Size([16, 3])
          if 36 <= idx < 54:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 54:
              raise ValueError(f"ds_ratio: 'pad_to_most' error")
  
      # ds_ratio 为 Dict[str, float]
      ds_ratio = {"d1": 1.0, "d2": 2.0, "d3": 2.0}
      dl8 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          ds_ratio=ds_ratio,
          drop_last=True,
      )
      for idx, batch in enumerate(dl8):
          if idx < 1:
              # d1
              assert batch["x"].shape == torch.Size([16, 4])
          if 1 <= idx < 4:
              # d2
              assert batch["x"].shape == torch.Size([16, 3])
          if 4 <= idx < 41:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 41:
              raise ValueError(f"ds_ratio: 'pad_to_most' error")
  
      ds_ratio = {"d1": 0.1, "d2": 0.6, "d3": 1.0}
      dl9 = MixDataLoader(
          datasets=datasets,
          mode="sequential",
          ds_ratio=ds_ratio,
          drop_last=True,
      )
      for idx, batch in enumerate(dl9):
          if idx < 1:
              # d2
              assert batch["x"].shape == torch.Size([16, 3])
          if 1 <= idx < 19:
              # d3
              assert batch["x"].shape == torch.Size([16, 4])
  
          assert _test_pad_val(batch["x"], val=0)
          if idx >= 19:
              raise ValueError(f"ds_ratio: 'pad_to_most' error")
  
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 1 for calling the TestMixDataLoader obj's underlying member method code with example usage: obj.test_sequential_init() and returns: new_batch