class_docstr: Transformer encoder-decoder model.
      
class_docstr_tok: ["Transformer","encoder-decoder","model","."]
code: def __init__(
      self,
      config: ModelParallelConfig,
      encoder,
      decoder,
      # AttnMaskType enum mask type (e.g., padding, casual)
      encoder_attn_mask_type: AttnMaskType = None,
      decoder_attn_mask_type: AttnMaskType = None,
      hidden_steps: int = None,
      hiddens_module: MegatronHiddensModule = None,  # allows for hidden state transformations before the decoder
  ):
      super(MegatronTransformerEncoderDecoderModule, self).__init__(
          config=config
      )
  
      self.encoder = encoder
      self.decoder = decoder
      self.hidden_steps = hidden_steps
      if (
          isinstance(encoder, MegatronPerceiverEncoderModule)
          and hidden_steps is None
      ):
          raise ValueError(
              f"hidden_steps cannot be None for perceiver encoders. It is needed to compute the encoder-decoder cross attention mask."
          )
  
      self.hiddens_module = hiddens_module
      if self.hiddens_module is not None and not isinstance(
          self.hiddens_module, MegatronHiddensModule
      ):
          raise TypeError(
              f"hiddens_module must be of type MegatronHiddensModule, but got {type(self.hiddens_module)} instead."
          )
  
      # try to infer mask_type if not given
      if encoder_attn_mask_type is None:
          if encoder is None:
              encoder_attn_mask_type = None
          # Perceiver does not have a `.model` attribute, assume it always uses padding mask.
          elif isinstance(encoder, MegatronPerceiverEncoderModule):
              encoder_attn_mask_type = AttnMaskType.padding
          elif hasattr(encoder.model, "self_attn_mask_type"):
              encoder_attn_mask_type = encoder.model.self_attn_mask_type
          else:
              raise AttributeError(
                  "Could not find an attribute for encoder self_attn_mask_type, make sure it is set when instatiating the encoder or pass it to the constructor of this class."
              )
      if decoder_attn_mask_type is None:
          if decoder is None:
              decoder_attn_mask_type = None
          elif hasattr(decoder.model, "self_attn_mask_type"):
              decoder_attn_mask_type = decoder.model.self_attn_mask_type
          else:
              raise AttributeError(
                  "Could not find an attribute for decoder self_attn_mask_type, make sure it is set when instatiating the decoder or pass it to the constructor of this class."
              )
  
      self.encoder_attn_mask_type = encoder_attn_mask_type
      self.decoder_attn_mask_type = decoder_attn_mask_type
  
      self._encoder_key = "encoder"
      self._decoder_key = "decoder"
      self._hiddens_module = "hiddens_module"
  
file_path: NeMo/nemo/collections/nlp/modules/common/megatron/megatron_encoder_decoder.py
imports: from ast import Mod
  import torch
  from nemo.collections.nlp.modules.common.megatron.hiddens import MegatronHiddensModule
  from nemo.collections.nlp.modules.common.megatron.megatron_perceiver_encoders import MegatronPerceiverEncoderModule
  from nemo.collections.nlp.modules.common.megatron.module import MegatronModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults
label_desc: Use image node_id 1 to create a new MegatronTransformerEncoderDecoderModule object from inherited base classes: MegatronModule with example: obj = MegatronTransformerEncoderDecoderModule(config, encoder, decoder, encoder_attn_mask_type, decoder_attn_mask_type, hidden_steps, hiddens_module)