class_docstr: The base class for distribution over a random variable.
  
  Examples:
  
  .. testcode::
  
      import torch
      from ray.rllib.core.models.configs import MLPHeadConfig
      from ray.rllib.models.torch.torch_distributions import TorchCategorical
  
      model = MLPHeadConfig(input_dims=[1]).build(framework="torch")
  
      # Create an action distribution from model logits
      action_logits = model(torch.Tensor([[1]]))
      action_dist = TorchCategorical.from_logits(action_logits)
      action = action_dist.sample()
  
      # Create another distribution from a dummy Tensor
      action_dist2 = TorchCategorical.from_logits(torch.Tensor([0]))
  
      # Compute some common metrics
      logp = action_dist.logp(action)
      kl = action_dist.kl(action_dist2)
      entropy = action_dist.entropy()
class_docstr_tok: ["The","base","class","for","distribution","over","a","random","variable",".","Examples",":","..","testcode",":",":","import","torch","from","ray.rllib.core.models.configs","import","MLPHeadConfig","from","ray.rllib.models.torch.torch_distributions","import","TorchCategorical","model","=","MLPHeadConfig","(","input_dims=","[","1","]",")",".build","(","framework=","''","torch","''",")","#","Create","an","action","distribution","from","model","logits","action_logits","=","model","(","torch.Tensor","(","[","[","1","]","]",")",")","action_dist","=","TorchCategorical.from_logits","(","action_logits",")","action","=","action_dist.sample","(",")","#","Create","another","distribution","from","a","dummy","Tensor","action_dist2","=","TorchCategorical.from_logits","(","torch.Tensor","(","[","0","]",")",")","#","Compute","some","common","metrics","logp","=","action_dist.logp","(","action",")","kl","=","action_dist.kl","(","action_dist2",")","entropy","=","action_dist.entropy","(",")"]
docstr: Returns a partial child of TorchMultiActionDistribution.
  
  This is useful if inputs needed to instantiate the Distribution from logits
  are available, but the logits are not.
docstr_tok: ["Returns","a","partial","child","of","TorchMultiActionDistribution",".","This","is","useful","if","inputs","needed","to","instantiate","the","Distribution","from","logits","are","available",",","but","the","logits","are","not","."]
code: def get_partial_dist_cls(
      parent_cls: "Distribution", **partial_kwargs
  ) -> "Distribution":
      """Returns a partial child of TorchMultiActionDistribution.
  
      This is useful if inputs needed to instantiate the Distribution from logits
      are available, but the logits are not.
      """
  
      class DistributionPartial(parent_cls):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
  
          @staticmethod
          def _merge_kwargs(**kwargs):
              """Checks if keys in kwargs don't clash with partial_kwargs."""
              overlap = set(kwargs) & set(partial_kwargs)
              if overlap:
                  raise ValueError(
                      f"Cannot override the following kwargs: {overlap}.\n"
                      f"This is because they were already set at the time this "
                      f"partial class was defined."
                  )
              merged_kwargs = {**partial_kwargs, **kwargs}
              return merged_kwargs
  
          @classmethod
          @override(parent_cls)
          def required_input_dim(
              cls, space: gym.Space, **kwargs
          ) -> int:
              merged_kwargs = cls._merge_kwargs(**kwargs)
              assert space == merged_kwargs["space"]
              return parent_cls.required_input_dim(**merged_kwargs)
  
          @classmethod
          @override(parent_cls)
          def from_logits(
              cls,
              logits: TensorType,
              **kwargs,
          ) -> "DistributionPartial":
              merged_kwargs = cls._merge_kwargs(**kwargs)
              distribution = parent_cls.from_logits(
                  logits, **merged_kwargs
              )
              # Replace the class of the returned distribution with this partial
              # This makes it so that we can use type() on this distribution and
              # get back the partial class.
              distribution.__class__ = cls
              return distribution
  
      # Substitute name of this partial class to match the original class.
      DistributionPartial.__name__ = f"{parent_cls}Partial"
  
      return DistributionPartial
  
file_path: ray/rllib/models/distributions.py
imports: from typing import Tuple
  import gymnasium
  import abc
  from ray.rllib.utils.annotations import ExperimentalAPI
  from ray.rllib.utils.typing import TensorType, Union
  from ray.rllib.utils.annotations import override
label_desc: Use image node_id 8 for calling the Distribution obj's underlying member method code with example usage: obj.get_partial_dist_cls(parent_cls) and returns: DistributionPartial, merged_kwargs, parent_cls, distribution