class_docstr: The FiD Model is a simpler version of the RAG Model.
  
  We override the encoder and decoder methods to join encoder outputs, and decode
  normally, respectively.
docstr: Concatenate all encoder outputs in model forward.
  
  :param input:
      2D [bsz, seqlen] input to the encoder
  :param input_lengths:
      1D [bsz] lengths of each input item
  :param query_vec:
      2D [bsz*n_turns, seqlen] input for the retriever
  :param input_turns_cnt:
      1D [bsz] number of dialogue turns for each input example
  
  :return (encoder_out, encoder_mask, input_turns_cnt, top_docs, top_doc_scores):
      encoder_out: *concatenated* encoded representations of context/document pairs
      encoder_mask: new mask for enc_out
      input_turns_cnt: pass along the input turns count for the decoder
      top_docs: List of top Documents for each batch example
      top_doc_scores: scores for each retrieved document.
docstr_tok: ["Concatenate","all","encoder","outputs","in","model","forward",".",":","param","input",":","2D","[","bsz",",","seqlen","]","input","to","the","encoder",":","param","input_lengths",":","1D","[","bsz","]","lengths","of","each","input","item",":","param","query_vec",":","2D","[","bsz","*","n_turns",",","seqlen","]","input","for","the","retriever",":","param","input_turns_cnt",":","1D","[","bsz","]","number","of","dialogue","turns","for","each","input","example",":","return","(","encoder_out",",","encoder_mask",",","input_turns_cnt",",","top_docs",",","top_doc_scores",")",":","encoder_out",":","*","concatenated","*","encoded","representations","of","context\/document","pairs","encoder_mask",":","new","mask","for","enc_out","input_turns_cnt",":","pass","along","the","input","turns","count","for","the","decoder","top_docs",":","List","of","top","Documents","for","each","batch","example","top_doc_scores",":","scores","for","each","retrieved","document","."]
code: def encoder(
      self,
      input: torch.LongTensor,
      input_lengths: torch.LongTensor,
      query_vec: torch.LongTensor,
      input_turns_cnt: torch.LongTensor,
      positions: Optional[torch.LongTensor] = None,
      segments: Optional[torch.LongTensor] = None,
  ) -> Tuple[
      torch.Tensor,
      torch.BoolTensor,
      Optional[torch.LongTensor],
      Optional[List[List[Document]]],
      Optional[torch.Tensor],
  ]:
      """
      Concatenate all encoder outputs in model forward.
  
      :param input:
          2D [bsz, seqlen] input to the encoder
      :param input_lengths:
          1D [bsz] lengths of each input item
      :param query_vec:
          2D [bsz*n_turns, seqlen] input for the retriever
      :param input_turns_cnt:
          1D [bsz] number of dialogue turns for each input example
  
      :return (encoder_out, encoder_mask, input_turns_cnt, top_docs, top_doc_scores):
          encoder_out: *concatenated* encoded representations of context/document pairs
          encoder_mask: new mask for enc_out
          input_turns_cnt: pass along the input turns count for the decoder
          top_docs: List of top Documents for each batch example
          top_doc_scores: scores for each retrieved document.
      """
      (
          enc_out,
          mask,
          input_turns_cnt,
          top_docs,
          top_doc_scores,
      ) = super().encoder(
          input,
          input_lengths,
          query_vec,
          input_turns_cnt,
          positions,
          segments,
      )  # type: ignore
  
      if input_turns_cnt is not None:
          # Input Turns is a tensor of dim [bsz]
          input = input.repeat_interleave(input_turns_cnt, dim=0)  # type: ignore
  
      new_out, new_mask = concat_enc_outs(
          input, enc_out, mask, self.embedding_size, self.pad_idx
      )
  
      return (
          new_out,
          new_mask,
          input_turns_cnt,
          top_docs,
          top_doc_scores,
      )
  
imports: from abc import abstractmethod
  from copy import deepcopy
  import torch
  import random
  from typing import Tuple, Union, Optional, List, Dict, Any
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
  from parlai.core.message import Message
  from parlai.agents.transformer.transformer import TransformerGeneratorModel
  from parlai.agents.rag.args import RetrieverType
  from parlai.agents.rag.modules import RagModel, Document, T5RagModel
  from parlai.agents.rag.rag import RagAgent
  from parlai.agents.rag.model_types import RagToken, get_forced_decoder_inputs, fix_incremental_state
  from parlai.utils.typing import TShared
  import parlai.utils.logging
  from parlai.tasks.wizard_of_internet import constants
label_desc: Use image node_id 4 for calling the FidModel obj's underlying member method code with example usage: obj.encoder(input, input_lengths, query_vec, input_turns_cnt, positions, segments) and returns: new_out,  new_mask,  input_turns_cnt,  top_docs,  top_doc_scores