code: def build_train_valid_test_datasets(
      cfg,
      trainer,
      data_prefix: List[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: List[str],
  ):
      """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.
      """
      # make sure there is one to one mapping  between data_prefix and knn_map_path
      assert len(data_prefix) == len(knn_map_path)
  
      # Single dataset.
      if len(data_prefix) == 1:
          return _build_train_valid_test_datasets(
              cfg,
              trainer,
              data_prefix[0],
              data_impl,
              splits_string,
              train_valid_test_num_samples,
              seq_length,
              seed,
              skip_warmup,
              tokenizer,
              retrieval_prefix,
              knn_map_path[0],
          )
  
      # Blending dataset.
      # Parse the values.
      output = get_datasets_weights_and_num_samples(
          data_prefix, train_valid_test_num_samples
      )
      prefixes, weights, datasets_train_valid_test_num_samples = output
      train_n, valid_n, test_n = map(
          sum, zip(*datasets_train_valid_test_num_samples)
      )
  
      # Build individual datasets.
      train_datasets = []
      valid_datasets = []
      test_datasets = []
      for i in range(len(prefixes)):
          (
              train_ds,
              valid_ds,
              test_ds,
          ) = _build_train_valid_test_datasets(
              cfg,
              trainer,
              prefixes[i],
              data_impl,
              splits_string,
              datasets_train_valid_test_num_samples[i],
              seq_length,
              seed,
              skip_warmup,
              tokenizer,
              retrieval_prefix,
              knn_map_path[i],
          )
          if train_ds:
              train_datasets.append(train_ds)
          if valid_ds:
              valid_datasets.append(valid_ds)
          if test_ds:
              test_datasets.append(test_ds)
  
      # Blend.
      blending_train_dataset = None
      if train_datasets:
          blending_train_dataset = BlendableDataset(
              train_datasets, weights, train_n
          )
      blending_valid_dataset = None
      if valid_datasets:
          blending_valid_dataset = BlendableDataset(
              valid_datasets, weights, valid_n
          )
      blending_test_dataset = None
      if test_datasets:
          blending_test_dataset = BlendableDataset(
              test_datasets, weights, test_n
          )
  
      return (
          blending_train_dataset,
          blending_valid_dataset,
          blending_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 1 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: blending_train_dataset,  blending_valid_dataset,  blending_test_dataset, _build_train_valid_test_datasets