class_docstr: 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 = "prompt_attention_mask"
      pad_keys = [
          "prompt_input_ids",
          "prompt_attention_mask",
          "special_tokens_mask",
          "labels",
      ]
  
      if padding:
          batch = batch_padding(
              self.cfg,
              batch,
              self.training,
              mask_key=mask_key,
              pad_keys=pad_keys,
              padding_side=self.cfg.tokenizer._padding_side,
          )
  
      output = self.backbone(
          input_ids=batch["prompt_input_ids"],
          attention_mask=batch["prompt_attention_mask"],
      )
  
      output.logits = self.classification_head(output[0][:, -1].float())
  
      if "labels" in batch:
          loss = self.loss_fn(
              output.logits, batch["class_label"].unsqueeze(1).float()
          )
          outputs["loss"] = loss
  
      outputs["logits"] = output.logits
  
      # 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_causal_classification_modeling_model.py
imports: import logging
  from typing import Any, Dict
  from torch import nn
  from transformers import AutoModelForCausalLM
  from llm_studio.src.utils.data_utils import batch_padding
  from llm_studio.src.utils.modeling_utils import create_nlp_backbone, 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