code: def get_chain_dataset(datasets, ds_config, rank=0):
      if len(datasets) > 1:
          if ds_config.get("bucketing_batch_size", None) is not None:
              bucketing_batch_sizes = calc_bucketing_batch_sizes(
                  ds_config, len(datasets)
              )
              logging.info(
                  f"Batch bucketing is enabled for {len(datasets)} buckets with adaptive batch sizes of {bucketing_batch_sizes}!"
              )
              for idx, dataset in enumerate(datasets):
                  datasets[idx] = audio_to_text.BucketingDataset(
                      dataset=dataset,
                      bucketing_batch_size=bucketing_batch_sizes[idx],
                  )
          else:
              logging.info(
                  f"Batch bucketing is enabled for {len(datasets)} buckets with fixed batch size of {ds_config['batch_size']}!"
              )
  
      if len(datasets) == 1:
          return datasets[0]
      bucketing_strategy = ds_config.get(
          "bucketing_strategy", "synced_randomized"
      )
      if bucketing_strategy == "fixed_order":
          return ChainDataset(datasets)
      elif bucketing_strategy == "synced_randomized":
          return audio_to_text.RandomizedChainDataset(
              datasets=datasets, rnd_seed=0
          )
      elif bucketing_strategy == "fully_randomized":
          return audio_to_text.RandomizedChainDataset(
              datasets=datasets,
              rnd_seed=random.randint(0, 30000) + rank,
          )
      else:
          raise ValueError(
              f"bucketing_strategy={bucketing_strategy} is not supported! Supported strategies are [fixed_order, fully_randomized, synced_randomized]."
          )
  
imports: import copy
  import json
  import random
  from math import isclose
  from typing import Any, List, Optional, Union
  import torch
  from omegaconf import DictConfig, OmegaConf, open_dict
  from omegaconf.listconfig import ListConfig
  from pytorch_lightning.callbacks import BasePredictionWriter
  from torch.utils.data import ChainDataset
  from nemo.collections.asr.data import audio_to_text, audio_to_text_dali
  from nemo.collections.asr.data.huggingface.hf_audio_to_text_dataset import get_hf_audio_to_text_bpe_dataset, get_hf_audio_to_text_char_dataset
  from nemo.collections.asr.parts.preprocessing.perturb import process_augmentations
  from nemo.collections.common.data.dataset import CodeSwitchedDataset, ConcatDataset
  from nemo.utils import logging
label_desc: Use image node_id 14 for calling a global function with example usage: get_chain_dataset(datasets, ds_config, rank) and returns: datasets, ChainDataset, audio_to_text, audio_to_text