class_docstr: Implements
  "Direct Preference Optimization:
  Your Language Model is Secretly a Reward Model"
  from https://arxiv.org/abs/2305.18290
class_docstr_tok: ["Implements","''","Direct","Preference","Optimization",":","Your","Language","Model","is","Secretly","a","Reward","Model","''","from","https",":","\/\/arxiv.org\/abs\/2305.18290"]
code: def forward(
      self,
      policy_chosen_logps: torch.FloatTensor,
      policy_rejected_logps: torch.FloatTensor,
      reference_chosen_logps: torch.FloatTensor,
      reference_rejected_logps: torch.FloatTensor,
  ) -> Tuple[torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]:
      pi_logratios = policy_chosen_logps - policy_rejected_logps
      ref_logratios = reference_chosen_logps - reference_rejected_logps
  
      losses = self.get_losses(logits=pi_logratios - ref_logratios)
      chosen_rewards = (
          self.cfg.training.beta
          * (policy_chosen_logps - reference_chosen_logps).detach()
      )
      rejected_rewards = (
          self.cfg.training.beta
          * (policy_rejected_logps - reference_rejected_logps).detach()
      )
  
      return (
          losses.mean(),
          chosen_rewards.mean(),
          rejected_rewards.mean(),
      )
  
file_path: h2o-llmstudio/llm_studio/src/losses/text_dpo_modeling_losses.py
imports: import logging
  from typing import Any, KeysView, Tuple
  import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 2 for calling the DPOLoss obj's underlying member method code with example usage: obj.forward(policy_chosen_logps, policy_rejected_logps, reference_chosen_logps, reference_rejected_logps) and returns: losses,  chosen_rewards,  rejected_rewards