code: def compute_weights_and_temperature_loss(
      q_values: tf.Tensor,
      epsilon: float,
      temperature: tf.Variable,
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Computes normalized importance weights for the policy optimization.
  
      Args:
        q_values: Q-values associated with the actions sampled from the target
          policy; expected shape [N, B].
        epsilon: Desired constraint on the KL between the target and non-parametric
          policies.
        temperature: Scalar used to temper the Q-values before computing normalized
          importance weights from them. This is really the Lagrange dual variable
          in the constrained optimization problem, the solution of which is the
          non-parametric policy targeted by the policy loss.
  
      Returns:
        Normalized importance weights, used for policy optimization.
        Temperature loss, used to adapt the temperature.
      """
  
      # Temper the given Q-values using the current temperature.
      tempered_q_values = tf.stop_gradient(q_values) / temperature
  
      # Compute the normalized importance weights used to compute expectations with
      # respect to the non-parametric policy.
      normalized_weights = tf.nn.softmax(tempered_q_values, axis=0)
      normalized_weights = tf.stop_gradient(normalized_weights)
  
      # Compute the temperature loss (dual of the E-step optimization problem).
      q_logsumexp = tf.reduce_logsumexp(tempered_q_values, axis=0)
      log_num_actions = tf.math.log(
          tf.cast(q_values.shape[0], tf.float32)
      )
      loss_temperature = (
          epsilon + tf.reduce_mean(q_logsumexp) - log_num_actions
      )
      loss_temperature = temperature * loss_temperature
  
      return normalized_weights, loss_temperature
  
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 1 for calling a global function with example usage: compute_weights_and_temperature_loss(q_values, epsilon, temperature) and returns: normalized_weights,  loss_temperature