class_docstr: Megatron GPT Supervised Fine-Tuning
class_docstr_tok: ["Megatron","GPT","Supervised","Fine-Tuning"]
code: def build_train_valid_test_datasets(self, stage):
      if stage != "test":
          logging.info("Building GPT SFT validation datasets.")
          # Wrap this in a list since the general finetuning parent class supports multi-validation.
          self._validation_ds = self._build_dataset(
              self.cfg.data.validation_ds, is_train=False
          )
          logging.info(
              f"Length of val dataset: {len(self._validation_ds[0])}"
          )
  
      if stage != "validate":
          if (
              hasattr(self.cfg.data, "test_ds")
              and self.cfg.data.test_ds.get("file_names", None)
              is not None
          ):
              logging.info("Building GPT SFT test datasets.")
              # Wrap this in a list since the general finetuning parent class supports multi-validation.
              self._test_ds = self._build_dataset(
                  self.cfg.data.test_ds, is_train=False
              )
              logging.info(
                  f"Length of test dataset: {len(self._test_ds[0])}"
              )
  
      if stage == "validate" or stage == "test":
          return
      logging.info("Building GPT SFT traing datasets.")
      self._train_ds = self._build_dataset(self.cfg.data.train_ds)
      logging.info(f"Length of train dataset: {len(self._train_ds)}")
  
imports: import itertools
  import json
  from functools import partial
  from typing import Any, Optional
  import torch
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.common.metrics import MetricStringToTorchMetric
  from nemo.collections.nlp.data.language_modeling.megatron.base_dataset_utils import get_datasets_weights_and_num_samples
  from nemo.collections.nlp.data.language_modeling.megatron.blendable_dataset import BlendableDataset
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_sft_chat_dataset import GPTSFTChatDataset
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_sft_dataset import GPTSFTDataset, GPTSFTPackedDataset
  from nemo.collections.nlp.data.language_modeling.megatron.megatron_batch_samplers import MegatronPretrainingBatchSampler
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.modules.common.megatron.utils import get_iterator_k_split
  from nemo.collections.nlp.modules.common.text_generation_utils import generate, get_computeprob_response
  from nemo.collections.nlp.parts.mixins.nlp_adapter_mixins import NLPAdapterModelMixin
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank
  from nemo.utils import AppState, logging
label_desc: Use image node_id 16 for calling the MegatronGPTSFTModel obj's underlying member method code with example usage: obj.build_train_valid_test_datasets(stage) without return types