docstr: Forward pass with the ability to pass in token-embedded inputs.
docstr_tok: ["Forward","pass","with","the","ability","to","pass","in","token-embedded","inputs","."]
code: def forward(
      self, input, encoder_state, embedded_input=None, incr_state=None
  ):
      """
      Forward pass with the ability to pass in token-embedded inputs.
      """
  
      encoder_output, encoder_mask = encoder_state
  
      if input is not None:
          seq_len = input.size(1)
          positions = input.new(seq_len).long()
      else:
          seq_len = embedded_input.size(1)
          positions = embedded_input.new(seq_len).long()
      positions = torch.arange(seq_len, out=positions).unsqueeze(0)
  
      if incr_state is not None:
          # We're doing incremental decoding, so select only the most recent position
          if input is not None:
              input = input[:, -1:]
          if embedded_input is not None:
              embedded_input = embedded_input[:, -1:, :]
          if positions is not None:
              positions = positions[:, -1:]
      else:
          incr_state = {}
  
      if embedded_input is not None:
          tensor = embedded_input  # No need to copy because we only reassign below
      else:
          tensor = self.embeddings(input)
      if self.embeddings_scale:
          tensor = tensor * np.sqrt(self.dim)
      if self.variant == "xlm":
          tensor = self.norm_embeddings(tensor)
      if positions.max().item() > self.n_positions:
          warn_once(
              "You are inputting a sequence of {x} length, but only have "
              "--n-positions {y}. Set --truncate or increase --n-positions".format(
                  x=positions.max().item(), y=self.n_positions
              )
          )
      tensor = tensor + self.position_embeddings(positions).expand_as(
          tensor
      )
  
      if self.variant == "bart":
          tensor = self.norm_embeddings(tensor)
  
      tensor = self.dropout(tensor)  # --dropout
  
      new_incr_state = {}
      if getattr(self.layers, "is_model_parallel", False):
          tensor, new_incr_state = self._apply_model_parallel(
              tensor,
              encoder_output,
              encoder_mask,
              incr_state=incr_state,
          )
      else:
          for idx, layer in enumerate(self.layers):
              tensor, new_incr_state[idx] = layer(
                  x=tensor,
                  encoder_output=encoder_output,
                  encoder_mask=encoder_mask,
                  incr_state=incr_state.get(idx),
              )
  
      if self.variant == "prelayernorm":
          tensor = self.norm_embeddings(tensor)
  
      return tensor, new_incr_state
  
imports: from parlai.core.params import ParlaiParser
  import random
  from typing import List, Optional
  import numpy
  import torch
  from torch import nn
  from parlai.agents.transformer.modules import TransformerDecoder, TransformerGeneratorModel
  from parlai.core.agents import Agent
  from parlai.core.message import Message
  from parlai.core.opt import Opt
  from parlai.core.torch_classifier_agent import ConfusionMatrixMetric, WeightedF1Metric
  from parlai.utils.misc import warn_once
label_desc: Use image node_id 1 for calling the TransformerDecoderWithEmbeds obj's underlying member method code with example usage: obj.forward(input, encoder_state, embedded_input, incr_state) and returns: tensor,  new_incr_state