class_docstr: Transformer encoder module.
  
  For documentation on parameters that are take directly from opt,
  see parlai/agents/transformer/transformer.py
  
  :param opt: ParlAI-parsed options.
  :param vocabulary_size: Count of tokens/words in the dictionary.
  :param embedding: an embedding matrix for the bottom layer of the transformer.
      If none, one is created for this encoder.
  :param int padding_idx: Reserved padding index in the embeddings matrix.
  :param str reduction_type: Type of reduction at the end of the encoder.
  :param int n_positions: Size of the position embeddings matrix.
  :param int n_segments: Number of segments/lang/sentence embeddings.
  :param bool embeddings_scale: Scale embeddings relative to their dimensionality.
      Found useful in fairseq.
class_docstr_tok: ["Transformer","encoder","module",".","For","documentation","on","parameters","that","are","take","directly","from","opt",",","see","parlai\/agents\/transformer\/transformer.py",":","param","opt",":","ParlAI-parsed","options",".",":","param","vocabulary_size",":","Count","of","tokens\/words","in","the","dictionary",".",":","param","embedding",":","an","embedding","matrix","for","the","bottom","layer","of","the","transformer",".","If","none",",","one","is","created","for","this","encoder",".",":","param","int","padding_idx",":","Reserved","padding","index","in","the","embeddings","matrix",".",":","param","str","reduction_type",":","Type","of","reduction","at","the","end","of","the","encoder",".",":","param","int","n_positions",":","Size","of","the","position","embeddings","matrix",".",":","param","int","n_segments",":","Number","of","segments\/lang\/sentence","embeddings",".",":","param","bool","embeddings_scale",":","Scale","embeddings","relative","to","their","dimensionality",".","Found","useful","in","fairseq","."]
docstr: Reduce transformer output at end of forward pass.
  
  :param tensor:
      encoded input
  :param mask:
      mask for encoded input
  
  :return (tensor, mask):
      returns the reduced tensor, and mask if appropriate
docstr_tok: ["Reduce","transformer","output","at","end","of","forward","pass",".",":","param","tensor",":","encoded","input",":","param","mask",":","mask","for","encoded","input",":","return","(","tensor",",","mask",")",":","returns","the","reduced","tensor",",","and","mask","if","appropriate"]
code: def reduce_output(
      self, tensor: torch.Tensor, mask: torch.BoolTensor
  ) -> Tuple[torch.Tensor, Optional[torch.BoolTensor]]:
      """
      Reduce transformer output at end of forward pass.
  
      :param tensor:
          encoded input
      :param mask:
          mask for encoded input
  
      :return (tensor, mask):
          returns the reduced tensor, and mask if appropriate
      """
      tensor *= self.output_scaling
      if self.reduction_type == "first":
          return tensor[:, 0, :], None
      elif self.reduction_type == "max":
          return tensor.max(dim=1)[0], None
      elif self.reduction_type == "mean":
          divisor = (
              mask.float()
              .sum(dim=1)
              .unsqueeze(-1)
              .clamp(min=1)
              .type_as(tensor)
          )
          output = tensor.sum(dim=1) / divisor
          return output, None
      elif self.reduction_type is None or "none" in self.reduction_type:
          return tensor, mask
      else:
          raise ValueError(
              "Can't handle --reduction-type {}".format(
                  self.reduction_type
              )
          )
  
imports: from __future__ import annotations
  from typing import Tuple, Optional, Union
  import numpy
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import create_position_codes, get_n_positions_from_options, LAYER_NORM_EPS, MultiHeadAttention, TransformerFFN
  from parlai.agents.transformer.modules.modular import swappable
  from parlai.core.opt import Opt
  from parlai.core.params import default
  from parlai.utils.misc import warn_once
  from parlai.utils.torch import PipelineHelper
  from parlai.utils.fsdp import fsdp_wrap
  from parlai.nn.checkpoint import checkpoint_wrapper
label_desc: Use image node_id 5 for calling the TransformerEncoder obj's underlying member method code with example usage: obj.reduce_output(tensor, mask) and returns: tensor,  None, tensor,  None, output,  None, tensor,  mask