class_docstr: PyTorch specific Policy class to use with RLlib.
class_docstr_tok: ["PyTorch","specific","Policy","class","to","use","with","RLlib","."]
code: def compute_log_likelihoods(
      self,
      actions: Union[List[TensorStructType], TensorStructType],
      obs_batch: Union[List[TensorStructType], TensorStructType],
      state_batches: Optional[List[TensorType]] = None,
      prev_action_batch: Optional[
          Union[List[TensorStructType], TensorStructType]
      ] = None,
      prev_reward_batch: Optional[
          Union[List[TensorStructType], TensorStructType]
      ] = None,
      actions_normalized: bool = True,
      **kwargs,
  ) -> TensorType:
      if self.action_sampler_fn and self.action_distribution_fn is None:
          raise ValueError(
              "Cannot compute log-prob/likelihood w/o an "
              "`action_distribution_fn` and a provided "
              "`action_sampler_fn`!"
          )
  
      with torch.no_grad():
          input_dict = self._lazy_tensor_dict(
              {
                  SampleBatch.CUR_OBS: obs_batch,
                  SampleBatch.ACTIONS: actions,
              }
          )
          if prev_action_batch is not None:
              input_dict[SampleBatch.PREV_ACTIONS] = prev_action_batch
          if prev_reward_batch is not None:
              input_dict[SampleBatch.PREV_REWARDS] = prev_reward_batch
          seq_lens = torch.ones(len(obs_batch), dtype=torch.int32)
          state_batches = [
              convert_to_torch_tensor(s, self.device)
              for s in (state_batches or [])
          ]
  
          # Exploration hook before each forward pass.
          self.exploration.before_compute_actions(explore=False)
  
          # Action dist class and inputs are generated via custom function.
          if self.action_distribution_fn:
              # Try new action_distribution_fn signature, supporting
              # state_batches and seq_lens.
              try:
                  (
                      dist_inputs,
                      dist_class,
                      state_out,
                  ) = self.action_distribution_fn(
                      self,
                      self.model,
                      input_dict=input_dict,
                      state_batches=state_batches,
                      seq_lens=seq_lens,
                      explore=False,
                      is_training=False,
                  )
              # Trying the old way (to stay backward compatible).
              # TODO: Remove in future.
              except TypeError as e:
                  if (
                      "positional argument" in e.args[0]
                      or "unexpected keyword argument" in e.args[0]
                  ):
                      (
                          dist_inputs,
                          dist_class,
                          _,
                      ) = self.action_distribution_fn(
                          policy=self,
                          model=self.model,
                          obs_batch=input_dict[SampleBatch.CUR_OBS],
                          explore=False,
                          is_training=False,
                      )
                  else:
                      raise e
  
          # Default action-dist inputs calculation.
          else:
              dist_class = self.dist_class
              dist_inputs, _ = self.model(
                  input_dict, state_batches, seq_lens
              )
  
          action_dist = dist_class(dist_inputs, self.model)
  
          # Normalize actions if necessary.
          actions = input_dict[SampleBatch.ACTIONS]
          if (
              not actions_normalized
              and self.config["normalize_actions"]
          ):
              actions = normalize_action(
                  actions, self.action_space_struct
              )
  
          log_likelihoods = action_dist.logp(actions)
  
          return log_likelihoods
  
imports: import copy
  import functools
  import logging
  import math
  import os
  import threading
  import time
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
  import gymnasium
  import numpy
  import tree
  import ray
  from ray.rllib.models.catalog import ModelCatalog
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.torch.torch_action_dist import TorchDistributionWrapper
  from ray.rllib.models.torch.torch_modelv2 import TorchModelV2
  from ray.rllib.policy.policy import Policy, PolicyState
  from ray.rllib.policy.rnn_sequencing import pad_batch_to_sequences_of_same_size
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils import NullContextManager, force_list
  from ray.rllib.utils.annotations import DeveloperAPI, override
  from ray.rllib.utils.error import ERR_MSG_TORCH_POLICY_CANNOT_SAVE_MODEL
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.metrics import DIFF_NUM_GRAD_UPDATES_VS_SAMPLER_POLICY, NUM_AGENT_STEPS_TRAINED, NUM_GRAD_UPDATES_LIFETIME
  from ray.rllib.utils.metrics.learner_info import LEARNER_STATS_KEY
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.spaces.space_utils import normalize_action
  from ray.rllib.utils.threading import with_lock
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
  from ray.rllib.utils.typing import AlgorithmConfigDict, GradInfoDict, ModelGradients, ModelWeights, TensorStructType, TensorType
label_desc: Use image node_id 4 for calling the TorchPolicy obj's underlying member method code with example usage: obj.compute_log_likelihoods(actions, obs_batch, state_batches, prev_action_batch, prev_reward_batch, actions_normalized) and returns: log_likelihoods