code: def build_all_datasets(
      cfg,
      tokenizer,
      train_valid_test_num_samples,
  ):
      """Build train, valid, and test RETRO datasets.
      There is one to one mapping between data_prefix and knn_map_path.
      Currently only supports one retrieval dataset.
      """
      train_dataset = RetroQAFineTuneDataset(
          cfg.train_ds.get("file_name"),
          tokenizer,
          cfg.train_ds.get("answer_only_loss"),
          tokenizer.pad_id,
          cfg.train_ds.get("seq_length"),
          cfg.train_ds.get("add_bos"),
          cfg.train_ds.get("add_eos"),
          train_valid_test_num_samples[0],
          cfg.train_ds.get("seed"),
          cfg.train_ds.get("neighbors"),
      )
      val_dataset = RetroQAFineTuneDataset(
          cfg.val_ds.get("file_name"),
          tokenizer,
          cfg.val_ds.get("answer_only_loss"),
          tokenizer.pad_id,
          cfg.val_ds.get("seq_length"),
          cfg.val_ds.get("add_bos"),
          cfg.val_ds.get("add_eos"),
          train_valid_test_num_samples[1],
          cfg.val_ds.get("seed"),
          cfg.val_ds.get("neighbors"),
      )
      test_dataset = RetroQAFineTuneDataset(
          cfg.test_ds.get("file_name"),
          tokenizer,
          cfg.test_ds.get("answer_only_loss"),
          tokenizer.pad_id,
          cfg.test_ds.get("seq_length"),
          cfg.test_ds.get("add_bos"),
          cfg.test_ds.get("add_eos"),
          train_valid_test_num_samples[2],
          cfg.test_ds.get("seed"),
          cfg.test_ds.get("neighbors"),
      )
  
      return train_dataset, val_dataset, test_dataset
  
imports: import json
  from functools import partial
  import torch
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.common.data import ConcatMapDataset
  from nemo.collections.common.metrics import MetricStringToTorchMetric
  from nemo.collections.common.metrics.classification_accuracy import ExactStringPerCategoryMatchMetric
  from nemo.collections.nlp.data.common.sequence_to_sequence_dataset import SequenceToSequenceDataset
  from nemo.collections.nlp.data.language_modeling.megatron.base_dataset_utils import get_datasets_weights_and_num_samples, get_train_valid_test_split_
  from nemo.collections.nlp.data.language_modeling.megatron.blendable_dataset import BlendableDataset
  from nemo.collections.nlp.data.language_modeling.megatron.megatron_batch_samplers import MegatronPretrainingBatchSampler
  from nemo.collections.nlp.data.language_modeling.megatron.retro_fine_tune_dataset import RetroQAFineTuneDataset
  from nemo.collections.nlp.models.language_modeling.megatron_retrieval_model import MegatronRetrievalModel
  from nemo.collections.nlp.models.language_modeling.megatron_t5_model import MegatronT5Model, T5Sentinel
  from nemo.collections.nlp.parts.nlp_overrides import GlobalBatchDataFetcher
  from nemo.utils import AppState, logging
label_desc: Use image node_id 1 for calling a global function with example usage: build_all_datasets(cfg, tokenizer, train_valid_test_num_samples) and returns: train_dataset,  val_dataset,  test_dataset