class_docstr: Combo FiD Model.
  
  This model receives a new input that indicates which batch items require
  retrieval/FiD encoding, and which can be used in a standard encoder/decoder pass.
class_docstr_tok: ["Combo","FiD","Model",".","This","model","receives","a","new","input","that","indicates","which","batch","items","require","retrieval\/FiD","encoding",",","and","which","can","be","used","in","a","standard","encoder\/decoder","pass","."]
docstr: Override Standard FiD.encoder to account for skip_retrieval inputs.
  
  With `skip_retrieval` inputs, we forward directly through the `seq2seq_encoder`
  
  Otherwise, we call super().encoder to retrieve and concatenate outputs.
  
  :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
  :param skip_retrieval_vec:
      1D [bsz] indicator for whether to skip retrieval.
  
  :return (encoder_out, encoder_mask, input_turns_cnt, top_docs, top_doc_scores):
      encoder_out: *concatenated* (or not) 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: ["Override","Standard","FiD.encoder","to","account","for","skip_retrieval","inputs",".","With","`","skip_retrieval","`","inputs",",","we","forward","directly","through","the","`","seq2seq_encoder","`","Otherwise",",","we","call","super","(",")",".encoder","to","retrieve","and","concatenate","outputs",".",":","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",":","param","skip_retrieval_vec",":","1D","[","bsz","]","indicator","for","whether","to","skip","retrieval",".",":","return","(","encoder_out",",","encoder_mask",",","input_turns_cnt",",","top_docs",",","top_doc_scores",")",":","encoder_out",":","*","concatenated","*","(","or","not",")","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,
      skip_retrieval_vec: torch.BoolTensor,
      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],
  ]:
      """
      Override Standard FiD.encoder to account for skip_retrieval inputs.
  
      With `skip_retrieval` inputs, we forward directly through the `seq2seq_encoder`
  
      Otherwise, we call super().encoder to retrieve and concatenate outputs.
  
      :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
      :param skip_retrieval_vec:
          1D [bsz] indicator for whether to skip retrieval.
  
      :return (encoder_out, encoder_mask, input_turns_cnt, top_docs, top_doc_scores):
          encoder_out: *concatenated* (or not) 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.
      """
      # If we have a full batch of retrieve (or not), can use simple logic here.
      if torch.all(skip_retrieval_vec):
          new_out, new_mask = self.seq2seq_encoder(
              input, positions, segments
          )
          return new_out, new_mask, None, None, None
      elif torch.all(~skip_retrieval_vec):
          output = super().encoder(
              input,
              input_lengths,
              query_vec,
              input_turns_cnt,
              positions,
              segments,
          )
          self.top_docs = output[-2]
          return output
  
      assert all(
          t is None for t in [input_turns_cnt, positions, segments]
      )
      # Encode with `super()` call for non-skip-retrieval inputs
      (
          enc_out_retrieval,
          mask_retrieval,
          input_turns_cnt,
          top_docs,
          top_doc_scores,
      ) = super(ComboFidModel, self).encoder(
          input[~skip_retrieval_vec],
          input_lengths[~skip_retrieval_vec],
          query_vec[~skip_retrieval_vec],
          input_turns_cnt,
          positions,
          segments,
      )
      # Encode with seq2seq_encoder for skip-retrieval inputs
      (
          enc_out_skip_retrieval,
          mask_skip_retrieval,
      ) = self.seq2seq_encoder(input[skip_retrieval_vec])
  
      (
          new_out,
          new_mask,
          new_top_docs,
          new_top_doc_scores,
      ) = interleave_fid_combo_outputs(
          enc_out_retrieval,
          enc_out_skip_retrieval,
          mask_retrieval,
          mask_skip_retrieval,
          skip_retrieval_vec,
          top_docs,
          top_doc_scores,
      )
      self.top_docs = new_top_docs
  
      return (
          new_out,
          new_mask,
          input_turns_cnt,
          new_top_docs,
          new_top_doc_scores,
      )
  
imports: import torch
  from typing import List, Tuple, Optional, Dict, Any
  from parlai.agents.fid.fid import FidModel
  from parlai.agents.rag.args import RetrieverType
  from parlai.agents.rag.retrievers import Document, BLANK_DOC, SearchQuerySearchEngineRetriever, RagRetriever, retriever_factory
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
  import parlai.utils.logging
label_desc: Use image node_id 5 for calling the ComboFidModel obj's underlying member method code with example usage: obj.encoder(input, input_lengths, query_vec, input_turns_cnt, skip_retrieval_vec, positions, segments) and returns: new_out,  new_mask,  input_turns_cnt,  new_top_docs,  new_top_doc_scores, new_out,  new_mask,  None,  None,  None, output