code: def pad_batch(batch, pad_id, max_len):
      context_lengths = []
      max_context_length = max([len(tokens) for tokens in batch])
      for tokens in batch:
          context_length = len(tokens)
          if context_length < max_context_length + max_len:
              tokens.extend(
                  [pad_id]
                  * (max_context_length + max_len - context_length)
              )
          context_lengths.append(context_length)
      return batch, context_lengths
  
file_path: NeMo/nemo/collections/nlp/modules/common/lm_utils.py
imports: import os
  from typing import List, Optional, Union
  from attr import asdict
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from nemo.collections.nlp.modules.common.bert_module import BertModule
  from nemo.collections.nlp.modules.common.decoder_module import DecoderModule
  from nemo.collections.nlp.modules.common.encoder_module import EncoderModule
  from nemo.collections.nlp.modules.common.huggingface.huggingface_utils import get_huggingface_lm_model, get_huggingface_pretrained_lm_models_list
  from nemo.collections.nlp.modules.common.megatron.megatron_utils import get_megatron_pretrained_bert_models
  from nemo.collections.nlp.modules.common.transformer.transformer import NeMoTransformerConfig
  from nemo.collections.nlp.modules.common.transformer.transformer_utils import get_huggingface_transformer, get_nemo_transformer
  from nemo.utils import AppState, logging
label_desc: Use image node_id 1 for calling a global function with example usage: pad_batch(batch, pad_id, max_len) and returns: batch,  context_lengths