code: def get_rnn_init_state(
      combiner_outputs: Dict[str, torch.Tensor],
      sequence_reducer: SequenceReducer,
      num_layers: int,
  ) -> torch.Tensor:
      """Computes the hidden state that the RNN decoder should start with.
  
      Args:
          combiner_outputs: Dictionary of tensors from the outputs of the combiner and other output features.
          sequence_reducer: SequenceReducer to reduce rank-3 to rank-2.
          num_layers: Number of layers the decoder uses.
  
      Returns:
          Tensor of [num_layers, batch_size, hidden_size].
      """
      if ENCODER_OUTPUT_STATE not in combiner_outputs:
          # Use the combiner's hidden state.
          encoder_output_state = combiner_outputs[HIDDEN]
      else:
          # Use the encoder's output state.
          encoder_output_state = combiner_outputs[ENCODER_OUTPUT_STATE]
          if isinstance(encoder_output_state, tuple):
              if len(encoder_output_state) == 2:
                  # LSTM encoder. Use the hidden state and ignore the cell state.
                  encoder_output_state = encoder_output_state[0]
              elif len(encoder_output_state) == 4:
                  # Bi-directional LSTM encoder. Use the average of hidden states and ignore cell state.
                  encoder_output_state = torch.mean(
                      [encoder_output_state[0], encoder_output_state[2]]
                  )
              else:
                  raise ValueError(
                      f"Invalid sequence decoder inputs with keys: {combiner_outputs.keys()} with extracted encoder "
                      + f"state: {encoder_output_state.size()} that was invalid. Please double check the compatibility "
                      + "of your encoder and decoder."
                  )
  
      if len(encoder_output_state.size()) > 3:
          raise ValueError(
              "Init state for RNN decoders only works for 1d or 2d tensors (encoder_output)."
          )
  
      if len(encoder_output_state.size()) == 3:
          # Reduce to [batch_size, hidden_size].
          encoder_output_state = sequence_reducer(encoder_output_state)
  
      return repeat_2D_tensor(encoder_output_state, num_layers)
  
imports: from typing import Dict, Tuple
  import torch
  from ludwig.constants import ENCODER_OUTPUT_STATE, HIDDEN
  from ludwig.modules.reduction_modules import SequenceReducer
label_desc: Use image node_id 2 for calling a global function with example usage: get_rnn_init_state(combiner_outputs, sequence_reducer, num_layers) and returns: repeat_2D_tensor