class_docstr: Transformer decoder model.
      
code: def _calculate_dec_att_mask(self, dec_attn_mask, eod_positions):
      # # convert to Megatron mask
  
      # customized attention mask, starts with causal attention mask
      dec_attn_mask_3d = build_attention_mask_3d(
          source_mask=dec_attn_mask,
          target_mask=dec_attn_mask,
          attn_mask_type=AttnMaskType.causal,
      )
      # add the attention mask reset
      if eod_positions is not None:
          # to mask out the token ids [id, id,  eod, id, pad, eod, id, id]
          # so attention is not across eod, mask should be:
          # [false, true,  true, true,  true, true,  true,  true]
          # [false, false, true, true,  true, true,  true,  true]
          # [false, false, false,true,  true, true,  true,  true]
          # [true,  true,  true, false, true, true,  true,  true]
          # [true,  true,  true, true,  true, true,  true,  true]
          # [true,  true,  true, false, true, false, true,  true]
          # [true,  true,  true, true,  true, true,  false, true]
          # [true,  true,  true, true,  true, true,  false, false]
          for batch, eod_pos in zip(*eod_positions):
              eod_plus_one = eod_pos.item() + 1
              dec_attn_mask_3d[batch][
                  eod_plus_one:, :eod_plus_one
              ] = True
      dec_attn_mask_3d = dec_attn_mask_3d[:, None, :, :]
      return dec_attn_mask_3d
  
imports: import torch
  import torch.nn.functional
  from einops import rearrange, repeat
  from nemo.collections.nlp.modules.common.megatron.module import MegatronModule
  from nemo.collections.nlp.modules.common.megatron.position_embedding import RotaryEmbedding
  from nemo.collections.nlp.modules.common.megatron.transformer import ParallelTransformer
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults, build_attention_mask_3d
label_desc: Use image node_id 3 for calling the MegatronRetrievalTransformerDecoderModule obj's underlying member method code with example usage: obj._calculate_dec_att_mask(dec_attn_mask, eod_positions) and returns: dec_attn_mask_3d