class_docstr: Model for causal language modeling problem type.
class_docstr_tok: ["Model","for","causal","language","modeling","problem","type","."]
code: def forward(
      self,
      batch: Dict,
      padding: bool = True,
  ) -> Dict:
      # disable cache if gradient checkpointing is enabled
      if self.cfg.architecture.gradient_checkpointing:
          self.backbone.config.use_cache = False
  
      outputs: Dict = {}
      mask_key = "attention_mask"
      pad_keys = [
          "input_ids",
          "attention_mask",
          "special_tokens_mask",
          "labels",
      ]
  
      if padding:
          batch = batch_padding(
              self.cfg,
              batch,
              self.training,
              mask_key=mask_key,
              pad_keys=pad_keys,
          )
  
      output = self.backbone(
          input_ids=batch["input_ids"],
          attention_mask=batch["attention_mask"],
          output_hidden_states=True,
      )
  
      if (
          self.cfg.prediction.metric == "Perplexity"
          and not self.training
      ):
          outputs["perplexity"] = self.perplexity(
              output.logits, batch["labels"]
          )
  
      if self.training:
          last_hidden_state = output.hidden_states[-1]
  
          # force upcast in fp32 if logits are in half-precision
          if output.logits.dtype != torch.float32:
              output.logits = output.logits.float()
  
          outputs["logits"] = output.logits
          outputs["value"] = self.value_head(last_hidden_state).squeeze(
              -1
          )
  
      # enable cache again if gradient checkpointing is enabled
      if self.cfg.architecture.gradient_checkpointing:
          self.backbone.config.use_cache = True
  
      return outputs
  
file_path: h2o-llmstudio/llm_studio/src/models/text_rlhf_language_modeling_model.py
imports: import logging
  from typing import Any, Dict
  import torch
  from torch import nn
  from transformers import AutoModelForCausalLM
  from llm_studio.src.metrics.text_causal_language_modeling_metrics import Perplexity
  from llm_studio.src.utils.data_utils import batch_padding
  from llm_studio.src.utils.modeling_utils import create_nlp_backbone, generate, prepare_lora
label_desc: Use image node_id 2 for calling the Model obj's underlying member method code with example usage: obj.forward(batch, padding) and returns: outputs