class_docstr: Base class for RLlib's PyTorch models.
  
  This class defines the interface for RLlib's PyTorch models and checks
  whether inputs and outputs of forward are checked with `check_input_specs()` and
  `check_output_specs()` respectively.
  
  Example usage for a single Flattening layer:
  
  .. testcode::
  
      from ray.rllib.core.models.configs import ModelConfig
      from ray.rllib.core.models.torch.base import TorchModel
      import torch
  
      class FlattenModelConfig(ModelConfig):
          def build(self, framework: str):
              assert framework == "torch"
              return TorchFlattenModel(self)
  
      class TorchFlattenModel(TorchModel):
          def __init__(self, config):
              TorchModel.__init__(self, config)
              self.flatten_layer = torch.nn.Flatten()
  
          def _forward(self, inputs, **kwargs):
              return self.flatten_layer(inputs)
  
      model = FlattenModelConfig().build("torch")
      inputs = torch.Tensor([[[1, 2]]])
      print(model(inputs))
  
  .. testoutput::
  
      tensor([[1., 2.]])
class_docstr_tok: ["Base","class","for","RLlib","'s","PyTorch","models",".","This","class","defines","the","interface","for","RLlib","'s","PyTorch","models","and","checks","whether","inputs","and","outputs","of","forward","are","checked","with","`","check_input_specs","(",")","`","and","`","check_output_specs","(",")","`","respectively",".","Example","usage","for","a","single","Flattening","layer",":","..","testcode",":",":","from","ray.rllib.core.models.configs","import","ModelConfig","from","ray.rllib.core.models.torch.base","import","TorchModel","import","torch","class","FlattenModelConfig","(","ModelConfig",")",":","def","build","(","self",",","framework",":","str",")",":","assert","framework","==","``","torch","''","return","TorchFlattenModel","(","self",")","class","TorchFlattenModel","(","TorchModel",")",":","def","__init__","(","self",",","config",")",":","TorchModel.__init__","(","self",",","config",")","self.flatten_layer","=","torch.nn.Flatten","(",")","def","_forward","(","self",",","inputs",",","*","*","kwargs",")",":","return","self.flatten_layer","(","inputs",")","model","=","FlattenModelConfig","(",")",".build","(","``","torch","''",")","inputs","=","torch.Tensor","(","[","[","[","1",",","2","]","]","]",")","print","(","model","(","inputs",")",")","..","testoutput",":",":","tensor","(","[","[","1.",",","2",".","]","]",")"]
docstr: Returns the output of this model for the given input.
  
  This method only makes sure that we have a spec-checked _forward() method.
  
  Args:
      inputs: The input tensors.
      **kwargs: Forward compatibility kwargs.
  
  Returns:
      dict: The output tensors.
docstr_tok: ["Returns","the","output","of","this","model","for","the","given","input",".","This","method","only","makes","sure","that","we","have","a","spec-checked","_forward","(",")","method",".","Args",":","inputs",":","The","input","tensors",".","*","*","kwargs",":","Forward","compatibility","kwargs",".","Returns",":","dict",":","The","output","tensors","."]
code: def forward(
      self, inputs: Union[dict, TensorType], **kwargs
  ) -> Union[dict, TensorType]:
      """Returns the output of this model for the given input.
  
      This method only makes sure that we have a spec-checked _forward() method.
  
      Args:
          inputs: The input tensors.
          **kwargs: Forward compatibility kwargs.
  
      Returns:
          dict: The output tensors.
      """
  
      # When `always_check_shapes` is set, we always check input and output specs.
      # Note that we check the input specs twice because we need the following
      # check to always check the input specs.
      if self.config.always_check_shapes:
  
          @check_input_specs("input_specs", only_check_on_retry=False)
          @check_output_specs("output_specs")
          def checked_forward(self, input_data, **kwargs):
              return self._forward(input_data, **kwargs)
  
          return checked_forward(self, inputs, **kwargs)
  
      return self._forward(inputs, **kwargs)
  
file_path: ray/rllib/core/models/torch/base.py
imports: import abc
  import logging
  from typing import Tuple, Union
  import numpy
  from ray.rllib.core.models.base import Model
  from ray.rllib.core.models.configs import ModelConfig
  from ray.rllib.core.models.specs.checker import is_input_decorated, is_output_decorated, check_input_specs, check_output_specs
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.typing import TensorType
  from ray.util import log_once
label_desc: Use image node_id 2 for calling the TorchModel obj's underlying member method code with example usage: obj.forward(inputs) and returns: self, checked_forward, self