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: Creates a Distribution from logits.
  
  The caller does not need to have knowledge of the distribution class in order
  to create it and sample from it. The passed batched logits vectors might be
  split up and are passed to the distribution class' constructor as kwargs.
  
  Args:
      logits: The logits to create the distribution from.
      **kwargs: Forward compatibility placeholder.
  
  Returns:
      The created distribution.
  
  .. testcode::
  
      import numpy as np
      from ray.rllib.models.distributions import Distribution
  
      class Uniform(Distribution):
          def __init__(self, lower, upper):
              self.lower = lower
              self.upper = upper
  
          def sample(self):
              return self.lower + (self.upper - self.lower) * np.random.rand()
  
          def logp(self, x):
              ...
  
          def kl(self, other):
              ...
  
          def entropy(self):
              ...
  
          @staticmethod
          def required_input_dim(space):
              ...
  
          def rsample(self):
              ...
  
          @classmethod
          def from_logits(cls, logits, **kwargs):
              return Uniform(logits[:, 0], logits[:, 1])
  
      logits = np.array([[0.0, 1.0], [2.0, 3.0]])
      my_dist = Uniform.from_logits(logits)
      sample = my_dist.sample()
docstr_tok: ["Creates","a","Distribution","from","logits",".","The","caller","does","not","need","to","have","knowledge","of","the","distribution","class","in","order","to","create","it","and","sample","from","it",".","The","passed","batched","logits","vectors","might","be","split","up","and","are","passed","to","the","distribution","class","'","constructor","as","kwargs",".","Args",":","logits",":","The","logits","to","create","the","distribution","from",".","*","*","kwargs",":","Forward","compatibility","placeholder",".","Returns",":","The","created","distribution",".","..","testcode",":",":","import","numpy","as","np","from","ray.rllib.models.distributions","import","Distribution","class","Uniform","(","Distribution",")",":","def","__init__","(","self",",","lower",",","upper",")",":","self.lower","=","lower","self.upper","=","upper","def","sample","(","self",")",":","return","self.lower","+","(","self.upper","-","self.lower",")","*","np.random.rand","(",")","def","logp","(","self",",","x",")",":","...","def","kl","(","self",",","other",")",":","...","def","entropy","(","self",")",":","...","@","staticmethod","def","required_input_dim","(","space",")",":","...","def","rsample","(","self",")",":","...","@","classmethod","def","from_logits","(","cls",",","logits",",","*","*","kwargs",")",":","return","Uniform","(","logits","[",":",",","0","]",",","logits","[",":",",","1","]",")","logits","=","np.array","(","[","[","0.0",",","1.0","]",",","[","2.0",",","3.0","]","]",")","my_dist","=","Uniform.from_logits","(","logits",")","sample","=","my_dist.sample","(",")"]
code: def from_logits(cls, logits: TensorType, **kwargs) -> "Distribution":
      """Creates a Distribution from logits.
  
      The caller does not need to have knowledge of the distribution class in order
      to create it and sample from it. The passed batched logits vectors might be
      split up and are passed to the distribution class' constructor as kwargs.
  
      Args:
          logits: The logits to create the distribution from.
          **kwargs: Forward compatibility placeholder.
  
      Returns:
          The created distribution.
  
      .. testcode::
  
          import numpy as np
          from ray.rllib.models.distributions import Distribution
  
          class Uniform(Distribution):
              def __init__(self, lower, upper):
                  self.lower = lower
                  self.upper = upper
  
              def sample(self):
                  return self.lower + (self.upper - self.lower) * np.random.rand()
  
              def logp(self, x):
                  ...
  
              def kl(self, other):
                  ...
  
              def entropy(self):
                  ...
  
              @staticmethod
              def required_input_dim(space):
                  ...
  
              def rsample(self):
                  ...
  
              @classmethod
              def from_logits(cls, logits, **kwargs):
                  return Uniform(logits[:, 0], logits[:, 1])
  
          logits = np.array([[0.0, 1.0], [2.0, 3.0]])
          my_dist = Uniform.from_logits(logits)
          sample = my_dist.sample()
      """
      raise NotImplementedError
  
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 7 for calling the Distribution obj's underlying member method code with example usage: obj.from_logits(cls, logits) without return types