class_docstr: GPT-2 Language model.
class_docstr_tok: ["GPT-2","Language","model","."]
code: def forward(
      self,
      input_ids,
      position_ids,
      attention_mask,
      loss_mask=None,
      labels=None,
      token_type_ids=None,
      layer_past=None,
      get_key_value=False,
      forward_method_parallel_output=None,
      encoder_input=None,
      set_inference_key_value_memory=False,
      inference_max_sequence_len=None,
      checkpoint_activations_all_layers=None,
  ):
      # input_ids: [b, s]
      # position_ids: [b, s]
      # attention_mask: [1, 1, s, s]
  
      lm_output = self.language_model(
          input_ids,
          position_ids,
          attention_mask,
          layer_past=layer_past,
          get_key_value=get_key_value,
          encoder_input=encoder_input,
          set_inference_key_value_memory=set_inference_key_value_memory,
          inference_max_sequence_len=inference_max_sequence_len,
          checkpoint_activations_all_layers=checkpoint_activations_all_layers,
      )
  
      if self.post_process:
          if loss_mask is not None:
              loss_lm_output = lm_output.transpose(0, 1)[
                  loss_mask == 1
              ].unsqueeze(1)
              loss_labels = labels[loss_mask == 1].unsqueeze(0)
          else:
              loss_lm_output = lm_output
              loss_labels = labels
          post_process_result = post_language_model_processing(
              loss_lm_output,
              loss_labels,
              self.language_model.output_layer.weight
              if not self.share_embeddings_and_output_weights
              else self.word_embeddings_weight(),
              get_key_value,
              self.parallel_output,
              forward_method_parallel_output,
              self.fp16_lm_cross_entropy,
              return_logits=encoder_input is not None,
              sequence_parallel=self.sequence_parallel,
              gradient_accumulation_fusion=self.config.gradient_accumulation_fusion,
          )
          if loss_mask is not None:
              if isinstance(post_process_result, tuple):
                  loss, logits = post_process_result
              else:
                  loss, logits = post_process_result, None
  
              res = torch.zeros_like(labels).type_as(loss)
              res[loss_mask == 1] = loss
              return res if logits is None else (res, logits)
          else:
              return post_process_result
      else:
          return lm_output
  
file_path: NeMo/nemo/collections/nlp/models/language_modeling/megatron/gpt_model.py
imports: import torch
  from nemo.collections.nlp.modules.common.megatron.language_model import get_language_model
  from nemo.collections.nlp.modules.common.megatron.module import MegatronModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults, init_method_normal, parallel_lm_logits, scaled_init_method_normal
label_desc: Use image node_id 3 for calling the GPTModel obj's underlying member method code with example usage: obj.forward(input_ids, position_ids, attention_mask, loss_mask, labels, token_type_ids, layer_past, get_key_value, forward_method_parallel_output, encoder_input, set_inference_key_value_memory, inference_max_sequence_len, checkpoint_activations_all_layers) and returns: lm_output, unknown, post_process_result