class_docstr: This class serves as a micro library for forward function substitution of
  T5 models under pipeline setting.
class_docstr_tok: ["This","class","serves","as","a","micro","library","for","forward","function","substitution","of","T5","models","under","pipeline","setting","."]
docstr: This function is modified on the basis of transformers.models.t5.modeling_gpt2.T5EncoderModel.forward.
  Please refer to original code of transformers for more details.
  ```
docstr_tok: ["This","function","is","modified","on","the","basis","of","transformers.models.t5.modeling_gpt2.T5EncoderModel.forward",".","Please","refer","to","original","code","of","transformers","for","more","details",".","``","`"]
code: def t5_encoder_model_forward(
      self: T5EncoderModel,
      input_ids: Optional[torch.LongTensor] = None,
      attention_mask: Optional[torch.FloatTensor] = None,
      head_mask: Optional[torch.FloatTensor] = None,
      inputs_embeds: Optional[torch.FloatTensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
      stage_manager: Optional[PipelineStageManager] = None,
      hidden_states: Optional[torch.FloatTensor] = None,
      position_bias: Optional[torch.Tensor] = None,
      encoder_decoder_position_bias: Optional[torch.Tensor] = None,
      backward_tensor_keys: Optional[List[str]] = None,
      stage_index: Optional[List[int]] = None,
      decoder_starting_stage: Optional[int] = None,
  ) -> Union[Tuple[torch.FloatTensor], BaseModelOutput]:
      r"""
      This function is modified on the basis of transformers.models.t5.modeling_gpt2.T5EncoderModel.forward.
      Please refer to original code of transformers for more details.
      ```"""
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      outputs = T5PipelineForwards.t5_stack_forward(
          self.encoder,
          input_ids=input_ids,
          attention_mask=attention_mask,
          inputs_embeds=inputs_embeds,
          head_mask=head_mask,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
          stage_manager=stage_manager,
          hidden_states=hidden_states,
          position_bias=position_bias,
          encoder_decoder_position_bias=encoder_decoder_position_bias,
          stage_index=stage_index,
          decoder_starting_stage=decoder_starting_stage,
      )
  
      return outputs
  
file_path: colossalai/colossalai/shardformer/modeling/t5.py
imports: import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from torch.nn import CrossEntropyLoss
  from torch.utils.checkpoint import checkpoint
  from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPastAndCrossAttentions, Seq2SeqLMOutput, Seq2SeqModelOutput
  from transformers.models.t5.modeling_t5 import T5EncoderModel, T5ForConditionalGeneration, T5Model, T5Stack
  from transformers.utils import logging
  from colossalai.pipeline.stage_manager import PipelineStageManager
label_desc: Use image node_id 4 for calling the T5PipelineForwards obj's underlying member method code with example usage: obj.t5_encoder_model_forward(input_ids, attention_mask, head_mask, inputs_embeds, output_attentions, output_hidden_states, return_dict, stage_manager, hidden_states, position_bias, encoder_decoder_position_bias, backward_tensor_keys, stage_index, decoder_starting_stage) and returns: outputs