class_docstr: A recurrent GRU encoder.
  
  This encoder has...
  - Zero or one tokenizers.
  - One or more GRU layers.
  - One linear output layer.
code: def __init__(self, config: RecurrentEncoderConfig) -> None:
      TorchModel.__init__(self, config)
  
      # Maybe create a tokenizer
      if config.tokenizer_config is not None:
          self.tokenizer = config.tokenizer_config.build(
              framework="torch"
          )
          gru_input_dims = config.tokenizer_config.output_dims
      else:
          self.tokenizer = None
          gru_input_dims = config.input_dims
  
      # We only support 1D spaces right now.
      assert len(gru_input_dims) == 1
      gru_input_dim = gru_input_dims[0]
  
      gru_weights_initializer = get_initializer_fn(
          config.hidden_weights_initializer, framework="torch"
      )
      gru_bias_initializer = get_initializer_fn(
          config.hidden_bias_initializer, framework="torch"
      )
  
      # Create the torch GRU layer.
      self.gru = nn.GRU(
          gru_input_dim,
          config.hidden_dim,
          config.num_layers,
          batch_first=config.batch_major,
          bias=config.use_bias,
      )
  
      # Initialize, GRU weights, if necessary.
      if gru_weights_initializer:
          gru_weights_initializer(
              self.gru.weight,
              **config.hidden_weights_initializer_config or {},
          )
      # Initialize GRU bias, if necessary.
      if gru_bias_initializer:
          gru_bias_initializer(
              self.gru.weight,
              **config.hidden_bias_initializer_config or {},
          )
  
imports: from typing import Optional
  import tree
  from ray.rllib.core.models.base import Encoder, ActorCriticEncoder, StatefulActorCriticEncoder, STATE_IN, STATE_OUT, ENCODER_OUT
  from ray.rllib.core.models.base import Model, tokenize
  from ray.rllib.core.models.configs import ActorCriticEncoderConfig, CNNEncoderConfig, MLPEncoderConfig, RecurrentEncoderConfig
  from ray.rllib.core.models.specs.specs_base import Spec
  from ray.rllib.core.models.specs.specs_base import TensorSpec
  from ray.rllib.core.models.specs.specs_dict import SpecDict
  from ray.rllib.core.models.torch.base import TorchModel
  from ray.rllib.core.models.torch.primitives import TorchMLP, TorchCNN
  from ray.rllib.models.utils import get_initializer_fn
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.framework import try_import_torch
label_desc: Use image node_id 1 to create a new TorchGRUEncoder object from inherited base classes: TorchModel, Encoder with example: obj = TorchGRUEncoder(config)