class_docstr: Decoder with general structure of Chen et al., The Best of Both Worlds:
  Combining Recent Advances in Neural Machine Translation, 2018.
  https://arxiv.org/abs/1804.09849
class_docstr_tok: ["Decoder","with","general","structure","of","Chen","et","al.",",","The","Best","of","Both","Worlds",":","Combining","Recent","Advances","in","Neural","Machine","Translation",",","2018.","https",":","\/\/arxiv.org\/abs\/1804.09849"]
docstr: Initial (hidden, cell) values for LSTM layers are zero.
  
  For encoder-decoder attention, key and value are computed once from
  the encoder outputs and stay the same throughout decoding.
docstr_tok: ["Initial","(","hidden",",","cell",")","values","for","LSTM","layers","are","zero",".","For","encoder-decoder","attention",",","key","and","value","are","computed","once","from","the","encoder","outputs","and","stay","the","same","throughout","decoding","."]
code: def _init_prev_states(self, encoder_out):
      """
      Initial (hidden, cell) values for LSTM layers are zero.
  
      For encoder-decoder attention, key and value are computed once from
      the encoder outputs and stay the same throughout decoding.
      """
      (
          encoder_x,
          src_tokens,
          encoder_padding_mask,
      ) = self._unpack_encoder_out(encoder_out)
      batch_size = torch.onnx.operators.shape_as_tensor(encoder_x)[1]
  
      if self.proj_encoder_layer is not None:
          encoder_x = self.proj_encoder_layer(encoder_x)
  
      states = []
      for _ in range(self.num_layers):
          hidden = self._init_hidden(encoder_out, batch_size).type_as(
              encoder_x
          )
          cell = torch.zeros([1, batch_size, self.lstm_units]).type_as(
              encoder_x
          )
          states.extend([hidden, cell])
  
      # (key, value) for encoder-decoder attention computed from encoder
      # output and remain the same throughout decoding
      key = self.attention.k_proj(encoder_x)
      value = self.attention.v_proj(encoder_x)
  
      # (key, value) kept in shape (bsz, num_heads, seq_len, head_dim)
      # to avoid repeated transpose operations
      seq_len, batch_size_int, _ = encoder_x.shape
      num_heads = self.attention.num_heads
      head_dim = self.attention.head_dim
      key = (
          key.view(seq_len, batch_size_int * num_heads, head_dim)
          .transpose(0, 1)
          .view(batch_size_int, num_heads, seq_len, head_dim)
      )
      value = (
          value.view(seq_len, batch_size_int * num_heads, head_dim)
          .transpose(0, 1)
          .view(batch_size_int, num_heads, seq_len, head_dim)
      )
      states.extend([key, value])
  
      return states
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from fairseq.models import FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture, transformer
  from fairseq.modules import MultiheadAttention
  from pytorch_translate import multilingual_model, transformer, vocab_reduction
  from pytorch_translate.utils import torch_find
label_desc: Use image node_id 12 for calling the HybridRNNDecoder obj's underlying member method code with example usage: obj._init_prev_states(encoder_out) and returns: states