code: def _build_train_valid_test_datasets(
      cfg,
      trainer,
      data_prefix,
      data_impl,
      splits_string,
      train_valid_test_num_samples,
      seq_length,
      seed,
      skip_warmup,
      tokenizer,
  ):
      """Build train, valid, and test datasets."""
  
      # Indexed dataset.
      delay_data_mmap = cfg.data.get("delay_data_mmap", False)
      indexed_dataset = get_indexed_dataset_(
          data_prefix, data_impl, skip_warmup, delay_data_mmap
      )
  
      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,
              )
              drop_last = True
              if name == "valid":
                  drop_last = cfg.data.get("validation_drop_last", True)
              dataset = GPTDataset(
                  cfg,
                  trainer,
                  tokenizer,
                  name,
                  data_prefix,
                  documents,
                  indexed_dataset,
                  train_valid_test_num_samples[index],
                  seq_length,
                  seed,
                  drop_last=drop_last,
              )
          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
  import time
  import numpy
  import torch
  from omegaconf.dictconfig import DictConfig
  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.indexed_dataset import deallocate_indexed_dataset_memory
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import make_dataset
  from nemo.core import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 3 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) and returns: train_dataset,  valid_dataset,  test_dataset, dataset