class_docstr: Recurrent decoder module.
  
  Can be used as a standalone language model or paired with an encoder.
docstr: Decode from input tokens.
  
  :param xs: (bsz x seqlen) LongTensor of input token indices
  :param encoder_output: output from RNNEncoder. Tuple containing
      (enc_out, enc_hidden, attn_mask) tuple.
  :param incremental_state: most recent hidden state to the decoder.
      If None, the hidden state of the encoder is used as initial state,
      and the full sequence is computed. If not None, computes only the
      next forward in the sequence.
  
  :returns: (output, hidden_state) pair from the RNN.
  
      - output is a bsz x time x latentdim matrix. If incremental_state is
          given, the time dimension will be 1. This value must be passed to
          the model's OutputLayer for a final softmax.
      - hidden_state depends on the choice of RNN
docstr_tok: ["Decode","from","input","tokens",".",":","param","xs",":","(","bsz","x","seqlen",")","LongTensor","of","input","token","indices",":","param","encoder_output",":","output","from","RNNEncoder",".","Tuple","containing","(","enc_out",",","enc_hidden",",","attn_mask",")","tuple",".",":","param","incremental_state",":","most","recent","hidden","state","to","the","decoder",".","If","None",",","the","hidden","state","of","the","encoder","is","used","as","initial","state",",","and","the","full","sequence","is","computed",".","If","not","None",",","computes","only","the","next","forward","in","the","sequence",".",":","returns",":","(","output",",","hidden_state",")","pair","from","the","RNN",".","-","output","is","a","bsz","x","time","x","latentdim","matrix",".","If","incremental_state","is","given",",","the","time","dimension","will","be","1",".","This","value","must","be","passed","to","the","model","'s","OutputLayer","for","a","final","softmax",".","-","hidden_state","depends","on","the","choice","of","RNN"]
code: def forward(self, xs, encoder_output, incremental_state=None):
      """
      Decode from input tokens.
  
      :param xs: (bsz x seqlen) LongTensor of input token indices
      :param encoder_output: output from RNNEncoder. Tuple containing
          (enc_out, enc_hidden, attn_mask) tuple.
      :param incremental_state: most recent hidden state to the decoder.
          If None, the hidden state of the encoder is used as initial state,
          and the full sequence is computed. If not None, computes only the
          next forward in the sequence.
  
      :returns: (output, hidden_state) pair from the RNN.
  
          - output is a bsz x time x latentdim matrix. If incremental_state is
              given, the time dimension will be 1. This value must be passed to
              the model's OutputLayer for a final softmax.
          - hidden_state depends on the choice of RNN
      """
      enc_state, enc_hidden, attn_mask = encoder_output
      # in case of multi gpu, we need to transpose back out the hidden state
      attn_params = (enc_state, attn_mask)
  
      if incremental_state is not None:
          # we're doing it piece by piece, so we have a more important hidden
          # seed, and we only need to compute for the final timestep
          hidden = _transpose_hidden_state(incremental_state)
          # only need the last timestep then
          xs = xs[:, -1:]
      else:
          # starting fresh, or generating from scratch. Use the encoder hidden
          # state as our start state
          hidden = _transpose_hidden_state(enc_hidden)
  
      if isinstance(hidden, tuple):
          hidden = tuple(x.contiguous() for x in hidden)
      else:
          hidden = hidden.contiguous()
  
      # sequence indices => sequence embeddings
      seqlen = xs.size(1)
      xes = self.dropout(self.lt(xs))
  
      if self.attn_time == "pre":
          # modify input vectors with attention
          # attention module requires we do this one step at a time
          new_xes = []
          for i in range(seqlen):
              nx, _ = self.attention(
                  xes[:, i : i + 1], hidden, attn_params
              )
              new_xes.append(nx)
          xes = torch.cat(new_xes, 1).to(xes.device)
  
      if self.attn_time != "post":
          # no attn, we can just trust the rnn to run through
          output, new_hidden = self.rnn(xes, hidden)
      else:
          # uh oh, post attn, we need run through one at a time, and do the
          # attention modifications
          new_hidden = hidden
          output = []
          for i in range(seqlen):
              o, new_hidden = self.rnn(
                  xes[:, i, :].unsqueeze(1), new_hidden
              )
              o, _ = self.attention(o, new_hidden, attn_params)
              output.append(o)
          output = torch.cat(output, dim=1).to(xes.device)
  
      return output, _transpose_hidden_state(new_hidden)
  
imports: import math
  import torch
  import torch.nn
  from torch.nn.parameter import Parameter
  from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence
  import torch.nn.functional
  from parlai.utils.torch import neginf
  from parlai.core.torch_generator_agent import TorchGeneratorModel
label_desc: Use image node_id 2 for calling the RNNDecoder obj's underlying member method code with example usage: obj.forward(xs, encoder_output, incremental_state) and returns: output,  _transpose_hidden_state