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: Draw a sample from the distribution.
  
  Args:
      sample_shape: The shape of the sample to draw.
      return_logp: Whether to return the logp of the sampled values.
      **kwargs: Forward compatibility placeholder.
  
  Returns:
      The sampled values. If return_logp is True, returns a tuple of the
      sampled values and its logp.
docstr_tok: ["Draw","a","sample","from","the","distribution",".","Args",":","sample_shape",":","The","shape","of","the","sample","to","draw",".","return_logp",":","Whether","to","return","the","logp","of","the","sampled","values",".","*","*","kwargs",":","Forward","compatibility","placeholder",".","Returns",":","The","sampled","values",".","If","return_logp","is","True",",","returns","a","tuple","of","the","sampled","values","and","its","logp","."]
code: def sample(
      self,
      *,
      sample_shape: Tuple[int, ...] = None,
      return_logp: bool = False,
      **kwargs,
  ) -> Union[TensorType, Tuple[TensorType, TensorType]]:
      """Draw a sample from the distribution.
  
      Args:
          sample_shape: The shape of the sample to draw.
          return_logp: Whether to return the logp of the sampled values.
          **kwargs: Forward compatibility placeholder.
  
      Returns:
          The sampled values. If return_logp is True, returns a tuple of the
          sampled values and its logp.
      """
  
file_path: ray/python/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 1 for calling the Distribution obj's underlying member method code with example usage: obj.sample() without return types