class_docstr: A recurrent LSTM encoder.
  
  This encoder has...
  - Zero or one tokenizers.
  - One or more LSTM 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"
          )
          lstm_input_dims = config.tokenizer_config.output_dims
      else:
          self.tokenizer = None
          lstm_input_dims = config.input_dims
  
      # We only support 1D spaces right now.
      assert len(lstm_input_dims) == 1
      lstm_input_dim = lstm_input_dims[0]
  
      lstm_weights_initializer = get_initializer_fn(
          config.hidden_weights_initializer, framework="torch"
      )
      lstm_bias_initializer = get_initializer_fn(
          config.hidden_bias_initializer, framework="torch"
      )
  
      # Create the torch LSTM layer.
      self.lstm = nn.LSTM(
          lstm_input_dim,
          config.hidden_dim,
          config.num_layers,
          batch_first=config.batch_major,
          bias=config.use_bias,
      )
  
      # Initialize LSTM layer weigths, if necessary.
      if lstm_weights_initializer:
          lstm_weights_initializer(
              self.lstm.all_weights,
              **config.hidden_weights_initializer_config or {},
          )
      # Initialize LSTM layer bias, if necessary.
      if lstm_bias_initializer:
          lstm_bias_initializer(
              self.lstm.bias,
              **config.hidden_bias_initializer_config or {},
          )
  
      self._state_in_out_spec = {
          "h": TensorSpec(
              "b, l, d",
              d=self.config.hidden_dim,
              l=self.config.num_layers,
              framework="torch",
          ),
          "c": TensorSpec(
              "b, l, d",
              d=self.config.hidden_dim,
              l=self.config.num_layers,
              framework="torch",
          ),
      }
  
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 TorchLSTMEncoder object from inherited base classes: TorchModel, Encoder with example: obj = TorchLSTMEncoder(config)