code: def get_batch_logps(
      logits: torch.FloatTensor,
      labels: torch.LongTensor,
      average_log_prob: bool = False,
  ) -> torch.Tensor:
      """
      Based upon the official implementation of DPO:
      https://github.com/eric-mitchell/direct-preference-optimization
  
      Compute the log probabilities of the given labels under the given logits.
      Args:
          logits:
              Logits of the model (unnormalized).
              Shape: (batch_size, sequence_length, vocab_size)
          labels:
              Labels for which to compute the log probabilities.
              Label tokens with a value of -100 are ignored.
              Shape: (batch_size, sequence_length)
          average_log_prob:
              If True, return the average log probability per (non-masked) token.
              Otherwise, return the sum of the
              log probabilities of the (non-masked) tokens.
      Returns:
          A tensor of shape (batch_size,) containing the average/sum
          log probabilities of the given labels under the given logits.
      """
      assert logits.shape[:-1] == labels.shape
  
      # shift labels and logits to account for next token prediction
      # See also text_causal_language_modeling_losses.py
      labels = labels[:, 1:].clone()
      logits = logits[:, :-1, :]
      loss_mask = labels != -100
  
      # dummy token; we'll ignore the losses on these tokens when loss_mask is applied
      # Needed to be able to apply torch.gather with index=labels.unsqueeze(2)
      labels[labels == -100] = 0
  
      per_token_logps = torch.gather(
          logits.log_softmax(-1), dim=2, index=labels.unsqueeze(2)
      ).squeeze(2)
  
      # both trl and original dpo repo have average_log_prob=False
      if average_log_prob:
          return (per_token_logps * loss_mask).sum(-1) / loss_mask.sum(
              -1
          )
      else:
          return (per_token_logps * loss_mask).sum(-1)
  
file_path: h2o-llmstudio/llm_studio/src/models/text_dpo_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 1 for calling a global function with example usage: get_batch_logps(logits, labels, average_log_prob) and returns: unknown, unknown