class_docstr: Helper class to simplify implementing RNN models with TorchModelV2.
  
  Instead of implementing forward(), you can implement forward_rnn() which
  takes batches with the time dimension added already.
  
  Here is an example implementation for a subclass
  ``MyRNNClass(RecurrentNetwork, nn.Module)``::
  
      def __init__(self, obs_space, num_outputs):
          nn.Module.__init__(self)
          super().__init__(obs_space, action_space, num_outputs,
                           model_config, name)
          self.obs_size = _get_size(obs_space)
          self.rnn_hidden_dim = model_config["lstm_cell_size"]
          self.fc1 = nn.Linear(self.obs_size, self.rnn_hidden_dim)
          self.rnn = nn.GRUCell(self.rnn_hidden_dim, self.rnn_hidden_dim)
          self.fc2 = nn.Linear(self.rnn_hidden_dim, num_outputs)
  
          self.value_branch = nn.Linear(self.rnn_hidden_dim, 1)
          self._cur_value = None
  
      @override(ModelV2)
      def get_initial_state(self):
          # Place hidden states on same device as model.
          h = [self.fc1.weight.new(
              1, self.rnn_hidden_dim).zero_().squeeze(0)]
          return h
  
      @override(ModelV2)
      def value_function(self):
          assert self._cur_value is not None, "must call forward() first"
          return self._cur_value
  
      @override(RecurrentNetwork)
      def forward_rnn(self, input_dict, state, seq_lens):
          x = nn.functional.relu(self.fc1(input_dict["obs_flat"].float()))
          h_in = state[0].reshape(-1, self.rnn_hidden_dim)
          h = self.rnn(x, h_in)
          q = self.fc2(h)
          self._cur_value = self.value_branch(h).squeeze(1)
          return q, [h]
docstr: Adds time dimension to batch before sending inputs to forward_rnn().
  
  You should implement forward_rnn() in your subclass.
docstr_tok: ["Adds","time","dimension","to","batch","before","sending","inputs","to","forward_rnn","(",")",".","You","should","implement","forward_rnn","(",")","in","your","subclass","."]
code: def forward(
      self,
      input_dict: Dict[str, TensorType],
      state: List[TensorType],
      seq_lens: TensorType,
  ) -> Tuple[TensorType, List[TensorType]]:
      """Adds time dimension to batch before sending inputs to forward_rnn().
  
      You should implement forward_rnn() in your subclass."""
      # Creating a __init__ function that acts as a passthrough and adding the warning
      # there led to errors probably due to the multiple inheritance. We encountered
      # the same error if we add the Deprecated decorator. We therefore add the
      # deprecation warning here.
      if log_once("recurrent_network_tf"):
          deprecation_warning(
              old="ray.rllib.models.torch.recurrent_net.RecurrentNetwork"
          )
      flat_inputs = input_dict["obs_flat"].float()
      # Note that max_seq_len != input_dict.max_seq_len != seq_lens.max()
      # as input_dict may have extra zero-padding beyond seq_lens.max().
      # Use add_time_dimension to handle this
      self.time_major = self.model_config.get("_time_major", False)
      inputs = add_time_dimension(
          flat_inputs,
          seq_lens=seq_lens,
          framework="torch",
          time_major=self.time_major,
      )
      output, new_state = self.forward_rnn(inputs, state, seq_lens)
      output = torch.reshape(output, [-1, self.num_outputs])
      return output, new_state
  
imports: import numpy
  import gymnasium
  from gymnasium.spaces import Discrete, MultiDiscrete
  import tree
  from typing import Dict, List, Union, Tuple
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.torch.misc import SlimFC
  from ray.rllib.models.torch.torch_modelv2 import TorchModelV2
  from ray.rllib.policy.rnn_sequencing import add_time_dimension
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.view_requirement import ViewRequirement
  from ray.rllib.utils.annotations import override, DeveloperAPI
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space
  from ray.rllib.utils.torch_utils import flatten_inputs_to_1d_tensor, one_hot
  from ray.rllib.utils.typing import ModelConfigDict, TensorType
  from ray.rllib.utils.deprecation import deprecation_warning
  from ray.util.debug import log_once
label_desc: Use image node_id 1 for calling the RecurrentNetwork obj's underlying member method code with example usage: obj.forward(input_dict, state, seq_lens) and returns: output,  new_state