code: def concat_enc_outs(
      input: torch.LongTensor,
      enc_out: torch.Tensor,
      mask: torch.BoolTensor,
      embedding_size: int,
      padding_idx: int,
      right_padded: bool = True,
  ) -> Tuple[torch.Tensor, torch.BoolTensor]:
      """
      Concatenate Encoder Outputs.
  
      Does the whole "FiD" thing; each query/document pair is independently encoded in the
      Encoder, so we need to concatenate all the outputs prior to sending to the decoder.
  
      :param input:
          [bsz, seqlen] original input to the encoder
      :param enc_out:
          [bsz * n_docs, seqlen] output representations from the encoder
      :param mask:
          encoder mask
      :param embedding_size:
          emb/hidden size of the enc representations
      :param padding_idx:
          pad token index; used for mask purposes.
      :param right_padded:
          whether the input is right padded (true) or left padded (false)
  
      :return (new_out, new_mask):
          return the encoder output and encoder mask, appropriately concatenated.
      """
      bsz, n_docs = input.size(0), enc_out.size(0) // input.size(0)
      split_enc_out = enc_out.split([n_docs] * bsz, dim=0)
      split_mask = mask.split([n_docs] * bsz, dim=0)
  
      concat_outs: List[torch.Tensor] = []
      concat_lengths = []
      for i in range(bsz):
          mask_i = split_mask[i].view(-1)
          out_i = split_enc_out[i].reshape(-1, embedding_size)[mask_i]
          concat_outs.append(out_i)
          concat_lengths.append(out_i.size(0))
  
      new_out = enc_out.new(bsz, max(concat_lengths), embedding_size)
      new_mask: torch.BoolTensor = mask.new(bsz, max(concat_lengths))  # type: ignore
      new_out.fill_(padding_idx)
      new_mask.fill_(False)
  
      for i, (out_i, length_i) in enumerate(
          zip(concat_outs, concat_lengths)
      ):
          if right_padded:
              new_out[i, :length_i] = out_i
              new_mask[i, :length_i] = True
          else:
              new_out[i, new_out.size(1) - length_i :] = out_i
              new_mask[i, new_out.size(1) - length_i :] = True
  
      return new_out, new_mask
  
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 1 for calling a global function with example usage: concat_enc_outs(input, enc_out, mask, embedding_size, padding_idx, right_padded) and returns: new_out,  new_mask