class_docstr: The dataset class for prompt-tuning or p-tuning pretrained GPT models.
  
  Args:
      data (list[strings], list[dicts]): (1) paths to .jsonl or .json files, (2) dict objects corresponding to each input example
      tokenizer (tokenizer): Tokenizer from frozen language model
      virtual_prompt_source (Enum): Either VirtualPromptSource.NO_PROMPTS or VirtualPromptSource.PROMPT_ENCODER
      task_templates (dict): Dictionary containing all task template information needed to format prompts. Created in the GPTPromptLearningModel class.
      pseudo_tokens (list[strings]): A list of virtual prompt token placeholders e.g [<prompt_1>, <prompt_2>, ...] up to max num virtual tokens
      pad_token_id (int): ID of pad token from tokenizer
      max_seq_length (int): maximum sequence length for each dataset examples. Examples will either be truncated to fit this length or dropped if they cannot be truncated.
      min_seq_length (int): min length of each data example in the dataset. Data examples will be dropped if they do not meet the min length requirements. 
      add_bos (bool): Whether to add a beginning of sentence token to each data example
      add_eos (bool): Whether to add an end of sentence token to each data example
      for_train (bool): Whether you're creating a dataset for training or inference
      tokens_to_generate (int): (inference only) Number of tokens to generate during inference
code: def __init__(
      self,
      data,
      tokenizer,
      virtual_prompt_source: VirtualPromptSource,
      task_templates: dict,
      pseudo_tokens,
      pad_token_id: int,
      max_seq_length: int,
      min_seq_length: int = 1,
      add_bos: bool = False,
      add_eos: bool = True,
      for_train: bool = True,
      tokens_to_generate=None,
      cache_data_path: str = None,  # the cache file
      load_cache: bool = True,  # whether to load from the cache if it is available
  ):
      self.tokenizer = tokenizer
      self.virtual_prompt_source = virtual_prompt_source
      self.task_templates = task_templates
      self.pseudo_tokens = pseudo_tokens
      self.pseudo_token_ids = set(
          self.tokenizer.tokens_to_ids(self.pseudo_tokens)
      )
      self.pad_token_id = pad_token_id
      self.max_seq_length = max_seq_length
      self.min_seq_length = min_seq_length
      self.add_bos = add_bos
      self.add_eos = add_eos
      self.for_train = for_train
      self.examples = []
  
      if not self.for_train:
          self.tokens_to_generate = tokens_to_generate
  
      assert (
          self.min_seq_length <= max_seq_length
      ), "Min sequence length should be less than or equal to max"
      assert (
          self.max_seq_length > 0
      ), "Max sequence length should be greater than 0"
  
      logging.info("Loading and tokenizing dataset ... ")
  
      if (
          load_cache
          and cache_data_path is not None
          and os.path.exists(cache_data_path)
      ):
          # load it from the cache
          logging.info(
              f"load the data from the cache file {cache_data_path}"
          )
          with open(cache_data_path, "rb") as f:
              self.examples = pickle.load(f)
      else:
          # Data is just a list of dicts already loaded from a json file or passed in directly as a dict
          if isinstance(data[0], dict):
              self.load_data(data)
  
          # Datasets are a list of file path strings to .json or .jsonl files
          elif isinstance(data[0], str):
              for path in data:
                  dataset = open(path, "r", encoding="utf-8")
                  self.load_data(dataset)
          else:
              raise ValueError(
                  "Datasets must be a list of filepath strings or a list of data example dicts"
              )
          if cache_data_path is not None:
              # the first worker save the results into the cache file
              app_state = AppState()
              if app_state._global_rank == 0:
                  with open(cache_data_path, "wb") as f:
                      pickle.dump(self.examples, f)
                  logging.info(
                      f"save the data to the cache file {cache_data_path}"
                  )
  
imports: import json
  import os
  import pickle
  import torch
  from tqdm.auto import tqdm
  from nemo.collections.nlp.modules.common import VirtualPromptSource
  from nemo.collections.nlp.modules.common.megatron.utils import build_position_ids
  from nemo.core import Dataset
  from nemo.utils import AppState, logging
label_desc: Use image node_id 1 to create a new GPTPromptLearningDataset object from inherited base classes: Dataset with example: obj = GPTPromptLearningDataset(data, tokenizer, virtual_prompt_source, task_templates, pseudo_tokens, pad_token_id, max_seq_length, min_seq_length, add_bos, add_eos, for_train, tokens_to_generate, cache_data_path, load_cache)