class_docstr: Torchscriptable version of `BertEncoder` from Huggingface transformers v2.3.0
  https://github.com/huggingface/transformers/blob/v2.3.0/transformers/modeling_bert.py # noqa
  
  Modifies the `forward` function as well as uses scriptable `BertLayerJit`
  
  Changes to `forward` function::
      Typed inputs and modifies the output to be of Tuple[Tensor] type in scripting
      mode. Due to different possible types when `output_hidden_states` or
      `output_attentions` are enable, we do not support these in scripting mode
class_docstr_tok: ["Torchscriptable","version","of","`","BertEncoder","`","from","Huggingface","transformers","v2.3.0","https",":","\/\/github.com\/huggingface\/transformers\/blob\/v2.3.0\/transformers\/modeling_bert.py","#","noqa","Modifies","the","`","forward","`","function","as","well","as","uses","scriptable","`","BertLayerJit","`","Changes","to","`","forward","`","function",":",":","Typed","inputs","and","modifies","the","output","to","be","of","Tuple","[","Tensor","]","type","in","scripting","mode",".","Due","to","different","possible","types","when","`","output_hidden_states","`","or","`","output_attentions","`","are","enable",",","we","do","not","support","these","in","scripting","mode"]
code: def forward(
      self,
      hidden_states: Tensor,
      attention_mask: Optional[Tensor],
      encoder_hidden_states: Optional[Tensor] = None,
      encoder_attention_mask: Optional[Tensor] = None,
      output_attentions: bool = False,
      output_hidden_states: bool = False,
      return_dict: bool = False,
      head_mask: Optional[Tensor] = None,
  ) -> Tuple[Tensor]:
      all_hidden_states = ()
      all_attentions = ()
      for i, layer_module in enumerate(self.layer):
          if not torch.jit.is_scripting() and output_hidden_states:
              all_hidden_states = all_hidden_states + (hidden_states,)
  
          layer_outputs = layer_module(
              hidden_states,
              attention_mask,
              None,
              encoder_hidden_states,
              encoder_attention_mask,
          )
          hidden_states = layer_outputs[0]
  
          if not torch.jit.is_scripting() and output_attentions:
              all_attentions = all_attentions + (layer_outputs[1],)
  
      # Add last layer
      if not torch.jit.is_scripting() and output_hidden_states:
          all_hidden_states = all_hidden_states + (hidden_states,)
  
      outputs = (hidden_states,)
      if not torch.jit.is_scripting():
          if output_hidden_states:
              outputs = outputs + (all_hidden_states,)
          if output_attentions:
              outputs = outputs + (all_attentions,)
      return outputs
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
  from mmf.utils.patch import restore_saved_modules, safecopy_modules
  from torch import nn, Tensor
label_desc: Use image node_id 2 for calling the BertEncoderJit obj's underlying member method code with example usage: obj.forward(hidden_states, attention_mask, encoder_hidden_states, encoder_attention_mask, output_attentions, output_hidden_states, return_dict, head_mask) and returns: outputs