class_docstr: RNN encoder using nn.LSTM for cuDNN support / ONNX exportability.
class_docstr_tok: ["RNN","encoder","using","nn.LSTM","for","cuDNN","support","\/","ONNX","exportability","."]
code: def forward(self, src_tokens, src_lengths):
      if self.left_pad:
          # convert left-padding to right-padding
          src_tokens = utils.convert_padding_direction(
              src_tokens, self.padding_idx, left_to_right=True
          )
  
      # If we're generating adversarial examples we need to keep track of
      # some internal variables
      self.tracker.reset()
  
      bsz, seqlen = pytorch_translate_utils.get_source_tokens_tensor(
          src_tokens
      ).size()
  
      # embed tokens
      x = self.embed_tokens(src_tokens)
      if self.encoder_context_embed:
          x = self.embed_tokens_context(x)
  
      # Apply feature level noising is specified
      if (
          self.embed_noising_mode
          and self.embed_noising_layer is not None
      ):
          x = self.embed_noising_layer(x)
      # Track token embeddings for generation white-box adversarial example
      self.tracker.track(
          x, "token_embeddings", retain_grad=self.track_gradients
      )
  
      x = F.dropout(x, p=self.dropout_in, training=self.training)
  
      # B x T x C -> T x B x C
      x = x.transpose(0, 1)
      embedded_words = x
  
      # Allows compatibility with Caffe2 inputs for tracing (int32)
      # as well as the current format of Fairseq-Py inputs (int64)
      if src_lengths.dtype is torch.int64:
          src_lengths = src_lengths.int()
  
      unpacked_output, final_hiddens, final_cells = self.bilstm(
          embeddings=x, lengths=src_lengths
      )
  
      return (
          unpacked_output,
          final_hiddens,
          final_cells,
          src_lengths,
          src_tokens,
          embedded_words,
      )
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.onnx.operators
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.modules import AdaptiveSoftmax
  from pytorch_translate import attention, rnn_cell, utils, vocab_reduction
  from pytorch_translate.common_layers import ContextEmbedding, DecoderWithOutputProjection, Embedding, Linear, RNNLayer, VariableTracker
  from pytorch_translate.data import data
  from pytorch_translate.multi_model import MultiDecoder, MultiEncoder
  from pytorch_translate.multilingual import MultilingualDecoder, MultilingualEncoder
  from pytorch_translate.ngram import NGramDecoder
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import maybe_cat, maybe_cuda, torch_find
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence, pad_packed_sequence
label_desc: Use image node_id 3 for calling the LSTMSequenceEncoder obj's underlying member method code with example usage: obj.forward(src_tokens, src_lengths) and returns: unpacked_output,  final_hiddens,  final_cells,  src_lengths,  src_tokens,  embedded_words