code: def dataio_prepare(hparams):
      data_folder = hparams["data_folder"]
  
      train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["train_csv"],
          replacements={"data_root": data_folder},
      )
  
      # We remove longer and shorter files from the train.
      train_data = train_data.filtered_sorted(
          sort_key="duration",
          key_max_value={"duration": hparams["avoid_if_longer_than"]},
          key_min_value={"duration": hparams["avoid_if_shorter_than"]},
      )
  
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["valid_csv"],
          replacements={"data_root": data_folder},
      )
  
      datasets = [train_data, valid_data]
  
      def get_output_lengths(input_lengths):
          """Function to get the output length of the feature extractor this is
          necessery to compute the masks of wav2vec2.
          """
  
          def _conv_out_length(input_length, kernel_size, stride):
              return torch.floor(
                  (input_length - kernel_size) / stride + 1
              )
  
          for kernel_size, stride in zip(
              hparams["latentextractor_kernels"],
              hparams["latentextractor_strides"],
          ):
              input_lengths = _conv_out_length(
                  input_lengths, kernel_size, stride
              )
          return input_lengths.to(torch.long)
  
      @sb.utils.data_pipeline.takes("wav")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav):
          sig = sb.dataio.dataio.read_audio(wav)
          assert sig.dim() == 1, sig.dim()
  
          # Audio normalization
          with torch.no_grad():
              sig = F.layer_norm(sig, sig.shape)
          return sig
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
      sb.dataio.dataset.set_output_keys(datasets, ["id", "sig"])
  
      # We create the DynamicBatch Sampler
      dynamic_hparams = hparams["dynamic_batch_sampler_train"]
  
      train_sampler = DynamicBatchSampler(
          train_data,
          **dynamic_hparams,
          length_func=lambda x: x["duration"],
      )
  
      # We define the custom collation function that is necessary for w2v2 to
      # generate masks.
      w2v_mask_collate_fn_partial = partial(
          w2v_mask_collate_fn,
          get_out_len_fn=get_output_lengths,
          mask_prob=hparams["mask_prob"],
          mask_length=hparams["mask_length"],
      )
  
      train_loader_kwargs = {
          "batch_sampler": train_sampler,
          "collate_fn": w2v_mask_collate_fn_partial,
          "num_workers": hparams["train_dataloader_options"][
              "num_workers"
          ],
          "pin_memory": True,
      }
  
      valid_loader = SaveableDataLoader(
          valid_data,
          collate_fn=w2v_mask_collate_fn_partial,
          num_workers=hparams["test_dataloader_options"]["num_workers"],
          batch_size=hparams["test_dataloader_options"]["batch_size"],
          pin_memory=True,
      )
  
      return train_data, valid_loader, train_loader_kwargs
  
imports: import logging
  import sys
  import time
  from functools import partial
  import speechbrain
  import torch
  import torch.nn.functional
  from torch.nn.parallel import DistributedDataParallel
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain import Stage
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.dataio.dataloader import SaveableDataLoader
  from speechbrain.dataio.sampler import DynamicBatchSampler
  from speechbrain.lobes.models.wav2vec import w2v_mask_collate_fn
  from speechbrain.lobes.models.wav2vec import sample_negatives
  from speechbrain.core import AMPConfig
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: train_data,  valid_loader,  train_loader_kwargs, input_lengths, sig, torch