class_docstr: Combo model.
  
  This model can handle contexts with and without retrieved documents.
class_docstr_tok: ["Combo","model",".","This","model","can","handle","contexts","with","and","without","retrieved","documents","."]
docstr: Copy most of the ComboFidModel.forward here, but include the target_lengths for
  the encoder.
  
  Note, however, that we don't use it.
docstr_tok: ["Copy","most","of","the","ComboFidModel.forward","here",",","but","include","the","target_lengths","for","the","encoder",".","Note",",","however",",","that","we","do","n't","use","it","."]
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,
      target_lengths: 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],
  ]:
      """
      Copy most of the ComboFidModel.forward here, but include the target_lengths for
      the encoder.
  
      Note, however, that we don't use it.
      """
      # 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.unsqueeze(-1),
              new_mask,
              None,
              None,
              None,
          )  # need to unsqueeze to handle in decoder
      elif torch.all(~skip_retrieval_vec):
          output = super().encoder(
              input,
              input_lengths,
              query_vec,
              input_turns_cnt,
              None,
              positions,
              segments,
          )
          self.top_docs = output[-2]  # type: ignore
          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,
          _,
          top_docs,
          top_doc_scores,
      ) = super().encoder(
          input[~skip_retrieval_vec],  # type: ignore
          input_lengths[~skip_retrieval_vec],  # type: ignore
          query_vec[~skip_retrieval_vec],  # type: ignore
          input_turns_cnt,
          None,  # don't pass target lengths when combining
          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.unsqueeze(-1),
          mask_retrieval,
          mask_skip_retrieval,
          skip_retrieval_vec,
          top_docs,  # type: ignore
          top_doc_scores,  # type: ignore
          right_padded=False,
      )
      self.top_docs = new_top_docs
      return (
          new_out,
          new_mask,
          input_turns_cnt,
          new_top_docs,
          new_top_doc_scores,
      )
  
imports: from typing import Optional, Type, Tuple, List, Dict, Any
  import torch
  import torch.nn
  from parlai.agents.fid.fid import FidModel, concat_enc_outs
  from parlai.agents.hugging_face.gpt2 import GPT2Decoder, Gpt2Agent
  from parlai.agents.rag.args import RetrieverType
  from parlai.agents.rag.modules import RagModel
  from parlai.agents.rag.retrievers import Document, BLANK_DOC, SearchQuerySearchEngineRetriever, retriever_factory, RagRetriever
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
  import parlai.utils.logging
  from projects.seeker.agents.seeker_modules import ComboFidSearchQuerySearchEngineRetriever
  from projects.seeker.agents.seeker_modules import combo_fid_retriever_factory, interleave_fid_combo_outputs, ComboFidModel
label_desc: Use image node_id 3 for calling the ComboGPT2Model obj's underlying member method code with example usage: obj.encoder(input, input_lengths, query_vec, input_turns_cnt, skip_retrieval_vec, target_lengths, 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