code: def compute_parametric_kl_penalty_and_dual_loss(
      kl: tf.Tensor,
      alpha: tf.Variable,
      epsilon: float,
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Computes the KL cost to be added to the Lagragian and its dual loss.
  
      The KL cost is simply the alpha-weighted KL divergence and it is added as a
      regularizer to the policy loss. The dual variable alpha itself has a loss that
      can be minimized to adapt the strength of the regularizer to keep the KL
      between consecutive updates at the desired target value of epsilon.
  
      Args:
        kl: KL divergence between the target and online policies.
        alpha: Lagrange multipliers (dual variables) for the KL constraints.
        epsilon: Desired value for the KL.
  
      Returns:
        loss_kl: alpha-weighted KL regularization to be added to the policy loss.
        loss_alpha: The Lagrange dual loss minimized to adapt alpha.
      """
  
      # Compute the mean KL over the batch.
      mean_kl = tf.reduce_mean(kl, axis=0)
  
      # Compute the regularization.
      loss_kl = tf.reduce_sum(tf.stop_gradient(alpha) * mean_kl)
  
      # Compute the dual loss.
      loss_alpha = tf.reduce_sum(
          alpha * (epsilon - tf.stop_gradient(mean_kl))
      )
  
      return loss_kl, loss_alpha
  
file_path: acme/acme/tf/losses/mpo.py
imports: from typing import Dict, Tuple, Union
  import sonnet
  import tensorflow
  import tensorflow_probability
label_desc: Use image node_id 4 for calling a global function with example usage: compute_parametric_kl_penalty_and_dual_loss(kl, alpha, epsilon) and returns: loss_kl,  loss_alpha