class_docstr: The dataset class for prompt-tuning or p-tuning pretrained T5 models.
class_docstr_tok: ["The","dataset","class","for","prompt-tuning","or","p-tuning","pretrained","T5","models","."]
docstr: Pad enc_input, dec_input, labels in batch to max batch length while building loss_mask, enc_mask, and dec_mask 
docstr_tok: ["Pad","enc_input",",","dec_input",",","labels","in","batch","to","max","batch","length","while","building","loss_mask",",","enc_mask",",","and","dec_mask"]
code: def pad_batch_and_build_loss_mask(
      self, enc_input, dec_input, dec_labels
  ):
      """Pad enc_input, dec_input, labels in batch to max batch length while building loss_mask, enc_mask, and dec_mask"""
  
      # have labels (during training and validation)
      if dec_input[0] and dec_labels[0]:
          max_dec_input_length = (
              max([len(item) for item in dec_input])
              if dec_input[0]
              else 0
          )
          max_label_length = (
              max([len(item) for item in dec_labels])
              if dec_labels[0]
              else 0
          )
  
          loss_mask = [
              ([1] * (len(item)))
              + ([0] * (max_label_length - len(item)))
              for item in dec_labels
          ]
          dec_input = [
              item
              + [self.tokenizer.pad_id]
              * (max_dec_input_length - len(item))
              for item in dec_input
          ]
          labels = [
              item
              + [self.tokenizer.pad_id] * (max_label_length - len(item))
              for item in dec_labels
          ]
  
          dec_input = torch.LongTensor(dec_input).contiguous()
          labels = torch.LongTensor(labels).contiguous()
          loss_mask = torch.LongTensor(loss_mask).contiguous()
  
          dec_mask = (
              (dec_input != self.tokenizer.pad_id).long().contiguous()
          )
  
      # during inference
      else:
          dec_input, labels, loss_mask, dec_mask = (
              None,
              None,
              None,
              None,
          )
  
      # for all training, validation, and inference
      max_enc_query_length = (
          max([len(item) for item in enc_input]) if enc_input[0] else 0
      )
      enc_input = [
          item
          + [self.tokenizer.pad_id] * (max_enc_query_length - len(item))
          for item in enc_input
      ]
      enc_input = torch.LongTensor(enc_input).contiguous()
  
      enc_mask = (
          (enc_input != self.tokenizer.pad_id).long().contiguous()
      )
  
      return enc_input, dec_input, labels, loss_mask, enc_mask, dec_mask
  
file_path: NeMo/nemo/collections/nlp/data/language_modeling/megatron/t5_prompt_learning_dataset.py
imports: import json
  import torch
  from tqdm.auto import tqdm
  from nemo.collections.nlp.data.language_modeling.megatron.base_prompt_learning_dataset import BasePromptLearningDataset
  from nemo.collections.nlp.models.language_modeling.megatron_t5_model import T5Sentinel
  from nemo.collections.nlp.modules.common import VirtualPromptSource
  from nemo.collections.nlp.modules.common.megatron.utils import build_position_ids
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the T5PromptLearningDataset obj's underlying member method code with example usage: obj.pad_batch_and_build_loss_mask(enc_input, dec_input, dec_labels) and returns: enc_input,  dec_input,  labels,  loss_mask,  enc_mask,  dec_mask