code: def _build_train_valid_test_datasets(
      cfg,
      trainer,
      data_prefix: str,
      data_impl: str,
      splits_string: str,
      train_valid_test_num_samples,
      seq_length: int,
      seed: int,
      skip_warmup: bool,
      tokenizer,
      retrieval_prefix: str,
      knn_map_path: str,
  ):
      """Build train, valid, and test datasets."""
  
      # Indexed dataset.
      indexed_dataset: MMapRetrievalIndexedDataset = (
          get_indexed_dataset_(data_prefix, data_impl, skip_warmup)
      )
      knn_index: KNNIndex = KNNIndex(knn_map_path, skip_warmup)
      retrieval_index: MMapRetrievalIndexedDataset = (
          get_indexed_dataset_(retrieval_prefix, data_impl, skip_warmup)
      )
  
      total_num_of_documents = indexed_dataset.sizes.shape[0]
      splits = get_train_valid_test_split_(
          splits_string, total_num_of_documents
      )
  
      # Print stats about the splits.
      logging.info(" > dataset split:")
  
      def print_split_stats(name, index):
          logging.info("    {}:".format(name))
          logging.info(
              "     document indices in [{}, {}) total of {} "
              "documents".format(
                  splits[index],
                  splits[index + 1],
                  splits[index + 1] - splits[index],
              )
          )
  
      print_split_stats("train", 0)
      print_split_stats("validation", 1)
      print_split_stats("test", 2)
  
      def build_dataset(index, name):
          dataset = None
          if splits[index + 1] > splits[index]:
              documents = np.arange(
                  start=splits[index],
                  stop=splits[index + 1],
                  step=1,
                  dtype=np.int32,
              )
              dataset = RETRODataset(
                  cfg,
                  trainer,
                  tokenizer,
                  name,
                  data_prefix,
                  documents,
                  indexed_dataset,
                  train_valid_test_num_samples[index],
                  seq_length,
                  seed,
                  knn_index,
                  retrieval_index,
              )
          return dataset
  
      train_dataset = build_dataset(0, "train")
      valid_dataset = build_dataset(1, "valid")
      test_dataset = build_dataset(2, "test")
  
      return (train_dataset, valid_dataset, test_dataset)
  
imports: import os
  from typing import List
  import numpy
  import torch
  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.gpt_dataset import _build_index_mappings, get_indexed_dataset_
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_retrieval_dataset import KNNIndex, MMapRetrievalIndexedDataset
  from nemo.core import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling a global function with example usage: _build_train_valid_test_datasets(cfg, trainer, data_prefix, data_impl, splits_string, train_valid_test_num_samples, seq_length, seed, skip_warmup, tokenizer, retrieval_prefix, knn_map_path) and returns: train_dataset,  valid_dataset,  test_dataset, dataset